How AWS builds Serverless services using Serverless Chris Munns Principal Developer Advocate AWS Serverless © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
A presentation at Serverless Days London in July 2019 in London, UK by Chris Munns
How AWS builds Serverless services using Serverless Chris Munns Principal Developer Advocate AWS Serverless © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
About me: Chris Munns - munns@amazon.com, @chrismunns • Principal Developer Advocate - Serverless • New Yorker • Previously: • AWS Business Development Manager – DevOps, July ’15 - Feb ‘17 • AWS Solutions Architect Nov, 2011- Dec 2014 • Formerly on operations teams @Etsy and @Meetup • Little time at a hedge fund, Xerox and a few other startups • Rochester Institute of Technology: Applied Networking and Systems Administration ’05 • Internet infrastructure geek © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Why are we here today? © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. https://secure.flickr.com/photos/mgifford/4525333972
How AWS builds Serverless services using Serverless © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
How AWS builds Serverless services using Serverless © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Instead A focus on events © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Going back to Amazon © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Photo by Chris Munns
Development transformation at Amazon: 1994-2001 monolithic architecture + hierarchical organization © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2002+ decoupled services + 2 pizza teams
Two-pizza teams Full ownership Full accountability Aligned incen:ves “DevOps” © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At first there was Amazon S3 © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At first there was Amazon S3* © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At first there was Amazon S3* *OK so Amazon SQS was the first service announced, S3 was the first to GA. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon S3 at launch: © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon S3 today: © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
I have a bucket Amazon Simple Storage Service (S3) © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2006-2014
Objects can go in Object Object Object Object Object Amazon Simple Storage Service (S3) Object Object Object Object Object Object © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2006-2014
But then…. Object Object Object Object Object Amazon Simple Storage Service (S3) Object Object Object Object Object Object © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2006-2014
But then what happens from here? Object Object Object Object Object Amazon Simple Storage Service (S3) Object Object Object Object Object Object © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2006-2014 ?
Workflow for S3 stored objects 2006-2014 There were two main ways of working with data in S3 in this time: • Performing List calls, acting. Client • Parallel client calls to ”notify” some system that objects were stored, polling that system, acting. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Bucket with objects Amazon Simple Queue Service Amazon EC2 Instances
In 2013 AWS Announced Amazon Kinesis Client Client Client Client Amazon Kinesis Client Client Client https://aws.amazon.com/about-aws/whats-new/2013/11/14/introducing-amazon-kinesis/ © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In 2013 AWS Announced Amazon Kinesis Client Client Client Client Amazon Kinesis Client Client Client ? https://aws.amazon.com/about-aws/whats-new/2013/11/14/introducing-amazon-kinesis/ © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
In 2013 AWS Announced Amazon Kinesis Client Amazon DynamoDB for KCL Checkpoints Client Client Client Amazon Kinesis Client Amazon EC2 Instances running the Kinesis Client Library Client Client https://aws.amazon.com/about-aws/whats-new/2013/11/14/introducing-amazon-kinesis/ © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
And then came AWS Lambda in Nov 2014 © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon S3 + AWS Lambda Object Object Object Object Object Amazon Simple Storage Service (S3) Object Object Object Object Object Object © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon Kinesis + AWS Lambda Client Client Client Client Client Client Client © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Kinesis
AWS Lambda ❤ Events Events event [i-’vent] noun A signal that a system’s state has changed. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Lambda ❤ Events Events Objects placed in an S3 bucket generates an event. Data being put into Kinesis is an event. Messages placed in Amazon SNS is an event. And so on and so on. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
And then Amazon API Gateway launched in July 2015 Amazon API Gateway © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
And then Amazon API Gateway launched in July 2015 !HAPPY 4TH BIRTHDAY ! API GATEWAY!!! Amazon API Gateway © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway + AWS Lambda Client Client Client Client Client Amazon API Gateway Client Client © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway + AWS Lambda Client Client Client Client Again, Events! Client Amazon API Gateway Client Client © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
APIs are the front door of microservices © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Photo by chris,an koch on Unsplash
But not every microservice needs to be API based… © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
And even fewer microservices need to be synchronous… © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon S3 today: I P A e r a e s e h t f o m l l e a h t t f o No y n a m , s d u e o n o bas r h c n y s t o n e ar © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Synchronous APIs POST /order Client © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 201 Order service
Synchronous APIs POST /order Order service Client POST /order retry after failure Client © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 201 Order service
Synchronous APIs POST /order Client 201 © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. POST /invoice Order service 201 Invoice service
Synchronous APIs POST /order Client 201 © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. POST /invoice Order service 201 Invoice service
Synchronous APIs POST /order POST /invoice Who own’s the Order retry? For how long? Invoice service service 201 the client ever know? Etc.. Client Does201 This effectively creates a “tight coupling” where failures become harder to recover from © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Over time though our architecture evolves © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Architecture v2 © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Long-term architecture © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Long-term architecture What does failure recovery look like for this? © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sadness. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Photo by Justin Veenema on Unsplash
Async to the rescue! © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Photo by Andrew Yardley on Unsplash
Events are asynchronous Client Service A Service B Client Service A Service B Synchronous Asynchronous Commands Events © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Asynchronous APIs POST /order Client 201 POST /invoice Order service Get /invoice Client 200 © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Invoice service Invoice service
What do we do with these arrows? Order service © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. An order was created!
Amazon SNS Data 1. Data published to a topic Simple, flexible, fully managed publish/subscribe messaging and mobile push notification service for high throughput, highly reliable message delivery Messages are published to a Topic SNS Topic 2. Lambda function(s) invoked Lambda function Lambda function © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Topics can have multiple subscribers (fanout) Messages can be filtered and only sent to certain subscribers Asynchronous
Event fanout with Amazon SNS Order service An order was created! SNS © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At some point we run into new challenges © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Event fanout with Amazon SNS Order service An order was created! SNS © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At some point the flow of events might need to become more than unidirectional Order service SNS © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At some point the flow of events might need to become more than unidirectional What if we need to ”update” all the other services of a status change on an event that was broadcast to several already? • • ”Credit card failed payment” “Inventory issue” What if that update only needs to go to some select number of other processors of that event? • • Marketing campaign tracker doesn’t care that an order failed, just that new ones come in Inventory manager doesn’t care about failed credit card charges How do we avoid re-coupling the system? • A mass of deciated SNS topics per workflow? How do we make it so that the system can flexibly grow without modifications to every other component? Ugh © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sadness. © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Photo by Justin Veenema on Unsplash
What if events were observable, not directed? © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What if events were observable, not directed? Joe, please create an invoice. Directed Commands © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Ok, here it is
What if events were observable, not directed? I don’t care about this Joe, please create an invoice. Customer X just ordered a widget Ok, here it is I’ll add that to the sales report Directed Observable Commands Events © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. I’ll send an invoice
Sharing events with event routers Abstracts producers and consumers © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Selects and filters events
Event routers in AWS AWS Service Topics Amazon Simple Notification Service © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Characteristics Lambda/SQS/HTTP targets Nearly unlimited subscriptions Filter on event metadata
NEW!!! • Removes friction of writing “point-to-point integrations” Amazon EventBridge Serverless event bus for ingesting and processing data across AWS services and SaaS applications © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Fully managed, pay-as-you-go • Works across dozens of AWS and SaaS applications • Provides simple programming model
NEW!!! • 90+ AWS Services as sources Amazon EventBridge • 17 AWS Services as targets • 1$ per 1 Million events put in to a bus • No additional cost for delivery to targets Serverless event bus for ingesting and processing data across AWS services and SaaS applications © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge • Built on the same technology as CloudWatch Events • Durably stores messages and retries failed connections to targets (for up to 24 hours) • Secured by AWS Identity and Access Management (IAM) • Event payload is JSON based, no dictated schema Amazon • Events Put in via single API call from AWS-SDKs or EventBridge via 3rd party partner SaaS providers © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Event routers in AWS AWS Service Topics Event buses Amazon Simple Notification Service Amazon EventBridge © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Characteristics Lambda/SQS/HTTP targets Nearly unlimited subscriptions Filter on event metadata 19 AWS targets Native SaaS event sources Metadata and payload routing
Amazon EventBridge Event Buses Event Sources Targets AWS Lambda Default event bus Amazon Kinesis Custom event bus AWS Step Functions Event source SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Event sources AWS Lambda Default event bus Amazon Kinesis Custom event bus AWS Step Functions Event source SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Example put event code (node.js) Event sources (cont) var AWS = require(‘aws-sdk’); cwevents.putEvents(params, function(err, data) { AWS.config.update({region: ‘REGION’}); if (err) { console.log(“Error”, err); AWS Lambda // Create CloudWatchEvents service object Default event bus } else { var cwevents = new AWS.CloudWatchEvents({apiVersion: ‘2015-10console.log(“Success”, data.Entries); 07’}); Amazon Kinesis } }); var params = { Custom event bus Entries: [ { AWS Step Functions “detail-type”: “Ticket Created”, Event “source”: “aws.partner/example.com/123”, source SaaS event bus Rules “detail”: { “ticketId”: ”987654321”, “department”: “billing”, “creator”: “user12345” … }}]}; © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Additional targets
Amazon EventBridge AWS Lambda Default event bus Amazon Kinesis Custom event bus AWS Step Functions Event source SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Event buses AWS Lambda Default event bus Amazon Kinesis Custom event bus AWS Step Functions Event source SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge AWS Lambda Default event bus Amazon Kinesis Custom event bus AWS Step Functions Event source SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Example event: { “detail-type”: “Ticket Created”, “source”: “aws.partner/example.com/123”, AWS services “detail”: { “ticketId”: ”987654321”, AWS Lambda Default event bus Amazon Kinesis “department”: “billing”, Custom events Custom event bus “creator”: “user12345” … } SaaS apps AWS Step Functions Event source } SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Example event: Example rule: { { “source”: [“aws.partner/example.com/123”] AWS Lambda “detail-type”: “Ticket Created”, “source”: “aws.partner/example.com/123”, AWS services “detail”: { “ticketId”: ”987654321”, Default event bus } Amazon Kinesis “department”: “billing”, Custom events Custom event bus “creator”: “user12345” … } SaaS apps AWS Step Functions Event source } SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Example event: Example rule: { { “detail”: { “detail-type”: “Ticket Created”, “source”: “aws.partner/example.com/123”, AWS services “detail”: { “ticketId”: ”987654321”, “department”: [“billing”, “fulfillment”] Default event bus } Amazon Kinesis } “department”: “billing”, Custom events Custom event bus “creator”: “user12345” … } SaaS apps AWS Lambda AWS Step Functions Event source } SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Example event: Example rule: { { “detail-type”: [“Ticket Resolved”] AWS Lambda “detail-type”: “Ticket Created”, “source”: “aws.partner/example.com/123”, AWS services “detail”: { “ticketId”: ”987654321”, Default event bus } Amazon Kinesis “department”: “billing”, Custom events Custom event bus “creator”: “user12345” … } SaaS apps AWS Step Functions Event source } SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge Targets AWS Lambda Default event bus Amazon Kinesis Custom event bus AWS Step Functions Event source SaaS event bus Rules Additional targets © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EventBridge Integration Partners © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Common use cases Take action SaaS application Amazon EventBridge AWS Lambda SaaS application Amazon EventBridge AWS Step Functions Applications and resources Run workflows Apply intelligence Amazon Comprehend SaaS application Amazon EventBridge AWS Lambda Amazon SageMaker © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Common use cases Audit and analyze SaaS application Amazon EventBridge Amazon Kinesis Data Firehose Amazon S3 AWS Lambda Amazon DynanmoDB fetch Synchronize data SaaS application © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon EventBridge Amazon Athena
Order service SNS © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Events with Amazon EventBridge Order service Amazon EventBridge © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Events with Amazon EventBridge • Order service Amazon EventBridge © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Your services can both produce messages onto the bus and consume just the messages they need from the bus Services don’t need to know about each other, just about the bus.
aws.amazon.com/eventbridge © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Chris Munns munns@amazon.com @chrismunns © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. https://www.flickr.com/photos/theredproject/3302110152/
? © 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. https://secure.flickr.com/photos/dullhunk/202872717/