Easy ReviewDOP-C02
SDLC Automation71

CodeDeploy

Automate application deployments, validate replacements, shift traffic, and recover failed releases.

CodeDeploy deploys application revisions to EC2 and on-premises servers, Lambda functions, or ECS services. Choose targets and rollout rules, run lifecycle validation, and configure monitoring and rollback for each deployment.

Applications and deployment groups

CodeDeploy uses an application to keep release resources together. A revisionA version of application content and deployment instructions that CodeDeploy can release. is a version to deploy; a deployment groupThe deployment targets and associated settings that CodeDeploy uses for an application release. identifies where it goes; a deployment configurationRules that control rollout pace and decide whether a deployment succeeds. defines the rollout rules.

How it works

  1. Create an application for its compute platformThe type of computing resource on which an application is deployed., meaning the type of resource that runs the application.
  2. Supply a revision. For EC2/On-Premises, this is an archive with application files and an AppSpecA deployment instruction file describing resources or file installation and optional lifecycle hooks. file, the deployment instructions.
  3. Select a deployment group and its targets. Use the platform table below to distinguish them.
  4. Give CodeDeploy a service roleAn IAM role that permits an AWS service to act on AWS resources., an IAM roleAn AWS identity with permissions that software or users can assume. that authorizes the service to act on AWS resources, and choose a deployment configuration.
Platform Deployment targets Deployment type CodeDeploy agent
EC2/On-Premises Tagged instances or named Auto Scaling groupsA collection of EC2 instances managed together for scaling and availability. In-placeA deployment that updates the application on its existing instances.; blue/greenA deployment that prepares a replacement environment before moving traffic from the original environment. for EC2 only Required
Lambda Function versions described by AppSpec files Blue/green traffic shift Not required
ECS Cluster and service, listenersA load balancer entry point that receives requests and directs them to target groups., and two target groupsA set of registered destinations to which a load balancer routes requests. Blue/green task setA set of ECS tasks running an application version during deployment. replacement Not required

In-place updates existing servers. Blue/green moves traffic from an original environment to a replacement. An ECS task set is a group of tasks running a particular application version.

Exam cues

  • If the question says instances must match several independent tag conditions, think separate tag groups, because a match is required in every group.
  • If the question says deploy to an Auto Scaling group, think group name, because CodeDeploy identifies that group by name.
  • If the question says update on-premises servers, think in-place, because EC2/On-Premises blue/green supports EC2 instances only.

Remember

  • Three compute platforms: EC2/On-Premises, Lambda, and ECS.
  • Up to three tag groups, each with up to ten tags.
  • Tags use OR within a group and AND across groups.
  • Deployment configurations govern both rollout pace and success conditions.

Trap: Putting every tag in one group broadens selection: an instance needs only one matching tag in that group.

From the AWS docs (17)
  • An application groups the revisions, deployment groups, and deployment configurations used to release an application.
  • An EC2/On-Premises revision is an archive containing application content and an AppSpec file.
  • A deployment configuration defines rollout rules and success or failure conditions.
  • The compute platforms are EC2/On-Premises, AWS Lambda, and Amazon ECS.
  • In-place deployment stops, updates, starts, and validates an application on existing EC2 or on-premises instances.
  • Blue/green deployment on the EC2/On-Premises platform replaces EC2 instances; on-premises instances are not supported.
  • Lambda deployments shift traffic between function versions, and ECS deployments shift traffic between original and replacement task sets.
  • An EC2/On-Premises deployment group selects instances using tags, Auto Scaling group names, or both.
  • A Lambda deployment group identifies AppSpec files and stores deployment options such as alarms and rollback settings.
  • An ECS deployment group identifies a cluster, service, production listener, optional test listener, and two target groups.
  • An instance matches a tag group when it matches at least one tag in that group.
  • With multiple tag groups, an instance must match at least one tag in every group.
  • A deployment group supports up to three tag groups with up to ten tags each.
  • A CodeDeploy service role authorizes operations on target resources, publishing SNS notifications, and reading CloudWatch alarms.
  • Only EC2/On-Premises deployments require the CodeDeploy agent.
  • An ECS task set runs an application version as a group of tasks.
  • AppSpec is the deployment instruction file used to describe deployment resources or file installation and hooks.

AppSpec and file handling

An AppSpecA deployment instruction file describing resources or file installation and optional lifecycle hooks. file is CodeDeploy’s deployment instruction file. It tells the service which resources to update or tells the instance agent which files to copy and which scripts to run.

How it works

  1. Package EC2/On-Premises content with a file in YAMLA text format used to express structured configuration such as an AppSpec file., a text format for configuration, named appspec.yml at the revisionA version of application content and deployment instructions that CodeDeploy can release. root. Lambda and ECS also accept the JSONA text format for structured data that Lambda and ECS AppSpec files can use. data format and direct console input.
  2. Describe what changes. EC2 uses files mappings and optional file permissions; Lambda names the function, aliasA named reference to a Lambda function version that can also split traffic between versions., and versions; ECS names the task definitionThe configuration that describes how containers should run in an ECS application., container, and port. A task definition is the configuration used to run containers. Its ARNAn identifier that uniquely names an AWS resource. is its AWS resource identifier.
  3. During EC2 Install, resolve each source relative to AppSpec and copy it to the fully qualified destination on the instance.
  4. Apply file_exists_behavior to conflicting files outside the previous successful deployment. The AppSpec setting overrides the command line interface (CLI) or programmatic interface (API) setting.
  5. On redeployment, remove files recorded in CodeDeploy’s cleanup file. HookA named point in deployment where a specified script or validation function can run. scripts must handle the files they created themselves.
AppSpec value Conflicting file behavior
DISALLOW Fail the deployment; default
OVERWRITE Replace the instance file with the revision copy
RETAIN Keep and use the instance copy

Exam cues

  • If the question says files already exist on a server being adopted into CodeDeploy, think file conflict behavior, because unmanaged files cause the default deployment to fail.
  • If the question says a rollbackA release of a previous application revision as a new deployment. lost locally maintained files, think the failed deployment’s overwrite behavior, because rollback cannot retain deleted content.
  • If the question says CLI and AppSpec conflict handling disagree, think AppSpec precedence, because that setting controls the listed files.

Remember

  • Normal EC2/On-Premises: YAML, appspec.yml, revision root.
  • Lambda and ECS: YAML or JSON.
  • File mappings apply to EC2/On-Premises, with DISALLOW as the default conflict policy.

Trap: Rollback redeploys application content. It does not undo arbitrary file changes made by scripts or recover local files already overwritten.

From the AWS docs (16)
  • An AppSpec file describes deployment resources or file installation and optional lifecycle hooks.
  • For a normal EC2/On-Premises deployment, AppSpec must be YAML named appspec.yml at the revision root.
  • Lambda and ECS AppSpec files accept YAML or JSON and can be entered directly in the console.
  • The EC2/On-Premises files section maps revision sources to instance destinations during Install.
  • A files source path is relative to the AppSpec file; destination is a fully qualified instance path.
  • EC2/On-Premises AppSpec can specify permissions for deployed files.
  • Lambda AppSpec resources specify the function name, alias, current version, and target version.
  • ECS AppSpec resources specify the task definition ARN, container name, and container port.
  • DISALLOW is the default file_exists_behavior and fails on conflicting files outside the previous successful deployment.
  • OVERWRITE replaces a conflicting file on the instance with the revision copy.
  • RETAIN keeps the conflicting instance file and uses it in the deployment.
  • AppSpec file_exists_behavior applies to all files and takes precedence over the CLI or API file-exists setting.
  • Before redeployment, CodeDeploy uses its cleanup file to remove files it installed, but leaves files created by hook scripts.
  • A rollback uses the last successful deployment content-handling option, but cannot retain files already removed by the failed deployment.
  • An ECS task definition describes how the application containers run.
  • An ARN uniquely identifies an AWS resource.

Agent setup

The CodeDeploy agent is the software on an EC2 or on-premises server that carries out deployments. It retrieves instructions and revisionA version of application content and deployment instructions that CodeDeploy can release. content, then runs the deployment steps on that server.

