A developer is creating an AWS Lambda function that fetches metadata from an external third-party API and saves the results to an Amazon DynamoDB table. The external API requires an API key for authentication. The developer needs to optimize the function's performance by minimizing connection latency and ensuring the API key is secured according to AWS best practices.
Which two actions should the developer take to meet these requirements? (Select two.)
- Initialize the DynamoDB client and the HTTP client outside of the Lambda handler method.Cevap
- Store the API key in AWS Secrets Manager, retrieve it using the AWS SDK inside the Lambda function, and cache the retrieved key in a global variable outside the handler.Cevap
- CHardcode the API key in the Lambda function's source code and initialize the AWS SDK client inside the handler method.
- DRe-create the DynamoDB client and the HTTP connection inside the handler method for every invocation to ensure clean execution states.
- EDeploy the Lambda function in a private VPC subnet without configuring a NAT Gateway to isolate the traffic to the external API.
Cevap
Initialize the DynamoDB client and the HTTP client outside of the Lambda handler method, and store the API key in AWS Secrets Manager, retrieving and caching it in a global variable outside the handler.
Initializing database clients and HTTP clients outside the handler allows AWS Lambda to reuse these connections across warm invocations, significantly optimizing execution latency. Additionally, retrieving sensitive keys from AWS Secrets Manager programmatically and caching them in global variables ensures credentials are kept secure while preventing API call overhead on subsequent executions.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda execution context reuse and secure credential management using AWS Secrets Manager.