AWS CodeDeploy Flashcards
What is Code Deploy ?
CodeDeploy is a deployment service that automates application deployments to Amazon EC2 instances, on-premises instances, serverless Lambda functions, or Amazon ECS services.
You can deploy a nearly unlimited variety of application content, including:
- Serverless AWS Lambda functions.
- Web and configuration files.
- Executables.
- Packages.
- Scripts.
- Multimedia files.
Integrates with various CI/CD tools including Jenkins, GitHub, Atlassian, AWS CodePipeline as well as config management tools like Ansible, Puppet and Chef.
What information does CodeDeploy Application contain ?
An AWS CodeDeploy application contains information about what to deploy and how to deploy it.
Need to choose the compute platform:
- EC2/On-premises.
- AWS Lambda.
- Amazon ECS.
EC2/On-Premises: - EC2/On-Premises:
- Amazon EC2 cloud instances, on-premises servers, or both.
- Deployments that use the EC2/On-Premises compute platform manage the way in which traffic is directed to instances by using an in-place or blue/green deployment type.
CodeDeploy Application: AWS Lambda:
- Used to deploy applications that consist of an updated version of a Lambda function.
- You can manage the way in which traffic is shifted to the updated Lambda function versions during a deployment by choosing a canary, linear, or all-at-once configuration.
CodeDeploy Application: Amazon ECS:
Used to deploy an Amazon ECS containerized application as a task set.
CodeDeploy performs a blue/green deployment by installing an updated version of the application as a new replacement task set.
CodeDeploy reroutes production traffic from the original application task set to the replacement task set.
The original task set is terminated after a successful deployment.
You can manage the way in which traffic is shifted to the updated task set during a deployment by choosing a canary, linear, or all-at-once configuration.
What is a Deployment Group ?
Each deployment group belongs to one application and specifies:
- A deployment configuration – a set of deployment rules as well as success / failure conditions used during a deployment.
- Notifications configuration for deployment events.
- Amazon CloudWatch alarms to monitor a deployment.
- Deployment rollback configuration.
What are the Deployment Types
CodeDeploy provides two deployment type options – in-place and blue/green.
In-place deployment Principles
The application on each instance in the deployment group is stopped, the latest application revision is installed, and the new version of the application is started and validated.
You can use a load balancer so that each instance is deregistered during its deployment and then restored to service after the deployment is complete.
Only deployments that use the EC2/On-Premises compute platform can use in-place deployments.
Exam tip: AWS Lambda and Amazon ECS deployments cannot use an in-place deployment type.
Blue/green on an EC2/On-Premises compute platform PRinciples
The instances in a deployment group (the original environment) are replaced by a different set of instances (the replacement environment) using these steps:
Instances are provisioned for the replacement environment.
The latest application revision is installed on the replacement instances.
An optional wait time occurs for activities such as application testing and system verification.
Instances in the replacement environment are registered with an Elastic Load Balancing load balancer, causing traffic to be rerouted to them.
Instances in the original environment are deregistered and can be terminated or kept running for other uses.
Note: If you use an EC2/On-Premises compute platform, be aware that blue/green deployments work with Amazon EC2 instances only.
Blue/green on an AWS Lambda compute platform Principles
- Traffic is shifted from your current serverless environment to one with your updated Lambda function versions.
- You can specify Lambda functions that perform validation tests and choose the way in which the traffic shifting occurs.
- All AWS Lambda compute platform deployments are blue/green deployments.
- For this reason, you do not need to specify a deployment type.
Blue/green on an Amazon ECS compute platform Principles
- Traffic is shifted from the task set with the original version of an application in an Amazon ECS service to a replacement task set in the same service.
- You can set the traffic shifting to linear or canary through the deployment configuration.
- The protocol and port of a specified load balancer listener is used to reroute production traffic.
- During a deployment, a test listener can be used to serve traffic to the replacement task set while validation tests are run.
AppSpec File
The application specification file (AppSpec file) is a YAML-formatted, or JSON-formatted file used by CodeDeploy to manage a deployment.
The AppSpec file defines the deployment actions you want AWS CodeDeploy to execute.
The name of the AppSpec file for an EC2/On-Premises deployment must be appspec.yml.
The name of the AppSpec file for an Amazon ECS or AWS Lambda deployment must be appspec.yaml or appspec.yml.
AppSpec.yaml for AWS Lambda hooks ?
BeforeAllowTraffic – used to specify the tasks or functions you want to run before traffic is routed to the newly deployed Lambda function.
AfterAllowTraffic – used to specify the tasks or functions you want to run after the traffic has been routed to the newly deployed Lambda function.
How does In-place deployment (EC2 only) work ?
First, you create deployable content on your local development machine or similar environment, and then you add an application specification file (AppSpec file). The AppSpec file is unique to CodeDeploy. It defines the deployment actions you want CodeDeploy to execute. You bundle your deployable content and the AppSpec file into an archive file, and then upload it to an Amazon S3 bucket or a GitHub repository. This archive file is called an application revision (or simply a revision).
Next, you provide CodeDeploy with information about your deployment, such as which Amazon S3 bucket or GitHub repository to pull the revision from and to which set of Amazon EC2 instances to deploy its contents.
CodeDeploy calls a set of Amazon EC2 instances a deployment group. A deployment group contains individually tagged Amazon EC2 instances, Amazon EC2 instances in Amazon EC2 Auto Scaling groups, or both.
Each time you successfully upload a new application revision that you want to deploy to the deployment group, that bundle is set as the target revision for the deployment group.
In other words, the application revision that is currently targeted for deployment is the target revision. This is also the revision that is pulled for automatic deployments.
Next, the CodeDeploy agent on each instance polls CodeDeploy to determine what and when to pull from the specified Amazon S3 bucket or GitHub repository.
Finally, the CodeDeploy agent on each instance pulls the target revision from the Amazon S3 bucket or GitHub repository and, using the instructions in the AppSpec file, deploys the contents to the instance.
Blue/green deployments, What is it ?
A blue/green deployment is used to update your applications while minimizing interruptions caused by the changes of a new application version. CodeDeploy provisions your new application version alongside the old version before rerouting your production traffic.
AWS Lambda: Traffic is shifted from one version of a Lambda function to a new version of the same Lambda function.
Amazon ECS: Traffic is shifted from a task set in your Amazon ECS service to an updated, replacement task set in the same Amazon ECS service.
EC2/On-Premises: Traffic is shifted from one set of instances in the original environment to a replacement set of instances.
Note: All AWS Lambda and Amazon ECS deployments are blue/green. An EC2/On-Premises deployment can be in-place or blue/green.