23. Example – Strike a Balance
§ Set your Spot price > Market < On-Demand
§ Will always give you the market rate
at or under your bid
§ CloudWatch alarm on number of Spot
Instances in group
§ GroupInServiceInstances
§ Scale On-Demand group if #Instances in
Spot group drops below threshold
On-Demand
Auto Scaling
group
Master Node
Spot
Auto Scaling
group
Weather forecast raw data
Compute
Nodes
30. What are Reserved Instances (RIs)?
• RIs are a commitment in exchange for discount
• They behave like discount coupon booklets
• Each hourly RI coupon in the booklet tries to match to a
running instance, if matched it provides its full discount, if not
it expires
• RIs are a financial construct/layer on top of your AWS
infrastructure
RI coupon booklet
31. Convertible RI benefits
Convertible RIs allow changes in:
Instance Families (e.g. m4. -> c5.)
Instance sizes (e.g. .large -> .xlarge)
Operating System (e.g. Linux -> Windows)
Tenancy (e.g. shared -> dedicated)
You can:
Take advantage of newer instance types (e.g. m5)
Adapt your RIs as business needs change
Drastically reduce the likelihood of unused RIs
Take advantage of price reductions (maintain commit $, get more instances)
32. Instance Size Flexibility reduces the need to match RI size to
running instance size for Standard and Convertible RIs
If:
• RI is Regional
• RI and Instance use is Linux/UNIX (incl.
Amazon Linux, CentOS, Ubuntu), and
• RI and Instance is Shared tenancy
RDS size flexibility applies to MySQL, MariaDB,
PostgreSQL, and Amazon Aurora database
engines, as well as the “bring your own license”
(BYOL) edition of the Oracle DB.
m4.4xlarge
(4 units)
m4.2xlarge
(2 units)
m4.2xlarge
(2 units)
m4.8xlarge
(8 units)
One RI
Can apply to
more than 1
smaller
instance
Or part of
a larger
instance
4 units
receive
discounted
RI rate
35. Understand Your EBS Workload Characteristics
Solid State Drives (SSD) Hard Disk Drives (HDD)
Volume Type Provisioned IOPS SSD (io1) General Purpose SSD (gp2) Throughput Optimized HDD (st1) Cold HDD (sc1)
Description
Highest-performance SSD
volume designed for mission-
critical applications
General purpose SSD
volume that balances price
and performance for a wide
variety of transactional
workloads
Low cost HDD volume designed for
frequently accessed, throughput-
intensive workloads
Lowest cost HDD
volume designed for
less frequently
accessed workloads
Use Cases
§ Critical business
applications that require
sustained IOPS
performance, or more than
10,000 IOPS or 160 MiB/s
of throughput per volume
§ Large database workloads,
such as:
§ MongoDB
§ Cassandra
§ Microsoft SQL Server
§ MySQL
§ PostgreSQL
§ Oracle
§ Recommended for most
workloads
§ System boot volumes
§ Virtual desktops
§ Low-latency interactive
apps
§ Development and test
environments
§ Streaming workloads requiring
consistent, fast throughput at a
low price.
§ Big data
§ Data warehouses
§ Log processing
§ Cannot be a boot volume
§ Throughput-oriented
storage for large
volumes of data that
is infrequently
accessed
§ Scenarios where the
lowest storage cost
is important
§ Cannot be a boot
volume
More Expensive Cheaper
36. Use Amazon S3 Storage Tiers
Take advantage of Infrequent Access (IA)
§ No code changes using lifecycle policies* – immediate savings
§ Suitable for cold data (backup, log files, etc.) with requirement for
fast retrieval.
Example
§ Our app stores 100 TB of photos
§ Each photo is about 10 MB
§ Using Standard S3, we pay $2,250 per month [US Standard Region]
* Alternatively, you can directly PUT into Standard – IA by specifying STANDARD_IA in the x-amz-storage-class header.
37. Example – Activate a Policy
Move data after 30 days
Assume we can move 80% of the data
Of which 20% is still accessed regularly < twice per month
38. S3 – IA – Result!
35%
Saving
Same 100 TB (20 TB Standard/80 TB IA)
costs only $1,460 per month (US Standard)
39. Eliminate Your Web Server Tier
How much time do you spend on maintenance?
How secure is your web tier?
What is your capacity planning for your web tier?
40. Example – Using S3 Static Website Hosting
Not so “static”:
§ JavaScript (Client Side)
– (includes AWS SDK)
§ CORS
Plus:
§ No servers
§ No patching
§ No scaling rules
41. S3 Static Website Hosting Reference Architecture
S3 bucket
CloudFront
distribution
Web Tier
Cognito
Identity
CloudFront
logs
www.example.com
static.example.com
Availability Zone A Availability Zone B
Auto Scaling Group
www.example.com
static.example.com
web
servers
web
servers
42. The Cost of Using Your DB as a BLOB Store
Databases (particularly RDBMSs) make poor BLOB stores!
Negative in terms of performance
Negative in terms of management
Negative in terms of cost
43. Example – Storing Your BLOB in the RDBMS
CREATE OR REPLACE TABLE
user_images
(userid int,
imageguid char(36),
image BLOB);
For example
Each Image = 2MB
2,049K per row
3 million rows = 5.862 TB
RDS MySQL cost = $3,279.56
(US Standard) per month (multi-
AZ, Standard Storage) - approx
44. Store BLOB in S3, Metadata in RDS
CREATE OR REPLACE TABLE
user_images
(userid int,
imageguid char(36),
imageURL VARCHAR(1000));
Per row we now store 2K in the RDBMS
3 Million rows = 5.722 GB
S3 Storage = 5.862TB = $194.94 (storage)
+ 3MM Puts, 3MM Gets = $212.93 (inclusive,
GETs, PUTs, Storage)
RDS MySQL cost = $1,663.30 (US Standard)
per Month
Total: $1,876.23
42%
saving
47. Cache for Savings
Elastic Load
Balancing
EC2 App
Instances
Database
Instance
ElastiCache
Database Writes
App
Reads
Clients
Cache
Updates
Database Reads
Example 30,000 reads per second
db.m3.large – 30,000 PIOPS – Single-AZ: $3,889.68
cache.m3.large – 30,000 GETS per second: $355.02
90%
Saving!
48. DynamoDB
Pick the right tool for the job
Key/Value
Scalable
throughput
Low latency
Amazon Aurora
More complex
data/queries
Scalable
storage
Amazon
Redshift
Big (complex)
data
Higher
latency
ElastiCache
for Redis
Key/Value
In-Memory
(very) low
latency
49. Example - No one database to rule out all
MongoDB
Tracking
API
RTB
Engine
User&Stats
API
Tracking
API
RTB
Engine
DynamoDB
Decoupled
Amazon
Aurora
Amazon
Redshift
User&Stats
API
50. Queues – Not Just for Decoupling
SQS gives you tremendous power to decouple your
architecture
However, resilience is only one part of the story
Use queues to manage cost
51. SQS Trigger Auto Scaling Groups Based on Revenue
ApproximateAgeOfOldestMessage > 600
In our example, a single m4.large can process 1,000 images in an hour.
We don’t want paid customers to wait more than 10 minutes for their result.
ASG MIN 1, MAX 10, DESIRED 1
ApproximateNumberOfMessagesVisible >
1000
ASG MIN 0, MAX 1, DESIRED 0Free
Queue
Paid
Queue
Images
Source
mobile client
Auto
Scaling instances
Auto
Scaling instances
Images
Result
52. SQS Trigger Auto Scaling Groups Based on Revenue
In our example, a single m4.large can process 1,000 images in an hour.
We don’t want paid customers to wait more than 10 minutes for their result.
For example:
2,000 TXNs
50/50 free/premium
Free queue TXN cost:
$0.336/1,000 = $0.000336
*One instance
Paid queue TXN cost:
($0.336*6)/1,000 = $0.002016
*Six instances to meet 10 minute SLA
Free
Queue
Paid
Queue
Images
Source
mobile client
Auto
Scaling instances
Auto
Scaling instances
Images
Result
53. Simplify. Less Components. Less Cost.
Image
Source
mobile client
AWS
Lambda
For example:
Each TXN takes 3750ms
Assuming largest Lambda memory size
(1536 MB)
@ $ 0.000002501 per 100ms
Each TXN now costs $0.000937875
Premium queue TXN was $0.002016
S3 Event
Lambda
Result
53%
saving
Image
Result
55. Can Still Use SQS To Keep Free Tier Cheap
Free
Queue
Images
Sourcemobile client
Auto
Scaling
instances
More optimization
Make free tier even cheaper
using EC2 Spot Instances
Paid tier now gets instant
response (remove the 10
minute delay/SLA) at low cost
AWS
Lambda
Prefix-
based
Trigger
Image
Result
56. Public Subnet
Availability Zone A
Private Subnet
Public Subnet
Availability Zone B
Instance A
10.1.1.11 /24
Instance C
10.1.3.33 /24
Instance B
10.1.2.22 /24
Instance D
10.1.4.44 /24
Internet
Gateway
(IGW)
1 GB Data x 20
Intra-AZ by Private, Public or EIP = .01/GB
Elastic IP
205.x.x.27
Elastic IP
205.x.x.29
VPC 1
US-Standard Region
InFrom&OutToS3=0.00/GB
Amazon S3
Private Subnet
How To Save Data Transfer
§ You may use S3 to save on data transfer
between EC2 in different availability zones
(AZ).
§ The data transfer between two EC2 in
different AZ costs $0.01/GB, but S3 is free
to download from any AZ.
§ Consider the scenario where 1 GB data
is transferred 20 times from one EC2
server to another in different availability
zone. It will cost $0.20/GB (20 * 0.01).
§ However, if you are able to upload it to S3,
then you just pay for storage ($0.03 / GB /
month) and the best part is that data
transfer between S3 and EC2 is free.
§ Assuming data is deleted from S3 after a
day , the S3 cost will be $0.001. 99% cost
savings on that data transfer by using S3.
1
2
2
1
3
3
4
4
5
5
58. HA vs. Cost Optimization
Product owners often push for cost optimization
§ Ignoring their availability requirements
§ Until something fails…..
§ How much is your loses if your mobile apps down per
hour/day?
§ What will happen to your customer obsession?
§ Will it affect your company image in the market?
FIRST availability, THEN cost!
59. HA Protection for EC2 – Auto Recovery (Free)
An EC2 instance (virtual machine) is not highly available by default.
At least
100%
Saving
EBS Volume
Elastic IP1
2
§ A hardware or software failure
affects the EC2.
§ CW regular health check
spots that the EC2 has failed.
§ CW starts the recovery of the
EC2 on another EC2 host
server .
§ A new EC2 is launched on a
different EC2 host server
automatically.
§ The new EC2 is assigned the
same ID and IP address as
the old EC2 and linked to the
same EBS.
CloudWatch (CW)
1
EC2 EC2
2
3
3
4
4
5
5
5
EC2 Host Server EC2 Host Server
60. Economical Mitigation For AZ-Level Disruption
Availability Zone A Availability Zone B
Availability Zone A Availability Zone B Availability Zone C
Example Always maintain 12 instances even if one AZ is disrupted
24
Instances
18
Instances
25%
saving
62. Good cost management is about getting the right people to
care about spend and making saving easier
Allocate spend
through Tagging and a
multi-account strategy
Use the Cost Transparency
provided by AWS and
Key Performance Indicators
Use Cost Tools and
Automation
63. Pick the tool that provides the visibility you need
Simple, Static, Small
environment
Complex, Dynamic,
Large environment
1. Monthly AWS Invoice
2. AWS Billing
console
3. AWS Cost Explorer
and AWS Budgets
4. AWS Billing File Analysis,
DIY dashboards, and
3rd party tools
66. AWS Enterprise Support, AWS Professional Services, and
AWS Partners can guide your Cost journey, contact your
AWS Account Manager for more information
AWS Enterprise Support
https://aws.amazon.com/premiumsupport/enterprise-support/
AWS Professional Services
https://aws.amazon.com/professional-services/
AWS Partner Network
https://aws.amazon.com/partners/
68. Suggested next steps
1. Get your teams to use Cost Explorer to
understand where you are spending
2. Pick 1 technical lever of optimisation covered today,
set up a KPI to measure it, and improve it over time.
(e.g. resource scheduling / on-off)
3. Come to a future AWS event about Cost to
find out more about tools, methods, and
discuss the topic with other customers