deep dive: infrastructure as code

47
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved Infrastructure as Code with AWS CloudFormation Lee Kemp, Software Development Manager, AWS

Upload: amazon-web-services

Post on 04-Aug-2015

390 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Deep Dive: Infrastructure as Code

©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved

Infrastructure as Code

with AWS CloudFormationLee Kemp, Software Development Manager, AWS

Page 2: Deep Dive: Infrastructure as Code

You are on board …

continuous delivery

• services and applications

DevOps

• culture, automation, measurement, sharing

cloud

• infrastructure-as-code

Business needs to experiment, innovate, reduce risk

Page 3: Deep Dive: Infrastructure as Code

AWS CloudFormation

Page 4: Deep Dive: Infrastructure as Code

AWS CloudFormation

• Create templates of the infrastructure and applications you want to run on AWS

• Have the CloudFormation service automatically provision the required AWS resources and their relationships from the templates

• Easily version control, replicate, or update the infrastructure and applications using the templates

• Integrate with other development, CI/CD, and management tools

Page 5: Deep Dive: Infrastructure as Code

Basic workflow

design

create infrastructure

templates

write application

code

create stacks

iterate

Page 6: Deep Dive: Infrastructure as Code

depends on

Design: Building a food-ordering service

food catalog website

ordering website

customer DB service

inventory service

recommendations service

analytics servicefulfillment

service

payment

service

Page 7: Deep Dive: Infrastructure as Code

Create template for the food catalog website

security group

Auto Scaling group

EC2

instance

Elastic Load

Balancing

customer DB service

inventory service

recommendations service

software pkgs,

config, and data

CloudWatch

alarms

ElastiCache

Page 8: Deep Dive: Infrastructure as Code

Create template: Resources

security group

Auto Scaling group

EC2

instance

Elastic Load

Balancing

Software pkgs,

config, and data

CloudWatch

alarms

"Resources" : {"SecurityGroup" : {},"WebServerGroup" : {

"Type" : "AWS::AutoScaling::AutoScalingGroup","Properties" : {

"MinSize" : "1","MaxSize" : "3","LoadBalancerNames" : [ { "Ref" :

"LoadBalancer" } ],...

}},"LoadBalancer" : {},"CacheCluster" : {},"Alarm" : {}

},

CloudFormation template

ElastiCache

Page 9: Deep Dive: Infrastructure as Code

Create template: Parameters

Auto Scaling group

EC2

instance

recommendations Service

inventory service

customer DB service

info to customize stack at creation

Examples: instance type, app package version

