Skip to content

Shogan.tech

DevOps, automation, how-tos and more since 2008

  • About
  • Apps
    • Out of Office Changer for Exchange 2003
    • SkypeURLCollector – An easy way to collect information from Skype chats and send to Twitter.
    • Speed Maze, the game for iPhone / iPod Touch
    • Cosmosis – A 2D space shooter for iOS / iPhone / iPod Touch
    • vMetrics – Plugin for WordPress
    • Deep Space Skybox Pack
  • Contact

cross account

AWS SNS to Lambda Cross Account Setup

February 23, 2020 by Sean
AWS SNS to Lambda Cross Account Setup

You’ve got a SNS topic in Account A and you wish to subscribe a Lambda function to this topic in Account B.

Setting this up requires configuration on both account sides with resource-based permission policies being applied to SNS in one account and Lambda in the other.

In other words, you’ll need to setup the permissions for SNS and Lambda to allow both subscription and invocation.

Getting Started

You should already have your SNS topic in Account A and a suitable Lambda function subscriber in Account B. For example:

  • Account A Id: 5556667778 (SNS topic lives here)
  • Account B Id: 12345678901 (Lambda function lives here)

Configure SNS topic in Account A to allow Subscriptions from Account B

Use the AWS CLI to add a resource-based permission policy to the SNS topic (using it’s ARN). This will allow the Receive and Subscribe actions from Account B.

aws sns add-permission \
    --topic-arn "arn:aws:sns:us-east-1:5556667778:cross-account-topic" \
    --label "AllowSubscriptionFromAccountB" \
    --aws-account-id "12345678901" \
    --action-name "Receive" "Subscribe"

Configure the Lambda function in Account B to allow invocation from the SNS topic in Account A

Next, add a resource-based permission policy to your Lambda function in Account B. This policy will effectively allow the specific SNS topic in Account A to invoke the Lambda function.

It’s always good practice to follow the principle of least privilege (POLP). In this case you’re only allowing the specific SNS topic in one account to invoke the specific Lambda function you’re adding the policy to.

aws lambda add-permission \
    --function-name "cross-account-lambda-subscriber" \
    --statement-id "AllowInvokeFromExampleSns" \
    --principal "sns.amazonaws.com" \
    --action "lambda:InvokeFunction" \
    --source-arn "arn:aws:sns:us-east-1:5556667778:cross-account-topic"

Subscribe the Lambda function in Account B to the SNS topic in Account A

Of course you’ll need to actually subscribe the Lambda function to the SNS topic. From Account B (where your Lambda function is setup), run the following command to subscribe it to the SNS topic in Account A.

aws sns subscribe \
    --topic-arn "arn:aws:sns:us-east-1:5556667778:cross-account-topic" \
    --protocol "lambda" \
    --notification-endpoint "arn:aws:lambda:us-east-1:12345678901:function:cross-account-lambda-subscriber"

Concluding

Send a test message to your SNS topic and you should see the Lambda function process the message in the other account.

If you need to diagnose anything, remember to check Lambda CloudWatch monitoring logs, or use the SNS Delivery Status feature.

That’s all there is to setting up SNS to Lambda cross account permissions.

Categories AWS, Cloud, Devops Tags AWS, cross account, IAM, lambda, sns, subscription 7 Comments

Blogroll

  • Game Dev Assets
  • Hobbyist Coder
  • Trail Running for Life

Support me

Get $100 in credit over 60 days, and I'll receive $25 credit on DigitalOcean if you sign up by clicking below.

DigitalOcean Referral Badge

Categories

  • 3D Printing (2)
  • Anti-Virus (1)
  • apple (4)
  • ARM (1)
  • Automation (5)
  • Aviation (1)
  • AWS (13)
  • Azure (2)
  • Blackberry (1)
  • Builds (19)
  • Cloud (9)
  • Containers (2)
  • Creative (4)
  • Development (21)
  • Devops (30)
  • Diary (2)
  • Docker (2)
  • EUC (1)
  • Exchange Server (8)
  • Gaming (6)
  • Guest posts (1)
  • Home labs (12)
  • How-tos (107)
  • Kubernetes (22)
  • Life (2)
  • Linux / uBuntu (10)
  • Microsoft (19)
  • Networking (4)
  • PowerCLI (34)
  • Powershell (14)
  • Programming / VB (2)
  • Raspberry Pi (2)
  • Retro (5)
  • Reviews (6)
  • SBS 2008 (2)
  • Serverless (1)
  • SQL Server (4)
  • Storage (4)
  • Terraform (1)
  • The diary of Shogan (22)
  • Uncategorized (2)
  • Virtualization (56)
  • VMware (119)
  • Windows Server (9)
  • Windows Server 2008 (9)
  • Youtube / videos (4)

Archives

Recent Posts

  • AWS Control Tower Enrollment Gotchas October 25, 2023
  • DTrace/dtruss – an alternative to strace on macOS April 20, 2023
  • Stand Reminder App – Remember to Stand November 19, 2022
  • S3 Object Querying with JMESPath October 17, 2022
  • Vim Cheatsheet October 3, 2022
© 2025 Shogan.tech • Built with GeneratePress