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."
The Subscribe API call does return the subscription ARN though. From https://docs.aws.amazon.com/sns/latest/api/API_Subscribe.html:
The following element is returned by the service.
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.
CloudFormation Nonsense: Seven (7) SNS Subscriptions created for SQS Queues by a Template
SQS not receiving SNS messageasked 3 years ago
SES Status Notification with SQS FIFO Queueasked a month ago
Is it possible to get a SQS subscription's ARN using CDK?asked 4 months ago
is it possible that SQS Triggers to a Lambda Function Alias?Accepted Answer
How to use SNS or SQS on Unreal with FlexMatchasked 2 years ago
SNS to Lambda vs SNS to SQS to LambdaAccepted Answerasked 6 months ago
Publish to SNS topic using curlasked 3 years ago
While trying to create an SNS subscription, after choosing a topic, all protocols except SQS disappearasked 23 days ago
General AWS SNS subscription to GovCloud SQS - ARN Validation Failsasked 2 years ago