Documente Academic
Documente Profesional
Documente Cultură
Amazon EC2
Ian Massingham — Technical Evangelist
ianmas@amazon.com
@IanMmmm
Masterclass
2 Intended to educate you on how to get the best from AWS services
3 Show you how things work and how to get things done
Amazon EC2
Elastic Web-Scale
Amazon EC2
Easy to Start Reliable
Inexpensive Secure
Amazon EC2
Agenda
INSTANCES
Choice of instance
Purchasing options
families with differing
for cost optimization
resource ratios Import and export
virtual machines
Available in
Different Locations
docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
Extensive list of
supported operating
systems & software
aws.amazon.com/marketplace
Integrated with
other AWS
Services
Reserved Instances
Provide you with a significant discount (up to 75%)
compared to On-Demand Instance pricing
Spot Instances
Purchase compute capacity with no upfront commitment
and at hourly rates usually lower than the On-Demand rate
aws.amazon.com/ec2/purchasing-options/
Import and export
virtual machines
aws.amazon.com/ec2/vm-import/
Choice of instance
families with differing
resource ratios
aws.amazon.com/ec2/instance-types/
Type
i2.xlarge (Storage-Optimized)
Generation Family
T2 Instances : Low Cost EC2 Instances with
Burstable Performance
docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-instances.html
C4 Instances : Highest Compute
Performance on Amazon EC2
docs.aws.amazon.com/AWSEC2/latest/UserGuide/c4-instances.html
Start an EC2 instance
Launch your instance using console, CLI tools
or an AWS SDK
Launch your instance
EC2 Instance
local-‐hostname
local-‐ipv4
mac
Metadata
network/
placement/
public-‐hostname
public-‐ipv4
public-‐keys/
reservation-‐id
security-‐groups
services/
$ curl http://169.254.169.254/latest/user-‐data
docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
Windows
EC2 User data <script>…</script>
or
AWS provided AMIs include services that access
and execute the contents of the User data <powershell>…</powershell>
attribute in EC2 Instance Metadata at instance
creation time
Connect to your
Connect to your instance (optional) instance using standard
protocols (ssh/RDP)
Launch your instance
docs.aws.amazon.com/cli/latest/reference/ec2/index.html
AWS CLI
In this case:
In this case:
docs.aws.amazon.com/cli/latest/reference/ec2/index.html
Launching and Terminating Instances Python Boto3
[ec2.Instance(id='i-‐a459450e')]
>>>
ec2.instances.filter(InstanceIds=[‘i-‐a459450e’]).terminate()
[{u'TerminatingInstances':
[{u'InstanceId':
'i-‐a459450e',
u'CurrentState':
{u'Code':
32,
u'Name':
'shutting-‐down'},
u'PreviousState':
{u'Code':
0,
u'Name':
'pending'}}],
'ResponseMetadata':
{'HTTPStatusCode':
200,
'RequestId':
'f3956d8f-‐
ce21-‐47f2-‐88fc-‐ac53cde3137f'}}]
>>>
github.com/boto/boto3
STORAGE
Data Storage Options
Instance Store Amazon EBS
Physically attached
Persistent block level
to the host computer storage volumes
Type and amount differs
Magnetic
by instance type
General Purpose (SSD)
Provisioned IOPS (SSD)
Data dependent upon Data independent of
instance lifecycle instance lifecycle
Instance Store
Physically attached
to the host computer Instance store data persists if:
• The OS in the instance is rebooted
• The instance is restarted
Type and amount differs
by instance type
Instance store data is lost when:
• An underlying instance drive fails
• An EBS-backed instance is stopped
instance lifecycle
EBS Volumes
Amazon EBS
EBS volumes automatically Persistent block level
replicated within the Availability storage volumes
Zone (AZ) in which are created
Use EBS-optimized instances to Magnetic
deliver dedicated throughput General Purpose (SSD)
between Amazon EC2 and Amazon
EBS, with options between 500 and
Provisioned IOPS (SSD)
4,000 Mbps, depending on the
instance type Data independent of
instance lifecycle
EBS Volumes Amazon EBS
EBS volumes attached to a running
instance automatically detach from
Persistent block level
the instance with their data intact storage volumes
when that instance is terminated.
Magnetic
EBS volumes created and attached to
an instance at launch are deleted General Purpose (SSD)
when that instance is terminated. You Provisioned IOPS (SSD)
can modify this behavior by changing
the value of the flag
DeleteOnTermination. Data independent of
instance lifecycle
Amazon EBS
EBS Snapshots
Persistent block level
An EBS snapshot is a point-in-time storage volumes
backup copy of an EBS volume that
is stored in Amazon S3 Magnetic
Snapshots are incremental, only the General Purpose (SSD)
blocks that have changed after your Provisioned IOPS (SSD)
most recent snapshot are saved
Data independent of
instance lifecycle
Amazon EBS
EBS Snapshots Persistent block level
storage volumes
When you delete a snapshot, only the
data exclusive to that snapshot is
removed Magnetic
General Purpose (SSD)
Can be shared across AWS accounts
or copied across AWS regions
Provisioned IOPS (SSD)
Data independent of
instance lifecycle
Amazon EBS
EBS Encryption
Up to 16TB Up to 16TB
10,000 IOPS (burst) 20,000 IOPS
Up to 160 MBps Up to 320 MBps
DEMO:
EC2 STORAGE
NETWORKING
Virtual Private Cloud
aws.amazon.com/vpc/
Amazon VPC
aws.amazon.com/vpc/
VPC Networking
docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-peering.html
ClassicLink
Private Communication Between Classic EC2 Instances & VPC Resources
aws.amazon.com/blogs/aws/classiclink-private-communication-between-classic-ec2-instances-vpc-resources/
Elastic Load-Balancing
aws.amazon.com/elasticloadbalancing/
▶︎ Timeout Configuration
▶︎ Connection Draining
▶︎ Cross-zone Load Balancing
aws.amazon.com/elasticloadbalancing/
DEMO:
CREATING AN ELB
MONITORING, METRICS & LOGS
Amazon CloudWatch
aws.amazon.com/cloudwatch/
Amazon CloudWatch
CloudWatch Metrics in the EC2 Console
Monitoring Scripts for EC2 Instances
docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts.html
Amazon CloudWatch Logs
AWS
Resource
Your
Custom
Data
CloudWatch
CloudWatch Logs + Filter
AWS
Resource
Your
Custom
Data
CloudWatch
Alarm Actions
Amazon EC2
Notification Auto Recovery
(SNS)
Terminate
SECURITY & ACCESS CONTROL
Access Credentials Key Pairs
Access key and secret key used to Public key and private key used
authenticate when accessing AWS APIs to authenticate when accessing
an Amazon EC2 instance
USE IAM ROLES TO PASS ACCESS
CREDENTIALS TO AN INSTANCE
DEMO:
USING IAM ROLES
DEPLOYMENT
“IF YOU NEED TO SSH INTO YOUR
INSTANCE, YOUR DEPLOYMENT
PROCESS IS BROKEN.”
AMAZON MACHINE IMAGES
Amazon Community Your machine
maintained maintained images
Start an instance
Configure the instance
Create an AMI from your instance
Start new ones from the AMI
Bake an
Configure
AMI dynamically
+
AMI dynamically
Static configurations
less change management
Bake an
Configure
AMI dynamically
Continuous deployment
latest code
Environment specific
dev-test-prod
AUTO SCALING
Maintain EC2 instance Automatically Scale
availability Your Amazon EC2 Fleet
Detects impaired EC2 instances Follow the demand curve for your
Replaces the instances automatically applications
Reduce the need to manually
provision Amazon EC2 capacity
Run at optimal utilisation
Reusable Instance Templates
Provision instances based on a reusable template you
define, called a launch configuration.
Automated Provisioning
Keep your Auto Scaling group healthy and balanced,
whether you need one instance or 1,000.
Adjustable Capacity
Maintain a fixed group size or adjust dynamically based on
Amazon CloudWatch metrics.
Describes what Auto Scaling will aws
autoscaling
create-‐launch-‐configuration
Launch
-‐-‐launch-‐configuration-‐name
launch-‐config
create when adding Instances
-‐-‐image-‐id
ami-‐54cf5c3d
-‐-‐instance-‐type
m3.medium
Configuration Only one active launch
-‐-‐key-‐name
mykey
configuration at a time
-‐-‐security-‐groups
webservers
00:00 01:00 02:00 03:00 04:00 05:00 06:00 07:00 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 22:00 23:00
Utilisation & Auto Scaling Granularity
41 Instance Hours
m3.large @ $0.154/hr
= $6.314/day
00:00 01:00 02:00 03:00 04:00 05:00 06:00 07:00 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 22:00 23:00
Utilisation & Auto Scaling Granularity
70 Instance Hours
69%
SAV
t2.small @ $0.028/hr
ING
= $1.96/day
00:00 01:00 02:00 03:00 04:00 05:00 06:00 07:00 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 22:00 23:00
New Scaling Policies for More New
Responsive Scaling
aws.amazon.com/blogs/aws/auto-scaling-update-new-scaling-policies-for-more-responsive-scaling
OTHER DEPLOYMENT OPTIONS
AWS CodeDeploy
Coordinate automated deployments, just like Amazon
Dev
v1, v2, v3 CodeDeploy
Staging Production
aws.amazon.com/ecs/
Amazon EC2 Container Service: New Features
aws.amazon.com/blogs/aws/ec2-container-service-latest-features-customer-successes-and-more
COST OPTIMIZATION
On-Demand Instances
Pay for compute capacity by the hour with no long-term
commitments or upfront payments
Reserved Instances
Provide you with a significant discount (up to 75%)
compared to On-Demand Instance pricing
Spot Instances
Purchase compute capacity with no upfront commitment
and at hourly rates usually lower than the On-Demand rate
aws.amazon.com/ec2/purchasing-options/
Getting Started with Reserved Instances
aws.amazon.com/ec2/purchasing-options/reserved-instances/getting-started/
Spot Instances
Spot Instances are spare Amazon EC2 instances that you can bid on.
When your bid exceeds the Spot Price and spot capacity is available, your
Spot instance is launched and will run until the Spot market price exceeds
your bid (a Spot interruption).
aws.amazon.com/ec2/purchasing-options/spot-instances/
RESOURCES YOU CAN USE
TO LEARN MORE
aws.amazon.com/ec2
Getting Started with Amazon EC2:
http://aws.amazon.com/ec2/getting-started/
http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/GettingStartedTutorial.html
AWS Training & Certification
Try products, gain new skills, and Build technical expertise to Validate your proven skills and
get hands-on practice working design and operate scalable, expertise with the AWS platform
with AWS technologies efficient applications on AWS