A developer is building a serverless backend using AWS Lambda that queries an Amazon RDS database. To optimize performance and reduce database connection overhead, the developer wants to implement execution context reuse. The Lambda function also needs to retrieve database credentials securely from AWS Systems Manager Parameter Store.
Which two actions should the developer take to meet these performance and security requirements? (Select two.)
- Initialize the database connection pool outside of the Lambda handler function to reuse connections across subsequent invocations.Cevap
- Retrieve the database credentials from Parameter Store outside of the Lambda handler function, caching the values and implementing a refresh mechanism.Cevap
- CRetrieve the database credentials inside the handler function on every invocation to ensure the execution context remains completely stateless.
- DDeclare the database credentials as hardcoded string constants inside the Lambda function code to eliminate Parameter Store latency.
- EDeploy the Lambda function within a private VPC subnet without a NAT Gateway or VPC endpoint to establish a secure database channel.
Cevap
The developer should initialize the database connection pool outside the Lambda handler function to leverage execution context reuse, and fetch the database credentials from Parameter Store outside the handler, caching them with a mechanism to refresh the credentials before expiration.
To optimize performance, initialization logic such as database connection pools and credential retrieval should be executed outside the handler function. During subsequent warm invocations, the Lambda service reuses the same execution environment, allowing global variables and open network connections to remain active. Retrieving and caching credentials outside the handler reduces API overhead, while introducing a refresh mechanism ensures rotated credentials are eventually updated without manual restarts.
Adım Adım Çözüm
Anahtar Kavram
Optimizing AWS Lambda performance and security via execution context reuse and static initialization.