1
votes

I am trying to create a lambda function which can be invoked from SNS Topic events in the different region. My lambda is in EU-WEST-1 and the SNS Topic to be subscribed to is in EU-CENTRAL-1.

I am using the Serverless framework to deploy lambda. If I try to subscribe to a topic in the same region, it works successfully. But when I try to subscribe to a topic in a different region, I am getting error "Invalid parameter - TopicArn".

If I go to AWS console, I can successfully add a trigger to lambda to invoke from SNS in a different region.

I also tried running a NodeJS script to add cross-region SNS-lambda subscription. I am getting same "Invalid parameter - TopicArn" error from sns.Subscribe() method.

Is there a way to programmatically or via cloud formation subscribe lambda to SNS topic in a different region?

2
I'm just curious. Why are the Lambda function and SNS topic on different regions?Noel Llevares
We have enabled sns failover which, which publishes messages to another region in case of failover. We want to be able to process those.Tushar Kesare
You should use SQS if you need guaranteed delivery. Using another SNS as failover for SNS does not give you 100% guarantee.Noel Llevares
You may need to add SNS permission (so that SNS can invoke the Lambda function).krishna_mee2004

2 Answers

2
votes

By default your SNS client is pointing to EU-CENTRAL-1. Try set setRegion on snsClient like this,

snsClient.setRegion(Region.getRegion(Regions.EU-WEST-1));
0
votes

Yes it is possible to subscribe lambda to SNS topic in a different region. Use the "Region" parameter.

In CloudFormation (json) that would be:

"LambdaAmazonIpSpaceChangedSubscription" : {
  "Type" : "AWS::SNS::Subscription",
  "Properties" : {
    "Endpoint" : {"Fn::GetAtt" : ["LambdaFunction", "Arn"] },
    "Protocol" : "lambda",
    "TopicArn" : "arn:aws:sns:us-east-1:806199016981:AmazonIpSpaceChanged",
    "Region": "us-east-1"
  }
},