From 9875ae97a8430ac2e846f5989761b46a2af6894f Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Tue, 17 May 2022 15:29:38 +0800 Subject: [PATCH] add lambda info --- lambda/.gitignore | 1 + lambda/README.md | 10 ++++++++++ lambda/lambda_function.py | 20 ++++++++++++++++++++ lambda/requirements.txt | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 lambda/.gitignore create mode 100644 lambda/README.md create mode 100644 lambda/lambda_function.py create mode 100644 lambda/requirements.txt diff --git a/lambda/.gitignore b/lambda/.gitignore new file mode 100644 index 00000000..c4c4ffc6 --- /dev/null +++ b/lambda/.gitignore @@ -0,0 +1 @@ +*.zip diff --git a/lambda/README.md b/lambda/README.md new file mode 100644 index 00000000..270905c9 --- /dev/null +++ b/lambda/README.md @@ -0,0 +1,10 @@ +# Build the tippecanoe layer (binary) + +1. On an AWS Linux 2 instance or image: + + sudo yum update + sudo yum install git clang sqlite-devel zlib-devel + +2. Create a ZIP archive with the `tippecanoe` binary at `bin/tippecanoe` and upload as a Lambda layer +3. Copy [lambda_function.py](lambda_function.py) (python 3.9 runtime) +4. set the environment variable `OUTPUT_BUCKET` to your output bucket; give lambda IAM role access to input/output buckets \ No newline at end of file diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py new file mode 100644 index 00000000..a58a09db --- /dev/null +++ b/lambda/lambda_function.py @@ -0,0 +1,20 @@ +import os +import json +import subprocess +import boto3 +# if the input bucket is publicly readable +# from botocore import UNSIGNED +# from botocore.config import Config + +def lambda_handler(event, context): + bucket = event['Records'][0]['s3']['bucket']['name'] + key = event['Records'][0]['s3']['object']['key'] + #s3 = boto3.client('s3',config=Config(signature_version=UNSIGNED)) + s3 = boto3.client('s3') + s3.download_file(bucket,key,'/tmp/input.geojsonseq') + p = subprocess.check_call(['tippecanoe','-o','/tmp/output.mbtiles','/tmp/input.geojsonseq','--force']) + s3.upload_file('/tmp/output.mbtiles',os.environ['OUTPUT_BUCKET'],key + ".mbtiles") + return { + 'statusCode': 200, + 'body': json.dumps('Done!') + } diff --git a/lambda/requirements.txt b/lambda/requirements.txt new file mode 100644 index 00000000..844db8a4 --- /dev/null +++ b/lambda/requirements.txt @@ -0,0 +1,2 @@ +boto3==1.20.32 +botocore==1.23.32