Deployment and Management on AWS: A Deep Dive on Options and Tools

69
DEPLOYMENT AND MANAGEMENT ON AWS: A DEEP DIVE ON OPTIONS AND TOOLS Danilo Poccia Solutions Architect

description

AWS Elastic Beanstalk AWS OpsWorks AWS CloudFormation Amazon EC2

Transcript of Deployment and Management on AWS: A Deep Dive on Options and Tools

Page 1: Deployment and Management on AWS: A Deep Dive on Options and Tools

DEPLOYMENT AND MANAGEMENT ON AWS:A DEEP DIVE ON OPTIONS AND TOOLSDanilo Poccia – Solutions Architect

Page 2: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS Elastic Beanstalk

AWS OpsWorks

AWS CloudFormation

Amazon EC2

CONVENIENCE CONTROL

HIGH-LEVEL DO IT YOURSELF

Page 3: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS Elastic Beanstalk

AWS OpsWorks

AWS CloudFormation

Amazon EC2

CONVENIENCE CONTROL

HIGH-LEVEL DO IT YOURSELF

Page 4: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS Elastic Beanstalk

AWS OpsWorks

AWS CloudFormation

Amazon EC2

CONVENIENCE CONTROL

HIGH-LEVEL DO IT YOURSELF

Page 5: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS ELASTIC BEANSTALK

QUICKLY DEPLOY AND MANAGE APPLICATIONS

Page 6: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 7: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 8: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 9: Deployment and Management on AWS: A Deep Dive on Options and Tools

Application

Application Version Environment

!

!Environment Configuration

Configuration Template

Page 10: Deployment and Management on AWS: A Deep Dive on Options and Tools

NEW FEATURES SINGLE INSTANCE

WORKER ROLE

Page 11: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 12: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 13: Deployment and Management on AWS: A Deep Dive on Options and Tools

.ebextensions/01install.config

packages: yum: libmemcached: [] ruby-devel: [] gcc: [] rubygems: chef: '0.10.2' apt: mysql-client: []

packages: msi: mysql: http://dev.mysql.com/.../mysql-connector-net-6.6.5.msi/.../

Page 14: Deployment and Management on AWS: A Deep Dive on Options and Tools

.ebextensions/02copy.config

files: "/home/ec2-user/myfile" : mode: "000777" owner: ec2-user group: ec2-user source: http://foo.bar/myfile "/home/ec2-user/myfile2" : mode: "000777" owner: ec2-user group: ec2-user content: | # this is my file # with content

Page 15: Deployment and Management on AWS: A Deep Dive on Options and Tools

.ebextensions/03run.config

commands: test: command: myscript.py cwd: /home/ec2-user env: myvarname: myvarvalue

Page 16: Deployment and Management on AWS: A Deep Dive on Options and Tools

.ebextensions/04run_after.config

container_commands: collectstatic: command: "django-admin.py collectstatic --noinput" 01syncdb: command: "django-admin.py syncdb --noinput" leader_only: true 02migrate: command: "django-admin.py migrate" leader_only: true 99customize: command: "scripts/customize.sh"

Page 17: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS Elastic Beanstalk Resource Types Reference

AWS Resource Resource Type Identifier

Amazon CloudWatch AWS::CloudWatch::Alarm

DynamoDB Table AWS::DynamoDB::Table

Amazon ElastiCache Cache Cluster AWS::ElastiCache::CacheCluster

Amazon ElastiCache Security Group AWS::ElastiCache::SecurityGroup

Amazon ElastiCache Security Group Ingress AWS::ElastiCache::SecurityGroupIngress

Amazon SNS Subscription AWS::SNS::Subscription

Amazon SNS Topic AWS::SNS::Topic

Amazon SQS Queue AWS::SQS::Queue

Page 18: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS Elastic Beanstalk Built-in Resources

Resource Name Description

