Slide 1

Slide 1 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Taking Serverless to the Next Level Danilo Poccia Principal Evangelist, Serverless @danilop

Slide 2

Slide 2 text

© 2019, Amazon Web Services, Inc. or its Affiliates. “I know how to build a serverless function, now what?”

Slide 3

Slide 3 text

© 2019, Amazon Web Services, Inc. or its Affiliates.

Slide 4

Slide 4 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code

Slide 5

Slide 5 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code ✓ Make infrastructure changes repeatable and predictable ✓ Release infrastructure changes using the same tools as code changes ✓ Replicate production in a staging environment to enable continuous testing

Slide 6

Slide 6 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code best practices ✓ Infrastructure and application in the same source repository For example: AWS CloudFormation HashiCorp Terraform ✓ Deployments include infrastructure updates

Slide 7

Slide 7 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code for serverless apps For example: AWS Serverless Application Model (SAM) Serverless Framework AWS Lambda Amazon DynamoDB Amazon S3 ?

Slide 8

Slide 8 text

© 2019, Amazon Web Services, Inc. or its Affiliates. AWS Serverless Application Model (SAM) template AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetFunction: Type: AWS::Serverless::Function Properties: Handler: index.get Runtime: nodejs8.10 CodeUri: src/ Policies: - DynamoDBReadPolicy: TableName: !Ref MyTable Events: GetResource: Type: Api Properties: Path: /resource/{resourceId} Method: get MyTable: Type: AWS::Serverless::SimpleTable Just 20 lines to create: • Lambda function • IAM role • API Gateway • DynamoDB table O pen Source

Slide 9

Slide 9 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Use SAM CLI to package and deploy SAM templates pip install --user aws-sam-cli # Or even better use native installers sam init --name my-app --runtime python cd my-app/ sam local ... # generate-event/invoke/start-api/start-lambda sam validate # The SAM template sam build # Depending on the runtime sam package --s3-bucket my-packages-bucket \ --output-template-file packaged.yaml sam deploy --template-file packaged.yaml \ --stack-name my-stack-prod sam logs -n MyFunction --stack-name my-stack-prod -t # Tail sam publish # To the Serverless Application Repository CodePipeline Use CloudFormation deployment actions with any SAM application Jenkins Use SAM CLI plugin O pen Source

Slide 10

Slide 10 text

© 2019, Amazon Web Services, Inc. or its Affiliates. TweetSource: Type: AWS::Serverless::Application Properties: Location: ApplicationId: arn:aws:serverlessrepo:... SemanticVersion: 2.0.0 Parameters: TweetProcessorFunctionName: !Ref MyFunction SearchText: '#serverless -filter:nativeretweets' Nested apps to simplify solving recurring problems Standard Component Custom Business Logic aws-serverless-twitter-event-source app Polling schedule (CloudWatch Events rule) trigger TwitterProcessor SearchCheckpoint TwitterSearchPoller Twitter Search API

Slide 11

Slide 11 text

© 2019, Amazon Web Services, Inc. or its Affiliates. AWS Cloud Development Kit (CDK) npm install -g aws-cdk cdk init app --language typescript cdk synth cdk deploy cdk diff cdk destroy CodePipeline Use CloudFormation deployment actions with any synthesized CDK application Jenkins Use CDK CLI TypeScript JavaScript Python Java C# F# O pen Source

Slide 12

Slide 12 text

