CodeDeploy can be used to deploy code to EC2 instance of on-premise server.
- EC2 Instances
- On premise servers
- Serverless Lambda functions
- ECS Services
- S3 Buckets
- Github Repositories
- Bitbucket Repositories
- Need the code-deploy agent in the server
- A config file must be included in the root of the source code, like
- On commit, codeDeploy will pull the code
- Deploy according to the config files
- CodeDeploy agent will report the success/failure
CodeDeploy only do the deployment, do not provision resource
Blue/green deployments are only available for the EC2 Instances not the on-premise servers
When need to deploy in multiple environments, need to create multiple codeDeploy group
appspec.yml, we define how we get the codebase and deploy it.
File Section we define the source like s3 or github.
Then, have a sequence of following hooks and we can define our actions in these hook,
Application Stop: Stopping the existing version of app
DownloadBundle: Get/download the new codebase
BeforeInstall: Task to do before installing the new app
AfterInstall: Task to do after installing the app
ApplicationStart: Task to start the new app
ValidateService: A health check to determine if the app is running properly
All hooks are,
ApplicationStop -> DownloadBundle -> BeforeInstall -> Install -> AfterInstall -> ApplicationStart -> ValidateService -> BeforeAllowTraffic -> AllowTraffic -> AfterAllowTraffic
Types Of Deployment
In Place Deployment: Also known as
Half at a time. First half of the instance get deployed and then the other half of the application deployed.
Blue Green Deployment: Initially it keeps the previous instances and application. A new set of instance will be created and load balancer send traffic on both of these. If everything goes fine, all the traffic will go to the new instances.
Blue green deployment is not supported by on premise servers
Get Secure Parameters In CodeDeploy from Parameter Store
- Create IAM role to access the Parameter Store
Rollback When Missing Files
During rollback, if the existing files are removed or no permissions,
- Put these files in the instances
- Create a new application instance