+ All Categories
Home > Technology > AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Date post: 08-May-2015
Category:
Upload: amazon-web-services
View: 3,601 times
Download: 5 times
Share this document with a friend
Description:
AWS OpsWorks lets you model your application with layers that define the building blocks of your application: load balancers, application servers, databases, etc. But did you know that you can also extend OpsWorks layers or build your own custom layers? Whether you need to perform a specific task or install a new software package, OpsWorks gives you the tools to install and configure your instances consistently, and evolve them in an automated and predictable fashion through your application’s lifecycle. We'll dive into the development process including how to use attributes, recipes, and lifecycle events; show how to develop your environment locally; and provide troubleshooting steps that reduce your development time.
61
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc. DMG304 - AWS OpsWorks Under the Hood Jonathan Weiss & Reza Spagnolo, Amazon Web Services November 14 th , 2013
Transcript
Page 1: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc.

DMG304 - AWS OpsWorks Under the Hood

Jonathan Weiss & Reza Spagnolo, Amazon Web Services

November 14th, 2013

Page 2: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Agenda

• AWS OpsWorks event life cycle

• How to use custom cookbooks: MongoDB

• Chef in AWS OpsWorks vs. Chef server

Page 3: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Event Life Cycle

Page 4: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Agent on each

EC2 instance

The Heart of the Service

4

Agent on each

Amazon EC2 instance

Understands a set of commands that are

triggered by AWS OpsWorks.

The agent then runs a Chef solo run.

Page 5: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Life Cycle Events

5

setup configure deploy undeploy shutdown

Page 6: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Continuous Configuration new

Page 7: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Continuous Configuration new

Page 8: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Continuous Configuration new

onlin

e

setup

configure

Page 9: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Continuous Configuration new

onlin

e

setup

configure

deploy

Page 10: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Continuous Configuration n

ew

/ s

topped

onlin

e

setup

configure

terminating

shutting

down

deploy

configure

Page 11: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Setup Event

• Sent when instance boots

• Includes deploy event

• Use for initial installation

of software & services

Page 12: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Setup Event – Recipe Execution Order

AWS OpsWorks

setup recipes

Your setup recipes

AWS OpsWorks

deploy recipes

Your deploy recipes

Page 13: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Configure Event

• Sent to all instances when

any instance enters or

leaves online state

• Use for making sure the

configuration is up-to-date

Page 14: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Deploy Event

• Sent by deploy via UI/API

and is also part of each

setup

• Use for custom deployment

Page 15: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Undeploy Event

• Sent via UI/API when

apps are deleted

• Use to remove apps from

running instances

Page 16: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Shutdown Event

• Sent when an instance

is shut down

• ~45s to execute

• Use for clean shutdown

Page 17: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Customizing AWS OpsWorks

Page 18: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Customization Options

Built-in layers

Override Chef attributes via custom JSON

Override Chef attributes via custom cookbook

Overwrite Chef template file

Deploy hooks

Provide custom recipe to extend built-in layer

Provide custom recipe to create custom layer contr

ol

sim

ple

Page 19: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Built-in Layers

Open Source at http://github.com/aws/opsworks-cookbooks

Rails MySQL

PHP HAProxy

Node.js Memcached

Java Ganglia

Page 20: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Chef Templates

Template for /etc/apache2/apache2.conf

Page 21: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom JSON

Override Chef attributes of built-in cookbooks

# in apache2/attributes/default.rb default[:apache][:timeout] = 120

node.apache.timeout # => 60

{ ‘apache2‘: {‘timeout‘: 60 } }

Page 22: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Cookbook Attributes

Override Chef attributes of built-in cookbooks

# in apache2/attributes/default.rb default[:apache][:timeout] = 120

node.apache.timeout # => 60

# in mycookbook/attributes/apache.rb set[:apache][:timeout] = 60

Page 23: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Overwriting Chef Templates

Provide custom file at same location

$ cat mycookbook-repo/apache2/templates/apache2.conf.erb ... # # Example custom content # LogLevel error # change default type DefaultType text/json

Page 24: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Deploy Hooks

$ ls myapp/deploy/

before_migrate.rb

before_symlink.rb

before_restart.rb

after_restart.rb

Hooks use Capistrano syntax

Page 25: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Example Deploy Hook

Rails asset pipeline support

$ cat deploy/before_symlink.rb run "cd #{release_path} && \

RAILS_ENV=production bundle exec rake assets:precompile

sudo "/etc/init.d/myservice restart"

Page 26: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Cookbooks

Page 27: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Layers

Run anything that is scriptable with Chef – Erlang app server

– Cassandra DB cluster

– C daemon

– Custom PHP install

– …

Page 28: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Layers

Page 29: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Layers

Page 30: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Layers

$ ls mycookbook-repo/erlang/

recipes/install.rb

recipes/uninstall.rb

$ ls mycookbook-repo/e-app/

recipes/deploy.rb

recipes/undeploy.rb

Page 31: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom Layers

Page 32: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Different Configuration Managers

Call bash script from Chef bash "legacy bootstrap" do user "root" cwd "/tmp" code <<-EOH wget http://www.example.com/installer.tar.gz tar -zxf installer.tar.gz cd installer ./configure make make install EOH end

Page 33: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

AWS OpsWorks Attribute Tree

