serverless: Cross region SNS trigger
This is a (Bug Report)
Description
When trying to deploy a lambda with an SNS trigger in a different region the cloudformation script fails.
- What went wrong?
Cloudformation fails to create SNS event subscription for lambda with error:
invalid parameter: TopicArn
- What did you expect should have happened?
Expected the lambda to deploy (via cloudformation) with a trigger on an SNS topic in a different region.
- What was the config you used?
service: testservice
provider:
name: aws
runtime: nodejs6.10
region: us-west-1
functions:
hello:
handler: handler.run
events:
- sns: arn:aws:sns:eu-west-1:xxxxxxxxxxx:stresstest
- What stacktrace or error message from your provider did you see?
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (2.41 MB)...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - stresser-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - HelloLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - HelloLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - HelloLogGroup
CloudFormation - CREATE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - HelloLambdaPermissionStresstestSNS
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - HelloLambdaVersionOVTh8yMAX1zsFvyQcL4UekM3pyWBiYTwE71y8M
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - HelloLambdaPermissionStresstestSNS
CloudFormation - CREATE_IN_PROGRESS - AWS::SNS::Subscription - HelloSnsSubscriptionStresstest
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - HelloLambdaVersionOVTh8yMAX1zsFvyQcL4UekM3pyWBiYTwE71y8M
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - HelloLambdaVersionOVTh8yMAX1zsFvyQcL4UekM3pyWBiYTwE71y8M
CloudFormation - CREATE_FAILED - AWS::SNS::Subscription - HelloSnsSubscriptionStresstest
CloudFormation - CREATE_FAILED - AWS::Lambda::Permission - HelloLambdaPermissionStresstestSNS
CloudFormation - UPDATE_ROLLBACK_IN_PROGRESS - AWS::CloudFormation::Stack - stresser-dev
CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - stresser-dev
CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Permission - HelloLambdaPermissionStresstestSNS
CloudFormation - DELETE_COMPLETE - AWS::SNS::Subscription - HelloSnsSubscriptionStresstest
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Version - HelloLambdaVersionOVTh8yMAX1zsFvyQcL4UekM3pyWBiYTwE71y8M
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Permission - HelloLambdaPermissionStresstestSNS
CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Function - HelloLambdaFunction
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - HelloLogGroup
CloudFormation - DELETE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - HelloLogGroup
CloudFormation - DELETE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - stresser-dev
Similar or dependent issues:
Additional Data
Your Environment Information -----------------------------
OS: darwin
Node Version: 7.10.0
Serverless Version: 1.14.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 13
- Comments: 30 (12 by maintainers)
This is now supported in cloudformation, however, you have to add target region within cfn. Example: ` SNSSampleSubscription: Type: AWS::SNS::Subscription
In above example, lambda is in us-east-2, and it is subscribing to an sns in us-east-1. The “Region” allows you to do that.
I have created a Gist showing how to implement the custom resource with SLS:
https://gist.github.com/jscattergood/00a2ea6a80fe41a74c5c7efed1b238b4
Hey all - sorry if this is just me being dense, but this took me a while to figure out and I want to add a couple clarifications in case they help out others who run into this issue.
My lambda functions are in us-east-2, but I wanted to use a SNS queue in us-east-1 as a trigger.
I originally tried this in my serverless.yml file, but I got the “invalid parameter: TopicArn” error (like the original poster).
I didn’t know enough about serverless or cloudformation to know what @Imran99 meant by SubNameFromGeneratedCfn, so it took a lot of head scratching and searching.
After staring at my .serverless/cloudformation-template-update-stack.json for a while (and several failed attempts), I finally sorted it out. By searching for my SNS’s ARN in .serverless/cloudformation-template-update-stack.json, I found that the SubNameFromGeneratedCfn Imran99 was referring to was HandleBounceOrComplaintEmailSNSSnsSubscriptionemailbouncescomplaints (in my template). By using that name under resources, I was able get it working! So these two components of my serverless.yml file are:
Bottom line: use Imran99’s workaround, but note you’ll need to search .serverless/cloudformation-template-update-stack.json to figure out SubNameFromGeneratedCfn. Thank you all for the workaround!
@dschep why was this issue closed? I do not see any messages from maintainers as to whether this issue will be addressed. There isn’t a pending PR either.
I was able to modify my
serverless.ymlwith theRegionparameter and I can see that the subscription is created successfully against the correct topic.serverless.yml
I also had to ensure that
serverless-psuedo-parametersdidn’t auto replace the region so just a heads up if you are using that:I have the same problem. I need to subscribe to an us-east-1 ARN for the AWS marketplace but my whole infrastructure runs in us-west-2
Whilst there is now a workaround available it would be great if there was first class support for this on the sns event in serverless.
@srg-avai Yes, you can subscribe cross-region like the FAQ says. However, you can not do it (or could not at the time that I wrote that post) via CloudFormation. Thus, I ended up having to make a custom resource that did the cross-region subscription, and using that custom CloudFormation resource rather than using the built-in CF SNS subscription resource. Obviously, that’s not an option for the SLS team (since we’d all have to deploy custom resources to use SLS), but maybe their connections / weight with AWS could get the issue noticed if someone on their team reported it to AWS.
@jthomerson Q: Do my AWS Lambda functions need to be in the same region as my Amazon SNS usage? You can subscribe your AWS Lambda functions to an Amazon SNS topic in any region. https://aws.amazon.com/sns/faqs/
We need this on our project. What are the next steps for follow up with AWS? I’m sure you guys can pull more strings than we can to get this worked out with CloudFormation
In Account1 we subscribe SNS in region us-west-1, it will fail with error “Error code: InvalidParameter - Error message: Invalid parameter: TopicArn”
We need to switch Account1 to region us-east-1 to do the subscription, it will success.
Try the longer form for the event
I’ll look into why the short form is not adding it.