AWS CodeDeploy - basic intro

Post on 12-Apr-2017

203 views 1 download

transcript

AWS CodeDeployBy Anton Babenko, May 2016

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 anton@antonbabenko.com

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

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

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

Execution flow

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

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

Deployment configurationOne at a time

Half at a time

All at once

Custom

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

IntegrationsGithub webhooks

S3 + AWS Lambda

CircleCI, CodeShip, Jenkins, etc

AWS

Auto-scaling

ELB

SNS

Cloudwatch

Cloudtrail

Terraform

aws_codedeploy_app

aws_codedeploy_deployment_group

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.

Thank you!Questions ?