Custom JSON

Stack configuration JSON

Deployment JSON

Cookbook attributes

Chef - Ohai

Sources:

Page 34: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

AWS OpsWorks Attribute Tree - Categories

Multiple categories and namespaces

node[:opsworks]

node[:opsworks][:layers]

node[:opsworks][:instance]

node[:opsworks][:stack]

Built in layer specific -> i.e. node[:opsworks_java]

Built in recipe specific -> i.e. node[:apache2]

Page 35: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Walkthrough:

MongoDB on AWS OpsWorks

Page 36: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Architecture – MongoDB Replica Set

Page 37: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Objectives

• MongoDB as custom layer

• Use community cookbook

• Extend Java application layer

• Manage system life cycle

Page 38: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

MongoDB Custom Layer

• Chef community cookbook for MongoDB – https://github.com/edelight/chef-mongodb

• Cookbook functionality – Install

– Register with peers

– Service startup

– Clean shutdown

Page 39: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

MongoDB Custom Layer - Recipes

Page 40: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

MongoDB Custom Layer - Changes

Enable node discovery through AWS OpsWorks JSON

def replicaset_members(node)

replicaset_layer = node['opsworks']['instance']['layers'].first

instances = node['opsworks']['layers'][replicaset_layer]['instances']

instances.map do |name, instance|

member = Chef::Node.new

member.name(name)

member.default['hostname'] = name

member.default['fqdn'] = instance['private_dns_name']

member.default['ipaddress'] = instance['private_ip']

member

end

end

Page 41: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

MongoDB Custom Layer - Configuration

Custom JSON in MongoDB stack

Made available to every

Chef recipe

Integrates out of the box

with community cookbook

Page 42: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

MongoDB Custom Layer – EBS Setup

AWS OpsWorks support for EBS RAID

Setup the mount point passed through custom JSON

Page 43: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Extend Application Layer - Configure

Leverage configure

event definition of

built-in Java layer

Page 44: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Extend Application Layer - Template

Override application context template of built-in Java layer

$ cat opsworks_java/templates/default/webapp_context.xml.erb

<%

replicaset_name = node['mongodb']['replicaset_name']

mongo_nodes = node['opsworks']['layers'][replicaset_name]

['instances'].keys.map{|name| "#{name}:27017"}.join(",")

%>

<Context>

<Environment name="mongoNodes"

type="java.lang.String"

value="<%= mongo_nodes %>" />

</Context>

Page 45: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Package Your Custom Cookbook

Package your cookbook and its dependencies in a

single archive

java-mongodb-compound-cookbook/

├── apt/

├── build-essential/

├── python/

├── yum/

├── opsworks_java/

└── chef-mongodb/

Page 46: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Done !

Page 47: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Chef in AWS OpsWorks

vs.

Chef Server

Page 48: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Main Differences

• Chef setup

• One run vs. discrete events

• Push vs. pull

• Discovery: search & AWS OpsWorks attribute tree

• Data bags

Page 49: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Chef Setup

Chef Solo

&

AWS OpsWorks Backend

Chef Client

&

Chef Server

Page 50: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Life Cycle Events

• Give you fine-grained control

• Faster to execute

• Context

Page 51: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Push vs. Pull

• On-demand and automatic

• Respond immediately to changes in the stack

Page 52: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Discovery: Chef Search

AWS OpsWorks does not offer attribute search

Alternative:

node[:opsworks] with similar capabilities

to partial_search

Page 53: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

AWS OpsWorks Attribute Tree

Find all Rails application servers

rails_servers = node['opsworks']['layers']['rails-app']['instances']

rails_ips = rails_servers.map{|i| i['private_ip'] }

template "/etc/rails-server.conf" do

...

variables({

:ips => rails_server_ips

})

end

Page 54: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Encrypted Data Bags

• Upload encrypted JSON to S3

• Have instances access via IAM roles in a recipe

Page 55: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Custom JSON

Arbitrary JSON on stack that is available in Chef

if node.foo.bar ... elsif node.foo.baz ... end

{ ‘foo‘: { ‘bar‘: true, ‘baz‘: false } }

Page 56: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Store Secrets on Amazon S3

Access from instance via instance profiles

bucket = node['acme']['bucket'] key = node['acme']['key'] s3 = AWS::S3.new obj = s3.buckets[bucket].objects[key] obj.read

Page 57: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Recap

Page 58: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

AWS OpsWorks

• Life cycle framework

• Highly customizable

• Run anything

Page 59: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

More Information about AWS OpsWorks

• Do the AWS OpsWorks lab!

• Find us on the AWS Booth

• Follow us on twitter @AWSOpsWorks

• Find us on YouTube

• Blog: http://blogs.aws.amazon.com/application-management

• Survey: http://tinyurl.com/OpsWorksSurvey2013

Page 60: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Recommend Sessions

DMG305 - How Intuit Leveraged AWS OpsWorks

as the Engine of Our PaaS

Capen Brinkley & Rick Mendes of Intuit, inc.

Thursday, Nov 14, 4:15 PM - 5:15 PM – Murano 3206

Page 61: AWS OpsWorks Under the Hood (DMG304) | AWS re:Invent 2013

Please give us your feedback on this

presentation

As a thank you, we will select prize

winners daily for completed surveys!

DMG304


Recommended