aws-lambda-server

command module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

build go report codecov Go Reference GHCR

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-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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
mocks
mocklambda
Package mocklambda is a generated GoMock package.
Package mocklambda is a generated GoMock package.
mocksdk
Package mocksdk is a generated GoMock package.
Package mocksdk is a generated GoMock package.
pkg
app
Package app contains the startup code for the app.
Package app contains the startup code for the app.
aws/lambda
Package aws contains the services for AWS.
Package aws contains the services for AWS.
config
Package config contains the configuration structs.
Package config contains the configuration structs.
errorx
Package errorx contains error handling.
Package errorx contains error handling.
handler
Package handler contains the handler http.Handler logic.
Package handler contains the handler http.Handler logic.
routing
Package routing contains the http.Handler routing logic.
Package routing contains the http.Handler routing logic.
testcontext
Package testcontext provides a factory to create a simple context.Context with logger.
Package testcontext provides a factory to create a simple context.Context with logger.
testlogr
Package testlogr provides a logger for testing.
Package testlogr provides a logger for testing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL