Skip to content

Commit 0141755

Browse files
authored
Merge pull request #125 from kremerpatrick/master
Added AWS Lambda support
2 parents edd1659 + 7bb7253 commit 0141755

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

python/make_vcsp_2018.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def make_vcsp(lib_name, lib_path, md5_enabled):
344344
json.dump(_make_items(items, lib_version), f, indent=2)
345345

346346

347-
def make_vcsp_s3(lib_name, lib_path, skip_cert):
347+
def make_vcsp_s3(lib_name, lib_path, skip_cert, aws_default_region = None):
348348
"""
349349
lib_path is the library folder path on the bucket with pattern: [bucket-name]/[object-folder-path]
350350
@@ -371,7 +371,10 @@ def make_vcsp_s3(lib_name, lib_path, skip_cert):
371371
lib_folder_path = paths[1]
372372

373373
s3 = boto3.resource("s3")
374-
s3_client = boto3.client('s3')
374+
if aws_default_region is None:
375+
s3_client = boto3.client('s3')
376+
else:
377+
s3_client = boto3.client('s3',region_name=aws_default_region)
375378

376379
# check if the given s3 bucket exists
377380
try:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import json
2+
import make_vcsp_2018
3+
4+
def lambda_handler(event, context):
5+
buf = 'Lambda Content Library Handler. '
6+
try:
7+
buf = buf + "Event triggered by file: " + event["Records"][0]["s3"]["object"]["key"]
8+
except:
9+
print("No event key found.")
10+
buf = buf + " No S3 event key found."
11+
return {
12+
'statusCode': 200,
13+
'body': buf
14+
}
15+
16+
# If we don't filter out .json files, this script keeps firing in a loop.
17+
# We don't want the script to fire again when the script itself writes JSON files to the bucket.
18+
# You could also solve this problem by using a suffix filter in the S3 trigger configuration,
19+
# but you can only have one suffix per trigger. You would have to create a trigger for every
20+
# possible filetype that might get uploaded to the bucket.
21+
filename = (event["Records"][0]["s3"]["object"]["key"]).lower()
22+
if filename[-5:] == ".json":
23+
filter_status = "filtered"
24+
else:
25+
# Example usage: make_vcsp_2018.make_vcsp_s3('my-library','library-bucket/lib1',False,'us-east-2')
26+
# Argument description:
27+
# my-library - name of the library,
28+
# library-bucket/lib1 - S3 bucket name and folder name
29+
# false - Flag configured not to skip SSL validation
30+
# us-east-2 - default region
31+
# We pass the default region directly to the boto library so we don't have to configure environment variables in Lambda
32+
make_vcsp_2018.make_vcsp_s3('REPLACE-ME','REPLACE-ME',False,'REPLACE-ME')
33+
filter_status = "unfiltered"
34+
35+
return {
36+
'statusCode': 200,
37+
'body': buf,
38+
'filterStatus': filter_status
39+
}

0 commit comments

Comments
 (0)