mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
serverless README cleanups, wrangler.toml is gitignored
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
# PMTiles on Lambda
|
||||
# Installation
|
||||
|
||||
Generates a Lambda function for deploying PMTiles on Lambda behind Lambda Function URLs or API Gateway. (CloudFront is recommended as a cache in front.)
|
||||
See installation and configuration instructions at [Protomaps Docs: Deploy on AWS](https://protomaps.com/docs/cdn/aws)
|
||||
|
||||
The `Content-Type` header of responses will be `application/vnd.mapbox-vector-tile` : this is one of the [CloudFront compressible types](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types).
|
||||
|
||||
## How To Use
|
||||
|
||||
Self-contained Lambda ZIP:
|
||||
|
||||
[protomaps.github.io/PMTiles/lambda_function.zip](https://protomaps.github.io/PMTiles/lambda_function.zip)
|
||||
|
||||
(On Safari, right click -> Download Linked File... will keep the ZIP intact)
|
||||
## Development
|
||||
|
||||
Building the Lambda ZIP yourself:
|
||||
|
||||
@@ -18,17 +10,11 @@ Building the Lambda ZIP yourself:
|
||||
npm run build
|
||||
```
|
||||
|
||||
Upload the resulting `dist/lambda_function.zip` using the Lambda console or paste `dist/index.mjs`.
|
||||
Upload the resulting `dist/lambda_function.zip` using the Lambda console or copy and paste `dist/index.mjs`.
|
||||
|
||||
Configure these Lambda environment variables:
|
||||
## Test Events
|
||||
|
||||
* `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`
|
||||
* `CORS`: optional, set the value of the `Access-Control-Allow-Origin` response header. Examples: `https://example.com`, `*`. Only supports one origin, so useful for development or staging environments only. For production use you should use CloudFront CORS configuration.
|
||||
|
||||
## Test Event
|
||||
Simulate tile requests in the Lambda development console with these JSON events:
|
||||
|
||||
Lambda Function URLs:
|
||||
|
||||
@@ -38,7 +24,7 @@ Lambda Function URLs:
|
||||
}
|
||||
```
|
||||
|
||||
API Gateway (HTTP or REST):
|
||||
API Gateway (REST API with Lambda Proxy Integration):
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -47,12 +33,3 @@ API Gateway (HTTP or REST):
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html) environment variables or responses over 1 MB. For globally distributed caching, use CloudFront in combination with Lambda Function URLs.
|
||||
|
||||
### API Gateway
|
||||
|
||||
* your Lambda Proxy Integration route will need to specify a greedy capturing parameter called `proxy` e.g. `/{proxy+}` (the default).
|
||||
* API Gateway responses will always be GZIP-encoded, to work around binary content detection problems.
|
||||
|
||||
1
serverless/cloudflare/.gitignore
vendored
1
serverless/cloudflare/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
dist
|
||||
wrangler.toml
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
# PMTiles on Cloudflare Workers
|
||||
# Protomaps on Cloudflare
|
||||
|
||||
Use [rclone](https://rclone.org/downloads/) to upload your PMTiles archives to an R2 bucket. The Web UI is limited to 300 MB.
|
||||
See installation and configuration instructions at [Protomaps Docs: Deploy on Cloudflare](https://protomaps.com/docs/cdn/cloudflare)
|
||||
|
||||
# Getting started
|
||||
## Development
|
||||
|
||||
* First run `npm install` in the root `PMTiles/js` directory, then `npm install` in `PMTiles/serverless/cloudflare`
|
||||
Option 1: with Wrangler, run `npm run start` to serve your Worker on http://localhost:8787. The cache will not be active in development.
|
||||
|
||||
* Edit `wrangler.toml` with a new name + your development and production R2 buckets.
|
||||
|
||||
* Test in development: `npm run start`
|
||||
|
||||
* Publish the worker: `npm run deploy`
|
||||
|
||||
# Settings
|
||||
|
||||
By default, your worker will serve tiles at path `NAME/0/0/0.EXT` using the archive at the root of your bucket `NAME.pmtiles`, where EXT is one of `mvt`, `png`, `jpg` or `webp` depending on the tileset.
|
||||
|
||||
This behavior can be customized with optional environment variables:
|
||||
|
||||
`PMTILES_PATH` - A string like `folder/{name}.pmtiles` specifying the path to archives in your bucket. Default `{name}.pmtiles`
|
||||
|
||||
`TILES_PATH` - a string like `prefix/{name}/{z}/{x}/{y}.{ext}` specifying the tile path exposed by the worker. Default `{name}/{z}/{x}/{y}.{ext}`
|
||||
|
||||
`ALLOWED_ORIGINS` - a comma-separated list of allowed CORS origions. Default none. Examples: `https://example.com,https://localhost:3000`, `*`
|
||||
|
||||
|
||||
# Using the Workers web editor
|
||||
|
||||
Generate the Workers script using `npm run build` and copy `dist/index.js` to the editor.
|
||||
Option 2: Generate the Workers script using `npm run build` and copy `dist/index.js` to the editor.
|
||||
|
||||
@@ -3,7 +3,10 @@ main = "src/index.ts"
|
||||
compatibility_date = "2022-10-18"
|
||||
minify = true
|
||||
|
||||
# Replace the bucket names with your own
|
||||
r2_buckets = [
|
||||
{ binding = "BUCKET", preview_bucket_name = "my-bucket-development", bucket_name = "my-bucket-production" }
|
||||
]
|
||||
]
|
||||
|
||||
[vars]
|
||||
# ALLOWED_ORIGINS = "http://localhost:8000"
|
||||
# CACHE_MAX_AGE = 86400
|
||||
Reference in New Issue
Block a user