https://github.com/outofcoffee/lambda-http-gateway
Simple HTTP Gateway for AWS Lambda functions
https://github.com/outofcoffee/lambda-http-gateway
Last synced: 2 months ago
JSON representation
Simple HTTP Gateway for AWS Lambda functions
- Host: GitHub
- URL: https://github.com/outofcoffee/lambda-http-gateway
- Owner: outofcoffee
- Created: 2022-01-03T01:26:01.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-03-22T01:37:10.000Z (3 months ago)
- Last Synced: 2026-03-22T10:54:56.826Z (3 months ago)
- Language: Go
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lambda HTTP Gateway
Simple HTTP gateway for AWS Lambda. Acts as a lightweight API gateway for AWS Lambda functions.
## Run
You can download the binary for your platform from the [releases](https://github.com/outofcoffee/lambda-http-gateway/releases) page, or use the [Docker image](#docker-image).
> **Important:** Ensure the relevant AWS credentials are configured before run. The gateway uses the standard AWS mechanisms to authenticate/authorise with the AWS Lambda API, so the usual approaches of profiles/credentials apply.
### Binary
./lambdahttpgw
### Docker
docker run -it -p 8090:8090 outofcoffee/lambdahttpgw
> Note: the home directory for the `gateway` user that runs the binary is `/opt/gateway`
## Call Lambda function
Call the Lambda function via the gateway:
curl http://localhost:8090/MyLambdaName/some/path
...
> Note the prefix of the Lambda function name (`MyLambdaName` above), before the path. The function receives the portion of the path without the function name, i.e. `/some/path` in this example.
The Lambda function receives events in the standard AWS API Gateway JSON format, and is expected to respond in kind.
The gateway also supports [subdomain-based routing](./docs/routing.md), where the function name is extracted from the `Host` header instead of the path.
## Configuration
Environment variables:
| Variable | Meaning | Default | Example |
|-----------------------|-------------------------------------------------------------------------------------------------|-------------|------------------------------------|
| AWS_REGION | AWS region in which to connect to Lambda functions. | `eu-west-1` | `us-east-1` |
| BASE_DOMAIN | Base domain for subdomain routing. Required when `ROUTING_MODE=subdomain`. | Empty | `live.mocks.cloud` |
| CORS_PERMISSIVE | Enable permissive CORS: reflects the request Origin, allows common headers (Accept, Authorization, Content-Type etc.) and credentials. | `false` | `true` |
| FUNCTION_PREFIX | Optional prefix prepended to resolved function names before invoking Lambda. | Empty | `imposter-` |
| LOG_LEVEL | Log level (trace, debug, info, warn, error). | `debug` | `warn` |
| PORT | Port on which to listen. | `8090` | `8080` |
| REQUEST_ID_HEADER | Name of request header to use as request ID for logging. If absent, a UUID will be used. | Empty | `x-correlation-id` |
| ROUTING_MODE | Routing mode: `path` extracts function name from URL path, `subdomain` from the Host header. | `path` | `subdomain` |
| STATS_RECORDER | Whether to record number of hits for each function. | `false` | `true` |
| STATS_REPORT_INTERVAL | The frequency with which stats should be reported, if enabled. | `5s` | `2m` |
| STATS_REPORT_URL | URL to which stats should be reported. If not empty, hits are recorded for each function name. | Empty | `https://example.com` |
See [Routing](./docs/routing.md) for details on path-based vs subdomain-based routing.
See [CORS](./docs/cors.md) for details on permissive CORS support.
## Build
Prerequisites:
- Go 1.17+
Steps:
go build
## Docker image
Image on [Docker Hub](https://hub.docker.com/r/outofcoffee/lambdahttpgw):
outofcoffee/lambdahttpgw
## Stats recording and reporting
The Gateway can optionally record the number of hits per function and report it to an external hit counter server.
> This behaviour is disabled by default.
See [Stats recording and reporting](./docs) for details.