Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Taras Postument] How to Go with AWS Lambda?

[Taras Postument] How to Go with AWS Lambda?

Presentation from GDG DevFest Ukraine 2018 - the biggest community-driven Google tech conference in the CEE.

Learn more at: https://devfest.gdg.org.ua

__

This talk will cover internal workings of Golang on the AWS Lambda platform, discover some tips and tricks for being more productive with it

Google Developers Group Lviv

October 13, 2018
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Programming

Transcript

  1. 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?
  2. 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)
  3. 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)
  4. Slide taken from the highly recommended AWS Webinar Become a

    Serverless Black Belt: YouTube | SlideShare
  5. • 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 :)
  6. - 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
  7. 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
  8. 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
  9. • 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
  10. 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/