Aws-sdk-php: Method for Retrieving SQS Queue URL from ARN

Created on 27 Dec 2016  路  9Comments  路  Source: aws/aws-sdk-php

The SQSClient provides the method getQueueUrl which creates a URL given the Queue's name. However, there is no similar method available to construct the Queue's URL from its ARN, which happens to be returned by other methods such as listSubscriptionsByTopic in the SNSClient.

You can, of course, generate a Queue URL from its ARN manually, but how reliable and future proof is that if it's not part of the SDK itself?

Most helpful comment

Thank you for posting this question. Most of the AWS APIs are very consistent in how you address entities, but SQS is very weak in this regard. The various API methods accept and return either ARNs, queue names or queue URLs seemingly in a random pattern that makes them very difficult to deal with. Eventually I created a data structure within my application that allows me efficiently convert between these three identifiers.
If someone from the SQS team is reading this, please sort out this mess. Thanks.

All 9 comments

@anthonybarsotti Thank you for the feedback and thoughts!

You are correct that, The getQueueUrl method only accepts Queue's name and will return the queue URL. Also listSubscriptionsByTopic can be used to get url when an arn is passed.

Can you please elaborate on how are you generating the arn manually & also is there a specific reason you need to generate the url using arn as there are other ways like you mentioned of getting the QueueUrl?

Can you elaborate on how to get the URL from listSubscriptionsByTopic? Currently that method is providing the SQS ARN as the endpoint property of the return value for that function, not the URL.

@anthonybarsotti Thanks for the reply.

Using method listSubscriptionsByTopic you can get the the subscription's endpoint. It is detailed in our API docs.

To help me better understand your problem, please elaborate which URL you want to get and also it will be helpful to know the reason are you trying to get this.

Thanks.

Caveat. I'n not using this project but I'm interested in the answer to OP question. I am using the SDK for another language, but I'm using the ARN for some technologies (SNS) but the URL for this one (SQS). Since we are trying to generalize and avoid confusion, we are trying to just use ARNs everywhere in our configs. Is there a future proof method for converting the ARN to a URL, or is it subject to change?

@dbrownxc SQS's developer guide cautions that you should not create a queue URL on your own, as the format is not guaranteed to remain stable forever. The queue ARN contains the region, AWS account ID, and queue name, which can be used to call the GetQueueUrl operation.

Perfect, thanks!

Looks like questions have been answered or lacking information for ages, closing, yet feel free to reopen with further contents :)

Thank you for posting this question. Most of the AWS APIs are very consistent in how you address entities, but SQS is very weak in this regard. The various API methods accept and return either ARNs, queue names or queue URLs seemingly in a random pattern that makes them very difficult to deal with. Eventually I created a data structure within my application that allows me efficiently convert between these three identifiers.
If someone from the SQS team is reading this, please sort out this mess. Thanks.

I'd also add that using the boto3.client("resourcegroupstaggingapi") one really only gets queue arns returned from the API, meaning one has to do expensive additional API-calls and not-delightful string-operations to get the queueName and then the QueueURL.

Having another API endpoint for SQS that took arns would be enormously valuable here from a performance perspective...

Was this page helpful?
0 / 5 - 0 ratings