Skip to content

About

A dependency-free AWS Lambda custom runtime for Elixir, built on :inets/:httpc and the OTP-bundled JSON module, meant to run on a Lambda layer providing OTP.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

80 Commits

Folders and files

Repository files navigation

AWS.Lambda.Runtime

A dependency-free AWS Lambda custom runtime for Elixir.

AWS.Lambda.Runtime implements the Lambda Runtime API directly on top of :gen_tcp and the OTP-bundled JSON module — no HTTP client, no JSON library, and no other dependency beyond what ships with Erlang/OTP itself. It also wires up the mix release steps needed to package a function for the provided.al2023 runtime.

Installation

Add aws_lambda_runtime to your list of dependencies in mix.exs:

def deps do
  [
    {:aws_lambda_runtime, "~> 0.5.0"}
  ]
end

Quick start

Declare a release named lambda in mix.exs, with your handler. Embedding ERTS (include_erts: true) spares you an OTP layer to publish:

def project do
  [
    app: :hello_function,
    version: "0.1.0",
    elixir: "~> 1.18",
    deps: deps(),
    releases: [
      lambda: fn ->
        AWS.Lambda.Runtime.Release.lambda(handler: HelloFunction, include_erts: true)
      end
    ]
  ]
end

Write the handler:

defmodule HelloFunction do
  @behaviour AWS.Lambda.Runtime.Handler

  @impl true
  def handle(event, _context, _state) do
    {:ok, %{message: "hello from Elixir", received: event}}
  end
end

Build the package in the Lambda builder image, for the given Erlang and Elixir versions, then create the function and invoke it:

mix deps.get
mix aws_lambda.build 29.1.2 1.20.5 --output .

aws lambda create-function --function-name elixir-hello \
  --runtime provided.al2023 --architectures arm64 \
  --role arn:aws:iam::000000000000:role/lambda-elixir \
  --handler HelloFunction --zip-file fileb://function.zip

aws lambda invoke --function-name elixir-hello \
  --cli-binary-format raw-in-base64-out --payload '{"name":"Ada"}' out.json

Replace the role ARN with your own. Getting started goes through each step.

Guides

Development

mix deps.get
mix test

:telemetry is an optional dependency: CI also checks the library compiles without it, with MIX_ENV=prod mix compile --warnings-as-errors --no-optional-deps.

The Docker images the functions are built in, and the OTP layers, come from docker/. Changes are listed in the CHANGELOG.

License

MIT, see LICENSE.

Trademarks

"AWS", "Amazon Web Services", and "AWS Lambda" are trademarks of Amazon.com, Inc. or its affiliates. This project is an independent, community-maintained library and is not affiliated with, endorsed by, or sponsored by Amazon.com, Inc. or its affiliates.

About

A dependency-free AWS Lambda custom runtime for Elixir, built on :inets/:httpc and the OTP-bundled JSON module, meant to run on a Lambda layer providing OTP.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages