Implementing a custom aws lambda runtime using Crystal

Implementing a custom aws lambda runtime using Crystal

This presentation gives an introduction into the concept of function as a service. After a quick introduction into crystal it is shown how easy it is to write a custom AWS lambda runtime using the crystal programming language.

This presentation was held at the serverless munich meetup in early 2019.

D5cd900453405c985e97c63e9f92061d?s=128

Alexander Reelsen

January 22, 2019
Tweet

Transcript

  1. Custom AWS lambda runtimes ...and a crystal demo Alexander Reelsen

    @spinscale alr@spinscale.de
  2. There is no serverless architecture. It's just someone else's execution

    environment. Alex R. THE TRUTH[TM]
  3. WHO DAT? About me ▸ Working distributed at Elastic since

    2013 ▸ Elasticsearch developer ▸ Dislikes running own infrastructure ▸ Basketball & JVM fan, husband, dad
  4. AND NOW FOR A LESSON IN... Agenda ▸ Custom AWS

    Lambda runtimes ▸ Introduction into crystal lang ▸ A crystal based runtime
  5. AWS Lambda

  6. FAAS

  7. node.js

  8. python

  9. go

  10. java

  11. JVM

  12. startup time

  13. dependencies

  14. JIT

  15. 2015: custom runtime?

  16. node shim https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/

  17. 2018: custom runtime!

  18. all the languages!

  19. runtime flow

  20. CUSTOM RUNTIME

  21. CUSTOM RUNTIME AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap

  22. AWS ENDPOINT CUSTOM RUNTIME AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap

  23. AWS ENDPOINT CUSTOM RUNTIME GET /2018-06-01/runtime/invocation/next AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap

  24. AWS ENDPOINT CUSTOM RUNTIME GET /2018-06-01/runtime/invocation/next Lambda-Runtime-Aws-Request-Id: 123 { "body":

    "{ \"foo\": \"bar\" }", "requestContext": "{ ... }", "headers" : { ... } } AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap
  25. AWS ENDPOINT CUSTOM RUNTIME POST /2018-06-01/runtime/invocation/123/response { "body": "{ \"foo\":

    \"bar\" }", "headers" : { ... } } AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap
  26. AWS ENDPOINT CUSTOM RUNTIME POST /2018-06-01/runtime/invocation/123/response { "body": "{ \"foo\":

    \"bar\" }", "headers" : { ... } } HTTP OK 202 AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap
  27. AWS ENDPOINT CUSTOM RUNTIME POST /2018-06-01/runtime/invocation/123/error { "statusCode": 500, "body"

    : "..." } AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap
  28. AWS ENDPOINT CUSTOM RUNTIME POST /2018-06-01/runtime/init/error { "errorMessage" : "...",

    "errorType" : "..." } AWS_LAMBDA_RUNTIME_API=localhost:12345 _HANDLER="my_handler" /bin/bootstrap
  29. crystal

  30. readable

  31. fast

  32. statically typed

  33. batteries included

  34. None
  35. testing

  36. benchmarks

  37. metaprogramming

  38. fibers

  39. channels

  40. boehm gc

  41. c bindings

  42. dependency mgmt

  43. web frameworks

  44. binaries

  45. static binaries

  46. None
  47. None
  48. None
  49. demo

  50. summary

  51. easy

  52. $$$

  53. static binaries

  54. aws library

  55. examples

  56. static sites, dynamic

  57. slack hook

  58. github hook

  59. location tracking

  60. None
  61. scheduled jobs

  62. emails

  63. reverse geocoder

  64. thank you

  65. HYPER HYPER Links ▸ https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html ▸ https://docs.aws.amazon.com/lambda/latest/dg/runtimes-walkthrough.html ▸ https://crystal-lang.org ▸

    https://github.com/spinscale/crystal-aws-lambda ▸ AWS Lambda Under the Hood: https://www.youtube.com/watch?v=QdzV04T_kec ▸ Firecracker: https://firecracker-microvm.github.io/ ▸ Boehm GC: http://www.hboehm.info/gc/ ▸ FaastRuby: https://faastruby.io/getting-started-crystal/ ▸ Google Cloud Functions: https://github.com/sam0x17/gcf.cr ▸ Crystal on OpenFaas: https://github.com/TPei/crystal_openfaas
  66. None
  67. @spinscale alr@spinscale.de

  68. questions?