A company is deploying a serverless microservice that requires access to an Amazon RDS database. The database credentials must be rotated every 30 days. The design requires that the microservice retrieves these credentials securely, minimizes latency during invocations, and minimizes Secrets Manager API call costs. Which two actions should be taken to meet these requirements? (Select two.)
- Store the database credentials in AWS Secrets Manager and configure automatic rotation.Answer
- Retrieve and cache the credentials in a global variable outside of the Lambda handler function to reuse them across subsequent warm invocations.Answer
- CStore the database credentials in AWS Systems Manager Parameter Store as a Standard String parameter and enable native scheduled parameter rotation.
- DCall the Secrets Manager API to retrieve the credentials at the beginning of the handler function on every invocation to guarantee the most up-to-date credentials.
- EHardcode the database credentials directly within the Lambda function code and restrict access to the Lambda console using an IAM trust policy.
Answer
Store the database credentials in AWS Secrets Manager with automatic rotation, and retrieve and cache the credentials in a global variable outside of the Lambda handler function.
Storing the credentials in AWS Secrets Manager allows native integration with Amazon RDS for automated rotation. Retrieving the secret outside the handler function allows the Lambda execution context to cache the credentials in memory, meaning subsequent invocations (warm starts) do not need to make costly and high-latency API calls to Secrets Manager.
Step-by-Step Solution
Key Concept
AWS Lambda execution context reuse can be leveraged to cache static configuration and credentials retrieved from AWS Secrets Manager, optimizing performance and reducing external API call costs.