Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Agenda ● How does it differ from servers? ● What Gophers Squirrels have to do with it? ● How does it work? ● To Go or to NodeJS not to Go? ● What is Half Life AWS Lambda?

Slide 3

Slide 3 text

AWS Lambda is... ...Serverless Computing Platform

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

https://www.deviantart.com/mikoneyoru/art/VILIFY-213975744 How does it differ from running code on servers? - Pay per invocation (and time) (and resources) - “Cold” starts - “Warm” periods - Limited execution time - Stateless (mostly) - Event driven code execution - Generous free tier - “Endless” horizontal scaling - No operations (reboots, patching, etc)

Slide 6

Slide 6 text

Meet SAM (Serverless Application Model) & serverless framework

Slide 7

Slide 7 text

How does it work then?

Slide 8

Slide 8 text

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package main import "github.com/aws/aws-lambda-go/lambda" func init() { // do some initialization } func hello() (string, error) { return "Hello DevFest!", nil } func main() { lambda.Start(hello) } Minimal viable example // Valid handler function signatures: // func () // func () error // func (TIn), error // func () (TOut, error) // func (context.Context) error // func (context.Context, TIn) error // func (context.Context) (TOut, error) // func (context.Context, TIn) (TOut, error)

Slide 9

Slide 9 text

Slide taken from the highly recommended AWS Webinar Become a Serverless Black Belt: YouTube | SlideShare

Slide 10

Slide 10 text

https://djhworld.github.io/post/2018/01/27/running-go-aws-lambda-functions-locally/

Slide 11

Slide 11 text

Do I need to write code differently?

Slide 12

Slide 12 text

● Avoid “fat”/monolithic functions ● Read only what you need ● Do lazy initialization ● Think twice before adding new dependency/lib ● Try allocating more resources … and try to reduce them Cold starts are bad… so stay warm :)

Slide 13

Slide 13 text

- Environment is ephemeral, you can’t rely on it, but you can reuse it: ● Reuse global variables ● Use file system as cache (512mb in /tmp) ● Keep open connections - Language level concurrency not always needed since lambda executions are concurrent by itself

Slide 14

Slide 14 text

Handle failures! - Understand retry policies ● Sync calls never retried ● Async calls retried 2 times ● Stream retries until data expires - Leverage Dead Letter Queues ● Use SQS/SNS for replays Retry billed as new execution

Slide 15

Slide 15 text

Compare node, golang, python package size... Slide taken from the highly recommended AWS Webinar Become a Serverless Black Belt: YouTube | SlideShare Find the best resources allocation for your function: alexcasalboni/aws-lambda-power-tuning

Slide 16

Slide 16 text

● Go: ○ If you love Go, then the rest of the functions To Go or not to Go? ● NodeJS/Python: ○ Small functions (with no or little dependencies) ○ Functions that depend on AWS SDK only ● Java: ○ Never

Slide 17

Slide 17 text

Your reading homework: ● https://mikhail.io/2018/08/serverless-cold-start-war/ ● https://djhworld.github.io/post/2018/01/27/running- go-aws-lambda-functions-locally/ ● https://hackernoon.com/lambda-internals-exploring -aws-lambda-462f05f74076 ● https://medium.com/@galbashan1/aws-lambda-int ernals-part-2-going-deeper-1e12b9d2515f

Slide 18

Slide 18 text

Many thanks to Mart Vikus (@arcaderage) for this amazing Gordon Freeman arts: ● https://twitter.com/hashtag/30DaysOfHalfLife ● https://arcaderage.co/2016/10/06/30-days-of-half-life/

Slide 19

Slide 19 text

Questions are welcome www.linkedin.com/in/taras-postument [email protected]

Slide 20

Slide 20 text

Demo!!!!!!!!!!!!!!!!!!!!!!