AWS CodeDeploy

Post on 11-Apr-2017

2.688 views 6 download

Transcript of AWS CodeDeploy

AWSCodeDeploy

Agenda

1. Introduction to AWS CodeDeploy

2. Benefits

3. Understanding various Components and Workflow

4. Understanding AppSpec file A configuration file for AWS CodeDeploy

5. Demo Deploy a sample Web Application using AWS

CodeDeploy Deploy a next revision of Application, rollback to

previous revision

Introduction to AWS CodeDeploy

A service from AWS that automates code deployments

to Amazon EC2 instances

Easier for you to rapidly release new features, helps you avoid downtime during

deployment, and handles the complexity of updating your

applications

Automate deployments, eliminating the need for error- prone manual operations, and the service scales with your

infrastructure so you can easily deploy to one EC2 instance or

thousands

Benefits

Automated Deployments

CentralizedControl

Minimize Downtime

Easy To Adopt

Components and Workflow

Source : http://docs.aws.amazon.com

Workflow

Create Application

Specify Deploymen

t Group

Specify Deployment Configuratio

n

Upload RevisionDeployCheck Results

Redeploys as needed

How to deploy an application

Application – Lifecycle (with CodeDeploy)

Start

Application Stop

Download Bundle

Before Install Install

After Install

Application Start

Validate Service End

Directory structure of Application Bundle you will push to S3 or Github :

|--MyApp/|-- appspec.yml|-- scripts/| |-- install_dependencies.sh| |-- start_server.sh| |-- stop_server.sh|-- sub-directory/| |-- (various files...)|-- sub-directory/| |-- (various files...)|-- sub-directory/| |-- (various files...)|-- index.html|-- license.txt|-- readme.html|-- (other files...)

Note : appspec.yml file should be in root directory.The further directory Structure you can define in appspec.yml file.

Understanding AppSpec File

version: 0.0 os: linux files:- source: /index.htmldestination: /var/www/html/

hooks: BeforeInstall:- location: scripts/install_dependencies timeout: 300runas: root

- location: scripts/start_server timeout: 300runas: root

ApplicationStop:- location: scripts/stop_server timeout: 300runas: root

Understanding AppSpec File

Stop_server

#!/bin/bashyum install -y httpdrm -f /var/www/html/index.html

#!/bin/bash service httpd start

Install_dependencies

Start_server

#!/bin/bashisExistApp = `pgrep httpd` if [[ -n $isExistApp ]]; then

service httpd stopfi

Install or Upgrade, and

Configure, the AWS CLI

Pre-requisite for Configuring CodeDeploy

Create an IAM Instance Profile and

a Service Role

Install CodeDeploy Agent

IAM Role for instance

IAM Role for instance on which the code needs to be deployed

{"Statement":[{"Resource":"*","Action":["autoscaling:Describe*","cloudformation:Describe*","s3:Get*"],"Effect":"Allow"}]}

Edit Trust RelationShip :

{"Version": "2008-10-17","Statement": [{"Sid": "","Effect": "Allow", "Principal": {"Service": "ec2.amazonaws.com"

},"Action": "sts:AssumeRole"

}]

}

IAM Role for Service side

IAM Role which needs to be attached at Service side

{"Statement":[{"Resource":["*"],"Action":["ec2:Describe*"],"Effect":"Allow"},{"Resource":["*"],"Action":[ "autoscaling:CompleteLifecycleAction","autoscaling:DeleteLifecycleHook","autoscaling:Describe LifecycleHooks","autoscaling:DescribeAutoScalingGroups","autoscaling:PutLifecycleHook","autos caling:RecordLifecycleActionHeartbeat"],"Effect":"Allow"}]}

Edit Trust Relationship :

{"Version": "2008-10-17","Statement": [{"Sid": "1","Effect": "Allow", "Principal": {"Service": ["codedeploy.us-west-2.amazonaws.com", "codedeploy.us-east-1.amazonaws.com"

]},"Action": "sts:AssumeRole"

}]

}

Installation on Ubuntu

Installing AWS CLI and AWS CodeDeploy Agent on Ubuntu 14.04 LTS

sudo apt-get updatesudo apt-get install awscli sudo apt-get install ruby2.0 cd /home/ubuntusudo aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . --region us-east-1sudo chmod +x ./installsudo ./install auto

Commands to create and push application

Commands to create and push application to S3:

aws deploy create-application --application-name MyApp

aws deploy push \--application-name MyApp \--s3-location s3://CodeDeployDemoBucket/MyApp.zip \--ignore-hidden-files

Steps – Deploying code on Instances

Steps for deploying code on Instances / Auto Scaling Group

1.Create an Application

2.Create a Deployment Group• Specify the Instances / ASG by tags• Specify Service Role we created in early steps

3.Create a Deployment Configuration

4.Deploy a new Revision• Specify the Application, Deployment Group, and path of S3• In case of Git , connect using Git Credential• Enter Repository name, Commit ID and deployment description

5.Click on Deploy Now

To know more refer to the blog AWS CodeDeploy - A Sample Walkthrough

Troubleshooting and Limitations

Troubleshooting and LimitationsIf you do not see or cannot access specific applications, deployment groups, Amazon EC2 instances, or other deployment resources from either the AWS CLI or the AWS CodeDeployconsole, and you expect to see them, make sure that you're referencing one of thesupported regions

AWS CodeDeploy is currently supported only in the following regions:

• US East (N. Virginia) region (us-east-1)• US West (Oregon) region (us-west-2)

As this service is new, there are lots of limitation as of now: http://docs.aws.amazon.com/codedeploy/latest/userguide/limits.html

Checking Agent logs :

Log path: /var/log/aws/codedeploy-agent/codedeploy-agent.log

Contact us

Here’s how TOTHENEW uses AWS for better infrastructure management for your customers.

Click Here To Know More!

Have more queries on AWS? Talk to our AWS experts Now!

Talk To Our Experts!