How it works

  1. For EC2, attach an instance profileA container that supplies an IAM role to applications running on an EC2 instance., which supplies an IAM roleAn AWS identity with permissions that software or users can assume. to software on the instance. A role is an identity with permissions that software can assume. Give CodeDeploy its separate service roleAn IAM role that permits an AWS service to act on AWS resources. to manage deployment resources.
  2. Allow outbound HTTPSHTTP communication protected with TLS encryption. on port 443 to CodeDeploy and the revision store. For private access, provide CodeDeploy API and agent interface endpointsA private network entry point used to reach a service without a public internet connection., private entry points into those services, plus access to S3.
  3. When using the agent endpoint, set :enable_auth_policy: to true and grant the documented codedeploy-commands-secure permissions to the instance identity.
  4. Finish instance setup before starting the agent. With cfn-init, the CloudFormation bootstrapThe initial setup work performed after an instance starts. helper, install or start the agent after the other setup scripts.
  5. Install directly or use Systems Manager on managed instances. A State Manager associationAn instruction that specifies a desired configuration for managed instances on a schedule. is a scheduled instruction that keeps software configured as requested.
  6. For on-premises servers, install the agent, register each instance name with an IAM user ARNAn identifier that uniquely names an AWS resource. or IAM session ARN, and tag it. ARN means AWS resource identifier. Session registration uses temporary STS credentialsCredentials with a limited lifetime that authorize requests to AWS resources., which must be refreshed.
  7. If a hookA named point in deployment where a specified script or validation function can run. reads configuration from ParameterA named setting that software can retrieve from Parameter Store. Store, a store of named settings, authorize the identity making that request for the matching retrieval action, such as ssm:GetParameter or ssm:GetParameters.
Agent configuration option Systems Manager action
Never Skip agent installation
Only once Install once
Now and schedule updates Create a State Manager association for scheduled installation

Exam cues

  • If the question says deployment races instance setup, think start the agent last, because it can begin deployment before bootstrap finishes.
  • If the question says physical servers need temporary credentials, think IAM session ARN registration, because CodeDeploy supports STS session authentication.
  • If the question says no public internet, think CodeDeploy interface endpoints and an S3 gateway endpointA route-table destination that provides access to supported AWS services without a NAT device or internet gateway., because these provide private service access.

Remember

  • EC2/On-Premises needs the agent; Lambda and ECS do not.
  • Agent communication uses outbound HTTPS on port 443.
  • From July 2026, use Distributor package AWSCodeDeployAgentV2 for agent 2.x; AWSCodeDeployAgent serves 1.8.x.

Trap: Installing the agent does not register an on-premises server. Registration, credentials, and deployment tags are separate requirements.

From the AWS docs (23)
  • EC2/On-Premises requires the CodeDeploy agent; Lambda and ECS deployments do not.
  • The CodeDeploy agent communicates outbound using HTTPS on port 443.
  • An EC2 instance profile provides the agent permissions to communicate with CodeDeploy and download the S3 revision.
  • The CodeDeploy service role grants the service permissions to discover targets and operate on deployment resources.
  • Finish cfn-init bootstrap scripts before starting the CodeDeploy agent to avoid deployment ordering failures.
  • Using Systems Manager to install the CodeDeploy agent requires an instance configured for Systems Manager.
  • The Never agent configuration option skips installation through Systems Manager.
  • The Only once agent configuration option installs the CodeDeploy agent once through Systems Manager.
  • Now and schedule updates creates a State Manager association to install the agent on the chosen schedule.
  • From July 2026, the AWSCodeDeployAgentV2 Distributor package installs agent 2.0.x and later; AWSCodeDeployAgent serves the 1.8.x line.
  • CodeDeploy provides separate interface VPC endpoints for API operations and agent operations.
  • Using the agent endpoint requires enable_auth_policy set to true and the documented codedeploy-commands-secure permissions on the instance identity.
  • An S3 gateway endpoint lets instances access S3 without an internet gateway or NAT device.
  • RegisterOnPremisesInstance associates an instance name with either an IAM user ARN or an IAM session ARN, never both.
  • On-premises registration with an IAM session ARN uses temporary STS credentials that need periodic refresh.
  • On-premises instances must have the agent installed and be registered and tagged for deployment.
  • An identity that reads a Systems Manager parameter needs permission for the retrieval action, such as ssm:GetParameter or ssm:GetParameters, on the required parameters.
  • An instance profile passes an IAM role to software on an EC2 instance.
  • An IAM role is an identity with permissions that applications or services can assume.
  • An ARN uniquely identifies an AWS resource.
  • A State Manager association specifies the configuration to apply to managed instances on a schedule.
  • An interface endpoint provides a private service entry point in a VPC.
  • STS temporary security credentials expire and must be replaced to continue accessing AWS.

Lifecycle hooks

A lifecycle hookA named point in deployment where a specified script or validation function can run. runs your script at a defined point in a deployment. For EC2/On-Premises, the agent follows AppSpecA deployment instruction file describing resources or file installation and optional lifecycle hooks., its deployment instruction file, to stop the old application, install the revisionA version of application content and deployment instructions that CodeDeploy can release., start it, and check that it works.

How it works

  1. With a load balancer, run BeforeBlockTraffic, deregister the instance during BlockTraffic, and run AfterBlockTraffic.
  2. Run ApplicationStop from the previous successful revision. Skip it on an instance’s first deployment.
  3. Download the revision during DownloadBundle. Run BeforeInstall, copy files during Install, and run AfterInstall.
  4. Run ApplicationStart to start the application, then ValidateService to check it.
  5. With a load balancer, run BeforeAllowTraffic, register the instance during AllowTraffic, and run AfterAllowTraffic.

A load balancer directs requests to registered servers. Its traffic hooks surround the server update. Scripts within an event run sequentially in their AppSpec order; reserved agent operations cannot be replaced by hook scripts.

Exam cues

  • If the question says a new revision cannot fix a broken stop hook, think previous successful revision, because that is where ApplicationStop comes from.
  • If the question says one revision needs environment-specific settings, think DEPLOYMENT_GROUP_NAME, because the agent provides it to hooks.
  • If the question says multiple scripts share one event, think one combined timeout budget, because their configured timeouts must fit within the event limit.

Remember

  • Script timeout default: 3600 seconds. Combined timeout values per lifecycle event: at most 3600 seconds.
  • Hook context: APPLICATION_NAME, DEPLOYMENT_ID, DEPLOYMENT_GROUP_NAME, DEPLOYMENT_GROUP_ID, and LIFECYCLE_EVENT.
  • ApplicationStop, BeforeBlockTraffic, and AfterBlockTraffic use the previous successful revision. Other scripts use the current revision.
  • DownloadBundle, Install, BlockTraffic, and AllowTraffic are reserved operations.

Trap: Reordering hook names in YAMLA text format used to express structured configuration such as an AppSpec file. does not change lifecycle order. Only scripts within a hook run in the order listed there.

EC2 script hooks without load balancing
1234ApplicationStopprevious revisioniBeforeInstallbefore file copyAfterInstallafter file copyApplicationStartstart applicationValidateServicecheck application
  1. After the previous revision stop hook, the agent downloads the bundle and runs BeforeInstall.

  2. Install copies files, then AfterInstall runs.

  3. ApplicationStart starts the application.

  4. ValidateService checks the running application.

Box details (1)
ApplicationStop

Skip this hook on the first deployment.

From the AWS docs (14)
  • An EC2/On-Premises lifecycle hook maps a deployment event to scripts in AppSpec.
  • Without load balancing, the EC2 scriptable hook order is ApplicationStop, BeforeInstall, AfterInstall, ApplicationStart, ValidateService.
  • DownloadBundle and Install are agent operations and cannot run user hook scripts.
  • ApplicationStop uses AppSpec and scripts from the previous successful deployment and does not run on the first deployment.
  • ApplicationStop, BeforeBlockTraffic, and AfterBlockTraffic use scripts from the previous successful deployment.
  • Other EC2 hook scripts use the current deployment AppSpec.
  • For in-place deployments with a load balancer, traffic blocking hooks run before ApplicationStop and traffic allowing hooks run after ValidateService.
  • BlockTraffic deregisters instances and AllowTraffic registers them; both operations are reserved for the agent.
  • Scripts listed for an EC2 lifecycle event run sequentially in AppSpec order.
  • A hook script timeout defaults to 3600 seconds; all script timeout values within one lifecycle event must total no more than 3600 seconds.
  • EC2 hook scripts receive APPLICATION_NAME, DEPLOYMENT_ID, DEPLOYMENT_GROUP_NAME, DEPLOYMENT_GROUP_ID, and LIFECYCLE_EVENT environment variables.
  • A hook can use DEPLOYMENT_GROUP_NAME to select settings for the deployment environment.
  • The ignore-application-stop-failures option lets deployment continue despite failures in ApplicationStop, BeforeBlockTraffic, or AfterBlockTraffic.
  • A load balancer routes requests to instances that are registered with it.

Deployment configurations

