A developer is configuring a deployment group in AWS CodeDeploy to deploy an application to a fleet of Amazon EC2 instances. The developer creates a new IAM role to serve as the service role for the deployment group. However, when the deployment is initiated, it fails immediately with a service role authorization error before any lifecycle event scripts in the appspec.yml file are executed. Which configuration issue is the most likely cause of this failure?
- AThe trust policy of the IAM role attached to the EC2 instance profile is configured to allow codedeploy.amazonaws.com to assume the role instead of ec2.amazonaws.com.
- The IAM service role associated with the CodeDeploy deployment group does not have a trust policy that allows the codedeploy.amazonaws.com service principal to assume the role.Answer
- CThe appspec.yml file is configured with the AfterAllowTraffic lifecycle hook, which is invalid for deployments targeting the Amazon EC2 compute platform.
- DThe deployment group is configured to fetch the application source bundle from Systems Manager Parameter Store, which is not supported because CodeDeploy requires AWS Secrets Manager for source bundle retrieval.
Answer
The IAM service role associated with the CodeDeploy deployment group does not have a trust policy that allows the codedeploy.amazonaws.com service principal to assume the role.
The correct option is correct because AWS CodeDeploy needs to assume the specified service role to perform operations such as registering instances, updating Auto Scaling groups, and interacting with load balancers. This trust is established via the trust policy of the role, which must explicitly allow the 'codedeploy.amazonaws.com' service principal to perform the 'sts:AssumeRole' action. If this trust policy is missing or incorrect, the CodeDeploy service cannot assume the role, and the deployment fails immediately with an authorization error.
Step-by-Step Solution
Key Concept
AWS CodeDeploy IAM service role and trust relationship requirements