lambda default progress is public [#13]

This commit is contained in:
Brandon Liu
2022-07-06 12:21:12 +08:00
parent fbc7b02123
commit e6ab02ddd3
3 changed files with 12 additions and 6 deletions
+1
View File
@@ -1 +1,2 @@
*.zip *.zip
tmp/*
+7 -3
View File
@@ -8,6 +8,7 @@
2. Create a ZIP archive with the `tippecanoe` binary at `bin/tippecanoe` and upload as a Lambda layer 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) 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 4. set the environment variable `OUTPUT_BUCKET` to your output bucket; give lambda IAM role access to input/output buckets
5. Enable ACLs on the output bucket
```json ```json
{ {
@@ -17,13 +18,16 @@
"Sid": "AllowGet", "Sid": "AllowGet",
"Effect": "Allow", "Effect": "Allow",
"Action": "s3:GetObject", "Action": "s3:GetObject",
"Resource": "arn:aws:s3:::tippecanoe-lambda-input/*" "Resource": "arn:aws:s3:::protomaps-tippecanoe-test/*"
}, },
{ {
"Sid": "AllowPut", "Sid": "AllowPut",
"Effect": "Allow", "Effect": "Allow",
"Action": "s3:PutObject", "Action": [
"Resource": "arn:aws:s3:::tippecanoe-lambda-output/*" "s3:PutObject",
"s3:PutObjectAcl"
],
"Resource": "arn:aws:s3:::protomaps-tippecanoe-test-output/*"
} }
] ]
} }
+4 -3
View File
@@ -3,9 +3,10 @@ import json
import subprocess import subprocess
import sys import sys
import boto3 import boto3
from botocore import UNSIGNED
from botocore.config import Config
# if the input bucket is publicly readable # if the input bucket is publicly readable
# from botocore import UNSIGNED
# from botocore.config import Config
#s3 = boto3.client('s3',config=Config(signature_version=UNSIGNED)) #s3 = boto3.client('s3',config=Config(signature_version=UNSIGNED))
def lambda_handler(event, context): def lambda_handler(event, context):
@@ -36,7 +37,7 @@ def run_tippecanoe(executable, tmpdir, bucket_name, input_key):
for line in p.stderr: for line in p.stderr:
try: try:
j = json.loads(line) j = json.loads(line)
s3.put_object(Body=json.dumps(j),Bucket=os.environ['OUTPUT_BUCKET'],Key=root + ".progress") s3.put_object(Body=json.dumps(j),Bucket=os.environ['OUTPUT_BUCKET'],Key=root + ".progress",ACL="public-read",ContentType="application/json",ContentDisposition="inline")
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
pass pass
s3.upload_file(output_path,os.environ['OUTPUT_BUCKET'],root + ".mbtiles") s3.upload_file(output_path,os.environ['OUTPUT_BUCKET'],root + ".mbtiles")