If you want to deploy your workloads without the burden of managing servers or operating systems, this webinar is for you. During the session, we will explore four re-usable serverless architectural patterns for supporting web apps, stream processing apps, batch processing apps, and automation apps. For each pattern, we provide a TCO analysis and comparison with the server-based equivalent. We also discuss the considerations and nuances associated with each pattern, with AWS customers sharing their experiences of deploying them. The information covered in the webinar is relevant for architects, system operators, and anyone looking for a better understanding of how serverless architectures can help them save money and improve agility.
2. Agenda
Serverless characteristics and practices
3-tier web application
Batch processing
Stream processing
Operations automation
Serverless on the edge
Wrap-up/Q&A
4. Serverless patterns built with functions
Functions are the unit of deployment and scale
Scales per request—users cannot over or under-provision
Never pay for idle
Skip the boring parts; skip the hard parts
5. Lambda considerations and best practices
AWS Lambda is stateless—architect accordingly
• Assume no affinity with underlying compute
infrastructure
• Local filesystem access and child process may not
extend beyond the lifetime of the Lambda request
6. Lambda considerations and best practices
Can your Lambda functions
survive the cold?
• Instantiate AWS clients and
database clients outside the
scope of the handler to take
advantage of connection re-use.
• Schedule with CloudWatch
Events for warmth
• ENIs for VPC support are
attached during cold start
import sys
import logging
import rds_config
import pymysql
rds_host = "rds-instance"
db_name = rds_config.db_name
try:
conn = pymysql.connect(
except:
logger.error("ERROR:
def handler(event, context):
with conn.cursor() as cur:
Executes with
each invocation
Executes during
cold start
7. Lambda considerations and best practices
How about a file system?
• Don’t forget about /tmp (512 MB
scratch space)
exports.ffmpeg = function(event,context)
{
new ffmpeg('./thumb.MP4', function (err,
video)
{
if (!err) {
video.fnExtractFrameToJPG('/tmp’)
function (error, files) { … }
…
if (!error)
console.log(files);
context.done();
...
8. Lambda considerations and best practices
Custom CloudWatch metrics
• 40 KB per POST
• Default Acct Limit of 150 TPS
• Consider aggregating with Kinesis
def put_cstate ( iid, state ):
response = cwclient.put_metric_data(
Namespace='AWSx/DirectConnect',
MetricData=[
{
'MetricName':'ConnectionState',
'Dimensions': [
{
'Name': 'ConnectionId',
'Value': iid
},
],
'Value': state,
'Unit': 'None’
…
17. Amazon API Gateway best practices
Use mock integrations
Signed URL from API Gateway for large or binary file
uploads to S3
Use request/response mapping templates for legacy
apps and HTTP response codes
Asynchronous calls for Lambda > 30s
18. Root/
/{proxy+} ANY Your Node.js
Express app
Greedy variable, ANY method, proxy integration
Simple yet very powerful:
• Automatically scale to meet demand
• Only pay for the requests you receive
20. Characteristics
Large data sets
Periodic or scheduled tasks
Extract Transform Load (ETL) jobs
Usually non-interactive and long running
Many problems fit MapReduce programming model
22. Considerations and best practices
Cascade mapper functions
Lambda languages vs. SQL
Speed is directly proportional to the concurrent Lambda
function limit
Use DynamoDB/ElastiCache/S3 for intermediate state of
mapper functions
Lambda MapReduce Reference Architecture
28. More about fan-out pattern
• Keep up with peak shard capacity
• 1000 records / second, OR
• 1 MB / second
• Consider parallel synchronous Lambda invocations
• Rcoil for JS (https://github.com/sapessi/rcoil) can help
• Dead letter queue to retry failed Lambda invocations
29. Best practices
• Tune batch size when Lambda is triggered by Amazon
Kinesis Streams – reduce number of Lambda
invocations
• Tune memory setting for your Lambda function – shorten
execution time
• Use KPL to batch messages and saturate Amazon
Kinesis Stream capacity
31. Amazon Kinesis Analytics
Sensors
Amazon Kinesis:
Stream
Amazon Kinesis Analytics:
Window Aggregation
Amazon Kinesis Streams
Producer S3:
Aggregated Output
CREATE OR REPLACE PUMP "STREAM_PUMP" AS INSERT INTO
"DESTINATION_SQL_STREAM"
SELECT STREAM "device_id",
FLOOR("SOURCE_SQL_STREAM_001".ROWTIME TO MINUTE) as "round_ts",
SUM("measurement") as "sample_sum",
COUNT(*) AS "sample_count"
FROM "SOURCE_SQL_STREAM_001"
GROUP BY "device_id", FLOOR("SOURCE_SQL_STREAM_001".ROWTIME TO MINUTE);
Aggregation
Time Window
33. Serverless
• Amazon Kinesis Stream with 5
shards
Cost comparison
Server-based on EC2
• Kafka cluster (3 x m3.large)
• Zookeeper cluster (3 x m3.large)
• Consumer (1 x c4.xlarge)
Service Monthly Cost
Amazon Kinesis Streams $ 58.04
AWS Lambda $259.85
Amazon S3 (Intermediate Files) $ 84.40
Amazon CloudWatch $ 4.72
Total $407.01
Service Monthly Cost
EC2 Kafka Cluster $292.08
EC2 Zookeeper Cluster $292.08
EC2 Consumer $152.99
Total On-Demand $737.15
1-year All Upfront RI $452.42
34. Compare related services
Amazon Kinesis Streams Amazon SQS Amazon SNS
Message Durability Up to retention period Up to retention period Retry delivery (depends on
destination type)
Maximum Retention Period 7 days 14 days Up to retry delivery limit
Message Ordering Strict within shard Standard - Best effort
FIFO – Strict within Message
Group
None
Delivery semantics Multiple consumers per
shard
Multiple readers per queue (but
one message is only handled
by one reader at a time)
Multiple subscribers per
topic
Scaling By throughput using Shards Automatic Automatic
Iterate over messages Shard iterators No No
Delivery Destination Types Kinesis Consumers SQS Readers HTTP/S, Mobile Push,
SMS, Email, SQS, Lambda
37. Automation characteristics
• Respond to alarms or events
• Periodic jobs
• Auditing and Notification
• Extend AWS functionality
…All while being Highly Available and Scalable
38. Automation: dynamic DNS for EC2 instances
AWS Lambda:
Update Route53
Amazon CloudWatch Events:
Rule Triggered
Amazon EC2 Instance
State Changes
Amazon DynamoDB:
EC2 Instance Properties
Amazon Route53:
Private Hosted Zone
Tag:
CNAME = ‘xyz.example.com’
xyz.example.com A 10.2.0.134
41. Serverless by Design
A visual approach to serverless development
Event-driven architectures
https://sbd.danilop.net
https://github.com/danilop/ServerlessByDesign
43. Case Study
• PhotoVogue is an online photography platform. Launched in 2011
and part of Vogue Italia - which is owned by Condé Nast Italia - it
allows upcoming photographers to showcase their work.
• Amazon S3, AWS Lambda, Amazon API Gateway, Amazon CloudFront
• The Benefits
• Quicker provisioning, from days to hours
• 90% faster
• Cut IT costs by around 30%
• Seamless scalability
https://aws.amazon.com/solutions/case-studies/photovogue/
44. Case Study
• F-Secure Increases
Customer Insight and
Speeds Up Activation
Using AWS
https://aws.amazon.com/solutions/case-studies/f-secure/
45. Case Study
• UK Driver and Vehicle Licensing Agency Supports Secure, Data-
Driven Innovation
• An API-First Approach
• “We are decomposing our applications into smaller, discrete components so
we can choose the most appropriate technology”
• Amazon API Gateway
• “The speed with which we were able to deliver it was unprecedented”
• Experimenting with AWS Lambda
https://aws.amazon.com/solutions/case-studies/driver-and-vehicle-licensing-agency/
52. Snowball Edge Use Cases
“Snowball Edge enables us to extend the
innovative capabilities of HealthSuite, our cloud-
enabled connected health ecosystem of devices,
applications and digital tools supported by AWS,
even when there is no network support.”
Embedded Applications
—Dale Wiggins,
Business Leader, HealthSuite digital platform,
Philips
53. Snowball Edge Use Cases
“With AWS Snowball Edge, we can now collect
100 TB of data with no intermediate steps, and we
can also analyze the images immediately using
the onboard compute capabilities.”
Remote Locations for data collection and analysis
— Bob Cowen,
Director of Hatfield Marine Research Center,
Oregon State University
55. Lambda@Edge Use Cases
Demo build of a
CloudFront+S3 distribution,
using Lambda@Edge
to secure its HTTP headers
56. Lambda@Edge Use Cases
These processes include applying
transactional labels to purchases so
Blockbuster can track customer activity, and
providing personalized recommendations
based on previous purchases.
Blockbuster runs serverless compute
processes across AWS Regions and
Amazon CloudFront edge locations (using
Lambda@Edge) without provisioning or
managing servers.
57. “Serverless” Compliance
• ISO 9001 / 27001 / 27017 / 27018
• AWS Lambda
• Amazon API Gateway (excluding the use of Amazon API Gateway caching)
• PCI
• AWS Lambda
• Amazon API Gateway
• HIPAA BAA
• AWS Lambda
• Amazon API Gateway (excluding the use of Amazon API Gateway caching)
58. Best practices
• Document how to disable event triggers for your automation when
troubleshooting
• Gracefully handle API throttling by retrying with an exponential back-
off algorithm (AWS SDKs do this for you)
• Publish custom metrics from your Lambda function that are
meaningful for operations (e.g. number of EBS volumes
snapshotted)