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

990 views
826 views

Published on

AWS Elastic Beanstalk
AWS OpsWorks
AWS CloudFormation
Amazon EC2

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
990
On SlideShare
0
From Embeds
0
Number of Embeds
57
Actions
Shares
0
Downloads
31
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. DEPLOYMENT AND MANAGEMENT ON AWS:
 A DEEP DIVE ON OPTIONS AND TOOLS Danilo Poccia – Solutions Architect
  2. 2. AWS Elastic Beanstalk AWS OpsWorks AWS CloudFormation Amazon EC2 CONVENIENCE CONTROL HIGH-LEVEL DO IT YOURSELF
  3. 3. AWS Elastic Beanstalk AWS OpsWorks AWS CloudFormation Amazon EC2 CONVENIENCE CONTROL HIGH-LEVEL DO IT YOURSELF
  4. 4. AWS Elastic Beanstalk AWS OpsWorks AWS CloudFormation Amazon EC2 CONVENIENCE CONTROL HIGH-LEVEL DO IT YOURSELF
  5. 5. AWS ELASTIC BEANSTALK QUICKLY DEPLOY AND MANAGE APPLICATIONS
  6. 6. Application Application Version Environment ! !Environment Configuration Configuration Template
  7. 7. NEW FEATURES SINGLE INSTANCE WORKER ROLE
  8. 8. .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/.../
  9. 9. .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
  10. 10. .ebextensions/03run.config commands: test: command: myscript.py cwd: /home/ec2-user env: myvarname: myvarvalue
  11. 11. .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"
  12. 12. 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
  13. 13. 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.
  14. 14. Production Environment Test Environment master branch test branch Git Repository git commit git aws.push git aws.push Swap URLs
  15. 15. AWS OPSWORKS MODEL AND MANAGE THE ENTIRE APPLICATION
  16. 16. STACKS
  17. 17. LAYERS
  18. 18. INSTANCES
  19. 19. APPS
  20. 20. LIFE CYCLE EVENTS setup configure deploy undeploy shutdown
  21. 21. CONTINUOUS CONFIGURATIONnew/stopped online requested pending booting setup configure terminating shutting down deploy configure
  22. 22. AWS OPSWORKS SAMPLE USE CASE
  23. 23. GATHER AND SHIP LOGS TO AMAZON S3 AS SOON AS THE CPU LOAD IS TOO HIGH
  24. 24. AWS OPSWORKS STORES 1-MINUTE METRICS IN CLOUDWATCH
  25. 25. EVERY INSTANCE CREATES AN ALARM FOR HIGH CPU LOAD
  26. 26. CLOUDWATCH ALARM ACTION:
 WRITE TO SNS TOPIC
  27. 27. SNS PUBLISHES TO QUEUE IN SQS
  28. 28. WATCHER INSTANCE POLLS
 SQS FOR NOTIFICATIONS
  29. 29. ON ALARM NOTIFICATION,
 CALL OPSWORKS API TO …
  30. 30. EXECUTE A SCRIPT ON THE
 AFFECTED SERVER
  31. 31. LOGS ARE GATHERED AND
 WRITTEN TO AMAZON S3
  32. 32. CHEF 11.10 + BERKSHELF
  33. 33. AWS CLOUDFORMATION INFRASTRUCTURE IS CODE
  34. 34. CLOUDFORMATION
 TEMPLATE
  35. 35. Stack
  36. 36. Stack Template
  37. 37. Stack Template Conditions Resources References Mappings Outputs Parameters
  38. 38. 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."! }! }
  39. 39. 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"! }! }! }
  40. 40. 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" ]}! }! }
  41. 41. Conditions Resources References Outputs Parameters "Resources" :{! "MySimpleImage" : {! "Type" : "AWS::EC2::Image",! "Properties" : {! "ImageId" : "myLinuxBundle-2011-12-30",! }! }! } Mappings
  42. 42. Conditions References Outputs Parameters "Parameters" : {! "MyURL" : {! "Type" : "String",! "Default" : "http://aws.amazon.com"! },! ! ...! ! "Outputs" : {! "URL" : {! "Value" : { "Ref" : "MyURL" }! }! } Mappings Resources
  43. 43. Conditions Outputs Parameters "Outputs" : {! "URL" : {! "Value" : "http://aws.amazon.com/cloudformation"! }! } Mappings Resources References
  44. 44. Conditions Outputs Mappings References Pseudo Parameters Resource Properties Parameters Resources Intrinsic Functions
  45. 45. 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
  46. 46. Conditions Outputs Mappings References Pseudo Parameters Resource Properties Parameters Resources "Outputs" {! "MyStacksRegion" : { "Value" : { "Ref" : "AWS::Region" } }! } Intrinsic Functions
  47. 47. Conditions Outputs Mappings References Pseudo Parameters Resource Properties Parameters Resources "Outputs" : {! "URL" : {! "Value" : { "Fn::GetAtt" : [ "MyLoadBalancer", "DNSName" ] }! }! } Intrinsic Functions Name Fn::Base64 Fn::FindInMap Fn::GetAtt Fn::GetAZs Fn::Join Ref
  48. 48. Stack Template Conditions Resources References Mappings Outputs Parameters Pseudo Parameters Resource Properties Intrinsic Functions
  49. 49. {    "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"            }        }    } }
  50. 50. "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"        }    }
  51. 51. {      "Parameters"  :  {    "KeyName"  :  {            "Description"  :  "Name  of  an  existing  EC2
                                              KeyPair  to  enable  SSH
                                              access  to  the  instance",            "Type"  :  "String"        }    }, }
  52. 52. AMAZON EC2 API / SDK / CLI
  53. 53. aws ec2 describe-instances! --filter Name=instance-state-name,Values=running,! Name=tag:aws:autoscaling:groupName,Values=XXX! --query Reservations[].Instances[].PublicDnsName! --output text
  54. 54. 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! !
  55. 55. 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! !
  56. 56. 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! !
  57. 57. AWS CLI http://aws.amazon.com/cli/! https://github.com/aws/aws-cli! +! ./jq! https://github.com/stedolan/jq
  58. 58. 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
  59. 59. AWS Elastic Beanstalk AWS OpsWorks AWS CloudFormation Amazon EC2 CONVENIENCE CONTROL HIGH-LEVEL DO IT YOURSELF
  60. 60. DEPLOYMENT AND MANAGEMENT ON AWS:
 A DEEP DIVE ON OPTIONS AND TOOLS Danilo Poccia – Solutions Architect

×