mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
lambda + API Gateway proper path integration; fix exceptions when archive missing
This commit is contained in:
@@ -34,8 +34,21 @@ def get_object_bytes(key, offset, length):
|
|||||||
# and returns API Gateway V2 / Lambda Function dict responses
|
# and returns API Gateway V2 / Lambda Function dict responses
|
||||||
# Does not work with CloudFront events/Lambda@Edge; see README
|
# Does not work with CloudFront events/Lambda@Edge; see README
|
||||||
def lambda_handler(event, context):
|
def lambda_handler(event, context):
|
||||||
uri = event["rawPath"]
|
path = None
|
||||||
name, tile = parse_tile_path(os.environ.get("TILE_PATH"), uri)
|
if event.get("pathParameters"):
|
||||||
|
# API Gateway (HTTP or REST)
|
||||||
|
if "tile_path" in event["pathParameters"]:
|
||||||
|
path = "/" + event["pathParameters"]["tile_path"]
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"statusCode": 500,
|
||||||
|
"body": "Proxy integration missing tile_path parameter",
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# Lambda Function URL
|
||||||
|
path = event.get("rawPath")
|
||||||
|
|
||||||
|
name, tile = parse_tile_path(os.environ.get("TILE_PATH"), path)
|
||||||
|
|
||||||
if not tile:
|
if not tile:
|
||||||
return {"statusCode": 400, "body": "Invalid tile URL"}
|
return {"statusCode": 400, "body": "Invalid tile URL"}
|
||||||
@@ -46,12 +59,12 @@ def lambda_handler(event, context):
|
|||||||
)
|
)
|
||||||
|
|
||||||
reader = Reader(get_bytes)
|
reader = Reader(get_bytes)
|
||||||
minzoom = int(reader.header().metadata["minzoom"])
|
|
||||||
maxzoom = int(reader.header().metadata["maxzoom"])
|
|
||||||
if tile.z < minzoom or tile.z > maxzoom:
|
|
||||||
return {"statusCode": 404, "body": "Tile not found"}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
minzoom = int(reader.header().metadata["minzoom"])
|
||||||
|
maxzoom = int(reader.header().metadata["maxzoom"])
|
||||||
|
if tile.z < minzoom or tile.z > maxzoom:
|
||||||
|
return {"statusCode": 404, "body": "Tile not found"}
|
||||||
|
|
||||||
tile_data = reader.get(tile.z, tile.x, tile.y)
|
tile_data = reader.get(tile.z, tile.x, tile.y)
|
||||||
if not tile_data:
|
if not tile_data:
|
||||||
return {"statusCode": 204}
|
return {"statusCode": 204}
|
||||||
|
|||||||
Reference in New Issue
Block a user