1 Answer
- Newest
- Most votes
- Most comments
0
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."
answered 2 years ago
Relevant content
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 7 months 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