Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sns): race condition exists between sqs queue policy and sns subscription #21797

Merged
merged 12 commits into from
Oct 2, 2022

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
},
"SubscriberQueuenestedstackstestNestedStack1topic089C5EB1396F65087": {
"Type": "AWS::SNS::Subscription",
"DependsOn": "SubscriberQueuePolicy25A0799E",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
Expand All @@ -109,6 +110,7 @@
},
"SubscriberQueuenestedstackstestNestedStack1topic1150E1A929A2C267E": {
"Type": "AWS::SNS::Subscription",
"DependsOn": "SubscriberQueuePolicy25A0799E",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
Expand All @@ -127,6 +129,7 @@
},
"SubscriberQueuenestedstackstestNestedStack1topic209B8719858511914": {
"Type": "AWS::SNS::Subscription",
"DependsOn": "SubscriberQueuePolicy25A0799E",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
},
"MyQueueawscdkcodebuildeventsMyTopic550011DCF72DE3ED": {
"Type": "AWS::SNS::Subscription",
"DependsOn": "MyQueuePolicy6BBEDDAC",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
},
"MyQueueawscdksnseventtargetMyTopicB7575CD87304D383": {
"Type": "AWS::SNS::Subscription",
"DependsOn": "MyQueuePolicy6BBEDDAC",
"Properties": {
"Protocol": "sqs",
"TopicArn": {
Expand Down
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-sns-subscriptions/lib/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export class SqsSubscription implements sns.ITopicSubscription {

// add a statement to the queue resource policy which allows this topic
// to send messages to the queue.
this.queue.addToResourcePolicy(new iam.PolicyStatement({
const queuePolicyDependable = this.queue.addToResourcePolicy(new iam.PolicyStatement({
resources: [this.queue.queueArn],
actions: ['sqs:SendMessage'],
principals: [snsServicePrincipal],
conditions: {
ArnEquals: { 'aws:SourceArn': topic.topicArn },
},
}));
})).policyDependable;

// if the queue is encrypted, add a statement to the key resource policy
// which allows this topic to decrypt KMS keys
Expand Down Expand Up @@ -77,6 +77,7 @@ export class SqsSubscription implements sns.ITopicSubscription {
filterPolicy: this.props.filterPolicy,
region: this.regionFromArn(topic),
deadLetterQueue: this.props.deadLetterQueue,
subscriptionDependency: queuePolicyDependable,
};
}

Expand Down
Loading