A developer is implementing a real-time data processing pipeline where an AWS Lambda function consumes batches of records from an Amazon Kinesis Data Stream. To securely write the processed results to an Amazon RDS database instance, the Lambda function is configured to run inside a private subnet of a Virtual Private Cloud (VPC). During testing, the Lambda function fails to retrieve records from the Kinesis Data Stream and consistently times out. Which of the following configurations should the developer implement to resolve this connection issue?
- AConfigure the Lambda function's VPC settings to enable a public IP address and configure the security group to allow outbound traffic to all destinations.
- BModify the Lambda function's trust policy to allow the Kinesis service principal (kinesis.amazonaws.com) to assume the execution role.
- Configure an interface VPC endpoint (AWS PrivateLink) for Amazon Kinesis in the VPC, or route the private subnet traffic through a NAT Gateway in a public subnet.Answer
- DIncrease the Lambda function's execution timeout to 15 minutes to allow the runtime to reuse the container context and establish connection pools during initialization.
Answer
Configure an interface VPC endpoint (AWS PrivateLink) for Amazon Kinesis in the VPC, or route the private subnet traffic through a NAT Gateway in a public subnet.
The correct answer is to configure an interface VPC endpoint or route traffic through a NAT Gateway. This is correct because Lambda functions deployed inside a private subnet of a VPC do not have public IP addresses or route tables that directly point to the internet. Since the Kinesis API endpoint is located on the public internet, the Lambda function needs a way to route traffic out of the VPC to reach Kinesis. An interface VPC endpoint (AWS PrivateLink) allows the Lambda function to connect privately to Kinesis using private IP addresses within the VPC, without requiring traffic to traverse the public internet. Alternatively, a NAT Gateway placed in a public subnet allows the Lambda function to route its internet-bound traffic through the NAT Gateway and Internet Gateway to reach public AWS service endpoints.
Step-by-Step Solution
Key Concept
VPC Networking and Connectivity for AWS Lambda stream consumers