You can configure the redrive policy on an Amazon SNS subscription. If SNS cannot deliver the message after the number of attempts set in its delivery policy, SNS will send it to the dead-letter queue specified in the redrive policy.
import{Queue}from'@aws-cdk/aws-sqs';import{Topic}from'@aws-cdk/aws-sns';import{UrlSubscription}from'@aws-cdk-aws-sns-subscriptions';exportclassMyStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);// Dead letter queueconstmyDLQ=newQueue(scope,'MyDLQ',);// SNS TopicconstmyTopic=newTopic(scope,'MyTopic');// Adding an URL subscriptionmyTopic.addSubscription(newUrlSubscription('https://example.com',{// Configure the redrive policy for the subscriptiondeadLetterQueue:myDLQ,}));}}
1 2 3 4 5 6 7 8 9101112131415
{"Resources":{"MySubscription":{"Type":"AWS::SNS::Subscription","Properties":{"Protocol":"https","Endpoint":"https://example.com/""TopicArn":"my-topic-arn",// Configure the redrive policy for the subscription"RedrivePolicy":"{ \"deadLetterTargetArn\": \"arn:aws:sqs:us-east-2:123456789012:MyDeadLetterQueue\"}"}}}}
1 2 3 4 5 6 7 8 910111213
Resources:MySubscription:Type:AWS::SNS::SubscriptionProperties:Protocol:httpsEndpoint:https://example.com/TopicArn:"my-topic-arn"# Configure the redrive policy for the subscriptionRedrivePolicy:|{"deadLetterTargetArn": "arn:aws:sqs:us-east-2:123456789012:MyDeadLetterQueue"}
# For subscriptions to Lambda function endpointsfunctions:MyFunction:handler:hello.handlerevents:-sns:topicName:my-topic# Configure the redrive policy for the subscription to the Lambda functionredrivePolicy:deadLetterTargetArn:arn:aws:sqs:us-east-2:123456789012:MyDeadLetterQueue# For subscriptions to other types of endpointresources:Resources:MySubscription:Type:AWS::SNS::SubscriptionProperties:Protocol:httpsEndpoint:https://example.com/TopicArn:"my-topic-arn"# Configure the redrive policy for the subscription to another type of resourceRedrivePolicy:|{"deadLetterTargetArn": "arn:aws:sqs:us-east-2:123456789012:MyDeadLetterQueue"}
1 2 3 4 5 6 7 8 9101112
resource"aws_sns_topic_subscription""this"{endpoint="https://example.com/"protocol="https"topic_arn="my-topic-arn" # Configure the redrive policy for the subscriptionredrive_policy=<<EOF{ "deadLetterTargetArn": "arn:aws:sqs:us-east-2:123456789012:MyDeadLetterQueue"}EOF}