-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserialize_image_lambda.py
More file actions
35 lines (27 loc) · 932 Bytes
/
serialize_image_lambda.py
File metadata and controls
35 lines (27 loc) · 932 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
import json
import json
import boto3
import base64
s3 = boto3.client('s3')
def lambda_handler(event, context):
"""A function to serialize target data from S3"""
# Get the s3 address from the Step Function event input
key = event["s3_key"] ## TODO: fill in
bucket = event["s3_bucket"] ## TODO: fill in
# Download the data from s3 to /tmp/image.png
## TODO: fill in
boto3.resource('s3').Bucket(bucket).download_file(key, "/tmp/image.png")
# We read the data from a file
with open("/tmp/image.png", "rb") as f:
image_data = base64.b64encode(f.read())
# Pass the data back to the Step Function
print("Event:", event.keys())
return {
'statusCode': 200,
'body': {
"image_data": image_data,
"s3_bucket": bucket,
"s3_key": key,
"inferences": []
}
}