Soru

Zorluk: OrtaAWS CodeDeploy

A developer is configuring a blue/green deployment for an Amazon ECS service using AWS CodeDeploy. The developer wants to run a validation script to perform smoke tests before production traffic is routed to the new task set. The developer creates the following `appspec.yaml` file:

yaml
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: "arn:aws:ecs:us-east-1:123456789012:task-definition/my-app:1"
LoadBalancerInfo:
ContainerName: "my-app-container"
ContainerPort: 8080
Hooks:
- BeforeAllowTraffic:
- location: scripts/run-smoke-tests.sh
timeout: 300

During deployment, the CodeDeploy agent fails to parse the AppSpec file. How should the developer modify the AppSpec file to resolve this issue?

  1. Replace the BeforeAllowTraffic script block with the Amazon Resource Name (ARN) of an AWS Lambda function that executes the validation logic.Cevap
  2. B
    Change the Resources section name to files and specify the destination path for the run-smoke-tests.sh script on the ECS container instances.
  3. C
    Update the IAM trust policy of the ECS Task Execution Role to allow the codedeploy.amazonaws.com service principal to assume the role.
  4. D
    Store the content of the validation script in AWS Systems Manager Parameter Store and reference the parameter path under the BeforeAllowTraffic hook.

Cevap

Replace the BeforeAllowTraffic script block with the Amazon Resource Name (ARN) of an AWS Lambda function that executes the validation logic.
For Amazon ECS deployments, CodeDeploy AppSpec files require the hooks to reference the Amazon Resource Name (ARN) of an AWS Lambda function rather than a local file path. The script execution structure (location, timeout, runas) is only supported for Amazon EC2 and on-premises deployments. Replacing the script block with the Lambda ARN enables CodeDeploy to trigger the validation function properly.

Adım Adım Çözüm

1
Analyze the target deployment platform and AppSpec configuration.
The target platform is Amazon ECS, and the AppSpec file defines Resources and Hooks sections.
Different compute platforms (EC2 vs ECS/Lambda) have different AppSpec validation schemas and lifecycle hook requirements.
2
Evaluate the syntax used under the BeforeAllowTraffic hook in the AppSpec file.
The developer specified a local script path ('location: scripts/run-smoke-tests.sh'), which is EC2-specific syntax.
For ECS deployments, CodeDeploy lifecycle hooks must map to an AWS Lambda function ARN rather than a local file path.
3
Select the correction that provides a valid AWS Lambda function ARN for the ECS hook.
Replacing the script block with a Lambda function ARN resolves the parser error.
This complies with the ECS AppSpec specification for Hook definitions.

Anahtar Kavram

For Amazon ECS and AWS Lambda deployments in CodeDeploy, AppSpec lifecycle hooks can only execute validation tests via AWS Lambda functions specified by their ARNs, not through local shell scripts.
Bu soruyu puanla