Skip to content

Lambda with VPC for ECR access

0

Hi! I have a simple but important question. I have a lambda with a VPC attached without internet access. The lambda is also created with an ECR as code source. My question is, if I create this lambda with the vpc, will the lambda lose connection to ECR repos and internet?

Thanks for the help.

1 Answer
1
Accepted Answer

Yes, when you attach a Lambda function to a VPC without internet access, it will lose connection to both ECR repositories and the internet in general. By default, Lambda functions have access to the public internet, but when you attach a function to a VPC, it can only access resources available within that VPC.

For your Lambda function to continue accessing ECR repositories while being connected to a VPC, you would need to implement one of these solutions:

  1. Configure your VPC to have internet access by setting up a NAT Gateway in a public subnet and configuring the route table of your private subnet to route internet-bound traffic through the NAT Gateway.

  2. Create VPC endpoints for the AWS services you need to access, including ECR. This allows your Lambda function to privately access these services without traversing the public internet.

It's important to note that Lambda functions don't actually run in your VPC - they run in the Lambda service VPC. When you configure a Lambda for VPC access, AWS creates an Elastic Network Interface (ENI) in your VPC and routes all the Lambda's network traffic via that ENI. This is why the function loses direct internet access when attached to a VPC without proper internet connectivity configuration.
Sources
Giving Lambda functions access to resources in an Amazon VPC - AWS Lambda
Connecting Lambda inside a VPC to resources outside a VPC | AWS re:Post
About API Gateway Websocket and Lambda Invoke in VPC | AWS re:Post

answered a year ago

EXPERT

reviewed 10 months ago

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.