Question #1020
A company is developing a latency-sensitive application. Part of the application includes several AWS Lambda functions that need to initialize as quickly as possible. The Lambda functions are written in .NET and contain initialization code outside the handlers to load configuration files, initialize dependencies, and establish database connections.
Which solution will meet the startup performance requirement MOST cost-effectively?
Move all the initialization code to the handlers for each Lambda function. Activate Lambda SnapStart for each Lambda function. Configure SnapStart to reference the unpublished $LATEST version of each Lambda function.
Publish a version of each Lambda function. Create an alias for each Lambda function pointing to the published version. Configure provisioned concurrency for each alias and enable SnapStart for the unpublished $LATEST versions.
Publish a version of each Lambda function. Enable SnapStart for the published versions. Configure provisioned concurrency for the $LATEST versions and move the database connection logic into the handlers.
Update the Lambda functions to include a pre-snapshot hook. Move the database connection initialization into the handlers. Publish a version of each Lambda function. Activate Lambda SnapStart for the published versions of the Lambda functions.
Explanation
Answer D is correct because:
1. SnapStart Requires Published Versions: SnapStart only works with published Lambda versions, not the $LATEST alias. Publishing a version is necessary.
2. Pre-Snapshot Hook: Ensures initialization code (e.g., configs, dependencies) runs once during snapshot creation, reducing cold starts.
3. Database Connections in Handlers: Moving connection logic into handlers ensures fresh connections on each invocation, avoiding stale connections from snapshots.
Why other options are incorrect:
- A: SnapStart cannot be applied to $LATEST.
- B: SnapStart cannot be enabled on $LATEST, and mixing Provisioned Concurrency with SnapStart is redundant.
- C: Provisioned Concurrency on $LATEST is unnecessary if SnapStart is used on published versions.
Key Points:
- Use SnapStart with published versions.
- Avoid long-lived resources (e.g., DB connections) in initialization code.
- Pre-snapshot hooks optimize initialization for SnapStart.
Answer
The correct answer is: D