Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Going Serverless Sebastian Hesse · K15t · @seeebiii Tips & tricks for developing a serverless cloud app

Slide 3

Slide 3 text

Work on the same issue data, in different projects, on different Jira instances. Keeping your data in sync Backbone Issue Sync for Jira

Slide 4

Slide 4 text

About Serverless

Slide 5

Slide 5 text

Our Use Cases Scheduled Tasks Long Running Tasks Webhooks

Slide 6

Slide 6 text

Typical Cloud Architecture Serverless Architecture

Slide 7

Slide 7 text

Our Cloud Setup Other Services AWS Lambda Amazon Web Services

Slide 8

Slide 8 text

AWS Lambda

Slide 9

Slide 9 text

AWS Lambda module.exports = function (event, context, cb) { cb(null, "Hello World"); }

Slide 10

Slide 10 text

Event-based Architecture

Slide 11

Slide 11 text

Development Setup

Slide 12

Slide 12 text

Local Execute, test and debug your code on your local machine. Cloud Upload your code to the cloud and execute it there. Development

Slide 13

Slide 13 text

Local Cloud - Serverless Framework - Serverless Application Model (SAM) with
 SAM CLI - LocalStack - AWS Cloud9 - Upload & execute - No debugging possible* * bit.ly/debugging-lambda-dotnet

Slide 14

Slide 14 text

Considerations Tests You should always write tests which can already identify bugs. Quick Updates Local code updates are faster. But you can optimize your cloud code updates. Real Environment Local code execution always needs to simplify something: services, access policies or more. bit.ly/test-lambda-functions

Slide 15

Slide 15 text

Start Coding!

Slide 16

Slide 16 text

Manually managing Lambda functions is a pain.

Slide 17

Slide 17 text

Infrastructure as Code Use a tool to describe your infrastructure as code. This helps you to keep track of all your Lambda functions. CI/CD Pipeline Automate your deployment as much as possible. Use tools like Bitbucket Pipelines, AWS CodePipeline or similar. Deployment

Slide 18

Slide 18 text

Versioning Not all customers update your app at the same time. Be prepared! Preprocess your app descriptor. "webhooks": [ { "event": "jira:issue_updated", "url": "/webhook?v={{version}}" } ]

Slide 19

Slide 19 text

Best Practices

Slide 20

Slide 20 text

Best Practices Function Scope 1.

Slide 21

Slide 21 text

Example Tasks Further Processing Sync Content Receive Webhooks

Slide 22

Slide 22 text

“Keep it simple, stupid.”

Slide 23

Slide 23 text

Focus Focus on one task and do it well. Reusability Reuse functions within your app. Performance Keep a high performance, because every millisecond costs you money. Considerations

Slide 24

Slide 24 text

Response Times Response Time in ms 0 250 500 750 1000 # Request 1 2 3 4 5 Cold Start Function is "warm"

Slide 25

Slide 25 text

Response Times Response Time in ms 0 250 500 750 1000 # Request 1 2 3 4 5 Cold Start Function is "warm"

Slide 26

Slide 26 text

The bigger your artifact, the slower
 the startup time*.

Slide 27

Slide 27 text

Which programming language can I use?

Slide 28

Slide 28 text

All programming languages can be used.

Slide 29

Slide 29 text

Can I use framework X ?

Slide 30

Slide 30 text

No! Keep your function size as small as possible.

Slide 31

Slide 31 text

Can I use AWS Lambda as a REST API?

Slide 32

Slide 32 text

No! If you are concerned about response times.

Slide 33

Slide 33 text

Response Times Response Time in ms 0 250 500 750 1000 # Request 1 2 3 4 5 Cold Start is always there!

Slide 34

Slide 34 text

API Gateway Built resilient APIs backed by Lambda functions. AWS AppSync Build your own serverless backend using AWS AppSync which is powered by GraphQL. Serverless REST API bit.ly/aws-appsync-blog

Slide 35

Slide 35 text

Best Practices Communication 2.

Slide 36

Slide 36 text

Synchronous Communication

Slide 37

Slide 37 text

Synchronous Communication

Slide 38

Slide 38 text

