Skip to content

Repository files navigation

glambda

Write AWS Lambda functions in Gleam!

Package VersionHex Docs

Write your Lambda function as an http handler, or accept direct events as normal Gleam types.

Glambda only supports the JavaScript target. Your compiled code uses the AWS Lambda Node.js runtime.

gleam add glambda

HTTP Handler

importglambda.{typeContext}importgleam/http/request.{typeRequest}importgleam/http/response.{typeResponse,Response}importgleam/javascript/promise.{typePromise}importgleam/option.{typeOption,Some}fnhandle_request(_req:Request(Option(String)),ctx:Context,)->Promise(Response(Option(String))){letjson="{\"functionName\": \""<>ctx.function_name<>"\"}"Response(200,[#("content-type","application/json; charset=utf-8")],Some(json),)|>promise.resolve}// This is the actual function lambda invokespubfnhandler(event,ctx){glambda.http_handler(handle_request)(event,ctx)}

Event Handler

importglambda.{typeApiGatewayProxyEventV2,typeApiGatewayProxyResultV2,typeContext,ApiGatewayProxyResultV2,}importgleam/dictimportgleam/javascript/promise.{typePromise}importgleam/option.{Some}fnevent_handler(_event:ApiGatewayProxyEventV2,ctx:Context,)->Promise(ApiGatewayProxyResultV2){ApiGatewayProxyResultV2(status_code:200,headers:dict.from_list([#("content-type","application/json")]),body:Some("{\"functionName\": \""<>ctx.function_name<>"\"}"),is_base64_encoded:False,cookies:[],)|>promise.resolve}// This is the actual function lambda invokespubfnhandler(event,ctx){glambda.api_gateway_proxy_v2_handler(event_handler)(event,ctx)}

Check out the examples directory for examples of each supported event type, deployable with SST.

Supported Events

  • ApiGatewayProxyEventV2 (can be handled directly or as a Request(Option(String)))
  • EventBridgeEvent
  • SqsEvent

Further documentation can be found at https://hexdocs.pm/glambda.

Development

gleam run # Run the project
gleam test# Run the tests

About

Write AWS Lambda functions in Gleam!

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages