Skip to content

How can I publish from lambda to SNS?

0

The lambda has AmazonSNSFullAccess, the outbound rules for the lambda are allowed and the lambda is in a public subnet with an internet gateway. I want to publish from a lambda to an SNS topic but it always times out. What could be the problem?

1 Answer
2
Accepted Answer

Hello.

If you just want to send messages from Lambda to SNS, there is no need to connect to VPC.
If you have a requirement to connect Lambda to a VPC, please use NAT Gateway or set up a VPC endpoint for SNS.
Even if Lambda is placed in a public subnet, a public IP address is not attached, so a NAT Gateway or VPC endpoint is required to access AWS services.
https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc-internet.html
https://docs.aws.amazon.com/sns/latest/dg/sns-vpc-tutorial.html

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • You should attach your function to a private subnet, not a public one. You should also use the SNS VPC Endpoint to access the SNS service.

  • What seems a bit strange to me is that I tried pushing from Lambda in VPC with same config into SQS and it worked fine so I thought that it should work with SNS. Do SNS and SQS behave differently in this manner?

  • I can't say for sure without looking at your VPC settings in detail, but I think you have a VPC endpoint configured for SQS. If Lambda is connected to a VPC, outbound communication from Lambda will go through the VPC. Therefore, if there is no NAT Gateway or VPC endpoint in the VPC, you will not be able to access AWS services from Lambda.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.