Progress on elm-serverless and AWS services

There was a query around backends in Elm and I said I would give an update on elm-serverless. https://package.elm-lang.org/packages/the-sett/elm-serverless/latest/ - this lets you write AWS Lambda functions in Elm.

I have ported the core AWS package from Kevin Tonon’s 0.18 work: https://package.elm-lang.org/packages/the-sett/elm-aws-core/latest/. This is just the re-usable code that is needed for signing AWS requests and so on.

I have worked privately on the code generator for the stubs for the actual AWS services, but today pushed it to GitHub in case anyone else would like to see the work in progress: https://github.com/rupertlssmith/elm-aws-codegen. There is a set of slides there, that you can paste into Elm Dive SVG to see some of the background work I did looking into codegen in Elm:

https://github.com/rupertlssmith/elm-aws-codegen/blob/master/slides/codegen_elm.svg
https://myrho.github.io/dive-svg/

So I am currently working on that with a view to getting some AWS Service stubs working in the near future.

===

I took a look at the code generator Kevin wrote for creating Elm stubs to invoke AWS services, and tried to work directly on it to bring it forward to 0.19 and also to cover more of the AWS services. In the end, I decided it would be simpler to rewrite the code generator from scratch in Elm.

My main motivation for starting from scratch on the codegen is that the #1 AWS Service that I want to use is DynamoDB. The data model for that one is recursive, and that is going to require some code that can interpret a data model in order to figure out in what ways it is recursive and correctly generate code for that; a significant level of sophistication beyond where the original code generator was at.

Records in Elm cannot be recursive, so to have a record that can recursively contain an instance of itself, you have to wrap it in a custom type:

type RecursiveRec = 
    RecursiveRec { field1: String, field2 : Int, ..., child : Maybe RecursiveRec }

It is also necessary to make use of Decode.lazy when working with recursive structures.

10 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.