+ All Categories
Home > Technology > AWS CodeDeploy - basic intro

AWS CodeDeploy - basic intro

Date post: 12-Apr-2017
Category:
Upload: anton-babenko
View: 203 times
Download: 1 times
Share this document with a friend
13
AWS CodeDeploy By Anton Babenko, May 2016
Transcript
Page 1: AWS CodeDeploy - basic intro

AWS CodeDeployBy Anton Babenko, May 2016

Page 2: AWS CodeDeploy - basic intro

Hi!Anton Babenko

I enjoy AWS, DevOps and web-development.

I am AWS Certified Solution Architect, SysOps and DevOps.

I work as DevOps engineer at Your.MD.

I am one of organizers of AWS User Group Norway meetups( Next meetup - “Big data experience at Schibsted”, 30th of May, 17:30 at MESH )

github.com/antonbabenko linkedin.com/in/antonbabenko [email protected]

Page 3: AWS CodeDeploy - basic intro

What is AWS CodeDeploy?

Fully managed service which allows deployment to Amazon EC2 and on-premise instancesRequires no modifications to existing code and is technology agnosticCan deploy from Amazon S3 buckets and Github reposFree

Page 4: AWS CodeDeploy - basic intro

Getting started

Install codedeploy agent

Prepare your application (add appspec.yml)

Create archive and register application revision

Create archive, upload it to S3 and register application revision:

aws deploy push

Register application revision (can be combined with ghr):

aws deploy register-application-revision

Configure target environment (“deployment group”)

Deploy application revision

Page 5: AWS CodeDeploy - basic intro

Deploy

Deploy application revision (myapp-v1.0.zip) to deployment group (myapp-prod) according to deployment configuration (CodeDeployDefault.OneAtATime):

aws deploy create-deployment \--application-name myapp \--deployment-config-name CodeDeployDefault.OneAtATime \--deployment-group-name myapp-prod \--description "My app v1.0 deployment to production" \--s3-location bucket=myapp-archives,bundleType=zip,key=myapp-v1.0.zip

Page 6: AWS CodeDeploy - basic intro

Execution flow

Page 7: AWS CodeDeploy - basic intro

appspec.ymlversion: 0.0os: linuxfiles: - source: Config/config.txt destination: webapps/Config - source: source destination: /webapps/myApp# permissions: # skipped on this examplehooks: ApplicationStop: - location: codedeploy/playbooks/application_stop.yml BeforeInstall: - location: codedeploy/playbooks/before_install.yml - location: Scripts/UnzipDataBundle.sh AfterInstall: - location: codedeploy/playbooks/after_install.yml ApplicationStart: - location: codedeploy/playbooks/application_start.yml timeout: 3600 ValidateService: - location: Scripts/MonitorService.sh timeout: 3600 runas: codedeployuser

Page 8: AWS CodeDeploy - basic intro

codedeploy/playbooks/application_stop.yml#!/usr/bin/env ansible-playbook---- hosts: localhost

gather_facts: false become: true

tasks: - name: Stop supervisor service ignore_errors: yes supervisorctl: name: "search" state: stopped

Page 9: AWS CodeDeploy - basic intro

Deployment configurationOne at a time

Half at a time

All at once

Custom

Page 10: AWS CodeDeploy - basic intro

Deployment groupOptions:

One per environment (development-site, staging-site, production-site)

Blue-green fashion:

production-site-blue + application revision v1.0

production-site-green + application revision v1.1

Page 11: AWS CodeDeploy - basic intro

IntegrationsGithub webhooks

S3 + AWS Lambda

CircleCI, CodeShip, Jenkins, etc

AWS

Auto-scaling

ELB

SNS

Cloudwatch

Cloudtrail

Terraform

aws_codedeploy_app

aws_codedeploy_deployment_group

Page 12: AWS CodeDeploy - basic intro

ConsiderationsS3 bucket and CodeDeploy application should be in the same AWS region

S3 cross-region replication does not work for private files

Solution: Register application revision for each region/bucket individually

Take care of created files not managed by CodeDeploy yourself

Solution: Use BeforeInstall hook

No control of what revision to deploy during ASG scaling activity

No straightforward solutions I know, only hacks (wrapper-application, triggers to SNS)

Watch out for infinite EC2 restarts during ASG scaling activity

Solution: Use ValidateService hook wisely

Hint: Test deployments on both running and newly created instances

Execution logs are not available in console if deployment was successful

Solution: Always stream logs somewhere (for eg, AWS Cloudwatch)

Note: CodeDeploy has been designed to deploy single application per EC2 instance.

Page 13: AWS CodeDeploy - basic intro

Thank you!Questions ?


Recommended