An application developer is implementing a Lambda function that validates user sessions. The function must query a Redis cluster running in the private subnets of a custom VPC. At the same time, the function needs to send validation logs to an external analytics provider's HTTPS endpoint on the public internet. How should the developer configure the VPC network paths to allow the Lambda function to access both the private Redis cluster and the public HTTPS endpoint?
- AAssociate the Lambda function with the private subnets of the VPC. Do not provision a NAT Gateway, since Lambda functions run in a managed service environment and automatically route internet-bound API requests through the default AWS internet gateway.
- Place the Lambda function in the private subnets of the VPC. Create a NAT Gateway in a public subnet, and add a route in the private subnet route table that directs traffic to the NAT Gateway. Ensure the Redis security group allows inbound traffic from the Lambda function's security group.Answer
- CDeploy the Lambda function outside the VPC to maintain internet access. Store the Redis connection strings in AWS Systems Manager Parameter Store, and enable the Parameter Store native automatic rotation feature to securely rotate the Redis credentials without exposing them to the internet.
- DPlace the Lambda function in the private subnets of the VPC. Modify the Lambda execution role's trust policy to trust the VPC's Elastic Network Interface (ENI), allowing it to bypass security groups and route traffic directly to the external HTTPS endpoint.
Answer
Place the Lambda function in the private subnets of the VPC. Create a NAT Gateway in a public subnet, and add a route in the private subnet route table that directs traffic to the NAT Gateway. Ensure the Redis security group allows inbound traffic from the Lambda function's security group.
The correct answer provides the standard, secure pattern for accessing both private VPC resources and the public internet from an AWS Lambda function. By associating the Lambda function with the private subnets, it can reach the Redis cluster. By routing outbound internet traffic () from the private subnets through a NAT Gateway in a public subnet, the function can safely establish HTTPS connections to the public analytics API.
Step-by-Step Solution
Key Concept
A Lambda function configured to access resources within a private VPC subnet requires a NAT Gateway or VPC Endpoint to communicate with any endpoints on the public internet.