© 2019, Amazon Web Services, Inc. or its Affiliates. CDK Lambda cron example export class LambdaCronStack extends cdk.Stack { constructor(app: cdk.App, id: string) { super(app, id); const lambdaFn = new lambda.Function(this, 'Singleton', { code: new lambda.InlineCode(fs.readFileSync('lambda-handler.py’, { encoding: 'utf-8' })), handler: 'index.main', timeout: cdk.Duration.seconds(300), runtime: lambda.Runtime.PYTHON_3_7, }); const rule = new events.Rule(this, 'Rule', { schedule: events.Schedule.expression('cron(0 18 ? * MON-FRI *)') }); rule.addTarget(new targets.LambdaFunction(lambdaFn)); } } Lambda function CloudWatch Events rule TypeScript CloudFormation Stack Set the target

Slide 13

Slide 13 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code

Slide 14

Slide 14 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments

Slide 15

Slide 15 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Source Build Test Production Continuous Integration / Continuous Deployment

Slide 16

Slide 16 text

© 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 Lambda function code 100%

Slide 17

Slide 17 text

© 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 code 100% Run PreTraffic hook against v2 code before it receives traffic v2 code 0%

Slide 18

Slide 18 text

© 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 code 90% Wait for 15 minutes, roll back in case of alarm v2 code 10%

Slide 19

Slide 19 text

© 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda canary deployment API Gateway Lambda function weighted alias “live” v1 code 0% Run PostTraffic hook and complete deployment v2 code 100%

Slide 20

Slide 20 text

© 2019, Amazon Web Services, Inc. or its Affiliates. CodeDeploy – Lambda deployments in SAM templates Resources: GetFunction: Type: AWS::Serverless::Function Properties: AutoPublishAlias: live DeploymentPreference: Type: Canary10Percent10Minutes Alarms: - !Ref ErrorsAlarm - !Ref LatencyAlarm Hooks: PreTraffic: !Ref PreTrafficHookFunction PostTraffic: !Ref PostTrafficHookFunction Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce CustomCodeDeployConfiguration

Slide 21

Slide 21 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments

Slide 22

Slide 22 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product

Slide 23

Slide 23 text

© 2019, Amazon Web Services, Inc. or its Affiliates. v1 v2 v3 Customer needs Project Product

Slide 24

Slide 24 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Project Product Reach milestone Customer value Lifecycle costs Cost to reach milestone Backward looking Forward looking

Slide 25

Slide 25 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Product Features Defects Risks Debts Product development Business Customers Security & Compliance Developers & Architects Avoid Overutilization

Slide 26

Slide 26 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Positive Chat – Serverless architecture Amazon DynamoDB Amazon Cognito Amazon API Gateway WebSocket connection PositiveChat Lambda function Connections table Conversations table Topics table Web browser AWS Cloud S3 bucket for static assets (HTML, CSS, JS) Authentication Authorization To be implemented Amazon Comprehend Amazon Translate Amazon Rekognition To be implemented https://github.com/danilop/serverless-positive-chat D em o

Slide 27

Slide 27 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Positive Chat https://pchat.demo.danilop.net/?room=Belgrade D em o

Slide 28

Slide 28 text

© 2019, Amazon Web Services, Inc. or its Affiliates. $ wc -l positive-chat/app.js 326 positive-chat/app.js $ wc -l www/index.js 204 www/index.js backend + frontend ≃ 460 lines of code removing empty lines and comments

Slide 29

Slide 29 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Serverless for Product Development Less code, more speed Focus on what you want to build Estimate the cost per user or per feature Link business models and tiers to features and costs Faster to turn an idea into a prototype Prototypes are easier to bring in production Service updates enable new features

Slide 30

Slide 30 text

© 2019, Amazon Web Services, Inc. or its Affiliates.

Slide 31

Slide 31 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product

Slide 32

Slide 32 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices

Slide 33

Slide 33 text

© 2019, Amazon Web Services, Inc. or its Affiliates. “Complexity arises when the dependencies among the elements become important.” Scott E. Page, John H. Miller Complex Adaptive Systems

Slide 34

Slide 34 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Monolithic Application Services Microservices

Slide 35

Slide 35 text

© 2019, Amazon Web Services, Inc. or its Affiliates. © 2019, Amazon Web Services, Inc. or its Affiliates. “A complex system that works is invariably found to have evolved from a simple system that worked.” Gall’s Law

Slide 36

Slide 36 text

© 2019, Amazon Web Services, Inc. or its Affiliates. © 2019, Amazon Web Services, Inc. or its Affiliates. “A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over with a working simple system.”

Slide 37

Slide 37 text

© 2019, Amazon Web Services, Inc. or its Affiliates. “Amazon S3 is intentionally built with a minimal feature set. The focus is on simplicity and robustness.” – Amazon S3 Press Release, March 14, 2006

Slide 38

Slide 38 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon S3 8 → more than 200 microservices Mai-Lan Tomsen Bukovec VP and GM, Amazon S3

Slide 39

Slide 39 text

© 2019, Amazon Web Services, Inc. or its Affiliates. How does Serverless work? Storage Databases Analytics Machine Learning . . . Your unique business logic User uploads a picture Customer data updated Anomaly detected API call . . . Fully-managed services Events Functions

Slide 40

Slide 40 text

© 2019, Amazon Web Services, Inc. or its Affiliates. What is an “event” ? “something that happens” Events tell us a fact Immutable time series Time What 2019 06 21 08 07 06 CustomerCreated 2019 06 21 08 07 09 OrderCreated 2019 06 21 08 07 13 PaymentSuccessful 2019 06 21 08 07 17 CustomerUpdated . . . . . .

Slide 41

Slide 41 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Commands Vs Events Command Has an intent Directed to a target Personal communication ”CreateUser” “AddProduct” Event It’s a fact For others to observe Broadcast one to many ”UserCreated” “ProductAdded”

Slide 42

Slide 42 text

Photo by J W on Unsplash Can we help more?

Slide 43

Slide 43 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge A serverless event bus service for SaaS and AWS services • Fully managed, pay-as-you-go • Native integration with SaaS providers • 15 target services • Easily build event-driven architectures N ew

Slide 44

Slide 44 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge Event source SaaS event bus Custom event bus Default event bus Rules AWS Lambda Amazon Kinesis AWS Step Functions Additional targets

Slide 45

Slide 45 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge AWS services Custom events SaaS apps Event source SaaS event bus Custom event bus Default event bus Rules AWS Lambda Amazon Kinesis AWS Step Functions Additional targets "detail-type": "source": "aws.partner/example.com/123", "detail": "ticketId": "department": "creator":

Slide 46

Slide 46 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge AWS services Custom events SaaS apps Event source SaaS event bus Custom event bus Default event bus Rules AWS Lambda Amazon Kinesis AWS Step Functions Additional targets "detail-type": "source": "aws.partner/example.com/123" "detail": "ticketId": "department": "creator": "source":

Slide 47

Slide 47 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge AWS services Custom events SaaS apps Event source SaaS event bus Custom event bus Default event bus Rules AWS Lambda Amazon Kinesis AWS Step Functions Additional targets "detail-type": "source": "aws.partner/example.com/123", "detail": "ticketId": "department": "billing" "creator": "detail": "department": ["billing", "fulfillment"]

Slide 48

Slide 48 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge AWS services Custom events SaaS apps Event source SaaS event bus Custom event bus Default event bus Rules AWS Lambda Amazon Kinesis AWS Step Functions Additional targets "detail-type": "Ticket Created" "source": "aws.partner/example.com/123", "detail": "ticketId": "department": "billing", "creator": "detail-type": ["Ticket Resolved"]

Slide 49

Slide 49 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Common use cases

Slide 50

Slide 50 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Common use cases

Slide 51

Slide 51 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Amazon EventBridge integration partners

Slide 52

Slide 52 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices

Slide 53

Slide 53 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices Focus on your team

Slide 54

Slide 54 text

© 2019, Amazon Web Services, Inc. or its Affiliates. You Build It, You Run It “This brings developers into contact with the day-to-day operation of their software. It also brings them into day-to- day contact with the customer.” – Werner Vogels CTO, Amazon.com

Slide 55

Slide 55 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Team size & communication paths = ( − 1) 2 Communication paths in a team of N people

Slide 56

Slide 56 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Two pizza teams Photo by Kristina Bratko on Unsplash

Slide 57

Slide 57 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Separable Vs complex tasks Separable task Complex task

Slide 58

Slide 58 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Ability as a collection of cognitive tools Adam Ability = 5 { A, B, C, D, E } For example: A – mobile development on iOS B – back end development in Java C – data analytics in Python D – complex SQL queries E – …

Slide 59

Slide 59 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Ability as a collection of cognitive tools Adam Carl Betsy { C, D, G } Ability = 5 Ability = 4 Ability = 3 { A, B, E, F } { A, B, C, D, E }

Slide 60

Slide 60 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Diversity bonus model – Team with best abilities Adam Carl Betsy { C, D, G } Ability = 5 Ability = 4 Ability = 3 Team Ability = 6 { A, B, E, F } { A, B, C, D, E }

Slide 61

Slide 61 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Diversity bonus model – Team with more cognitive tools Adam Carl Betsy { A, B, E, F } { A, B, C, D, E } { C, D, G } Ability = 5 Ability = 4 Ability = 3 Team Ability = 7

Slide 62

Slide 62 text

© 2019, Amazon Web Services, Inc. or its Affiliates. No diversity, no bonus – Beware hiring managers Adam Carl Betsy { A, B, C, D } { A, B, C, D, E } { B, C, D } Ability = 5 Ability = 4 Ability = 3

Slide 63

Slide 63 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Some cognitive tools must be learned in order Adam Carl Betsy { A, B, C, D } { A, B, C, D, E } { A, B, C } Ability = 5 Ability = 4 Ability = 3

Slide 64

Slide 64 text

© 2019, Amazon Web Services, Inc. or its Affiliates. 2,092 people who worked on 474 musicals from 1945 to 1989 Small world networks & creativity AJS Volume 111 Number 2 (September 2005): 000–000 PROOF 1 ᭧ 2005 by The University of Chicago. All rights reserved. 0002-9602/2005/11102-0003$10.00 Thursday Oct 13 2005 11:31 AM AJS v111n2 090090 VSJ Collaboration and Creativity: The Small World Problem1 Brian Uzzi Northwestern University Jarrett Spiro Stanford University Small world networks have received disproportionate notice in di- verse fields because of their suspected effect on system dynamics. The authors analyzed the small world network of the creative artists who made Broadway musicals from 1945 to 1989. Based on original arguments, new statistical methods, and tests of construct validity, they found that the varying “small world” properties of the systemic- level network of these artists affected their creativity in terms of the financial and artistic performance of the musicals they produced. The small world network effect was parabolic; performance in- creased up to a threshold after which point the positive effects reversed. Creativity aids problem solving, innovation, and aesthetics, yet our un- derstanding of it is still forming. We know that creativity is spurred when diverse ideas are united or when creative material in one domain inspires or forces fresh thinking in another. These structural preconditions suggest 1 Our thanks go out to Duncan Watts; Huggy Rao; Peter Murmann; Ron Burt; Matt Bothner; Frank Dobbin; Bruce Kogut; Lee Fleming; David Stark; John Padgett; Dan Diermeier; Stuart Oken; Jerry Davis; Woody Powell; workshop participants at the University of Chicago, University of California at Los Angeles, Harvard, Cornell, New York University, the Northwestern University Institute for Complex Organizations (NICO); and the excellent AJS reviewers, especially the reviewer who provided a remarkable 15, single-spaced pages of superb commentary. We particularly wish to thank Mark Newman for his advice and help in developing and interpreting the bipartite-affiliation network statistics. We also wish to give very special thanks to the Santa Fe Institute for creating a rich collaborative environment wherein these ideas first emerged, and to John Padgett, the organizer of the States and Markets group at the Santa Fe Institute. Direct correspondence to Brian Uzzi, Kellog School of Man- agement, Northwestern University, Evanston, Illinois 60208. E-mail: [email protected]

Slide 65

Slide 65 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices Focus on your team

Slide 66

Slide 66 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices Focus on your team Don’t reinvent the wheel

Slide 67

Slide 67 text

SCALING CHALLENGES 350 DONATIONS PER SECOND Case Study

Slide 68

Slide 68 text

OLD VS NEW March 2019 cost* $5,393 March 2015 cost* $83,908 *All hosting costs are paid for through corporate partnerships. 100% of public donations go to the projects we fund. Case Study

Slide 69

Slide 69 text

WE COULD DO IT ALL AGAIN TOMORROW Serverless services cost $92 Case Study

Slide 70

Slide 70 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices Focus on your team Don’t reinvent the wheel

Slide 71

Slide 71 text

© 2019, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code Automate deployments Project to product Event-driven microservices Focus on your team Don’t reinvent the wheel

Slide 72

Slide 72 text

© 2019, Amazon Web Services, Inc. or its Affiliates. © 2019, Amazon Web Services, Inc. or its Affiliates. Thank you! @danilop Please give me your feedback