Mayfly.Handler (Mayfly v0.1.0)

View Source

Handles the resolution and execution of Lambda function handlers.

Summary

Functions

Default handler function used when no handler is specified.

Executes the handler function with the given payload. Handles proper error conversion and response formatting.

Resolves the handler module and function from environment variables. Returns a tuple with {module, function}.

Functions

default_handler(payload)

@spec default_handler(map()) :: {:ok, String.t()}

Default handler function used when no handler is specified.

execute(payload, arg)

@spec execute(
  map(),
  {module(), atom()}
) :: {:ok, any()} | {:error, map()}

Executes the handler function with the given payload. Handles proper error conversion and response formatting.

resolve()

@spec resolve() :: {module(), atom()}

Resolves the handler module and function from environment variables. Returns a tuple with {module, function}.

Examples

iex> System.put_env("_HANDLER", "Elixir.MyModule.my_function")
iex> Mayfly.Handler.resolve()
{MyModule, :my_function}