I've been following the following blog post from Amazon (Scenario 3: Triggering a Lambda function from an Amazon S3 bucket notification in another account) about authorizing Lambda functions for various uses. I would like to setup a Lambda function to accept SNS messages from external accounts (external to the acct with the lambda function).
https://aws.amazon.com/blogs/compute/easy-authorization-of-aws-lambda-functions/
I was expecting to add the permission to invoke the function remotely as follows:
$ aws lambda add-permission \
--function-name MyFunction \
--region us-west-2 \
--statement-id Id-123 \
--action "lambda:InvokeFunction" \
--principal sns.amazonaws.com \
--source-arn arn:aws:sns:::<topic name> \
--source-account <account number> \
--profile adminuser
I then attempted to go to my SNS topic and set Lambda as the endpoint, and type in the remote ARN for the lambda function in the first account. This doesn't work so well, as the endpoint expects an arn for a function in the account...
Plan B: Try creating the subscription via the CLI to circumvent the limitation in the console...
aws sns --profile adminuser \
--region us-west-2 subscribe
--topic-arn arn:aws:sns:us-west-2:<account #>:<topic name>
--protocol lambda
--notification-endpoint arn:aws:lambda:us-west-2:<account id>:function:<lambda function name>
Response:A client error (AuthorizationError) occurred when calling the Subscribe operation: The account <account id> is not the owner of the lambda function arn:aws:lambda:us-west-2:<account id>:function:<function name>
Has anyone been able to invoke a Lambda Function from a "remote" SNS in another account? I'm a little stumped as to where I may have gone wrong... Based on the note in the blog post, I fully expected a remote SNS to work:Note: Amazon SNS (Simple Notification Service) events sent to Lambda works the same way, with “sns.amazonaws.com” replacing “s3.amazonaws.com” as the principal.