AWSEBAutoScalingGroup The name of the Auto Scaling group that Elastic Beanstalk uses when it launches Amazon EC2 instances.

AWSEBAutoScalingLaunchConfiguration The name for the launch configuration settings that Elastic Beanstalk uses when it launches EC2 instances.

AWSEBEnvironmentName The name of the Elastic Beanstalk environment.

AWSEBLoadBalancer The name of the elastic load balancer used in the Elastic Beanstalk environment.

AWSEBRDSDatabase The name of the Amazon RDS database.

AWSEBSecurityGroup The name for the EC2 security group that Elastic Beanstalk uses when it launches EC2 instances.

Page 19: Deployment and Management on AWS: A Deep Dive on Options and Tools

Production Environment

Test Environment

master branch

test branch

Git Repository

git commit

git aws.push

git aws.push

Swap URLs

Page 20: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS OPSWORKS MODEL AND MANAGE

THE ENTIRE APPLICATION

Page 21: Deployment and Management on AWS: A Deep Dive on Options and Tools

STACKS

Page 22: Deployment and Management on AWS: A Deep Dive on Options and Tools

LAYERS

Page 23: Deployment and Management on AWS: A Deep Dive on Options and Tools

INSTANCES

Page 24: Deployment and Management on AWS: A Deep Dive on Options and Tools

APPS

Page 25: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 26: Deployment and Management on AWS: A Deep Dive on Options and Tools

LIFE CYCLE EVENTS

setup configure deploy undeploy shutdown

Page 27: Deployment and Management on AWS: A Deep Dive on Options and Tools

CONTINUOUS CONFIGURATIONne

w /

stop

ped

onlin

e

requ

este

d pe

nding

bo

oting

setup

configure

terminating shutting down

deploy

configure

Page 28: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS OPSWORKS SAMPLE USE CASE

Page 29: Deployment and Management on AWS: A Deep Dive on Options and Tools

GATHER AND SHIP LOGS TO AMAZON S3 AS SOON AS

THE CPU LOAD IS TOO HIGH

Page 30: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS OPSWORKS STORES 1-MINUTE METRICS

IN CLOUDWATCH

Page 31: Deployment and Management on AWS: A Deep Dive on Options and Tools

EVERY INSTANCE CREATES AN ALARM FOR HIGH CPU LOAD

Page 32: Deployment and Management on AWS: A Deep Dive on Options and Tools

CLOUDWATCH ALARM ACTION:

WRITE TO SNS TOPIC

Page 33: Deployment and Management on AWS: A Deep Dive on Options and Tools

SNS PUBLISHES TO QUEUE IN SQS

Page 34: Deployment and Management on AWS: A Deep Dive on Options and Tools

WATCHER INSTANCE

POLLSSQS FOR

NOTIFICATIONS

Page 35: Deployment and Management on AWS: A Deep Dive on Options and Tools

ON ALARM NOTIFICATION,CALL OPSWORKS API TO …

Page 36: Deployment and Management on AWS: A Deep Dive on Options and Tools

EXECUTE A SCRIPT ON THE

AFFECTED SERVER

Page 37: Deployment and Management on AWS: A Deep Dive on Options and Tools

LOGS ARE GATHERED AND

WRITTEN TO AMAZON S3

Page 38: Deployment and Management on AWS: A Deep Dive on Options and Tools

CHEF 11.10 + BERKSHELF

Page 39: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS CLOUDFORMATION INFRASTRUCTURE IS CODE

Page 40: Deployment and Management on AWS: A Deep Dive on Options and Tools

CLOUDFORMATION TEMPLATE

Page 41: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 42: Deployment and Management on AWS: A Deep Dive on Options and Tools

Stack

Page 43: Deployment and Management on AWS: A Deep Dive on Options and Tools

Stack Template

Page 44: Deployment and Management on AWS: A Deep Dive on Options and Tools

Stack TemplateConditions

Resources

References

Mappings

Outputs

Parameters

Page 45: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Resources

