Is it possible to get a SQS subscription's ARN using CDK?

0

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?

1 Answer
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:

  1. Does the API provide it? Looking at the sns subscribe api call, it doesn't return the arn.
  2. 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."

AWS
Mike_O
answered 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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions