Labs ICT
Pro Login

CodeDeploy

What is CodeDeploy?

CodeDeploy is AWS's automated deployment service. Instead of manually copying files to servers and restarting applications, CodeDeploy does it all for you — consistently, reliably, and with minimal downtime.

Think of it as a smart delivery service for your code. You hand it the package, tell it where to deliver (EC2 instances, Lambda functions, or on-premises servers), and it handles the rest with options for rollback if something goes wrong.

Deployment Strategies

AllAtOnce deploys to all instances at once. Fast, but risky — if something breaks, everything breaks. Good for development, not for production.

Rolling deploys to a percentage of instances at a time. Like renovating a hotel one floor at a time — guests on other floors aren't affected.

Blue/Green creates an entirely new environment and switches traffic when ready. Zero downtime, instant rollback — just switch back to the old environment. It's the gold standard for production deployments.

Canary sends a small percentage of traffic to the new version first, then gradually increases. Like testing a new dish with a few customers before serving it to everyone.

How CodeDeploy Works

CodeDeploy uses an appspec.yml file that tells it what to do at each deployment stage: before install, after install, application start, and validation. You can run scripts at any stage.

The deployment process follows these steps: CodeDeploy pushes your code to instances, runs lifecycle hooks (scripts), validates the deployment, and either succeeds or rolls back based on health checks.

Integrating with Other Services

CodeDeploy works seamlessly with other AWS services. CodeCommit stores your code, CodeBuild builds it, CodeDeploy deploys it, and CodePipeline orchestrates the whole pipeline. Together, they form a complete CI/CD solution.

aws deploy create-deployment \
  --application-name my-app \
  --deployment-group-name my-group \
  --s3-location bucket=my-bucket,key=app/latest.zip

This command triggers a deployment from an S3 bucket. In practice, you'd trigger this from CodePipeline, but manual deployments are useful for hotfixes.

Rollbacks and Safety

If a deployment fails or instances fail health checks, CodeDeploy automatically rolls back to the previous version. This safety net means you can deploy with confidence knowing you can always revert.

You can also set up alarms in CloudWatch that trigger rollbacks if error rates spike after a deployment. It's like having a safety inspector watching every deployment and pulling the plug if something goes wrong.