Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let AWS lambda in a VPC to publish SNS notification?

Tags:

I have a lambda function that accesses my Postgres db in RDS via VPC. After it queries the db, I want to post a notification to SNS. Because my lambda function exists in my VPC, it cannot access SNS. I have an internet gateway on my VPC. I read through the VPC endpoint documentation and currently only s3 is supported.

Is there anyway to publish to SNS in a lambda function in a VPC?

like image 285
lawrence Avatar asked Mar 14 '16 22:03

lawrence


People also ask

How do I allow Lambda to publish SNS?

In order to grant a Lambda function access to an SNS topic, we have to attach an IAM policy to the function's execution role. The policy should grant permissions for all the Actions the function needs to perform on the topic.

Can SNS be inside a VPC?

You can create an Amazon SNS endpoint in your VPC using the AWS Management Console, the AWS CLI, an AWS SDK, the Amazon SNS API, or AWS CloudFormation. For information about creating and configuring an endpoint using the Amazon VPC console or the AWS CLI, see Creating an Interface Endpoint in the Amazon VPC User Guide.

Can you invoke a Lambda function using AWS SNS notification?

You can use a Lambda function to process Amazon Simple Notification Service (Amazon SNS) notifications. Amazon SNS supports Lambda functions as a target for messages sent to a topic. You can subscribe your function to topics in the same account or in other AWS accounts.

Can you invoke a Lambda in a VPC?

You can call any of the Lambda API operations from your VPC. For example, you can invoke the Lambda function by calling the Invoke API from within your VPC. For the full list of Lambda APIs, see Actions in the Lambda API reference.


Video Answer


2 Answers

UPDATE

As of April 2018, SNS supports VPC Endpoints via AWS PrivateLink. So, there will be no need to set up an Internet Gateway or a NAT instance in order for a Lambda function inside your VPC to publish SNS notifications.

See this blog post for more details.

like image 62
Khalid T. Avatar answered Sep 20 '22 12:09

Khalid T.


You will need a NAT server running in your VPC to route traffic outside of the VPC. AWS now offers a managed NAT service that makes this easier.

like image 26
garnaat Avatar answered Sep 23 '22 12:09

garnaat