aws-lambda-server
description
A server which invokes AWS lambda functions from http requests, mapping the request to the payload.
docker image
A docker image can be found at ghcr.io/tanemahuta/aws-lambda-server:<tag>
.
routing
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.
function 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.
request
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);
}
response
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.
command-line args
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-http-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
configuration
The configuration adds request matchers to a function. For the schema, start here
An annotated example config can be found here.
metrics, healthz and readyz
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 served
http_request_duration_seconds
: histogram for http request duration
http_request_size_bytes
: histogram for http request size
http_response_size_bytes
: histogram for http response size
aws_lambda_invocation_total
: counter for AWS lambda invocations by function ARN
aws_lambda_invocation_errors_total
: gauge for AWS lambda invocation errors by function ARN
aws_lambda_invocation_duration_seconds
: histogram AWS lambda invocation duration by function ARN
helm-chart
Helm charts are created from the charts directory and published to this repository.