-
Notifications
You must be signed in to change notification settings - Fork 4k
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-subscriptions): enable cross region subscriptions to sqs and lambda #17273
Conversation
lambda fixing cross region subscriptions to SQS and Lambda. This PR handles a couple different scenarios. This only applies to SNS topics that are instanceof sns.Topic, it does not apply to imported topics (sns.ITopic). The current behavior for imported topics will remain the same. 1. SNS Topic and subscriber (sqs or lambda) are created in separate stacks with explicit environment. In this case if the `region` is different between the two stacks then the topic region will be provided in the subscription. 2. SNS Topic and subscriber (sqs or lambda) are created in separate stacks, and _both_ are env agnostic (no explicit region is provided) In this case a region is not specified in the subscription resource, which means it is assumed that they are both created in the same region. The alternatives are to either throw an error telling the user to specify a region, or to create a CfnOutput with the topic region. Since it should be a rare occurrence for a user to be deploying a CDK app with multiple env agnostic stacks that are meant for different environments, I think the best option is to assume same region. 3. SNS Topic and subscriber (sqs or lambda) are created in separate stacks, and _one_ of them are env agnostic (no explicit region is provided) In this case if the SNS stack has an explicit environment then we will provide that in the subscription resource (assume that it is cross region). If the SNS stack is env agnostic then we will do nothing (assume they are created in the same region). fixes #7044,#13707
@@ -36,6 +36,12 @@ export class LambdaSubscription implements sns.ITopicSubscription { | |||
principal: new iam.ServicePrincipal('sns.amazonaws.com'), | |||
}); | |||
|
|||
// if the topic and function are created in different stacks | |||
// then we need to make sure the topic is created first | |||
if (topic.stack !== this.fn.stack) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible this topic is an imported (ITopic
)? If so, is this necessary?
My spidey sense tingles hard whenever we add a dependency like this; I feel like these types of aides lead to circular dependency bugs that aren't obvious and don't come to light until the next release. Just want to limit the blast radius to as small a use case as possible.
(Same question for the changes to sqs.ts
, obviously.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I could add a type check here as well. I did run into issues when testing this if the dependency is not explicit, the deployment would fail because the function (or sqs) stack was getting created before the topic stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…lambda (aws#17273) fixing cross region subscriptions to SQS and Lambda. This PR handles a couple different scenarios. This only applies to SNS topics that are instanceof sns.Topic, it does not apply to imported topics (sns.ITopic). The current behavior for imported topics will remain the same. 1. SNS Topic and subscriber (sqs or lambda) are created in separate stacks with explicit environment. In this case if the `region` is different between the two stacks then the topic region will be provided in the subscription. 2. SNS Topic and subscriber (sqs or lambda) are created in separate stacks, and _both_ are env agnostic (no explicit region is provided) In this case a region is not specified in the subscription resource, which means it is assumed that they are both created in the same region. The alternatives are to either throw an error telling the user to specify a region, or to create a CfnOutput with the topic region. Since it should be a rare occurrence for a user to be deploying a CDK app with multiple env agnostic stacks that are meant for different environments, I think the best option is to assume same region. 3. SNS Topic and subscriber (sqs or lambda) are created in separate stacks, and _one_ of them are env agnostic (no explicit region is provided) In this case if the SNS stack has an explicit environment then we will provide that in the subscription resource (assume that it is cross region). If the SNS stack is env agnostic then we will do nothing (assume they are created in the same region). fixes aws#7044,aws#13707 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
fixing cross region subscriptions to SQS and Lambda. This PR handles a
couple different scenarios. This only applies to SNS topics that are
instanceof sns.Topic, it does not apply to imported topics (sns.ITopic).
The current behavior for imported topics will remain the same.
stacks with explicit environment.
In this case if the
region
is different between the two stacks thenthe topic region will be provided in the subscription.
stacks, and both are env agnostic (no explicit region is provided)
In this case a region is not specified in the subscription resource,
which means it is assumed that they are both created in the same region.
The alternatives are to either throw an error telling the user to
specify a region, or to create a CfnOutput with the topic region. Since
it should be a rare occurrence for a user to be deploying a CDK app with
multiple env agnostic stacks that are meant for different environments,
I think the best option is to assume same region.
stacks, and one of them are env agnostic (no explicit region is provided)
In this case if the SNS stack has an explicit environment then we will
provide that in the subscription resource (assume that it is cross
region). If the SNS stack is env agnostic then we will do nothing
(assume they are created in the same region).
fixes #7044,#13707
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license