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

More Decks by Google Developers Group Lviv

Other Decks in Programming


  1. None
  2. 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?
  3. AWS Lambda is... ...Serverless Computing Platform

  4. None
  5. 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)
  6. Meet SAM (Serverless Application Model) & serverless framework

  7. How does it work then?

  8. 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)
  9. Slide taken from the highly recommended AWS Webinar Become a

    Serverless Black Belt: YouTube | SlideShare
  10. https://djhworld.github.io/post/2018/01/27/running-go-aws-lambda-functions-locally/

  11. Do I need to write code differently?

  12. • 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 :)
  13. - 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
  14. 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
  15. 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
  16. • 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
  17. 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
  18. 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/
  19. Questions are welcome www.linkedin.com/in/taras-postument trane9991@gmail.com

  20. Demo!!!!!!!!!!!!!!!!!!!!!!