Synchronous Communication

Slide 39

Slide 39 text

S3 Bucket Synchronous Communication

Slide 40

Slide 40 text

S3 Bucket API Gateway DynamoDB SQS Asynchronous Communication

Slide 41

Slide 41 text

bit.ly/lambda-triggers Asynchronous Communication

Slide 42

Slide 42 text

bit.ly/lambda-triggers Asynchronous Communication

Slide 43

Slide 43 text

Best Practices Scalability 3.

Slide 44

Slide 44 text

Lambda Functions are scaled automatically, right?

Slide 45

Slide 45 text

1000 webhooks at the same time is no exception.

Slide 46

Slide 46 text

Yes No Other services are not necessarily scaled. Lambda Functions are scaled by AWS.

Slide 47

Slide 47 text

Problem: Scaling

Slide 48

Slide 48 text

Problem: Scaling

Slide 49

Slide 49 text

Solution: Buffer Requests Kinesis

Slide 50

Slide 50 text

Best Practices Execution Management 4.

Slide 51

Slide 51 text

15 minutes execution time limit.

Slide 52

Slide 52 text

15 minutes are enough for my use case.

Slide 53

Slide 53 text

Really? How can you be sure?

Slide 54

Slide 54 text

- Retrieve data: 350 ms - Process data: 300 ms - Update data: 350 ms Example: Synchronize 1000 Issues 1 sec / issue => ~16 min.

Slide 55

Slide 55 text

Recursion Before timing out, store current state and call yourself again. Best Practices

Slide 56

Slide 56 text

Lambda Recursion module.exports = function(e, ctx, cb) { while (ctx.getRemainingTimeInMillis() > 1000) { // do something } // store state & call yourself again } 1.) Same instance problem 2.) Threshold uncertainty

Slide 57

Slide 57 text

Outsource Move bigger workloads to EC2 or other services. Best Practices Recursion Before timing out, store current state and call yourself again.

Slide 58

Slide 58 text

Serverless by managing servers? Without me!

Slide 59

Slide 59 text

Step Functions Manage the execution workflow and work around the time limit. Outsource Move bigger workloads to EC2 or other services. Best Practices Recursion Before timing out, store current state and call yourself again.

Slide 60

Slide 60 text

Step Functions Example { "StartAt": "Wait for Timestamp", "States": { "Wait for Timestamp": { "Type": "Wait", "SecondsPath": "$.seconds", "Next": "Send SNS Message" }, "Send SNS Message": { "Type": "Task", "Resource": "$LAMBDA_ARN", "Retry":[...], "End": true } } }

Slide 61

Slide 61 text

Best Practices Limits 5.

Slide 62

Slide 62 text

3 GB available for memory allocation.

Slide 63

Slide 63 text

Memory allocation and CPU power correlate.

Slide 64

Slide 64 text

50 MB Maximum artifact size for zipped files.

Slide 65

Slide 65 text

Improve your dependency management.

Slide 66

Slide 66 text

512 MB available for temporary, local storage.

Slide 67

Slide 67 text

Everything else goes into other storage services.

Slide 68

Slide 68 text

Best Practices Maintenance 6.

Slide 69

Slide 69 text

Clean Up Clean up data or make sure your data is still up-to-date. Log Collection Collect CloudWatch logs and store them somewhere else, e.g. in a file on S3. Monitoring Do health checks of your own services and send alarms to Slack. Maintenance

Slide 70

Slide 70 text

Examples - Shut down resources in your developer stacks - Clean up Lambda log groups - Analyze logs for keywords

Slide 71

Slide 71 text

Looking Ahead

Slide 72

Slide 72 text

Security bit.ly/secure-aws-lambda Legacy Code bit.ly/migrating-to-lambda Caching bit.ly/caching-in-lambda Further Topics

Slide 73

Slide 73 text

Serverless + Services =

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

Focus Keep your functions small. Find a good use case for your function. Scale Automatic scalability needs responsibility. Be Flexible Expand your functions as necessary. Takeaways

Slide 76

Slide 76 text

Subtitle Scale beyond. Sebastian Hesse · K15t · @seeebiii