A deployment configurationRules that control rollout pace and decide whether a deployment succeeds. defines how quickly CodeDeploy updates instances and when it calls the release successful. Minimum healthy hostsThe instance count or percentage that must stay available during a deployment. means the number or percentage of instances that must stay available during deployment.

How it works

  1. Choose a predefined configuration or create one with a required healthy instance count or percentage.
  2. CodeDeploy updates batches allowed by that configuration and evaluates its success rules.
  3. For EC2 blue/greenA deployment that prepares a replacement environment before moving traffic from the original environment., apply the rules when installing on replacements and registering them with the load balancer.
  4. If the rollout must progress by Availability ZoneA separate location within an AWS Region., a separate AWS location within a Region, use a custom zonal configuration. Optionally wait after each zone before progressing.
  5. To restart the last successful EC2/On-Premises in-placeA deployment that updates the application on its existing instances. revisionA version of application content and deployment instructions that CodeDeploy can release. without downloading a new one, use RESTART mode. Do not provide a revision or set updateOutdatedInstancesOnly to true.
EC2/On-Premises configuration Deployment pace Success rule
CodeDeployDefault.AllAtOnce Attempt all at once At least one succeeds
CodeDeployDefault.HalfAtATime Up to half per batch, rounded down At least half succeed, rounded up
CodeDeployDefault.OneAtATime One instance at a time All succeed, except a last-instance failure in a group with multiple instances

Exam cues

  • If the question says nine instances use HalfAtATime, think batches of up to four and at least five successes, because the two calculations round in different directions.
  • If the question says protect each Availability Zone during an EC2 in-place release, think custom zonal configuration, because predefined configurations do not support it.
  • If the question says protect half of each Auto Scaling groupA collection of EC2 instances managed together for scaling and availability., think beyond HalfAtATime alone, because its count covers the whole deployment groupThe deployment targets and associated settings that CodeDeploy uses for an application release..
  • If the question says an older custom in-place configuration times out after eight hours, check its creation date, because configurations created in June 2023 or later have a 12-hour limit.

Remember

  • Default: CodeDeployDefault.OneAtATime.
  • A single-instance deployment must succeed even with OneAtATime.
  • Zonal configuration supports EC2 in-place deployments only.
  • Without a zonal monitor duration, the next zone starts immediately.
  • A deployment group permits one concurrent deployment.
  • The in-place limit is 12 hours for predefined configurations and custom configurations created in June 2023 or later, but eight hours for older custom configurations.

Trap: A successful AllAtOnce deployment can still contain failed instances. Its success threshold is one instance.

Trap: Zonal rollbackA release of a previous application revision as a new deployment. uses random hosts; it does not replay the deployment one zone at a time.

From the AWS docs (19)
  • An EC2/On-Premises deployment configuration controls rollout rules and required healthy instance counts.
  • CodeDeployDefault.OneAtATime is the default EC2/On-Premises deployment configuration.
  • CodeDeployDefault.AllAtOnce attempts all instances concurrently and succeeds if at least one instance succeeds.
  • CodeDeployDefault.HalfAtATime updates up to half the instances in each batch, rounding down.
  • CodeDeployDefault.HalfAtATime succeeds when at least half the instances succeed, rounding up.
  • HalfAtATime counts instances across all Auto Scaling groups in the deployment group, not separately per Auto Scaling group.
  • CodeDeployDefault.OneAtATime deploys to one instance at a time and tolerates failure on the last instance when the group contains more than one instance.
  • With a single instance, OneAtATime succeeds only if that instance deployment succeeds.
  • Custom configurations specify minimum healthy hosts as an instance count or percentage.
  • Zonal deployment requires a custom configuration and supports EC2 in-place deployments only, excluding on-premises and blue/green.
  • Zonal configurations can wait for a monitor duration after each zone; without one, deployment starts in the next zone immediately.
  • A zonal deployment rollback operates on random hosts rather than one zone at a time.
  • For EC2 blue/green, the configuration controls installation on replacements and the rate of registering replacements for traffic.
  • An Availability Zone is a separate location within an AWS Region.
  • For nine instances, HalfAtATime deploys to up to four together and requires at least five successes.
  • A CodeDeploy deployment group permits one concurrent deployment.
  • EC2/On-Premises in-place deployments using predefined configurations or custom configurations created in June 2023 or later have a 12-hour limit; older custom configurations have eight hours.
  • CreateDeployment RESTART mode restarts the last successful revision without downloading a new revision and supports only EC2/On-Premises in-place deployments.
  • RESTART mode rejects a specified revision and updateOutdatedInstancesOnly set to true.

EC2 blue/green deployments

EC2 blue/greenA deployment that prepares a replacement environment before moving traffic from the original environment. deploys to replacement servers while the original servers remain available. Blue means the original fleet; green means its replacement. A load balancer moves traffic after the new revisionA version of application content and deployment instructions that CodeDeploy can release. is installed.

How it works

  1. Create the replacement environment by copying an Auto Scaling groupA collection of EC2 instances managed together for scaling and availability. or manually provisioning instances before deployment. An Auto Scaling group manages a set of EC2 instances together.
  2. Agents install and validate the revision on replacement instances. The original environment continues serving requests.
  3. Reroute immediately after installation, or wait while you test and manually choose to reroute. An expired manual wait stops the deployment.
  4. Register replacements at the rate set by the deployment configurationRules that control rollout pace and decide whether a deployment succeeds.. After traffic successfully moves, deregister the originals all at once.
  5. Keep original instances running or terminate them after the configured wait. While originals remain, a blue/green rollbackA release of a previous application revision as a new deployment. can route traffic back to them.

A target groupA set of registered destinations to which a load balancer routes requests. is a set of registered destinations for an Application or Network Load Balancer. The diagram uses an Application Load Balancer, abbreviated ALB.

Exam cues

  • If the question says test new EC2 servers before moving users, think blue/green with manual rerouting, because the replacement can be ready before receiving production traffic.
  • If the question says retain the previous fleet for recovery, think keep originals or delay termination, because traffic can return only while those instances exist.
  • If the question says provision green from the current Auto Scaling group, think automatic group copy, because CodeDeploy can create that replacement group.

Remember

  • EC2/On-Premises blue/green supports EC2 only.
  • A Classic, Application, or Network Load Balancer is required.
  • Registration of replacements follows the deployment configuration; originals deregister all at once.
  • A manual rerouting wait that expires produces Stopped.

Trap: Keeping the old fleet preserves a traffic recovery option. It does not guarantee an instantaneous rollback or preserve instances after their termination wait expires.

EC2 blue/green deployment with an ALB
Deployment groupprovision copy1install revision2AllowTraffic3BlockTraffic45CodeDeployapp + deployment groupiRevision bundleS3 or GitHubiALBlistener → target groupiBlue ASGoriginal instancesiGreen ASGreplacement (copied ASG)i
  1. Copy the specified Auto Scaling group to provision replacements, or provide instances manually before deployment.

  2. Agents install the revision on green and run installation, start, and validation hooks. ApplicationStop uses a previous successful revision if one exists.

  3. BeforeAllowTraffic, AllowTraffic, and AfterAllowTraffic surround green registration with the load balancer.

  4. After traffic successfully moves, the traffic-blocking events deregister the original instances all at once.

  5. Terminate originals after the configured wait or keep them running. Rollback can return traffic while originals exist.

Box details (5)
CodeDeploy

The application groups the revision, deployment group, and rollout configuration.

Revision bundle

Revision archive with application content and appspec.yml at its root.

ALB

CodeDeploy deregisters blue targets and registers green ones. BlockTraffic/AllowTraffic events are run by CodeDeploy, not by your scripts.

Blue ASG

Original instances can be kept running or terminated after a configured wait.

Green ASG

Replacement fleet created by copying an Auto Scaling group; manually provisioned instances are another option.

From the AWS docs (15)
  • EC2 blue/green installs a revision on replacement instances before rerouting load balancer traffic.
  • EC2/On-Premises blue/green supports EC2 instances, not on-premises instances.
  • Automatically copy Amazon EC2 Auto Scaling group creates a replacement group from the specified group.
  • Manually provision instances requires the replacement instances to exist before starting deployment.
  • EC2 blue/green requires a load balancer and supports Classic, Application, or Network Load Balancers.
  • Reroute traffic immediately registers replacement instances after provisioning and revision installation.
  • I will choose whether to reroute traffic waits for manual rerouting and marks the deployment Stopped if its wait expires.
  • The EC2 blue/green deployment configuration controls replacement registration rate, while originals deregister all at once after traffic successfully moves.
  • Original instances can be terminated after a configured wait or kept running.
  • EC2 blue/green replacement instances have install, start, validation, and traffic-allowing lifecycle events.
  • EC2 blue/green original instances have traffic-blocking lifecycle events; rollback allows traffic to originals and blocks replacements.
  • An EC2 blue/green rollback reroutes traffic to original instances as long as they have not been terminated.
  • An EC2 revision archive contains application content and AppSpec and can be stored in S3 or GitHub.
  • An Auto Scaling group manages a collection of EC2 instances as a logical group.
  • A target group is a set of registered destinations to which a load balancer routes requests.

Rollbacks

RollbackA release of a previous application revision as a new deployment. releases a previously deployed revisionA version of application content and deployment instructions that CodeDeploy can release. again so the application can return to a known working version. In CodeDeploy, this creates a new deployment with its own ID.

How it works

  1. Configure automatic rollback on deployment failure, alarmA rule that watches a metric and changes state when its evaluation conditions are met. thresholds, or both. Automatic recovery uses the last known good revision.
  2. To monitor application behavior, attach a CloudWatch alarm, a rule that watches a metric against a threshold. Grant the CodeDeploy service roleAn IAM role that permits an AWS service to act on AWS resources. cloudwatch:DescribeAlarms. Enable rollback on alarm thresholds as well as alarm monitoring.
  3. If rollback triggers, CodeDeploy starts another deployment. An individual release can override its deployment groupThe deployment targets and associated settings that CodeDeploy uses for an application release.’s rollback settings.
  4. For EC2 in-placeA deployment that updates the application on its existing instances. rollback, remove files tracked in the cleanup file and install the older revision. For EC2 blue/greenA deployment that prepares a replacement environment before moving traffic from the original environment., traffic can return to originals that still exist.
  5. For manual recovery, create a deployment that selects a previously deployed revision.
  6. To deploy a known working revision without an alarm configuration blocking it, override the alarm configuration for that deployment. The caller also needs codedeploy:UpdateDeploymentGroup.

Exam cues

  • If the question says rollback created a different deployment ID, think expected behavior, because CodeDeploy records recovery as a new deployment.
  • If the question says latency must trigger automatic recovery, think CloudWatch alarm plus rollback on alarm thresholds, because an alarm alone can stop without recovering.
  • If the question says a rollback must undo script side effects, think explicit recovery logic, because CodeDeploy does not reconcile arbitrary script actions.
  • If the question says CloudWatch alarm status is unavailable, think ignorePollAlarmFailure, because its default stops the deployment.

Remember

  • Automatic rollback uses the last known good revision.
  • A deployment can override the deployment group’s rollback configuration.
  • Continue deployments even if alarm status is unavailable is the ignorePollAlarmFailure option.
  • ignorePollAlarmFailure defaults to false. Set it to true to continue without an alarm status.
  • EC2 blue/green traffic recovery needs original instances that have not been terminated.

Trap: A rollback is not a snapshot restore. Files created or external changes made by scripts need their own recovery logic.

From the AWS docs (15)
  • CodeDeploy rollback redeploys a previous revision as a new deployment with a new deployment ID.
  • Automatic rollback can be configured for deployment failure or an alarm threshold and deploys the last known good revision.
  • An individual deployment can override its deployment group automatic rollback configuration.
  • Manual rollback creates a deployment using a previously deployed application revision.
  • A deployment group can stop a deployment when a configured CloudWatch alarm activates.
  • The Roll back when alarm thresholds are met setting redeploys the last known good revision on an attached alarm.
  • Continue deployments even if alarm status is unavailable corresponds to ignorePollAlarmFailure.
  • EC2 rollback removes files tracked in the cleanup file before reinstalling revision content.
  • CodeDeploy rollback does not reverse arbitrary actions performed by hook scripts.
  • EC2 blue/green rollback can return traffic to the original instances only if they have not been terminated.
  • Lambda rollback redeploys a previous revision and receives a new deployment ID.
  • A CloudWatch metric alarm evaluates a metric against a threshold over time.
  • ignorePollAlarmFailure defaults to false, stopping deployment if CodeDeploy cannot retrieve CloudWatch alarm status; true allows it to continue.
  • CreateDeployment can override a deployment group's alarm configuration, and the caller needs the UpdateDeploymentGroup IAM permission to specify the override.
  • CodeDeploy alarm monitoring requires CloudWatch access on the service role, including cloudwatch:DescribeAlarms.

Traffic validation hooks

Traffic validation hooksA named point in deployment where a specified script or validation function can run. run Lambda functions at defined points in a Lambda or ECS deployment. They let a deployment check the replacement before or after traffic moves. A hook is a named point where CodeDeploy can call your validation code.

How it works

  1. Name the optional validation functions in AppSpecA deployment instruction file describing resources or file installation and optional lifecycle hooks.. Lambda deployments expose BeforeAllowTraffic and AfterAllowTraffic.
  2. For ECS, select the hook based on what already exists at that point, using the table below. A task setA set of ECS tasks running an application version during deployment. is a collection of tasks running one application version.
  3. Run tests. An ECS test listenerA load balancer entry point that receives requests and directs them to target groups., a load balancer entry point for test requests, can route to the replacement before production moves.
  4. Call PutLifecycleEventHookExecutionStatus with the deployment ID, hook execution ID, and result. A callbackAn explicit API call by a validation function to report its result to CodeDeploy. means explicitly sending the result to CodeDeploy; a successful function return alone does not supply it.
ECS hook What can be checked
BeforeInstall Preconditions; replacement does not exist yet
AfterInstall Replacement task set and its target groupA set of registered destinations to which a load balancer routes requests. exist
AfterAllowTestTraffic Test listener routes to the replacement
BeforeAllowTraffic Final checks before production moves
AfterAllowTraffic Replacement serves production traffic

Install, AllowTestTraffic, and AllowTraffic perform the ECS resource and routing operations; the hooks surround them.

Exam cues

  • If the question says check a Lambda target version before users reach it, think BeforeAllowTraffic, because it precedes traffic shifting.
  • If the question says test ECS through a listener before production moves, think AfterAllowTestTraffic, because test routing is already active.
  • If the question says the validation function succeeded but deployment timed out, think missing status callback, because CodeDeploy waits for an explicit result.

Remember

  • Callback results: Succeeded or Failed only.
  • Callback deadline: one hour for Lambda and ECS validation functions.
  • ECS rollbackA release of a previous application revision as a new deployment. is unavailable at BeforeInstall; validation results from AfterInstall onward can trigger it.

Trap: AfterInstall means the replacement exists. It does not mean the test listener already routes to it; that follows AllowTestTraffic.

ECS Lambda hooks around resource and traffic changes
1234Check setupBeforeInstallCheck new tasksAfterInstallTest replacementAfterAllowTestTrafficApprove trafficBeforeAllowTrafficCheck live tasksAfterAllowTraffic
  1. Install creates the replacement task set before AfterInstall.

  2. AllowTestTraffic directs the optional test listener to the replacement before AfterAllowTestTraffic.

  3. BeforeAllowTraffic runs before the production traffic shift.

  4. AllowTraffic moves production traffic, then AfterAllowTraffic validates. Every configured validation function reports its result to CodeDeploy.

From the AWS docs (14)
  • Lambda and ECS lifecycle hooks invoke optional Lambda validation functions specified in AppSpec.
  • Lambda deployment hooks are BeforeAllowTraffic before the shift and AfterAllowTraffic after all traffic has shifted.
  • The ECS BeforeInstall hook runs before the replacement task set exists; rollback is not possible at this point.
  • The ECS AfterInstall hook runs after the replacement task set is created and associated with its target group.
  • ECS AfterAllowTestTraffic runs after the test listener sends traffic to the replacement task set.
  • ECS BeforeAllowTraffic runs before production shifts, and AfterAllowTraffic runs after production reaches the replacement task set.
  • The ECS scriptable hook order is BeforeInstall, AfterInstall, AfterAllowTestTraffic, BeforeAllowTraffic, AfterAllowTraffic.
  • ECS Install creates the replacement task set, AllowTestTraffic changes test routing, and AllowTraffic changes production routing.
  • ECS can use an optional test listener to reach the replacement task set before production traffic moves.
  • Validation functions must report their result with PutLifecycleEventHookExecutionStatus, using the deployment ID and lifecycle event hook execution ID.
  • Only Succeeded and Failed are accepted as validation results by PutLifecycleEventHookExecutionStatus.
  • A Lambda or ECS deployment fails if its validation function does not notify CodeDeploy within one hour.
  • For ECS, validation results from AfterInstall and later hooks can trigger rollback.
  • An ECS task set is a group of tasks running an application version.

Lambda and ECS traffic shifting

CodeDeploy releases Lambda and ECS applications by shifting traffic to a replacement version. For Lambda, an aliasA named reference to a Lambda function version that can also split traffic between versions. is a stable function name that routes requests to function versions. For ECS, a task setA set of ECS tasks running an application version during deployment. is a group of tasks running an application version. CodeDeploy creates a replacement task set alongside the original.

How it works

  1. For Lambda, identify the function alias and its current and target versions in AppSpecA deployment instruction file describing resources or file installation and optional lifecycle hooks.. Route the application requests through that alias.
  2. For ECS, use the CODE_DEPLOY deployment controllerThe service setting that selects which system manages ECS deployments., the service setting that delegates deployment to CodeDeploy. Specify two target groupsA set of registered destinations to which a load balancer routes requests. and a production listenerA load balancer entry point that receives requests and directs them to target groups. in the deployment groupThe deployment targets and associated settings that CodeDeploy uses for an application release.. A listener receives load balancer requests and routes them to a target group, a set of registered destinations.
  3. CodeDeploy creates the ECS replacement from the AppSpec task definitionThe configuration that describes how containers should run in an ECS application., the configuration for running its containers. Optionally route a test listener to this replacement before production moves.
  4. Shift traffic using the chosen configuration. Run optional Lambda validation functions at the supported hooksA named point in deployment where a specified script or validation function can run..
  5. To recover automatically on a CloudWatch alarmA rule that watches a metric and changes state when its evaluation conditions are met., attach the alarm and enable rollbackA release of a previous application revision as a new deployment. on alarm thresholds. For ECS, terminate the original task set after the configured wait.
Traffic pattern Mechanism Example
CanaryA traffic shift that sends an initial portion to the replacement and the rest after a waiting interval. Initial portion, wait, then remainder LambdaCanary10Percent5Minutes: 10 percent, then 90 percent five minutes later
LinearA traffic shift that moves equal portions at equal time intervals. Equal portions at equal intervals LambdaLinear10PercentEvery1Minute: 10 percent each minute
All-at-onceA deployment that moves all traffic to the replacement in one step. Move all traffic in one step Required for CodeDeploy ECS with an NLB

The example configuration names use the CodeDeployDefault. prefix. NLB means Network Load Balancer; ALB means Application Load Balancer.

Exam cues

  • If the question says try a small portion and then move everyone else, think canary, because it has an initial increment and a remaining increment.
  • If the question says equal portions at regular intervals, think linear, because it repeats the same traffic increment.
  • If the question says ECS canary through CodeDeploy behind an NLB, think change to an ALB, because the NLB option supports only all-at-once.
  • If the question says automatic recovery on errors, think alarm plus rollback configuration, because stopping on an alarm and rolling back are separate settings.

Remember

  • ECS needs two target groups and a production listener; its test listener is optional.
  • NLB with CodeDeploy: CodeDeployDefault.ECSAllAtOnce only.
  • Lambda and ECS deployment hooks invoke Lambda validation functions.

Trap: A manually stopped Lambda deployment without rollback can leave a weighted aliasA Lambda alias configured to divide requests between two function versions., an alias splitting requests across two versions. Resolve that state before another deployment.

Lambda traffic shifting with an alias
190%10% canary2alarm + rollback3Callersalias: liveweighted routingiVersion 190% → 0%Version 210% → 100%CloudWatch alarmsi
  1. Requests sent to the alias initially reach the current version.

  2. BeforeAllowTraffic validates the target. CodeDeployDefault.LambdaCanary10Percent5Minutes sends 10 percent to the target, then the remaining 90 percent five minutes later; AfterAllowTraffic follows.

  3. With alarm monitoring and automatic rollback on alarm thresholds configured, an alarm stops deployment and starts recovery.

Box details (2)
alias: live

For requests sent to this alias, CodeDeploy changes the traffic split between current and target versions.

CloudWatch alarms

Attach an alarm to stop deployment at its threshold. Enable rollback on alarm thresholds to return to the last known good revision.

ECS blue/green traffic shift
create replacement1test, then shift2drain original3CodeDeployCODE_DEPLOYiALB listenersproduction + testiBlue task setoriginal targetsiGreen task setreplacement targetsi
  1. CodeDeploy creates the replacement task set from the AppSpec task definition and associates the alternate target group.

  2. The optional test listener reaches green before CodeDeploy shifts production using the deployment configuration.

  3. The original task set is terminated after the configured wait.

Box details (4)
CodeDeploy

The ECS service delegates deployment to CodeDeploy. The deployment group names the service, listeners, and two target groups.

ALB listeners

The optional test listener can route validation traffic to the replacement task set before production shifts.

Blue task set

The original task set serves production until traffic moves. CodeDeploy can return traffic to it on rollback.

Green task set

The new task set uses the updated task definition and the alternate target group.

From the AWS docs (22)
  • Lambda AppSpec identifies a function alias, current version, and target version for traffic shifting.
  • Canary shifts traffic in an initial increment and moves the remainder after a waiting interval.
  • Linear shifts traffic in equal increments separated by equal time intervals.
  • All-at-once moves all traffic to the replacement in one step.
  • CodeDeployDefault.LambdaCanary10Percent5Minutes shifts 10 percent first and the remaining 90 percent five minutes later.
  • CodeDeployDefault.LambdaLinear10PercentEvery1Minute shifts 10 percent of traffic every minute until all traffic is shifted.
  • An ECS service deployed by CodeDeploy must use the CODE_DEPLOY deployment controller.
  • An ECS CodeDeploy deployment needs two target groups, a required production listener, and an optional test listener on an Application or Network Load Balancer.
  • CodeDeploy creates the replacement ECS task set from the AppSpec task definition and associates it with the alternate target group.
  • The optional ECS test listener reaches the replacement before production traffic shifts.
  • After an ECS deployment, the original task set is terminated according to the configured wait.
  • With a Network Load Balancer, CodeDeploy supports only CodeDeployDefault.ECSAllAtOnce.
  • CodeDeploy ECS canary and linear traffic shifting can use an Application Load Balancer.
  • CodeDeploy can stop deployments when an attached CloudWatch alarm reaches its threshold.
  • Automatic rollback on alarm thresholds must be configured to redeploy the last known good revision when an attached alarm activates.
  • Lambda deployment validation functions run at BeforeAllowTraffic and AfterAllowTraffic.
  • ECS CodeDeploy lifecycle validation hooks invoke Lambda functions.
  • Manually stopping a Lambda deployment without rollback can leave its alias referencing two versions and cause later deployments to fail.
  • A Lambda alias points to a function version and can split traffic between two versions.
  • An ECS task definition describes how application containers run.
  • An ECS task set runs an application version as a group of tasks.
  • In a ten-percent Lambda canary, the original version initially receives ninety percent; after the shift completes, the target receives all traffic.

Auto Scaling integration

CodeDeploy integrates with Auto Scaling so a newly launched EC2 instance receives application code before it enters service. A lifecycle hookA named point in deployment where a specified script or validation function can run. pauses an Auto Scaling state transition while deployment work runs.

How it works

  1. Name the Auto Scaling groupA collection of EC2 instances managed together for scaling and availability. in a CodeDeploy deployment groupThe deployment targets and associated settings that CodeDeploy uses for an application release. and provide the service roleAn IAM role that permits an AWS service to act on AWS resources.. CodeDeploy installs its mandatory launch hook.
  2. A new instance enters Pending:Wait, a paused launch state. The hook notifies an SQS queueA store that holds messages until a consumer retrieves them., a message buffer that CodeDeploy polls.
  3. CodeDeploy deploys to the waiting instance. Success signals CONTINUE; failure signals ABANDON, causing Auto Scaling to terminate it.
  4. If scale-outAn increase in the number of instances in an Auto Scaling group. occurs during an existing rollout, deploy the previously deployed revisionA version of application content and deployment instructions that CodeDeploy can release. to new instances. After that rollout succeeds, a follow-on deployment brings outdated instances up to date.
  5. Optionally enable a termination hook. It runs shutdown lifecycle events before scale-inA reduction in the number of instances in an Auto Scaling group., meaning removal of instances, without installing new code. Termination continues even if shutdown scripts fail.

Exam cues

  • If the question says new instances have older code during a rollout, think launch deploymentA deployment that installs application code while a new Auto Scaling instance waits to enter service. followed by an update, because CodeDeploy initially uses the previously deployed revision.
  • If the question says graceful shutdown before scale-in, think optional termination hook, because launch hooks only cover startup.
  • If the question says scheduled actions are suspended but instances still launch, think scaling policies, because ScheduledActions does not block their scale-out.
  • If an instance shuts down after one launch deployment fails while other CodeDeploy deployments remain pending, check for multiple deployment groups sharing the Auto Scaling group.

