A server which invokes AWS lambda functions from http requests, mapping the request to the payload.
A docker image can be found at ghcr.io/tanemahuta/aws-lambda-server:<tag>
.
Routing is achieved using gorilla/mux.
When using a path in the request route, you may use path variables
(e.g. /test/{id}
), which will be parsed and propagated to the lambda invocation.
The AWS lambda function is invoked using the aws-sdk.
If you need to attach an IAM role in an EKS cluster, check out this article.
The parsed request is being adapted using aws.LambdaRequest.
To handle the request, you can use the first parameter in your handler:
async function handler(req, ctx) {
console.log("hostname", req.host);
console.log("headers", req.headers);
console.log("method", req.method);
console.log("full uri", req.uri);
console.log("parsed path variables", req.vars);
console.log("read body", req.body);
}
The returned response is being adapted using aws.LambdaResponse.
An example response may look like this:
async function handler(req, ctx) {
return {
statusCode: 200,
headers: {
"Content-Type": "text/plain"
},
body: "Hello world"
}
}
Alternatively the body may be a JSON, which will be serialized by the server:
async function handler(req, ctx) {
return {
statusCode: 200,
headers: {
"Content-Type": "application/json"
},
body: {
"Hello": "World"
}
}
}
which will result in a {"Hello":"World"}
in the server's HTTP response body.
When running the binary, the following command line parameters can be used:
--devel=(true|false)
: run in development mode (logging)--config-file=<path>
: use the provided config file (default:/etc/aws-lambda-server/config.yaml
)--listen=<addr>
: use the provided listen address (default::8080
) for serving the requests towards the lambda--metrics-listen=<addr>
: use the provided listen address (default::8081
) for serving metrics/health/readiness checks
The configuration adds request matchers to a function. For the schema, start here
An annotated example config can be found here.
The application provides health (/healthz
) and readiness checks (/readyz
) listening to the
configured --metrics-listen
address.
Additionally, the following metrics are available:
http_requests_total
: counter for total http requests servedhttp_request_duration_seconds
: histogram for http request durationhttp_request_size_bytes
: histogram for http request sizehttp_response_size_bytes
: histogram for http response sizeaws_lambda_invocation_total
: counter for AWS lambda invocations by function ARNaws_lambda_invocation_errors_total
: gauge for AWS lambda invocation errors by function ARNaws_lambda_invocation_duration_seconds
: histogram AWS lambda invocation duration by function ARN
Helm charts are created from the charts directory and published to this repository.