CodeDeploy
- To deploy the application automatically to EC2 instances or on-premises server
- Note: They must be running CodeDeploy Agent
- The AWS CodeDeploy Agent will continuously polling AWS CodeDeploy for work to do
- They pull Application and
appspec.yml
from Github or S3appspec.yml
should be at the root of the projectfiles
: Copy some extra files from S3 and Github to the filesystemsource
: The source to copy fromdestination
: destination to paste to
hooks
: set of instructions to do to deploy the new version. Can have timeouts. Follows the following orderApplicationStop
DownloadBundle
BeforeInstall
Install
AfterInstall
Application Start
ValidateService
(Important)- To make sure the service is working correctly
- They pull Application and
- Agent then run the deployment instruction in
appspec.yml
- And then report success/failure status
- And then report success/failure status
Primary components
Application
- unique name for the application
Compute platform
- EC2, on premises, Lambda, ECS
Deployment Configuration
- Set of rules for success/failure. For example
- EC2/On-premises: minimum of healthy instances
- AWS Lambda / ECS: traffic is routed to the new instance
- When Failure happens
- EC2 instances will stay in failed
- New deployments will first be deployed to failed instances
- We can rollback, redeploy old deployment or enable automated rollback for failures
- One At A time
- Deploy 1 EC2 instance at a time. If one fails, then deployment stops
- Custom
- Can specify min healthy instances = 75%
- All At Once
- Quick but downtime, good for dev
- Half At A time
- We go 50% one by one
- Set of rules for success/failure. For example
Deployment group
- Group of EC2 instances (set of tagged EC2 instances)
- ASG
- Mix of ASG and Tags
- Customisation in scripts with
DEPLOYMENT_GROUP_NAME
environment variables
Deployment type
- In-place deployment
- Supports by EC2, On-premises, ASG
- For ASG, newly created EC2 instance will also get automatically deployed
- For In-place deployment we have the above (all-at-one, half-at-one, one at a time)
- Blue/Green Deployment
- Supports by EC2, AWS Lambda and EC2
- Use another ASG to deploy
- If everything is healthy then v1 will be taken down
- In-place deployment
IAM instance profile
- For EC2 to get permissions to access S3 and Github
Application Revision
- Application code +
appspect.yml
- Application code +
Service Role
- IAM Role for CodeDeploy to perform operations on EC2 instance
Target Revision
- Most recent revision that you want to deploy
Redeploy & Rollback
- Can be rollback
- Automatically
- When deployment failed
- When CloudWatch Alarms threshold trigger
- Manually
- Automatically
- We can disable rollbacks to not perform rollbacks as well
- Note: If rollback happens, it will redeploy the last known good revision.
- If we do an in-place upgrade, we need to re-deploy the original version. Only blue-green allow you to rollback.