A developer is deploying an AWS Lambda function that processes user sessions. The function must retrieve user profile data from an Amazon ElastiCache for Redis cluster located in a private subnet of a custom VPC. Additionally, the Lambda function needs to call the public AWS Secrets Manager API to retrieve database credentials. The developer configures the Lambda function's VPC settings with the private subnets and the security group of the VPC. During testing, the Lambda function successfully queries ElastiCache but times out when trying to call Secrets Manager. There are currently no VPC endpoints configured in the VPC.
How should the developer configure the VPC and Lambda settings to resolve this timeout issue?
- Create an interface VPC endpoint for Secrets Manager within the private subnets, or configure a NAT Gateway in a public subnet and route outbound traffic from the private subnets through the NAT Gateway.Cevap
- BConfigure the Lambda function to run in the public subnets of the VPC and ensure the VPC has an attached Internet Gateway to allow direct outbound communication to the Secrets Manager endpoint.
- CAssign a public IP address to the Lambda function by enabling the auto-assign public IP setting on the Elastic Network Interfaces (ENIs) created by the Lambda service in the private subnets.
- DUpdate the Lambda function's IAM execution role to include Secrets Manager as a trusted entity in the trust policy and grant the secretsmanager:GetSecretValue permission.
Cevap
Create an interface VPC endpoint for Secrets Manager within the private subnets, or configure a NAT Gateway in a public subnet and route outbound traffic from the private subnets through the NAT Gateway.
The correct answer states that the developer should create an interface VPC endpoint or configure a NAT Gateway. This is correct because the network timeout indicates the Lambda function running inside a private subnet does not have a network path to the public Secrets Manager endpoint. An interface VPC endpoint creates private network interfaces inside the private subnets for Secrets Manager. Alternatively, routing the private subnets' outbound traffic to a NAT Gateway located in a public subnet provides internet access to reach the public endpoint.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda VPC networking and private endpoints