Write AWS Lambda functions in Gleam!
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 glambdaimportglambda.{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)}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.
ApiGatewayProxyEventV2(can be handled directly or as aRequest(Option(String)))EventBridgeEventSqsEvent
Further documentation can be found at https://hexdocs.pm/glambda.
gleam run # Run the project
gleam test# Run the tests