Is it possible to get a SQS subscription's ARN using CDK?
I'm using CDK to setup an SNS topic and configure a subscription to an SQS queue. However I've noticed that the addSubscription
method of the Topic
class is void
and as such does not return anything after the subscription is added.
Is there a way to get the subscription ARN using the CDK constructs as I'd like to output the subscription ARN as a CloudFormation output?
There is no direct way via CDK to get the subscription ARN. Neither CfnTopic nor CfnSubscription return the subscription ARN or provide a way to retrieve it.
A helpful way to determine whether a value is available in CDK is this:
- Does the API provide it? Looking at the sns subscribe api call, it doesn't return the arn.
- Does CloudFormation's AWS::SNS::Subscription provide it? Looking at the doc, there are no attributes on this resource type.
This is a good indicator that CDK doesn't support it either, which we see in the CfnTopic and CfnSubscription docs.
You could use the list-subscriptions api in your CDK code to find the arn and store it in a CfnOutput.
An alternate approach you could take is to use a lambda-backed custom resource to create the subscription, use the list-subscriptions API to find the arn for the new subscription, and return the arn. But this seems like the "long way around the barn."
Relevant questions
CloudFormation Nonsense: Seven (7) SNS Subscriptions created for SQS Queues by a Template
asked 5 months agoSQS not receiving SNS message
asked 3 years agoSES Status Notification with SQS FIFO Queue
asked a month agoIs it possible to get a SQS subscription's ARN using CDK?
asked 4 months agois it possible that SQS Triggers to a Lambda Function Alias?
Accepted Answerasked 5 months agoHow to use SNS or SQS on Unreal with FlexMatch
asked 2 years agoSNS to Lambda vs SNS to SQS to Lambda
Accepted Answerasked 6 months agoPublish to SNS topic using curl
asked 3 years agoWhile trying to create an SNS subscription, after choosing a topic, all protocols except SQS disappear
asked 23 days agoGeneral AWS SNS subscription to GovCloud SQS - ARN Validation Fails
asked 2 years ago
The Subscribe API call does return the subscription ARN though. From https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html:
Response Elements
The following element is returned by the service.
SubscriptionArn
The ARN of the subscription if it is confirmed, or the string "pending confirmation" if the subscription requires confirmation. However, if the API request parameter ReturnSubscriptionArn is true, then the value is always the subscription ARN, even if the subscription requires confirmation.
Type: String