A developer is implementing an AWS Lambda function that queries an Amazon RDS for PostgreSQL DB instance. The Lambda function is configured to connect to the database using IAM database authentication. To minimize connection overhead and query latency, the developer initializes a database connection pool in the global scope (outside the Lambda handler function) and generates the IAM database authentication token once during this initialization. During initial testing, the Lambda function successfully connects to the RDS instance and retrieves data. However, when the application is left idle and then invoked again after 30 minutes, subsequent invocations fail with database authentication errors. Which action should the developer take to resolve this issue while maintaining optimal database connection management?
- AMove the database connection pool initialization and connection establishment entirely inside the Lambda handler function so that a new pool is created on every invocation.
- BConfigure the Lambda function's execution timeout to 15 minutes to force AWS Lambda to automatically recycle the execution context and refresh the token.
- Keep the connection pool in the global scope, but configure the pool to dynamically generate a new IAM database authentication token whenever a new connection is established.Answer
- DHardcode a static database credential token in the Lambda function's environment variables and decrypt it using AWS KMS helper tools on each invocation.