Remember

  • Launch hook: always enabled. Termination hook: optional.
  • outdatedInstancesStrategy: UPDATE enables follow-on updates; IGNORE disables them.
  • Custom Auto Scaling hooks have no guaranteed order relative to CodeDeploy events.
  • Scale-in during deployment can interrupt hooks and violate minimum healthy capacity.
  • CodeDeploy waits one hour for the agent to respond to pending deployments.

Trap: Failure during launch and failure during shutdown have different outcomes. Launch failure abandons the instance; shutdown failure still allows termination.

Auto Scaling waits for a launch deployment
123Launch hookinstance Pending:WaitLaunch noticepolled by CodeDeployCodeDeploylaunch deploymentLaunch resultCONTINUE or ABANDONi
  1. The Auto Scaling launch hook sends an SQS notification while the instance waits.

  2. CodeDeploy polls SQS and starts the launch deployment.

  3. After deploying, CodeDeploy signals CONTINUE on success or ABANDON on failure.

Box details (1)
Launch result

CONTINUE lets Auto Scaling finish launching. ABANDON causes instance termination.

From the AWS docs (17)
  • A CodeDeploy deployment group integrates with an Auto Scaling group by specifying its name and an appropriate service role.
  • CodeDeploy installs an Auto Scaling launch hook that cannot be disabled.
  • During an Auto Scaling launch deployment, the instance remains in Pending:Wait while CodeDeploy installs the revision.
  • A successful launch deployment signals CONTINUE; a failed launch deployment signals ABANDON and the instance is terminated.
  • The launch hook notifies an SQS queue polled by CodeDeploy, which starts the launch deployment.
  • Instances launched while a deployment is underway receive the previously deployed revision.
  • After a successful rollout, CodeDeploy starts a follow-on deployment to update instances left on the older revision.
  • The outdatedInstancesStrategy setting uses UPDATE to enable automatic outdated-instance updates and IGNORE to disable them.
  • CodeDeploy can suspend ScheduledActions during in-place deployment; this does not prevent scale-out driven by scaling policies.
  • The optional termination hook runs a termination deployment of shutdown lifecycle events before scale-in, without installing a revision.
  • A termination deployment allows instance termination to continue whether its shutdown hooks succeed or fail.
  • Execution order of custom Auto Scaling lifecycle hooks relative to CodeDeploy events cannot be predetermined.
  • Scale-in during deployment can interrupt instance hooks and fail the deployment if healthy capacity falls below the required minimum.
  • An Auto Scaling lifecycle hook pauses a launch or termination transition while additional work runs.
  • An SQS queue stores messages until consumers retrieve them.
  • With multiple CodeDeploy deployment groups on one Auto Scaling group, a failed deployment can cause instance shutdown while other deployments take up to an hour to time out.
  • CodeDeploy waits one hour for an agent to respond to pending deployments; lengthy instance initialization can prevent the agent from being ready in time.

Deployment troubleshooting

Troubleshooting CodeDeploy starts with the failed lifecycle event and its logs. Separate a server that cannot receive instructions from an application that installs but cannot pass validation or receive traffic.

How it works

  1. Identify the failed event and read its script or agent log. On Linux, hookA named point in deployment where a specified script or validation function can run. output is in /opt/codedeploy-agent/deployment-root/<group-id>/<deployment-id>/logs/scripts.log; agent activity is in /var/log/aws/codedeploy-agent/codedeploy-agent.log.
  2. If all events are skipped, check the agent, outbound HTTPSHTTP communication protected with TLS encryption. on port 443, the EC2 instance profileA container that supplies an IAM role to applications running on an EC2 instance., and the CodeDeploy service roleAn IAM role that permits an AWS service to act on AWS resources.. An instance profile supplies permissions to instance software; the service role supplies permissions to CodeDeploy itself.
  3. Check accurate instance time and available memory or disk space. The max_revisions agent setting controls retained deployment archives.
  4. Use the symptom table to narrow down an event failure. The combined Linux deployment log is /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log. A CloudWatch agent can collect these logs centrally.
  5. Add event notifications for future failures. A deployment groupThe deployment targets and associated settings that CodeDeploy uses for an application release. trigger publishes to an SNS topic, which distributes messages to subscribers such as email recipients. For automation after success, use an EventBridge rule, which matches events and invokes a target.

A health checkA recurring request that a load balancer uses to decide whether a target can receive traffic. is a recurring request that a load balancer uses to decide whether a target can receive traffic.

Symptom First explanation to investigate
AllowTraffic fails without a deployment log error Load balancer health checks
DownloadBundle: not opened for reading S3 access permissions, bucket Region, or S3 service error
Old ApplicationStop script keeps failing Previous successful revisionA version of application content and deployment instructions that CodeDeploy can release. supplies the script
Background server leaves hook waiting Standard input, output, and error still attached
Later Lambda deployments fail after a manual stop AliasA named reference to a Lambda function version that can also split traffic between versions. still splits traffic between two versions

Exam cues

  • If the question says all EC2 lifecycle events are skipped, think agent, connectivity, IAM, and host health, because deployment work may never have started.
  • If the question says a stop hook is broken in the old revision, think ignore-application-stop-failures for a corrective deployment, because replacing the script in the new bundle does not change the old hook.
  • If the question says email on deployment failure, think deployment group Failure trigger plus SNS, because CodeDeploy can publish the event directly.
  • If the question says automate work after a successful deployment, think an EventBridge rule matching the deployment state, because CodeDeploy sends state-change notifications.
  • If a recreated deployment group fails on files installed by the old group, think its new underlying ID, because cleanup tracks files by group ID.

Remember

  • EventBridge source: aws.codedeploy; detail type: CodeDeploy Deployment State-change Notification; success state: SUCCESS.
  • CodeDeploy-to-EventBridge delivery is best effortA service event delivery model in which some events might not reach EventBridge.: some service events might not arrive.
  • SNS triggers need service-role permission to publish to the topic.
  • For a stuck Lambda weighted aliasA Lambda alias configured to divide requests between two function versions., choose none under Weighted alias before redeploying the selected version.

Trap: A trailing & alone may leave a hook waiting. A background process must also redirect its standard input, output, and error.

Trap: Wire logging can reveal sensitive data. Enable it for diagnosis and disable it afterward.

From the AWS docs (27)
  • For skipped EC2 lifecycle events, check that the CodeDeploy agent is installed and running.
  • Skipped events can result from missing outbound HTTPS connectivity to CodeDeploy or S3 on port 443.
  • Skipped events can result from insufficient CodeDeploy service role or EC2 instance profile permissions.
  • Incorrect instance time can cause InvalidSignatureException and Signature expired deployment errors.
  • Memory or disk pressure can stop the agent; reducing max_revisions reduces retained deployment archives.
  • EC2 blue/green AllowTraffic failures without deployment log errors are typically caused by incorrectly configured load balancer health checks.
  • DownloadBundle UnknownError: not opened for reading can result from an S3 service error, missing S3 permissions, or a revision bucket in a different Region.
  • Wire logging can diagnose DownloadBundle errors and should be disabled after investigation because output can contain sensitive data.
  • A long-running Linux hook child process should run in the background with standard input, output, and error redirected so the hook can complete.
  • ApplicationStop, BeforeBlockTraffic, and AfterBlockTraffic use previous successful revision scripts; ignore-application-stop-failures can bypass their failures for a corrective deployment.
  • Linux script output is in /opt/codedeploy-agent/deployment-root/<group-id>/<deployment-id>/logs/scripts.log; agent activity is in /var/log/aws/codedeploy-agent/codedeploy-agent.log.
  • Linux combined deployment logs are in /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log.
  • The CloudWatch agent can collect EC2/On-Premises CodeDeploy logs for central viewing.
  • A manually stopped Lambda deployment without rollback may leave a two-version alias; choose none under Weighted alias and redeploy the selected version.
  • CodeDeploy deployment group triggers publish event notifications to an SNS topic and its subscribers, including email recipients.
  • Failure and Rollback are supported deployment event types for CodeDeploy SNS notification triggers.
  • The deployment group service role must have permission to publish to the trigger SNS topic.
  • CodeDeploy sends deployment and instance state-change notifications directly to EventBridge with source aws.codedeploy and best-effort delivery.
  • An EventBridge event pattern can select CodeDeploy Deployment State-change Notification events by detail-type.
  • CodeDeploy deployment state-change notifications support SUCCESS, FAILURE, START, STOP, QUEUED, and READY status filtering.
  • A CodeDeploy state-change rule can invoke a target such as a Lambda function when the selected deployment state occurs.
  • An instance profile provides an IAM role to software running on an EC2 instance.
  • A CodeDeploy service role authorizes the service to act on deployment resources.
  • An EventBridge rule uses an event pattern to match events and send matching events to a target.
  • Best-effort service event delivery does not guarantee that every CodeDeploy event reaches EventBridge.
  • A load balancer periodically sends health check requests to registered targets to determine whether they can receive traffic.
  • Recreating a deployment group gives it a different underlying ID, so CodeDeploy does not recognize files installed by the old group for cleanup.

