Mehran
Mehran

Reputation: 1304

AWS - Send Message to an SQS from a Lambda function inside a VPC

I have hosted a Lambda function using AWS Chalice inside a VPC since I want it to access a Serverless Aurora DB Instance. Now I also want this function to send_message() to an SQS.

I followed Tutorial: Sending a Message to an Amazon SQS Queue from Amazon Virtual Private Cloud and was able to call the SQS from inside my EC2. But even then I could not use my Lambda function to call the SQS.

It would be very helpful if someone could actually tell me how to do the whole thing manually rather than using the CloudFormation stack, or at least tell me how to get the SQS Endpoint working.

Upvotes: 3

Views: 3482

Answers (2)

John Rotenstein
John Rotenstein

Reputation: 269081

It appears that your situation is:

  • An Amazon VPC with an Amazon Aurora database
  • An AWS Lambda function that wants to communicate with the Aurora database AND an Amazon SQS queue

An AWS Lambda function can be configured as:

  • Connected to a subnet in a VPC, or
  • Not connected to a VPC, which means it is connected to the Internet

If you wish to have an AWS Lambda function communicate with resources inside a VPC AND the Internet, then you will need:

  • The Lambda function connected to a private subnet
  • A NAT Gateway in a public subnet
  • An Internet Gateway connected to the public subnet (it is most probably already in your VPC)

Alternatively, you can use a VPC Endpoint for SQS, which allows the Lambda function to access SQS without going to the Internet. If you are wanting to connect to multiple service (eg S3, SNS, SQS), it is probably easier just to use a NAT Gateway rather than creating VPC Endpoints for each service.

Upvotes: 2

Mark B
Mark B

Reputation: 200411

You either need to add a VPC Endpoint for SQS to your VPC, or place the Lambda function in subnets with a route to a NAT Gateway.

Upvotes: 0

Related Questions