Home

Awesome

elm serverless demo

This repo demonstrates how to use elm-package. It is kept up to date with that release version of the package. For a demo which is kept in sync with the master branch of elm-serverless see the demo embedded in that repo

Run locally

We use serverless-offline to run the server locally during development. To get started, clone this repo and then:

Which will start a server listening on port 3000. Note that the demo includes multiple, independent, elm-serverless programs which are deployed as a bundle. Each program contains:

Learn by reading the demos in the following order:

DemoPathDescription
Hello/Bare bones hello world app.
Routing/routingParse request path into Elm data.
Forms/formsShows how to parse a JSON body.
Config/configLoad per-instance configuration.
Pipelines/pipelinesBuild chains of middleware.
SideEffects/side-effectsHandle effects in the update loop.
Interop/interopCall JavaScript functions.
Quoted/quotedShows one way to organize a project.

See serverless.yml and webpack.config.js for details on how elm-serverless apps get mapped to base paths.

Deploy to AWS Lambda

Setup AWS_REGION, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY in your environment. Make sure you have sufficient permissions to perform a serverless deployment (either admin rights, or something more restricted). Then npm run deploy:demo. If all goes well you'll see something like this in the output:

endpoints:
  ANY - https://***.execute-api.us-east-1.amazonaws.com/dev/
  ANY - https://***.execute-api.us-east-1.amazonaws.com/dev/{proxy+}

Call the first endpoint to test your deployed function.

How it works

Two tools are involved in getting your elm app on AWS Lambda: