-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3batchproc.py
74 lines (54 loc) · 2.11 KB
/
s3batchproc.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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"]
itemsTable = request["itemsTable"]
outputBucket = request["outputBucket"]
jobId = request["jobId"]
invocationId = request['invocationId']
invocationSchemaVersion = request['invocationSchemaVersion']
taskId = request['taskId']
print("Input Object: {}/{}".format(bucketName, objectName))
ext = FileHelper.getFileExtenstion(objectName.lower())
print("Extension: {}".format(ext))
if(ext and ext in ["jpg", "jpeg", "png", "mov", "mp4"]):
itemId = str(uuid.uuid1())
ds = datastore.ItemStore(itemsTable)
ds.createItem(itemId, bucketName, objectName)
output = "Saved item {} for {}/{}".format(itemId, bucketName, objectName)
print(output)
results = [{
'taskId': taskId,
'resultCode': 'Succeeded',
'resultString': "Item submitted for processing with Id: {}".format(itemId)
}]
return {
'invocationSchemaVersion': invocationSchemaVersion,
'treatMissingKeysAs': 'PermanentFailure',
'invocationId': invocationId,
'results': results
}
def lambda_handler(event, context):
print("event: {}".format(event))
request = {}
# Parse job parameters
request["jobId"] = event['job']['id']
request["invocationId"] = event['invocationId']
request["invocationSchemaVersion"] = event['invocationSchemaVersion']
# Task
request["task"] = event['tasks'][0]
request["taskId"] = event['tasks'][0]['taskId']
request["objectName"] = urllib.parse.unquote_plus(event['tasks'][0]['s3Key'])
request["s3VersionId"] = event['tasks'][0]['s3VersionId']
request["s3BucketArn"] = event['tasks'][0]['s3BucketArn']
request["bucketName"] = request["s3BucketArn"].split(':')[-1]
request["itemsTable"] = os.environ['ITEMS_TABLE']
request["outputBucket"] = os.environ['OUTPUT_BUCKET']
return processRequest(request)