References

Mappings

Outputs

Parameters

"Parameters" : {! "InstanceType" : {! "Type" : "String",! "Default" : "t1.micro",! "AllowedValues" : ["t1.micro", "m1.small", "m1.large"],! "Description" : "Enter t1.micro, m1.small, or m1.large. Default is t1.micro."! }!}

Page 46: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Resources

References

Mappings

Outputs

Parameters

"Mappings" : {!"RegionMap" : {! "us-east-1" : {! "AMI" : "ami-76f0061f"! },! "us-west-1" : {! "AMI" : "ami-655a0a20"! },! "eu-west-1" : {! "AMI" : "ami-7fd4e10b"! },! "ap-southeast-1" : {! "AMI" : "ami-72621c20"! }! }!}

Page 47: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Resources

References

Mappings

Outputs

Parameters "Parameters" : {! "EnvType" : {! "Description" : "Environment type.",! "Default" : "test",! "Type" : "String",! "AllowedValues" : ["prod", "test"]! }!},!!"Conditions" : {! "CreateProdInstance" : {"Fn::Equals" : [{"Ref" : "EnvType"}, "prod"]}!}!!"ProductionInstance" : {! "Type" : "AWS::EC2::Instance",! "Condition" : "CreateProdInstance",! "Properties" : {! "InstanceType" : "c1.xlarge",! "SecurityGroups" : [ { "Ref" : "ProdSecurityGroup" } ],! "KeyName" : { "Ref" : "ProdKeyName" },! "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}! }!}

Page 48: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Resources

References

Outputs

Parameters

"Resources" :{! "MySimpleImage" : {! "Type" : "AWS::EC2::Image",! "Properties" : {! "ImageId" : "myLinuxBundle-2011-12-30",! }! }!}

Mappings

Page 49: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

References

Outputs

Parameters

"Parameters" : {! "MyURL" : {! "Type" : "String",! "Default" : "http://aws.amazon.com"! },!! ...!!"Outputs" : {! "URL" : {! "Value" : { "Ref" : "MyURL" }! }!}

Mappings

Resources

Page 50: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Outputs

Parameters

"Outputs" : {! "URL" : {! "Value" : "http://aws.amazon.com/cloudformation"! }!}

Mappings

Resources

References

Page 51: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Outputs

Mappings

References

Pseudo Parameters

Resource Properties

Parameters

Resources

Intrinsic Functions

Page 52: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Outputs

Mappings

References

Pseudo Parameters

Resource Properties

Parameters

Resources

Resources : {! "MyVolume" : {! "Type" : "AWS::EC2::Volume",! "Properties" : {! "Size" : "4",! "SnapshotId" : "snap234",! "AvailabilityZone" : "us-east-1a"! }! }! }

Intrinsic Functions

Page 53: Deployment and Management on AWS: A Deep Dive on Options and Tools

Conditions

Outputs

Mappings

References

Pseudo Parameters

Resource Properties

Parameters

Resources

"Outputs" {! "MyStacksRegion" : { "Value" : { "Ref" : "AWS::Region" } }!}

Intrinsic Functions

Page 55: Deployment and Management on AWS: A Deep Dive on Options and Tools

Stack TemplateConditions

Resources

References

Mappings

Outputs

Parameters Pseudo Parameters

Resource Properties

Intrinsic Functions

Page 56: Deployment and Management on AWS: A Deep Dive on Options and Tools

{    "Description"  :  "Create  RDS  with  username  and  password",    "Resources"  :  { !

       "MyDB"  :  {            "Type"  :  "AWS::RDS::DBInstance",            "Properties"  :  {                "AllocatedStorage"  :  "500",                "DBInstanceClass"  :  "db.m1.small",                "Engine"  :  "MySQL",                "EngineVersion"  :  "5.6",                "MasterUsername"  :  "MyName",                "MasterUserPassword"  :  "MyPassword"            }        }    } }

Page 57: Deployment and Management on AWS: A Deep Dive on Options and Tools

"AWS::CloudFormation::Init"  :  {    "config"  :  { !

       "packages"  :  {            "yum"  :  {                "mysql"                :  [],                "mysql-­‐server"  :  [],                "httpd"                :  [],                "php"                    :  [],                "php-­‐mysql"        :  []            }        },          "sources"  :  {            "/var/www/html"  :                  "https://s3.amazonaws.com/my-­‐builds/build-­‐v4.zip"        }    }

Page 58: Deployment and Management on AWS: A Deep Dive on Options and Tools

{      "Parameters"  :  {    "KeyName"  :  {            "Description"  :  "Name  of  an  existing  EC2                                              KeyPair  to  enable  SSH                                              access  to  the  instance",            "Type"  :  "String"        }    }, }

Page 59: Deployment and Management on AWS: A Deep Dive on Options and Tools
Page 60: Deployment and Management on AWS: A Deep Dive on Options and Tools

AMAZON EC2 API / SDK / CLI

Page 61: Deployment and Management on AWS: A Deep Dive on Options and Tools

aws ec2 describe-instances! --filter Name=instance-state-name,Values=running,! Name=tag:aws:autoscaling:groupName,Values=XXX! --query Reservations[].Instances[].PublicDnsName! --output text

Page 62: Deployment and Management on AWS: A Deep Dive on Options and Tools

for ip in $(!!

aws ec2 describe-instances! --filter Name=instance-state-name,Values=running,! Name=tag:aws:autoscaling:groupName,Values=XXX! --query Reservations[].Instances[].PublicDnsName! --output text!!

); do ssh -t ec2-user@$ip "sudo yum update"; done!!

Page 63: Deployment and Management on AWS: A Deep Dive on Options and Tools

for ip in $(!!

aws ec2 describe-instances! --filter Name=instance-state-name,Values=running,! Name=tag:aws:autoscaling:groupName,Values=XXX! --query Reservations[].Instances[].PublicDnsName! --output text!!

); do ssh -t ec2-user@$ip "cd /app ; git pull"; done!!

Page 64: Deployment and Management on AWS: A Deep Dive on Options and Tools

for ip in $(!!

aws ec2 describe-instances! --filter Name=instance-state-name,Values=running,! Name=tag:aws:autoscaling:groupName,Values=XXX! --query Reservations[].Instances[].PublicDnsName! --output text!!

); do ssh -t ec2-user@$ip "/app/update.sh"; done!!

Page 65: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS CLI http://aws.amazon.com/cli/!

https://github.com/aws/aws-cli!

+!./jq!

https://github.com/stedolan/jq

Page 66: Deployment and Management on AWS: A Deep Dive on Options and Tools

aws sns list-subscriptions |! jq -c '.Subscriptions[] |! select(.Protocol == "sqs")' |! while read s! do! if [ "$(aws sqs get-queue-url —queue-name! $(echo $s | jq -r .Endpoint |! sed ’s/^arn:aws:sqs:[^:]*:[^:]*://')! 2>&1 >/dev/null ;! echo $?)" != "0" ]! then! echo "Unsubscribing $s ..."! aws sns unsubscribe —subscription-arn! $(echo $s | jq -r .SubscriptionArn)! echo "Done."! fi;! done

Page 67: Deployment and Management on AWS: A Deep Dive on Options and Tools

AWS Elastic Beanstalk

AWS OpsWorks

AWS CloudFormation

Amazon EC2

CONVENIENCE CONTROL

HIGH-LEVEL DO IT YOURSELF

Page 68: Deployment and Management on AWS: A Deep Dive on Options and Tools

DEPLOYMENT AND MANAGEMENT ON AWS:A DEEP DIVE ON OPTIONS AND TOOLSDanilo Poccia – Solutions Architect

Page 69: Deployment and Management on AWS: A Deep Dive on Options and Tools