Not able to access internet inside Default AWS VPC from Lambda

Viewed 552

Hi I am developing a AWS serverless application, default VPC which has subnets attached with internet gateway. I have configured my lambda function inside default VPC. I am expecting the lambda to have internet connection to it as the subnets are attached with internet gateway. But unfortunately lambda function doesn't have internet access. Can someone help in access internet from lambda in this scenario

2 Answers

In default VPC all subnets are public. This means that even if you have NAT, your lambda will not work. To make it work you have to create a private subnet in your default VPC, setup it route tables to the NAT located in a public subnet, and then place your function in the private subnet.

You can give your VPC Lambda access to connect to the internet using either VPC end points or a NAT gateway like you have setup and is also described here (https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/). However this gives your Lambda access to the internet, it does not work in the other direction ie. give the Lambda access to from the internet side to to your Lambda. For that you need to use an API Gateway that fronts it etc.

Related