Flashcards

tap to flip
Answer

·

All 71 cards as a list

A team wants CodeDeploy to release a new version by replacing EC2 instances. Which deployment method fits?

Use an EC2 blue/green deployment. In-place deployment updates the application on existing instances.

Which CodeDeploy platforms support in-place and blue/green deployment?

In-place supports EC2 and on-premises instances. Blue/green supports EC2, Lambda, and ECS; it does not support on-premises instances.

What is the difference between a CodeDeploy application, deployment group, and deployment configuration?

The application groups release resources; the deployment group identifies targets and settings; the configuration defines rollout and success rules.

A CodeDeploy application must deploy to an Auto Scaling group as instances are replaced. How should the deployment group identify it?

Specify the Auto Scaling group name. CodeDeploy selects Auto Scaling groups by name rather than their instance tags.

A CodeDeploy EC2 deployment finds a conflicting file that was not installed by the previous successful deployment. Which AppSpec setting controls the result?

Use file_exists_behavior: DISALLOW fails by default, OVERWRITE replaces the file, and RETAIN keeps the instance copy.

What AppSpec formats and locations does CodeDeploy support for EC2/On-Premises compared with Lambda and ECS?

Normal EC2/On-Premises deployments require YAML named appspec.yml at the revision root. Lambda and ECS accept YAML or JSON, including console input.

A CodeDeploy rollback uses RETAIN but a local file removed by the failed release is still missing. Why?

RETAIN can only keep a file that still exists. A failed deployment using OVERWRITE may already have removed it.

A CodeDeploy EC2 release overwrites a manually installed configuration file and then fails. Can rollback recover that original local file?

Do not expect it to. CodeDeploy can redeploy revision files, but the overwritten local content is no longer available for RETAIN.

A CodeDeploy EC2 deployment uses RETAIN in AppSpec but OVERWRITE in its CLI request. Which setting wins?

AppSpec file_exists_behavior wins and applies to all files listed in files.

Does a CodeDeploy EC2 rollback delete files that a hook script created outside the installed revision files?

No. The cleanup file tracks files CodeDeploy installed; script-created files need script logic to reconcile them.

New EC2 instances configured by cfn-init fail their first CodeDeploy release because deployment starts before setup completes. What should change?

Finish the bootstrap scripts before starting the CodeDeploy agent. Install it last, or start an agent baked into the machine image as the final bootstrap step.

What does CodeDeploy require on EC2 that its Lambda and ECS deployments do not require?

The CodeDeploy agent. EC2 also needs an instance profile with permissions for deployment communication and the S3 revision.

How can CodeDeploy install and update its agent across a fleet with Systems Manager?

Configure instances for Systems Manager and choose Never, Only once, or Now and schedule updates. Scheduled updates use a State Manager association. Select AWSCodeDeployAgentV2 for agent 2.x or AWSCodeDeployAgent for 1.8.x.

What connectivity and credentials does a CodeDeploy agent on EC2 need for an S3 revision?

Outbound HTTPS on port 443 and an instance profile authorized to communicate with CodeDeploy and retrieve the S3 revision. Private endpoints require their documented agent authentication configuration.

A team wants to deploy with CodeDeploy to physical servers using expiring credentials. How should it register them?

Use RegisterOnPremisesInstance with the instance name and an IAM session ARN, configure the agent, and refresh STS credentials periodically. Do not supply an IAM user ARN in the same request.

An EC2 CodeDeploy agent must operate without public internet access. Which network paths should the design provide?

Provide CodeDeploy API and agent interface endpoints and S3 access, such as an S3 gateway endpoint. Enable the agent endpoint authentication setting and grant its command permissions.

An on-premises CodeDeploy hook authenticates successfully but cannot read application settings from Parameter Store. What permission should be checked?

Check the identity used by the hook for the matching retrieval permission, such as ssm:GetParameter or ssm:GetParameters, on the required parameters. Registration alone does not grant parameter access.

What is the scriptable hook order for an EC2/On-Premises CodeDeploy in-place deployment without a load balancer?

ApplicationStop, BeforeInstall, AfterInstall, ApplicationStart, ValidateService. DownloadBundle and Install are reserved agent operations between these hooks.

Why does CodeDeploy skip ApplicationStop on the first deployment to an EC2 instance, and use an older script on later deployments?

It reads ApplicationStop from the previous successful revision. No such revision exists on the first deployment.

What are the timeout default and event limit for EC2/On-Premises CodeDeploy hook scripts?

A script timeout defaults to 3600 seconds. The total of all script timeout values for one lifecycle event must not exceed 3600 seconds.

The same CodeDeploy revision goes to staging and production but needs different settings. How can an EC2 hook select them?

Read DEPLOYMENT_GROUP_NAME in the hook script and select the environment settings from that value.

A CodeDeploy EC2 deployment keeps failing in ApplicationStop even though the new revision fixes the script. How can the fixed revision be installed?

Use the ignore-application-stop-failures deployment option. The failing stop hook comes from the previous successful revision, so the new script is not used yet.

A CodeDeploy EC2 in-place deployment uses a load balancer. When are instances removed from traffic and restored?

BeforeBlockTraffic, BlockTraffic, and AfterBlockTraffic precede ApplicationStop. BeforeAllowTraffic, AllowTraffic, and AfterAllowTraffic follow ValidateService.

Which predefined EC2/On-Premises deployment configurations does CodeDeploy provide, and which is the default?

CodeDeployDefault.AllAtOnce, CodeDeployDefault.HalfAtATime, and CodeDeployDefault.OneAtATime. OneAtATime is the default.

For EC2/On-Premises CodeDeploy deployments, what success conditions distinguish AllAtOnce, HalfAtATime, and OneAtATime?

AllAtOnce needs at least one success. HalfAtATime needs at least half, rounded up. OneAtATime tolerates only a last-instance failure in a group with multiple instances; a single-instance group must succeed.

A CodeDeploy HalfAtATime deployment targets nine EC2 instances. How many can be updated together, and how many must succeed?

Up to four in a batch; at least five must succeed. Batch size rounds down and the success requirement rounds up.

A CodeDeploy release must update EC2 instances one Availability Zone at a time while keeping healthy capacity in each zone. What should be configured?

A custom deployment configuration with zonal configuration and minimum healthy hosts per zone. Predefined configurations do not provide this.

A CodeDeploy HalfAtATime deployment targets two Auto Scaling groups. Is half the capacity preserved in each group?

No. The calculation spans the whole deployment group, so a batch may be concentrated in one Auto Scaling group.

A CodeDeploy EC2 in-place deployment must restart the last successful application revision without downloading a new bundle. Which deployment mode applies?

Use RESTART. Do not supply a revision or set updateOutdatedInstancesOnly to true. RESTART is not supported for ECS or Lambda deployments.

An EC2 in-place CodeDeploy deployment uses a custom configuration created before June 2023 and exceeds eight hours. Why can it time out sooner than a newer configuration?

Older custom configurations have an eight-hour limit. Custom configurations created in June 2023 or later and predefined configurations have a 12-hour limit.

What does a deployment configuration control during an EC2 blue/green CodeDeploy deployment?

It controls installation on replacement instances and the rate at which replacements are registered for traffic.

In CodeDeploy EC2 blue/green, what do traffic rerouting, deployment configuration, and original-instance settings control?

Rerouting starts immediately or waits for your choice. The configuration sets replacement registration pace; originals deregister all at once. Originals are then kept or terminated after the selected wait.

An EC2 CodeDeploy blue/green release needs traffic returned to the original servers after a bad release. What must still be available?

The original instances must still exist. Keep them running or configure a suitable termination wait so CodeDeploy can reroute traffic back.

A CodeDeploy EC2 blue/green deployment installed successfully but became Stopped without moving users. Which setting explains this?

The manual traffic-rerouting wait expired. Choose whether to reroute traffic before that wait runs out.

A team wants CodeDeploy to provision an EC2 blue/green replacement fleet from its current Auto Scaling group. Which option fits?

