SERVERLESS
ARCHITECTURES
@RafalGancarz
Every Developer
WOULDN’T BE GREAT IF I COULD JUST RUN MY CODE SOMEWHERE?
Rafal Gancarz
Lead Consultant @ OpenCredo
@RafalGancarz
(CC) Ray Sadler
BUILDING BLOCKS
@RafalGancarz
AWS Lambda
Java, C#, NodeJS, Python
sync & async invocation
1 million invocations and 400k GB-s
free per month
$0.20 per 1 million requests and ~
$6.65 for 400k GB-s thereafter
@RafalGancarz
Execution model
event + context
callback (err, data)
(NodeJS)
return value
(Java, Python, C#)
@RafalGancarz
Hello World (NodeJS)
console.log(‘Loading function’)
exports.handler = (event, context, callback) => {
// console.log(JSON.stringify(event));
// your logic goes here
callback(null, 'Hello from Lambda’);
// callback(new Error(‘something went wrong’));
};
@RafalGancarz
Hello World (Python)
from __future__ import print_function
import json
print('Loading function')
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
// your logic goes here
return “Hello from Lambda”
#raise Exception('Something went wrong')
@RafalGancarz
AWS S3
durable, available* and scalable
functions as content processors
5 GB of storage and 15 GB of data
transfer out to Internet each month
for free
$0.03 per TB/month and $0.09 per
GB data transfer out to Internet
* vast majority of the time
@RafalGancarz
Image resizer
S3 object
S3 bucket
Lambda
function
upload
notification
put
@RafalGancarz
AWS API Gateway
security, caching, throttling
functions as API implementations
1 million requests free per month
$3.50 per 1 million requests and
$0.09/GB (for the first 10 TB, then
cheaper)
@RafalGancarz
NPM Registry
API
handler
API
Gateway
publisher
upload
NPM package
tarball
@RafalGancarz
AWS DynamoDB
document and key-value
function as triggered procedures
25 GB of storage and 25 units of read
capacity each month for free (~200k
requests per month)
$0.25 per GB/month and $0.0065 per
hour for 10 units of write capacity (36k
writes/hour) or 50 units of read capacity
(180k reads/hour)
@RafalGancarz
CRUD API
API
handler
API
Gateway
DynamoDB
table
record
processor
DynamoDB
table
trigger
@RafalGancarz
AWS SNS
pub-sub, push notifications
functions as destinations
1m publishes, 1m mobile push
notifications, 1k emails, 100k HTTP
notifications and 1 GB of data transfer out
each month for free
$0.50 per 1m publishes, $0.60 per 1m
HTTP notifications and $0.09 per GB data
transfer out to the Internet
@RafalGancarz
Async tasks
API
handler
API
Gateway
DynamoDB
table
SNS
topic
task
executor
@RafalGancarz
AWS Kinesis Streams
pub-sub, persistent
functions as consumers
no free tier
$0.015 per shard/hour, $0.014 per
1m PUT payload units (25KB) +
extended retention charges
data transfer is free
@RafalGancarz
AWS SQS
point to point messaging, persistent
poll based API, functions need to
consume messages explicitly
1m requests (API actions or
messages) each month for free
$0.40 per 1m requests (standard) or
$0.50 per 1m requests (FIFO)
@RafalGancarz
Persistent consumers
API
handler
API
Gateway
SNS
topic
SQS
queue
@RafalGancarz
Serverless Ecosystem (AWS)
SES
LEX
Cloud
Front
Route53
KMS
Cognito
Step
Functions
Security
Delivery
Messaging
Glacier
RDS
Redshift
Elasti
Cache
Athena
EMRES
Storage&Analytics
Artificial
Intelligence
Polly
Rekognition
Operations
IoT
Alexa
Skills
Internet of Things
Other
Cloud
Trail
Batch
ECS
EC2
Legend:
no servers in sight
servers visible
servers visible (VPC)
(CC) perceptions
ARCHITECTURE
PATTERNS
@RafalGancarz
Beware of the Monolith
@RafalGancarz
Serverless Components
A B C
D
@RafalGancarz
Sync integration
A B
HTTPS (IAM/?)
HTTPS (IAM)
@RafalGancarz
Async integration
A B
@RafalGancarz
Async notifications
A B
(CC) etherlore
CONTINUOUS
DELIVERY
DEPLOYMENT
@RafalGancarz
Infrastructure provisioning
A
AWS
CloudFormation
(SAM)
Hashicorp
Terraform
(S3 remote state)
@RafalGancarz
Build/deployment pipeline
1 checkout
build (compile/transpile + execute unit tests)
deploy to DEVELOPMENT environment + execute
component/API tests
deploy to TESTING environment + execute end to end tests
deploy to STAGING environment + execute smoke tests
deploy to PRODUCTION environment + execute smoke
tests
2
3
4
5
6
@RafalGancarz
Infrastructure provisioning
CI/CD orchestrator
A
B
C
DEVELOPMENT
A
B
C
TESTING
A
B
C
STAGING
A
B
C
PRODUCTION
@RafalGancarz
Code deployments
ES 2015
+rollupjs.org babeljs.io
apex.run
@RafalGancarz
Testing
Unit testing
(local/CI)
Acceptance testing
(test environment)
Smoke testing
(post deployment)
testing pyramid
Component testing
(dev environment)
@RafalGancarz
Testing
+ +
Unit testing (local + CI)
+
Acceptance/functional testing (AWS)
+
Smoke testing (AWS)
+
(mochajs.org) (chaijs.com) (sinonjs.org) (proxyquire)
(CC) haru__q
SECURITY
@RafalGancarz
Security in depth
A B
team
CI/CD
IAM
IAM
STS
IAM
IAM / API KEY / STS / CUSTOM
@RafalGancarz
Secret storage
API
handler
API
Gateway
secret
KMS
ciphertext
plaintext
key
generate key
(CC) Grégoire Lannoy
MONITORING
@RafalGancarz
AWS CloudWatch
scalable, managed
real-time monitoring
metrics, logs, alarms, events
(CC) Jérôme S
METRICS
@RafalGancarz
CloudWatch Metrics
retention: 1m (15 days), 5m (63 days),
1h (15 months)
basic monitoring (1m/5m) is free
10 metrics and 1 million API requests for
free each month
$0.30 per metric/month for the first 10k
metrics ($0.02 for metrics over 1M)
$0.01 for 1000 API requests
ALERTING
(CC) Martin Abegglen
@RafalGancarz
CloudWatch Alarms
watches metrics over time
can trigger a function via SNS
10 alarms per month for free
$0.10 per alarm per month
@RafalGancarz
Serverless Alerting
function
CW
alarm
SNS
topic
email
SMS
channel
CW
metric
condition
LOGGING
(CC) Mari Smith
@RafalGancarz
CloudWatch Logs
ingests and stores application logs
configurable retention period
5 GB data ingestion and 5 GB
archived storage per month for free
$0.5985 per GB ingested per month
$0.0315 per GB archived per month
@RafalGancarz
Log Collection
CloudWatch
log group
Lambda
service
stdout
Lambda
function
stderr
@RafalGancarz
Log Filtering
CloudWatch
log group
CloudWatch
metric
CloudWatch
alarm
filter condition
@RafalGancarz
Log Browsing
log group Elastic
Search
function
JSON
Kibana
Bunyan
EVENTS
(CC) JD Hancock
@RafalGancarz
CloudWatch Events
stores & streams application events
$1 per 1 million custom events
@RafalGancarz
DynamoDB dynamic capacity
function
SDK
event
metrics
table
HEALTH CHECKS
(CC) Rosmarie Voegtli
@RafalGancarz
Route53 Health Checks
monitors HTTP(S) endpoints
50 AWS endpoint checks per month
for free
$0.50 per health check per month
$1 per feature (HTTPS, string
matching, fast interval, latency) per
month
@RafalGancarz
Health Checks
health
check
metric alarm
api function table
TRACING
(CC) Ozzy Delaney
@RafalGancarz
AWS X-Ray
collects transaction traces
support for Lambda in preview
100k traces recorded and 1 million
traces retrieved/scanned free per
month
$5 per 1 million traces recorded and
$0.50 per 1 million traces retrieved/
scanned per month
AUDITING
(CC) The Steve
@RafalGancarz
AWS CloudTrail
audits all console, API, SDK activity
first copy of management event free
additional copies $2 per 100k
events
$0.10 per 100k data events
@RafalGancarz
WHAT IS
SERVERLESS?
(CC) theaucitron
@RafalGancarz
Cloud-native
@RafalGancarz
Platform as a Service
(PaaS)
@RafalGancarz
Event-driven
@RafalGancarz
Managed runtime
@RafalGancarz
Serverless ≠ FaaS
Faas
Serverless
FaaS = Function as a Service
@RafalGancarz
WHY
SERVERLESS?
(CC) snapp3r
@RafalGancarz
Availability
@RafalGancarz
Scalability
@RafalGancarz
Economy
@RafalGancarz
Time to market
@RafalGancarz
Security
@RafalGancarz
Operability
@RafalGancarz
Culture
CHALLENGES(CC) mangpages
@RafalGancarz
Infancy
@RafalGancarz
Rapid Evolution
@RafalGancarz
Provider Lock-in
@RafalGancarz
Capacity management
(DynamoDB, Kinesis Streams)
@RafalGancarz
Frameworks
@RafalGancarz
Tooling
THE FUTURE
(CC) matt northam
@RafalGancarz
Maturity
@RafalGancarz
Services & Tools
@RafalGancarz
Patterns
@RafalGancarz
Business Agility
(CC) Alan Turkus
THANK YOU!
QUESTIONS?
@RafalGancarz

Progscon 2017: Serverless Architectures - Rafal Gancarz