-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy paths3proc.py
48 lines (34 loc) · 1.32 KB
/
s3proc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import os
import uuid
import urllib
import datastore
from helper import FileHelper
def processRequest(request):
output = ""
print("request: {}".format(request))
bucketName = request["bucketName"]
objectName = request["objectName"]
documentsTable = request["documentsTable"]
outputTable = request["outputTable"]
print("Input Object: {}/{}".format(bucketName, objectName))
ext = FileHelper.getFileExtenstion(objectName.lower())
print("Extension: {}".format(ext))
if(ext and ext in ["jpg", "jpeg", "png", "pdf"]):
documentId = str(uuid.uuid1())
ds = datastore.DocumentStore(documentsTable, outputTable)
ds.createDocument(documentId, bucketName, objectName)
output = "Saved document {} for {}/{}".format(documentId, bucketName, objectName)
print(output)
return {
'statusCode': 200,
'body': json.dumps(output)
}
def lambda_handler(event, context):
print("event: {}".format(event))
request = {}
request["bucketName"] = event['Records'][0]['s3']['bucket']['name']
request["objectName"] = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'])
request["documentsTable"] = os.environ['DOCUMENTS_TABLE']
request["outputTable"] = os.environ['OUTPUT_TABLE']
return processRequest(request)