5.3-AWS CodeDeploy - Digital Cloud Training
5.3-AWS CodeDeploy - Digital Cloud Training
5.3-AWS CodeDeploy - Digital Cloud Training
You do not need to make changes to your existing code before you can use
CodeDeploy.
Similar open source tools include Ansible, Terraform, Chef, Puppet etc.
Integrates with various CI/CD tools including Jenkins, GitHub, Atlassian, AWS
CodePipeline as well as config management tools like Ansible, Puppet and
Chef.
CodeDeploy is a fully managed service.
CodeDeploy can use re-use existing setup tools, works with any application,
auto scaling integration.
CodeDeploy Application
An AWS CodeDeploy application contains information about what to deploy
and how to deploy it.
EC2/On-premises.
AWS Lambda.
Amazon ECS.
EC2/On-Premises:
Amazon ECS:
Deployment Type
CodeDeploy provides two deployment type options – in-place and
blue/green.
In-place deployment:
Exam tip: AWS Lambda and Amazon ECS deployments cannot use an in-
place deployment type.
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.
CodeDeploy sends the appspec.yml file (which must be at the root of your
source code).
EC2 instances are grouped by deployment group (e.g. dev, test, prod).
Note: CodeDeploy does not provision the resources – it deploys applications
not EC2 instances.
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 following code sample shows the format of an appspec.yml file for an
Amazon EC2 instance with WordPress:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html/WordPress
hooks:
BeforeInstall:
- location: scripts/install_dependencies.sh
timeout: 300
runas: root
AfterInstall:
- location: scripts/change_permissions.sh
timeout: 300
runas: root
ApplicationStart:
- location: scripts/start_server.sh
- location: scripts/create_test_db.sh
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server.sh
timeout: 300
runas: root
The files section specifies how to source and copy from S3 / GitHub to the
filesystem.
hooks are a set of instructions to be run to deploy the new version (hooks
have timeouts).
The Amazon ECS task definition file must be specified with its ARN in the
TaskDefinition instruction in the AppSpec file.
The container and port in your replacement task set where your Application
Load Balancer or Network Load Balancer reroutes traffic during a deployment
must be specified with the LoadBalancerInfo instruction in the AppSpec file.
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: "arn:aws:ecs:us-east-1:111222333444:task-definition/my-task-
definition-family-name:1"
LoadBalancerInfo:
ContainerName: "SampleApplicationName"
ContainerPort: 80
# Optional properties
PlatformVersion: "LATEST"
NetworkConfiguration:
AwsvpcConfiguration:
Subnets: ["subnet-1234abcd","subnet-5678abcd"]
SecurityGroups: ["sg-12345678"]
AssignPublicIp: "ENABLED"
Hooks:
- BeforeInstall: "LambdaFunctionToValidateBeforeInstall"
- AfterInstall: "LambdaFunctionToValidateAfterTraffic"
- AfterAllowTestTraffic: "LambdaFunctionToValidateAfterTestTrafficStarts"
- BeforeAllowTraffic: "LambdaFunctionToValidateBeforeAllowingProductionTraffic"
- AfterAllowTraffic: "LambdaFunctionToValidateAfterAllowingProductionTraffic"
Note: The hooks are different for each type of compute platform and not all
available hooks are shown. For more information on the available hooks for
each compute platform please read the AWS documentation here.
The format of the AppSpec.yaml file for use with AWS Lambda is as follows:
version: 0.0
Resources:
- myLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Name: "myLambdaFunction"
Alias: "myLambdaFunctionAlias"
CurrentVersion: "1"
TargetVersion: "2"
Hooks:
- BeforeAllowTraffic: "LambdaFunctionToValidateBeforeTrafficShift"
- AfterAllowTraffic: "LambdaFunctionToValidateAfterTrafficShift"
Revision
When updating to a new version a Revision includes everything needed to
deploy the new version: AppSpec file, application files, executables and
config files.
Deployment Configuration
In-place deployment (EC2 only)
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.
3. 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.
4. 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
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.
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.
Note: All AWS Lambda and Amazon ECS deployments are blue/green. An
EC2/On-Premises deployment can be in-place or blue/green.
For Amazon ECS and AWS Lambda there are three ways traffic can be shifted
during a deployment:
For Amazon EC2 you can choose how your replacement environment is
specified:
Connect Follow
About us Facebook
Contact us Youtube