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?

Jehan
已提问 2 个月前391 查看次数
2 回答
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
专家
Uri
已回答 2 个月前
profile picture
专家
已审核 1 个月前
profile picture
专家
已审核 2 个月前
  • 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
已接受的回答

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
已回答 2 个月前
profile picture
专家
已审核 2 个月前
  • 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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则