-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
39 lines (32 loc) · 970 Bytes
/
lambda_function.py
File metadata and controls
39 lines (32 loc) · 970 Bytes
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
import json
import helpers.images as image_helpers
import helpers.s3 as s3_helpers
import logging
logging.basicConfig()
logger = logging.getLogger("logger")
def handler(event, context):
body = {
"message": "A new S3 object has been uploaded",
"input": event
}
logger.error("Received a new S3 event: {}".format(event))
# Parse the event and extract the file information
records = event.get("Records", [])
for rec in records:
s3_dict = rec.get("s3")
bucket = {
"service": "s3",
"url": "https://s3.amazonaws.com",
"name": s3_dict.get("bucket").get("name"),
"region": rec.get("awsRegion")
}
object_key = s3_dict.get("object").get("key")
image_helpers.handle_image(
bucket=bucket,
object_key=object_key
)
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response