"Parameters" : {"CustomerDBServiceEndPoint" : {

"Description" : "URL of the Customer DB Service","Type" : "String"

},"CustomerDBServiceKey" : {

"Description" : "API key for the Customer DB Service",

"Type" : "String","NoEcho" : "true"

},"InstanceType" : {

"Description" : "WebServer EC2 instance type","Type" : "String","Default" : "m3.medium","AllowedValues" :

["m3.medium","m3.large","m3.xlarge"],"ConstraintDescription" : "Must be a valid

instance type"

CloudFormation template

Page 10: Deep Dive: Infrastructure as Code

Create template: Outputs

Elastic Load

Balancing

"Resources" : {

"LoadBalancer" : {},

...

},

"Outputs" : {

"WebsiteDNSName" : {

"Description" : "The DNS name of the website",

"Value" : {

"Fn::GetAtt" : [ "LoadBalancer", "DNSName" ]

}

}

}

CloudFormation template

Page 11: Deep Dive: Infrastructure as Code

Create template: Deploy and configure software

Auto Scaling group

EC2

instance

Software pkgs,

config, and data

"AWS::CloudFormation::Init": {

"webapp-config": {

"packages" : {}, "sources" : {}, "files" : {},

"groups" : {}, "users" : {},

"commands" : {}, "services" : {}

},

"chef-config" : {}

}

CloudFormation template

declarative

debuggable

updatable

highly secure

BIOT™ (Bring in

Other Tools)

Page 12: Deep Dive: Infrastructure as Code

Create template: Language features

Page 13: Deep Dive: Infrastructure as Code

Create stack

Page 14: Deep Dive: Infrastructure as Code

Operate stack

Page 15: Deep Dive: Infrastructure as Code

Use a wide range of AWS services

Auto Scaling

Amazon CloudFront

AWS CloudTrail

Amazon CloudWatch

AWS Data Pipeline (new)

Amazon DynamoDB

Amazon EC2

Amazon ECS (new)

Amazon ElastiCache

AWS Elastic Beanstalk

Elastic Load Balancing

AWS managed policies in IAM (new)

Amazon Kinesis

AWS Lambda (new)

AWS OpsWorks

Amazon RDS

Amazon Redshift

Amazon Route 53

Amazon S3

Amazon SimpleDB

Amazon SNS

Amazon SQS

Amazon VPC

and more …

Page 16: Deep Dive: Infrastructure as Code

Basic workflow

design

create infrastructure

templates

write application

code

create stacks

iterate

Page 17: Deep Dive: Infrastructure as Code

Infrastructure-as-code workflow

codeversion control

code review

integrate

“It’s all software”

Page 18: Deep Dive: Infrastructure as Code

“It’s all software” – Organize like it’s software

front-end services

• consumer website, seller website, mobile back end

back-end services

• search, payments, reviews, recommendations

shared services

• CRM DBs, common monitoring /alarms, subnets, security groups

base network

• VPCs, Internet gateways, VPNs, NATs

identity • IAM users, groups, roles

Page 19: Deep Dive: Infrastructure as Code

“It’s all software” – Build and operate like it’s

software

application software

source code

package

loader/interpreter

desired application state in memory

infrastructure software

JSON templates/JSON template generators

JSON templates

AWS CloudFormation

desired infrastructure in the cloud

Page 20: Deep Dive: Infrastructure as Code

Iterate on infrastructure

Page 21: Deep Dive: Infrastructure as Code

Update stack

in place blue-green

faster

cost-efficient

simpler state and

data migration

working stack

not touched

Page 22: Deep Dive: Infrastructure as Code

Extending AWS CloudFormation

Page 23: Deep Dive: Infrastructure as Code

Extend with custom resources

security group

Auto Scaling group

EC2

instance

Elastic Load

Balancing

software pkgs,

config, and data

CloudWatch

alarms

Web Analytics

ServiceAWS

CloudFormation

provision

AWS resources

"Resources" : {

"WebAnalyticsTrackingID" : {

"Type" : "Custom::WebAnalyticsService::TrackingID",

"Properties" : {

"ServiceToken" : "arn:aws:sns:...",

"Target" : {"Fn::GetAtt" : ["LoadBalancer", "DNSName"]},

"Plan" : "Gold"

}

},

...

“success” + metadata

“create, update, roll back, or delete”

+ metadata

ElastiCache

Page 24: Deep Dive: Infrastructure as Code

Lambda-powered custom resources

security group

Auto Scaling group

EC2

instance

Elastic Load

Balancing

software pkgs,

config, and data

CloudWatch

alarms

your AWS CloudFormation stack

// implement custom logic here

look up an AMI ID

your AWS Lambda functions

look up VPC ID and subnet ID

reverse an IP address

Lambda-powered

custom resources

ElastiCache

Page 25: Deep Dive: Infrastructure as Code

Application deployment as code

Page 26: Deep Dive: Infrastructure as Code

infrastructure provisioning

EC2

SQS, SNS, Amazon Kinesis, etc.

databases

VPC

IAM

application deployment

download packages, install software, configure

apps, bootstrap apps, update software, restart

apps, etc.

CloudFormation

• templatize

• replicate

• automate

Page 27: Deep Dive: Infrastructure as Code

Application deployment as code

inside a CloudFormation template

Amazon Machine Images

CloudFormation::Init

Chef, Puppet, CodeDeploy

OpsWorks

Chef

Page 28: Deep Dive: Infrastructure as Code

Metadata

AWS::CloudFormation::Init

AWS::CloudFormation::Init

declarative

reusable

grouping and ordering

debuggable

updatable

highly secure

BIOT™ (Bring in Other Tools)

ow.ly/DiNCm

Page 29: Deep Dive: Infrastructure as Code

AWS::CloudFormation::Init

"AWS::CloudFormation::Init": {

"webapp-config": {

"packages" : {}, "sources" : {}, "files" : {},

"groups" : {}, "users" : {},

"commands" : {}, "services" : {}

Declarative

Page 30: Deep Dive: Infrastructure as Code

AWS::CloudFormation::Init

Debuggable

Page 31: Deep Dive: Infrastructure as Code

AWS::CloudFormation::Init

Supports updates

"packages" : {}, "sources" : {}, "files" : {}, "groups" : {}, "users" : {},"commands" : {}, "services" : {}

Page 32: Deep Dive: Infrastructure as Code

AWS::CloudFormation::Init

"install_chef" : {},

"install_wordpress" : {

"commands" : {

"01_get_cookbook" : {}, ...,

"05_configure_node_run_list" : {

"command" : "knife node run_list add -z `knife node list -z` recipe[wordpress]",

"cwd" : "/var/chef/chef-repo",

"env" : { "HOME" : "/var/chef" }

Flexibility to bring in other tools, such as AWS CodeDeploy and Chef

ow.ly/DiNkz

Page 33: Deep Dive: Infrastructure as Code

AWS::CloudFormation::Init

"YourInstance": {

"Metadata": {

"AWS::CloudFormation::Authentication": {

"S3AccessCreds": {

"type": "S3",

"roleName": { "Ref" : "InstanceRole"},

"buckets" : ["your-bucket"]

}

},

"AWS::CloudFormation::Init": {}

Supports role-based authentication

securely download

choose auth type

IAM role is

recommended

ow.ly/DqkrB

Page 34: Deep Dive: Infrastructure as Code

Use AWS::CloudFormation::Init

"UserData": {

"# Get the latest CloudFormation helper scripts package\n","yum update -y aws-cfn-bootstrap\n",

"# Trigger CloudFormation::Init configuration \n","/opt/aws/bin/cfn-init --stack ", {"Ref": "AWS::StackId"},

" --resource WebServerInstance ", " --region ", {"Ref": "AWS::Region"}, "\n",

"# Signal completion\n","/opt/aws/bin/cfn-signal –e $? --stack ", {"Ref": "AWS::StackId"},

" --resource WebServerInstance ", " --region ", {"Ref": "AWS::Region"}, "\n"

Page 35: Deep Dive: Infrastructure as Code

Use CloudWatch Logs for debugging

"install_logs": {

"packages" : { ... "awslogs" ... },

"services" : { ... "awslogs" ... }

"files": {

"/tmp/cwlogs/cfn-logs.conf": {}

file = /var/log/cfn-init.loglog_stream_name = {instance_id}/cfn-init.log

file = /var/log/cfn-hup.loglog_stream_name = {instance_id}/cfn-hup.log

ow.ly/E0zO3

Page 36: Deep Dive: Infrastructure as Code

Use CloudWatch Logs for debugging

ow.ly/E0zO3

Page 37: Deep Dive: Infrastructure as Code

Bake AMIs for faster booting and for maintaining

golden images

dev/test stacks bake AMI staging/prod stacks

tracking

Page 38: Deep Dive: Infrastructure as Code

Using CloudFormation and OpsWorks

together

Page 39: Deep Dive: Infrastructure as Code

infrastructure provisioning

EC2

SQS, SNS, Amazon Kinesis, etc.

databases

VPC

IAM

application deployment

download packages, install software, configure

apps, bootstrap apps, update software, restart apps, etc.

CloudFormation

• templatize

• replicate

• automate

OpsWorks

• built-in application lifecycle

• interactive application console

OpsWorks and CloudFormation side by side

Page 40: Deep Dive: Infrastructure as Code

OpsWorks

• built-in application lifecycle

• interactive application console

infrastructure provisioning

EC2

SQS, SNS, Amazon Kinesis, etc.

databases

VPC

IAM

application deployment

download packages, install software, configure

apps, bootstrap apps, update software, restart apps, etc.

CloudFormation

• templatize

• replicate

• automate

OpsWorks “inside” CloudFormation

Page 41: Deep Dive: Infrastructure as Code

Infrastructure-as-code in a CI/CD pipeline

Page 42: Deep Dive: Infrastructure as Code

CloudFormation in a CI/CD pipeline

AWS CloudFormationIssue Tracker

app developers

DevOps engineers,infrastructure developers,

systems engineers

dev env code repo

app pkgs, CloudFormationtemplates, etc.

CI server

test

staging

prodcode review

“infrastructure as code"

app code and templates

Page 43: Deep Dive: Infrastructure as Code

Templatize existing resources

Page 44: Deep Dive: Infrastructure as Code

CloudFormer: Templatize existing resources

1. Launch a CloudFormer

application stack

2. Walk through the

CloudFormer UI and select

resources to templatize

4. Customize

Example: parameterize

resource properties

5. Create a new stack

Page 45: Deep Dive: Infrastructure as Code

Practitioners of infrastructure-as-code

• Developers/DevOps teams value CloudFormation for its ability to treat infrastructure as code, allowing them to apply software engineering principles, such as SOA, revision control, code reviews, integration testing to infrastructure.

• IT admins and MSPs value CloudFormation as a platform to enable standardization, managed consumption, and role specialization.

• ISVs value CloudFormation for its ability to support scaling out of multi-tenant SaaS products by quickly replicating or updating stacks. ISVs also value CloudFormation as a way to package and deploy their software in their customer accounts on AWS.

Page 46: Deep Dive: Infrastructure as Code

CHICAGO

Page 47: Deep Dive: Infrastructure as Code

©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved

CHICAGO