Soru

Zorluk: Çok zorDeployment Strategy Design

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 1010 minutes. If any errors or latency spikes occur during the deployment, the system must automatically and immediately route 100%100\% 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?

  1. A
    Perform 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 1010 minutes, using CloudWatch alarms to trigger a rollback of the CloudFormation stack.
  2. B
    Apply 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.
  3. 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
  4. D
    Deploy the new Lambda version as a completely separate Lambda function. Use an Application Load Balancer (ALB) with weighted target groups to route 10%10\% of traffic to the new Lambda function and 90%90\% 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 100%100\% of traffic back to the old function.

Cevap

Implement the database schema change using the expand/contract pattern, applying the backward-compatible schema update 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 to invoke the new version directly. Finally, use CloudWatch alarms on error rates to trigger an automated rollback.
The correct option properly uses the expand/contract pattern to perform a backward-compatible database schema change. It utilizes AWS CodeDeploy with the LambdaCanary10Percent10Minutes configuration to gradually shift traffic. By using the BeforeAllowTraffic lifecycle hook, the configuration ensures that validation tests are run against the new Lambda version (using its version ARN) before any production traffic is routed to it. Finally, integrating CloudWatch alarms with the CodeDeploy deployment group ensures that if errors occur during the canary phase, the deployment is automatically rolled back immediately.

Adım Adım Çözüm

1
Apply the database schema change using a backward-compatible (expand/contract) approach, adding the new column as nullable before deploying the new code.
The existing Lambda function version continues to function without errors because the database schema changes do not break its queries.
To ensure zero downtime, database schema modifications must be backward-compatible so that both old and new Lambda versions can run simultaneously.
2
Configure AWS CodeDeploy with the LambdaCanary10Percent10Minutes deployment configuration and define a BeforeAllowTraffic lifecycle hook in the AppSpec file.
The deployment process is defined to shift traffic gradually, but pauses before routing any production traffic to allow validation.
The BeforeAllowTraffic hook runs before CodeDeploy starts shifting production traffic, allowing validation of the new version beforehand.
3
Create a validation Lambda function invoked by the BeforeAllowTraffic hook that runs synthetic tests against the new Lambda version using its target version ARN.
The new Lambda version's functionality and database compatibility are verified using synthetic transactions.
Invoking the target version ARN directly allows testing the new version before it receives any production traffic.
4
Configure CloudWatch alarms for Lambda errors and latency spikes, and associate them with the CodeDeploy deployment group.
CodeDeploy monitors these alarms during the 1010-minute canary period and automatically rolls back if they are triggered.
This satisfies the requirement for an immediate, automated rollback in case of issues during the transition period.

Anahtar Kavram

Orchestrating safe Lambda deployments with CodeDeploy lifecycle hooks and backward-compatible database schema updates (expand/contract).
Bu soruyu puanla