Soru

Zorluk: ZorDebugging Lambda Execution and Configuration Issues

A developer has deployed a Python-based AWS Lambda function that synchronizes real-time multiplayer game leaderboards with an external third-party API and retrieves player metadata from an Amazon ElastiCache (Memcached) cluster located in a private VPC subnet. The Lambda function is configured to run inside the VPC and is associated with the private subnet containing the ElastiCache cluster. During load testing, the developer observes two symptoms: 1. The function is able to connect to the ElastiCache cluster, but all requests to the external third-party leaderboard API fail with a connection timeout error. 2. Under sustained high concurrent load, subsequent invocations of the Lambda function occasionally process stale player metadata that was cached during earlier invocations of the same execution context. Which two actions should the developer take to resolve these issues? (Select TWO.)

  1. Configure the Lambda function to run in private subnets that have a route pointing to a NAT Gateway located in a public subnet of the VPC.Cevap
  2. Modify the function code to clear or reinitialize global/module-level variables holding the cached player metadata at the start of each handler invocation.Cevap
  3. C
    Associate the Lambda function with a public subnet of the VPC and enable auto-assign public IP on the network interface to establish direct outbound routing.
  4. D
    Increase the Lambda function's timeout configuration to allow the global execution context to automatically refresh and purge its in-memory state between consecutive invocations.
  5. E
    Configure the Lambda execution role to allow the 'ec2:CreateNetworkInterface' and 'ec2:DescribeNetworkInterfaces' actions on the public subnets to bridge the external route.

Cevap

Configure the Lambda function to run in private subnets that have a route pointing to a NAT Gateway located in a public subnet of the VPC, and modify the function code to clear or reinitialize global/module-level variables holding the cached player metadata at the start of each handler invocation.
The correct solution involves routing outbound traffic through a NAT Gateway for internet access (resolving the timeout to the external API) and reinitializing global variables within the handler (resolving the stale data issue caused by context reuse).

Adım Adım Çözüm

1
Analyze the networking issue (Symptom 1)
Identify that the Lambda function is running in a private VPC subnet without outbound internet access, causing connections to the external API to time out.
VPC-connected Lambda functions require a NAT Gateway or VPC endpoints to access external endpoints.
2
Determine the required VPC networking configuration
Ensure the Lambda function is placed in private subnets whose route tables direct traffic to a NAT Gateway in a public subnet.
This establishes outbound internet connectivity while keeping the function securely isolated.
3
Analyze the state/cache issue (Symptom 2)
Identify that global variables are retaining player metadata across reused execution contexts.
AWS Lambda reuses containers (execution contexts) for performance, carrying over state declared outside the handler.
4
Implement the code fix for execution context reuse
Update the Lambda code to clear or reinitialize global metadata caches inside the handler method at the beginning of each execution.
This guarantees that each new request processes fresh data regardless of whether the execution context is new or reused.

Anahtar Kavram

AWS Lambda VPC networking outbound routing and execution context variable persistence.
Bu soruyu puanla