-
Notifications
You must be signed in to change notification settings - Fork 15
Get SQS Queue URL from ARN #15
Comments
We've initiated a request with the Lambda team to have the SQS Queue URL included with that event source (rather than needing it to be constructed from the ARN). |
Just add a little more information to @srchase reply. The SDKs currently don't have enough information on how the URL is constructed or whether they are generated in the same way across all the regions. It would be more reliable to have the URL in the Lambda event. |
That would be great! I'm currently managing multiple queues, this would be very helpful in deleting the messages |
Same situation here, multiple queues with Lambda trigger. Would be great to have the queue url on lambda event |
Hey, I was able to overcome the missing Queue URL with the following code in my NodeJS Function: var accountId = incomingRecord.eventSourceARN.split(":")[4];
var queueName = incomingRecord.eventSourceARN.split(":")[5];
var queueUrl = sqs.endpoint.href + accountId + '/' + queueName;
console.log( 'deleting from ' + queueUrl );
var params = {
QueueUrl: queueUrl, /* required */
ReceiptHandle: incomingRecord.receiptHandle /* required */
}; It's still a little "hacky" but it works, and means I don't need to specify the Queue URL in the function or any variables. |
Here is an example how you can get SQS queue URL by name using AWS CLI.
If you need to use environment variable then please use this sample
|
@srchase @AllanFly120 Is the request to the lambda team publicly visible? Do you know if it has been actioned yet? |
The viable alternative would be to allow users to specify SQS ARN instead of queue url in the SDK API // current code
sqsClient.deleteMessage { it.queueUrl(queueUrl).receiptHandle(receipt) }
// proposal
sqsClient.deleteMessage { it.queueArn(queueArn).receiptHandle(receipt) } In fact SNS client already works this way: snsClient.publish { it.topicArn(topicArn).message(message) } |
Any update on this? |
Needs to be done by the service team, I can reach out to them for their progress. |
@mkulak is correct. Other aws services seem to offer this flexibility. The ARN is all that is included in a message coming from a queue, and it seems pretty hacky to have to fiddle with the strings in order to poll the queue or send a message. |
Would also like to see this become more flexible. I have a simple API runner lambda that pulls request configs off multiple queues but I may need to update the message on failure so hardcoding the URL is not an option. Currently using the above "hack" from @tgxn to compose the URL. |
@ajredniwja, @srchase any chance there's an update on this? |
@ajredniwja @srchase It's been quite a while since the last update, do you know if and when we can expect this new field to be available? |
If you're provisioning via SAM template (or CloudFormation) you can just reference it in your template.yaml and pass in to lambda as an environment variable like this:
It is then available in process.env as:
|
Get SQS URL from eventSourceARN using Python function:
|
What's the reason behind the design decision of using queue url instead of queue ARN for a lot of the SQS commands anyway? |
Running into the converse while trying to subscribe an SQS queue to an SNS topic. I'm using the 2.x SDK (Java). I've got the queue URL from creating it with a CreateQueueRequest. However, the SNS SubscribeRequest builder needs the queue ARN for its endpoint. Is there example code of using SNS over SQS, preferably in Java and using the 2.x SDK (or some equally good library)? That might show a workaround for this problem. |
GetQueueAttributes.QueueArn
…On Wed, 20 Apr 2022, 00:23 Leif Bennett, ***@***.***> wrote:
Running into the converse while trying to subscribe an SQS queue to an SNS
topic. I'm using the 2.x SDK (Java). I've got the queue URL from creating
it with a CreateQueueRequest. However, the SNS SubscribeRequest builder
needs the queue ARN for its endpoint.
Is there example code of using SNS over SQS, preferably in Java and using
the 2.x SDK (or some equally good library)? That might show a workaround
for this problem.
—
Reply to this email directly, view it on GitHub
<#15 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEGPCWQVI66TGX3SCAKORB3VF457LANCNFSM4TNILE2Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
@leifbennett for any standard serverless patterns check: https://serverlessland.com/patterns (the patterns & videos are awesome) That sounds like a basic SNS -> SQS fan-out pattern you are describing there will probably be an official example as IaC (Infrastructure as Code) that you can simply deploy from the above website, or here is one I wrote recently in AWS SAM (as you can see it expects your index.js file to be in /dist folder with an exports.handler function - written for nodeJs - there will be Java examples in the patterns repo)
|
https://gist.github.com/MrSinisterX/5ed2ef3089e3be25430b932d88774f5f I faced the same issue and implemented this ugly but working solution. |
JavaScript version for anyone that might need it: // FIXME: https://github.com/aws/aws-sdk/issues/15
function sqsQueueUrlFromArn (arn) {
const parts = arn.split(':')
const service = parts[2]
const region = parts[3]
const accountId = parts[4]
const queueName = parts[5]
return `https://${service}.${region}.amazonaws.com/${accountId}/${queueName}`
} @srchase have you heard anything back from the Lambda team? |
@srchase it's been almost 5 years! People have been asking for updates for 2 years. Any news? |
To whoever is insterested. I created this helper function that takes two parameters, the account ID & the queue ARN if you have them in hand & this generates the queue URL. I use this for integration testing purposes
Here is an example of how I use it in my tests
|
P87037653 |
Thank you for your feedback. We've let the responsible internal team know and they've placed this on their backlog. We can't share specific timelines on when this might be implemented in GitHub; you should monitor the AWS News Blog for updates. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
It appears that an SQS ARN has all of the information needed to construct a queue URL. A function to do this mapping without having to make an API call would be useful.
Usecase Example:
I can create create a pull request if this idea is deemed valuable.
The text was updated successfully, but these errors were encountered: