mirror of
https://github.com/maplibre/martin.git
synced 2024-12-19 04:41:46 +03:00
9f9f18163c
This adds the lambda-web crate to adapt the actix App to speak to Lambda by way of the lambda_runtime crate. AWS Lambda has native support for scripting languages to execute a function directly; compiled languages must embed a runtime to fetch incoming events from Lambda and post the responses. This detects the environment variables to start up in Lambda mode instead of the normal HTTP server, and is added as an optional feature. Lambda has five (!) distinct ways of routing HTTP requests to a function; this supports some of them. (Specifically, the most obvious way to do this is with a Function URL, which is newest and simplest, and perhaps with CloudFront, which speaks to the Function URL and not Lambda directly.) The error handling could probably be refined, I was just trying to get this to compile. (Supported: API Gateway HTTP API with payload format version 2.0; API Gateway REST API; Lambda function URLs / Not supported: API Gateway HTTP API with payload format version 1.0; Application Load Balancer) Necessary for #1102 to be able to run the released packages directly, and only having to configure the appropriate environment. --------- Co-authored-by: Yuri Astrakhan <yuriastrakhan@gmail.com>
35 lines
1.3 KiB
Bash
Executable File
35 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
set -euo pipefail
|
||
|
||
have () {
|
||
hash -- "$1" 2>&-
|
||
}
|
||
|
||
if ! have sam; then
|
||
echo "The AWS Serverless Application Model Command Line Interface (AWS SAM CLI) "
|
||
echo "must be installed: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html"
|
||
exit 1
|
||
fi
|
||
|
||
# Just send a single request using `sam local invoke` to verify that
|
||
# the server boots, finds a source to serve, and can handle a request.
|
||
# TODO Run the fuller integration suite against this.
|
||
# In doing so, switch from `sam local invoke`, which starts and stops the
|
||
# server, to `sam local start-api`, which keeps it running.
|
||
|
||
EVENT=$(sam local generate-event apigateway http-api-proxy \
|
||
| jq '.rawPath="/"|.requestContext.http.method="GET"')
|
||
|
||
# `sam build` will copy the _entire_ context to a temporary directory,
|
||
# so just give it the files we need
|
||
mkdir -p .github/files/lambda-layer/bin/
|
||
if ! install ${MARTIN_BIN:-target/debug/martin} .github/files/lambda-layer/bin/; then
|
||
echo "Specify the binary, e.g. ‘MARTIN_BIN=target/x86_64-linux-unknown-musl/release/martin just test-lambda’"
|
||
exit 1
|
||
fi
|
||
cp ./tests/fixtures/pmtiles2/webp2.pmtiles .github/files/lambda-function/
|
||
sam build -t .github/files/lambda.yaml
|
||
|
||
echo "$EVENT" | sam local invoke -e - \
|
||
| jq -ne 'input.statusCode==200'
|