Top Banner
63

AWS APAC Webinar Week - Getting The Most From EC2

Jan 24, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AWS APAC Webinar Week - Getting The Most From EC2
Page 2: AWS APAC Webinar Week - Getting The Most From EC2

aws.amazon.com/webinars/apac/webinar-week | #AWSWebinarWeek

Page 3: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2Albert Ho, Solution [email protected]

Page 4: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 5: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 6: AWS APAC Webinar Week - Getting The Most From EC2

v

EC2 Basics

Virtual Servers in the Cloud• One instance to thousands of instances• In any public AWS region• Create, start, stop, configure, monitor as desired• Install any software: web, business, client/server, batch processing• Pay only for capacity you use• Variety of cost models Amazon EC2

Page 7: AWS APAC Webinar Week - Getting The Most From EC2

v

EC2 Basics: cost models

On-Demand Reserved Spot Dedicated

Pay upfront in exchange for hourly prices that are 50-75% lower than

On-Demand

Pay for compute capacity by the hour. No long-term

commitments

Bid for unused Amazon EC2 capacity

Launch instances in VPC on dedicated customer hardware

Customers can combine multiple purchase types to optimize pricing based on current and forecast capacity needs.

Spiky workloads Committed utilization Time-insensitive workloads Highly sensitive workloads

Page 8: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 9: AWS APAC Webinar Week - Getting The Most From EC2

v

Provisioning and Lifecycle

• Create -> Start -> Stop -> Terminate• Manually in console• Automate via API (or other tools)• Automatically based on demand

(demand curve)

Page 10: AWS APAC Webinar Week - Getting The Most From EC2

Sunday Monday Tuesday Wednesday Thursday Friday Saturday

Typical weekly traffic to Amazon.com

Page 11: AWS APAC Webinar Week - Getting The Most From EC2

Typical weekly traffic to Amazon.com

Sunday Monday Tuesday Wednesday Thursday Friday Saturday

Provisioned capacity

Page 12: AWS APAC Webinar Week - Getting The Most From EC2

November traffic to Amazon.com

November

Page 13: AWS APAC Webinar Week - Getting The Most From EC2

November traffic to Amazon.com76%

24%

Provisioned capacity

November

Page 14: AWS APAC Webinar Week - Getting The Most From EC2

November

November traffic to Amazon.com - Match IT Resources to Application Demand

Page 15: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 16: AWS APAC Webinar Week - Getting The Most From EC2

v

Instance TypesGPU

EnabledGeneral Purpose

Storage and IOOptimized

ComputeOptimized

Memory Optimized

M3 C3 I2

CG1M1 C1 CR1CC2 HI1 HS1

G2

M3 C3 I2 HS1

M2

R3G2

Added Instance

Types

Page 17: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 18: AWS APAC Webinar Week - Getting The Most From EC2

v

Amazon Machine Images

Your machine images

AMIs you have created from EC2 instancesCan be kept private or shared with other

accounts

Amazon maintained

Set of Linux and Windows imagesKept up to date by Amazon in each

region

Community maintained

Images published by other AWS usersManaged and maintained by Marketplace

partners

Page 19: AWS APAC Webinar Week - Getting The Most From EC2

v

Amazon Machine Images

Page 20: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 21: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping

Bake an AMI

Start an instance

Configure the instance

Create an AMI from your instance

Start new ones from the AMI

Page 22: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping

Bake an AMI

Start an instance

Configure the instance

Create an AMI from your instance

Start new ones from the AMI

Configure dynamically

Launch an instance

Use metadata service and cloud-init to perform actions on

instance when it launches

vs

Page 23: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping

Bake an AMI Configure dynamically

Build your base images and setup custom initialisation

scripts

Maintain your ‘golden’ base

Use bootstrapping to pass custom information in and

perform post launch tasks like pulling code from SVN

+

Page 24: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping

Bake an AMI Configure dynamically

Time consuming configuration (startup time)

Static configurations (less change management)

Page 25: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping

Bake an AMI Configure dynamically

Continuous deployment (latest code)

Environment specific (dev-test-prod)

Page 26: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: some examples• Install latest software• Copy data from S3• Register with DNS• Start services• Update packages• Reboot• Open port 80• Register with load balancer• Mount devices

Page 27: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: tools• Scripts on instance • Config Management Tools; puppet, chef, others.• Amazon OpsWorks

Page 28: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: metadata and userdata

• Every EC2 Instance has access to local instance metadata and userdata service

Instance request

User data

Instance

Meta-data service

Page 29: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: metadata and userdata

• Metadata: immutable information about the instance• Accessible from within the instance via HTTP at

http://169.254.169.254/latest/meta-data/• Script(s) on instance may retrieve useful information about the instance, such as:

• Host name• AMI ID• Instance ID• Public/Private DNS• Availability Zone

• An Example: Using Metadata to retrieve the hostname: # curl http://169.254.169.254/latest/meta-data/hostname ip-172-31-10-12.ap-southeast-2.compute.internal

Page 30: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: metadata and userdata

• User Data: pass up to 16KB of text to an instance on launch• Accessible from within the instance via HTTP at

http://169.254.169.254/latest/user-data/• Text can be parsed by script on instance and used to configure the

machine

Page 31: AWS APAC Webinar Week - Getting The Most From EC2

v

Custom script on AMI

(script_runner.py) fetches userdata,

parses it, and configures EC2 Instance

on boot

Bootstrapping: metadata and userdata

Page 32: AWS APAC Webinar Week - Getting The Most From EC2

v• CloudInit executes UserData on first boot if UserData begins with:• #! (Linux)• <script> (Windows; technically, EC2Config, not CloudInit, does this)

• CloudInit is installed on Amazon Linux, Ubuntu, and RHEL AMIs• EC2Config is installed on Windows Server AMIs• Both may be installed on other distributions via a package repo or

source

Bootstrapping: UserData and CloudInit

Page 33: AWS APAC Webinar Week - Getting The Most From EC2

v• UserData to install Apache and MySQL on boot, and attach an EIP:

#!/bin/bash

# Install Apache, PHP, and MySQL yum install –y httpd mysql-server # Attach an Elastic IP to this instance ec2-associate-address \ 23.34.45.56 \

-i $(curl http://169.254.169.254/latest/meta-data/instance-id)

Bootstrapping: UserData and CloudInit

Page 34: AWS APAC Webinar Week - Getting The Most From EC2

v• Fully-Functional• Partially Configured• Base OS, Config with Code

Bootstrapping: AMIs

Page 35: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: AMIs

Linux

JEE

Your Code

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Java App Stack

Example full stack required to run your

application.

Let’s use the 3 AMI/bootstrapping

techniques

Page 36: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: AMIs

Fully-functional AMI is pre-build and

ready to launch from the AMI inventory

Inventory of AMIs

Linux

JEE

Your Code

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Amazon EC2

Linux

JEE

Your Code

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Linux

JEE

Your Code

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Linux

JEE

Your Code

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Linux

JEE

Your Code

Log4J

Spring

Hibernate

Struts

Tomcat

Apache

Java AMI

Page 37: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: AMIs

Partially-configured AMI

A “Golden Image” is launched, with

scripts fetching/installing app code

and other supporting components on

boot

Inventory of AMIs

Amazon EC2

Java AMI

Your Code

Log4JSpring

Struts

Linux

JEE

Hibernate

Tomcat

Apache

Fetch on boot

Fetch on boot

Linux

JEE

Hibernat

e

Tomcat

Apache

Linux

JEE

Hibernat

e

Tomcat

Apache

Linux

JEE

Hibernat

e

Tomcat

Apache

Linux

JEE

Hibernat

e

Tomcat

Apache

Page 38: AWS APAC Webinar Week - Getting The Most From EC2

v

Bootstrapping: AMIs

Base OS AMI

An AMI with minimal components (OS,

J2EE, and Chef/Puppet) is launched.

All configuration occurs via

Chef/Puppet after instance launch

Inventory of AMIs

Amazon EC2

OS AMI

Fetch on boot

Linux

JEE

Your Code

Hibernate

TomcatLog4J

Spring

StrutsApache

Linux

JEE

Linux

JEEChef/

Puppet

Chef/Puppet

scripts

Page 39: AWS APAC Webinar Week - Getting The Most From EC2

Why do this?

AutomationLess fingers, less mistakes

AvailabilityDrive higher

availability with self-healing

SecurityInstances locked down by default

FlexibleShell,

Powershell, CloudFormation,

Chef, Puppet, OpsWorks

ScaleManage large scale

deployments and drive autoscaling

EfficiencyAudit and manage your estate with less time & effort

Page 40: AWS APAC Webinar Week - Getting The Most From EC2

Do Don’t

Some dos and don’ts

Use IAM roles

Go keyless if you can

Strike a balance between AMI and dynamic bootstrapping

Put your API access keys into code (and then publish to GIT) or bake

into AMIs (and share)

Page 41: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 42: AWS APAC Webinar Week - Getting The Most From EC2

v

Monitoring EC2 with CloudWatch

Page 43: AWS APAC Webinar Week - Getting The Most From EC2

Getting The Most out of EC2EC2 BasicsInstance LifecycleEC2 Instance TypesUsing Amazon Machine ImagesBootstrapping EC2 InstancesMonitoring EC2 with CloudWatchAutoscaling

Page 44: AWS APAC Webinar Week - Getting The Most From EC2

v• Auto Scaling

• Scale your Amazon EC2 capacity up or down automatically according to conditions you define

• Ensure that the number of Amazon EC2 instances you’re using increases seamlessly during demand spikes to maintain performance, and decreases automatically during demand lulls to minimize costs

Autoscaling

Page 45: AWS APAC Webinar Week - Getting The Most From EC2

Describes what Auto Scaling will create when adding

Instances - Similar to ec2-run-instances API command

AMIInstance Type

Security GroupInstance Key Pair

Only one active launch configuration at a time

Auto Scaling will terminate instances with old launch

configuration firstrolling update

Auto Scaling managed grouping of EC2 instances

Automatic health check to maintain pool size

Automatically scale the number of instances by policy – Min, Max,

Desired

Automatic Integration with ELB

Automatic distribution & balancing across AZs

Parameters for performing an Auto Scaling action

Scale Up/Down and by how much

ChangeInCapacity (+/- #)ExactCapacity (#)

ChangeInPercent (+/- %)

Cool Down (seconds)

Policy can be triggered by CloudWatch events

Launch Configuration Auto-Scaling Group Auto-Scaling Policy

Page 46: AWS APAC Webinar Week - Getting The Most From EC2

v

Autoscaling

Page 47: AWS APAC Webinar Week - Getting The Most From EC2

v

Autoscaling

Page 48: AWS APAC Webinar Week - Getting The Most From EC2

v

Autoscaling

Page 49: AWS APAC Webinar Week - Getting The Most From EC2

v

Autoscaling

Page 50: AWS APAC Webinar Week - Getting The Most From EC2

v

Autoscaling

Page 51: AWS APAC Webinar Week - Getting The Most From EC2

v

Availability Zone A Availability Zone B

Autoscaling: Auto Scaling Group

Page 52: AWS APAC Webinar Week - Getting The Most From EC2

v

Availability Zone A Availability Zone B

Autoscaling: Auto Scaling Group

Page 53: AWS APAC Webinar Week - Getting The Most From EC2

v

Availability Zone A Availability Zone B

Autoscaling: Auto Scaling Group

Page 54: AWS APAC Webinar Week - Getting The Most From EC2

v

Availability Zone A Availability Zone B

Autoscaling: Auto Scaling Group

Page 55: AWS APAC Webinar Week - Getting The Most From EC2

v

Availability Zone A Availability Zone B

Autoscaling: Auto Scaling Group

Page 56: AWS APAC Webinar Week - Getting The Most From EC2

vLatency

CloudWatchAuto Scaling

ELB

Auto scaling Group

Autoscaling: ELB + CloudWatch

Page 57: AWS APAC Webinar Week - Getting The Most From EC2

v• Tools Used:

• CloudFormation script – • Create a multi-AZ, load balanced and Auto Scaled sample web site running on an Apache

Web Server. The application is configured to span all Availability Zones in the region and is Auto-Scaled based on the CPU utilization of the web servers.

• CPU script – • Logging on to an m1.small instance to generate CPU load (simulating heavy CPU usage)

to see the autoscaling working:• while true; do echo “running”; done

Autoscaling: DEMO

Page 58: AWS APAC Webinar Week - Getting The Most From EC2

v• CloudFormation script• Auto-scaling group configuration:

• Min: 1• Max: 3• Cooldown: 300

• Scaling Policies:• Scaling Up:

• CPU Utilization > 80% for 1 consecutive periods of 60 seconds• Action: Add 1 instance• Then wait: 60 seconds before next operation

• Scaling Down:• CPU Utilization < 30% for 1 consecutive periods of 60 seconds• Action: Remove 1 instance• Then wait: 60 seconds before next operation

• 100% CPU Script (NASTY): while true; do echo “running”; done

Demo Information

Page 59: AWS APAC Webinar Week - Getting The Most From EC2

Stop doing these:Provisioning and fixing servers

Treating compute as physical thingsThinking of compute as a finite commitment

Page 60: AWS APAC Webinar Week - Getting The Most From EC2

and start doing these

SecurityBuild systems secure by

default

ElasticityStateless autoscaling

applications

Replace not fixBuild from scratch, don’t

fix somethingUnconstrained

Say goodbye to traditional capacity

planning

Be cost awareTag resources, play with

instance types

AutomationCreate instances when you need them, drop

them when not

Page 61: AWS APAC Webinar Week - Getting The Most From EC2

Online Labs | Training

Gain confidence and hands-on experience with AWS. Watch free

Instructional Videos and explore Self-Paced Labs

Instructor Led Classes

Learn how to design, deploy and operate highly available, cost-effective and secure

applications on AWS in courses led by qualified AWS instructors

Validate your technical expertise with AWS and use practice exams

to help you prepare for AWS Certification

AWS Certification

http://aws.amazon.com/training

Page 62: AWS APAC Webinar Week - Getting The Most From EC2
Page 63: AWS APAC Webinar Week - Getting The Most From EC2

v

Questions?

[email protected]