Invoking lambda attached to private subnets outside VPC

0

is it possible to invoke lambda attached to private subnets (having a NAT Gateway) from another lambda in the same account?

2 Answers
2

Of course. When a function is attached to a VPC it means that all its OUTBOUND traffic, the traffic initiated by the function, is routed via the ENI in the VPC. Regardless if you attach the function to a VPC or not, the only way to invoke a function is using the public Lambda Invoke API (either directly, like in your case from another function, or indirectly, by another service such as API Gateway or SQS).

profile pictureAWS
EXPERT
Uri
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
  • When attaching a lambda to a VPC, I thought it's assigned a private ip so that traffic can be private? And in case that lambda needs access to a private db how it's accessed?

  • Yes, when a Lambda function is attached to a VPC, it is assigned a private IP address within that VPC, allowing it to interact privately with other resources in the same VPC, including private databases. The Lambda function can access a private database directly using the VPC's internal networking, without the need for the traffic to go through the public internet.

  • Thank you for your answer. if vpc-attached lambda functions can interact with other resources in the vpc privately, why two lambdas in the same vpc cannot interact privately? I'm asking this because of this "regardless if you attach the function to a VPC or not, the only way to invoke a function is using the PUBLIC Lambda Invoke API"

1
Accepted Answer

For lambda A to be able to invoke lambda B function, lambda A needs to have access to the Lambda service endpoint, regardless if lambda B function runs in a VPC or not.

If Lambda A runs in your VPC it would need to access the Lambda service endpoint either through the internet (e.g., by using a NAT gateway) or using a VPC endpoint.

If Lambda A doesn't run in your VPC then it runs in an AWS managed VPC which has internet connection and therefore will be able to invoke lambda B (assuming the right permissions are in place of course).

Your misconception here is that when you invoke a lambda function you call that function directly. but the way it works is that you are actually calling the Lambda service endpoint.

AWS
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • Lambda(compute resources - firecracker VMs) always runs in AWS managed VPC irrespective of any configuration. When you configure your Lambda to run in your VPC, Lambda being a managed service of AWS just creates hyperplane ENIs inside your VPC unique per security group:subnet combination. This ENI is used for Lambda service to communicate with resources running privately inside your private subnet of your VPC.

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.

Guidelines for Answering Questions