An enterprise is preparing to deploy an update to a critical microservice running on AWS Lambda that interacts with an Amazon Aurora PostgreSQL Serverless v2 database. The update includes a database schema modification that adds a new column to a high-throughput table, and the new Lambda version depends on this column. The deployment must achieve zero downtime, allow validation of the new database schema and the new Lambda function version with synthetic test transactions before any production users access the new code, and shift traffic gradually over a period of minutes. If any errors or latency spikes occur during the deployment, the system must automatically and immediately route of traffic back to the old version. Which deployment strategy and database migration pattern will meet these requirements with the lowest risk and administrative overhead?
- APerform the database schema update in a pre-deployment pipeline step. Configure AWS CodeDeploy to use the LambdaAllAtOnce deployment configuration, but define a BeforeAllowTraffic hook that runs synthetic tests. Set up Amazon Route 53 weighted records pointing to two different API Gateway stages (v1 and v2) to gradually shift traffic over minutes, using CloudWatch alarms to trigger a rollback of the CloudFormation stack.
- BApply the database schema update directly during the Lambda function's initialization phase (outside the handler) to ensure the database is ready when the function starts. Configure AWS CodeDeploy using the LambdaCanary10Percent10Minutes deployment configuration. Define an AfterAllowTraffic lifecycle hook in the AppSpec file to execute a validation script against the new version. Configure a CloudWatch alarm on Lambda errors to trigger a rollback.
- Implement the database schema change using the expand/contract pattern, applying the backward-compatible schema update (adding the column as nullable) as a pre-deployment database task. Configure AWS CodeDeploy using the LambdaCanary10Percent10Minutes deployment configuration. Define a BeforeAllowTraffic lifecycle hook in the AppSpec file that executes a validation Lambda function. This function invokes the new Lambda version directly using its target version ARN to perform synthetic transaction tests. If validation succeeds, CodeDeploy shifts traffic and monitors CloudWatch alarms on error rates to trigger an automated rollback.Cevap
- DDeploy the new Lambda version as a completely separate Lambda function. Use an Application Load Balancer (ALB) with weighted target groups to route of traffic to the new Lambda function and to the old function. Execute an AWS Systems Manager Automation document on a cron schedule to run synthetic validation queries. If validation fails, update the ALB target group weights to route of traffic back to the old function.