Soru

Zorluk: OrtaServerless Development with AWS Lambda

A developer is designing an AWS Lambda function that processes payment transactions. The function needs to retrieve a payment gateway API key from AWS Systems Manager Parameter Store and write transaction status records to an Amazon DynamoDB table. The developer wants to optimize the function's startup time and runtime performance to handle sudden traffic spikes.

Which two configuration or coding practices should the developer implement to meet these requirements? (Select two.)

  1. Initialize the DynamoDB client outside of the Lambda handler function to enable execution context reuse.Cevap
  2. Retrieve the API key from Systems Manager Parameter Store outside of the Lambda handler function during the initialization phase.Cevap
  3. C
    Hardcode the payment API key directly in the Lambda function's source code to avoid runtime parameter fetching.
  4. D
    Re-initialize the DynamoDB client inside the Lambda handler function for each invocation to ensure connections are closed cleanly.
  5. E
    Deploy the Lambda function in a public subnet of a VPC with a direct route to an Internet Gateway to bypass routing latency to AWS endpoints.

Cevap

Initialize the DynamoDB client outside of the Lambda handler function, and retrieve the API key from Systems Manager Parameter Store outside of the Lambda handler function during the initialization phase.
Initializing the DynamoDB client and fetching parameters outside the handler leverages the Lambda execution environment lifecycle. Since the execution context is reused for warm starts, these initialization actions occur only during the cold start phase, saving significant time on subsequent invocations.

Adım Adım Çözüm

1
Analyze execution context reuse benefits in AWS Lambda.
Identify that variables and SDK clients initialized outside the handler function persist across multiple invocations in the same execution environment container.
This reduces the overhead of re-establishing TCP connections and performing initialization logic on every invocation.
2
Evaluate the placement of the Parameter Store lookup.
Placing the Parameter Store lookup outside the handler caches the API key in memory, avoiding redundant network requests during subsequent invocations.
Parameter caching in the global scope optimizes execution time and reduces costs related to API calls.
3
Address security and networking constraints.
Reject hardcoding credentials because of security risks. Reject deploying the Lambda function to a public subnet to access AWS services, because Lambda functions in a VPC require a NAT Gateway or VPC endpoint to route traffic to the internet/AWS endpoints.
Standard VPC routing requires private subnets with a NAT Gateway or VPC endpoints for Lambda functions to access external services safely.

Anahtar Kavram

Execution context reuse for caching SDK clients and configuration parameters.
Bu soruyu puanla