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.)
- Initialize the DynamoDB client outside of the Lambda handler function to enable execution context reuse.Cevap
- Retrieve the API key from Systems Manager Parameter Store outside of the Lambda handler function during the initialization phase.Cevap
- CHardcode the payment API key directly in the Lambda function's source code to avoid runtime parameter fetching.
- DRe-initialize the DynamoDB client inside the Lambda handler function for each invocation to ensure connections are closed cleanly.
- EDeploy 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
Anahtar Kavram
Execution context reuse for caching SDK clients and configuration parameters.