Files
PMTiles/serverless/aws
2022-07-28 17:16:42 -07:00
..
2022-07-12 21:19:03 +08:00
2022-07-23 13:01:17 +08:00
2022-07-20 16:38:36 +08:00
2022-07-20 16:38:36 +08:00

PMTiles on Lambda

Generates a Lambda function for deploying PMTiles on Lambda behind Lambda Function URLs or API Gateway. (CloudFront is recommended as a cache in front.)

How To Use

git clone https://github.com/protomaps/PMTiles
cd serverless/aws
python create_lambda_function.py

Upload the resulting lambda_function.zip using the Lambda console.

Configure these Lambda environment variables:

  • BUCKET: the S3 bucket name.
  • PMTILES_PATH: optional, define how a tileset name is translated into an S3 key. Default {name}.pmtiles
    • Example path setting for objects in a directory: my_folder/{name}/file.pmtiles
  • TILE_PATH: optional, define the URL route of the tiles API. Default /{name}/{z}/{x}/{y}.pbf

For API Gateway integration, your Lambda Proxy Integration route will need to specify a greedy capturing parameter called proxy e.g. /{proxy+} (the default). Also, your binary content types setting for REST APIs needs to be set to */* otherwise tiles will be returned as base64-encoded text.

Test Event

Lambda Function URLs:

{
  "rawPath": "/my-tileset-name/0/0/0.pbf"
}

API Gateway (HTTP or REST):

{
  "pathParameters": {
   "tile_path": "my-tileset-name/0/0/0.pbf"
  }
}

Monitoring

Lambda@Edge

Lambda@Edge's multi-region features have little benefit when fetching data from S3 in a single region, and Lambda@Edge doesn't support environment variables or responses over 1 MB. For globally distributed caching, use CloudFront in combination with Lambda Function URLs.