Automatically copy Amazon EC2 Auto Scaling group. CodeDeploy creates the replacement group from the specified source group.

What does CodeDeploy do when a failed deployment triggers configured automatic rollback?

Deploy the last known good revision as a new deployment with its own ID. It does not restore an earlier deployment record.

A CodeDeploy release must recover when a latency alarm fires. Is attaching the alarm enough?

Attach the CloudWatch alarm and enable Roll back when alarm thresholds are met. Alarm monitoring can stop a deployment, but rollback requires its own configuration.

An EC2 CodeDeploy rollback restores application files but leaves changes made by a hook script. Why?

Rollback removes tracked deployment files and redeploys revision content. CodeDeploy does not automatically reverse arbitrary script actions.

How can a CodeDeploy operator manually return to a known working revision without automatic rollback configured?

Create a new deployment using a previously deployed revision. The rollback has its own deployment ID.

A CodeDeploy deployment cannot retrieve its CloudWatch alarm status. What happens by default, and which option allows it to continue?

The deployment stops by default. Set ignorePollAlarmFailure to true to continue when alarm status cannot be retrieved.

A CodeDeploy operator must deploy a known working revision while overriding a deployment group's CloudWatch alarm configuration. What permission is required for the override?

The CreateDeployment caller also needs codedeploy:UpdateDeploymentGroup. Specify overrideAlarmConfiguration for that deployment.

A CodeDeploy deployment group must stop a release when a CloudWatch alarm activates. What permission must the CodeDeploy service role have to monitor the alarm?

Grant the service role cloudwatch:DescribeAlarms. Configure the alarm on the deployment group; configure rollback separately if recovery is also required.

Which CodeDeploy hooks validate a Lambda function deployment, and how do they report results?

BeforeAllowTraffic and AfterAllowTraffic. Their Lambda validation functions report Succeeded or Failed with PutLifecycleEventHookExecutionStatus within one hour.

Which Lambda validation hooks run during a CodeDeploy ECS deployment?

BeforeInstall, AfterInstall, AfterAllowTestTraffic, BeforeAllowTraffic, AfterAllowTraffic. AfterAllowTestTraffic follows test-listener routing to the replacement task set.

A CodeDeploy Lambda release needs to test the target version before live requests move. Where should validation run?

Use a Lambda validation function at BeforeAllowTraffic and report its result to CodeDeploy.

An ECS application deployed through CodeDeploy needs API tests against the replacement before production moves. What design supports this?

Configure the optional test listener and a Lambda validation function at AfterAllowTestTraffic. The listener reaches the replacement before the production shift.

A CodeDeploy validation Lambda returns successfully but the release later fails waiting for validation. What did the function miss?

The explicit PutLifecycleEventHookExecutionStatus callback. Report Succeeded or Failed with the deployment ID and hook execution ID within one hour.

An ECS CodeDeploy team wants to validate the replacement at BeforeInstall. Why is that hook too early?

The replacement task set does not exist yet. Use AfterInstall to check the created task set, or AfterAllowTestTraffic to test it through the test listener.

How do CodeDeployDefault.LambdaCanary10Percent5Minutes and CodeDeployDefault.LambdaLinear10PercentEvery1Minute differ?

Canary sends 10 percent first and the remaining 90 percent five minutes later. Linear adds 10 percent every minute until all traffic has moved.

A Lambda team needs gradual releases with automatic recovery when errors rise. How should it configure CodeDeploy?

Shift an alias with canary or linear traffic settings. Attach CloudWatch alarms and enable rollback when alarm thresholds are met; optionally add pre-traffic and post-traffic validation hooks.

How does CodeDeploy blue/green update an ECS service?

Create a replacement task set from the task definition, attach the alternate target group, optionally test it, and shift production traffic. Terminate the original after the configured wait.

An ECS service uses CodeDeploy and a Network Load Balancer but needs gradual traffic shifting. What should change?

Use an Application Load Balancer. CodeDeploy supports only CodeDeployDefault.ECSAllAtOnce with a Network Load Balancer.

A team needs a CodeDeploy canary release for ECS behind a Network Load Balancer. What load balancer meets the requirement?

An Application Load Balancer. The CodeDeploy controller cannot provide canary shifting through a Network Load Balancer.

How can CodeDeploy shift a Lambda release gradually and reverse it on an alarm?

Use an alias with canary or linear settings, attach a CloudWatch alarm, and enable automatic rollback on its threshold. Validation hooks can test before and after the shift.

For an ECS service deployed by CodeDeploy, where are the controller, listeners, target groups, and task definition configured?

Set the ECS service controller to CODE_DEPLOY. Put listeners and two target groups in the deployment group; put the task definition in AppSpec.

An Auto Scaling group adds instances during a CodeDeploy rollout. Which revision do those new instances receive, and how do they catch up?

They receive the previously deployed revision. After the rollout succeeds, CodeDeploy starts a follow-on deployment to update outdated instances unless those automatic updates are disabled.

How does CodeDeploy integrate with Auto Scaling instance launches and terminations?

The mandatory launch hook holds the instance in Pending:Wait for deployment, then signals CONTINUE or ABANDON. An optional termination hook runs shutdown events before scale-in.

During a CodeDeploy in-place deployment, can suspending scheduled actions prevent all Auto Scaling scale-outs?

No. Scaling policies can still launch instances while scheduled actions are suspended.

A CodeDeploy team suspended ScheduledActions but a scaling policy still launched instances during deployment. Is this expected?

Yes. Suspending scheduled actions does not block scaling-policy scale-outs.

During a CodeDeploy rollout, an Auto Scaling group launches an instance. Which revision does it receive?

The previously deployed revision. After a successful rollout, CodeDeploy starts a follow-on deployment for outdated instances.

How can a team disable automatic follow-on updates for instances left on an older revision during a CodeDeploy rollout?

Set outdatedInstancesStrategy to IGNORE. Use UPDATE to enable automatic updates.

Why can Auto Scaling scale-in cause an in-place CodeDeploy rollout to fail?

Scale-in can interrupt instance hooks and reduce healthy capacity below the required minimum.

An EC2 CodeDeploy deployment fails with HEALTH_CONSTRAINTS and every lifecycle event is skipped. What should be checked?

Check agent status, outbound CodeDeploy and S3 access on port 443, the instance profile and service role, accurate instance time, and memory or disk pressure. Reduce max_revisions if archive space contributes.

An EC2 CodeDeploy blue/green deployment fails at AllowTraffic but its deployment log has no error. What should be investigated?

The load balancer health check configuration. Incorrect checks can prevent replacement instances from accepting traffic successfully.

What can cause CodeDeploy DownloadBundle to report UnknownError: not opened for reading?

Missing S3 permissions, an S3 revision bucket in a different Region from the instances, or a transient S3 service error. Wire logging can identify the cause; disable it after investigation.

A CodeDeploy Linux hook starts a server with a trailing ampersand but deployment still waits and times out. How should the process be launched?

Background it and redirect stdin, stdout, and stderr, for example: server > /dev/null 2> /dev/null < /dev/null &.

Where can EC2 CodeDeploy operators inspect hook output and agent activity on Linux?

Read scripts.log under the deployment group and deployment directories, the combined codedeploy-agent-deployments.log, and /var/log/aws/codedeploy-agent/codedeploy-agent.log. Use the CloudWatch agent to collect them centrally.

A manually stopped CodeDeploy Lambda deployment had no rollback configured, and subsequent deployments fail. What recovery does AWS document?

Edit the Lambda alias, choose none under Weighted alias, and redeploy the version selected by the alias. The stopped deployment may have left it splitting traffic across two versions.

A team needs email when CodeDeploy deployment fails. Which built-in configuration avoids a polling function?

Create a deployment group Failure trigger targeting an SNS topic with email subscribers. Give the service role permission to publish to that topic.

A team wants a Lambda workflow to run after CodeDeploy succeeds. Which event integration should it use?

Use an EventBridge rule for source aws.codedeploy and detail-type CodeDeploy Deployment State-change Notification, filtered to SUCCESS, with the Lambda function as target.

A CodeDeploy deployment group was deleted and recreated with the same name. Why can deploying to the same EC2 paths fail with existing-file conflicts?

The recreated group has a different ID, so the agent does not identify the old group's files for cleanup. Remove the conflicting files or choose an appropriate overwrite or retain option.

You finished every topic of DOP-C02!

Your badge turned gold. Next step: book the exam on AWS. Once you pass, add yourself to Who passed.

Share

Share that you finished this certification

I finished every topic of AWS Certified DevOps Engineer - Professional (DOP-C02) on Easy Review. Come study too!