forked from CodelyTV/terraform-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
executable file
·35 lines (30 loc) · 904 Bytes
/
code.py
File metadata and controls
executable file
·35 lines (30 loc) · 904 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 urllib.parse
import boto3
import datetime
from datetime import datetime
dynamodb = boto3.client('dynamodb')
def lambda_handler(event, context):
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
data = dynamodb.put_item(
TableName='catalog',
Item={
'ImageId': {
'S': bucket + '/' + key
},
'LastUpdatedTime': {
'S': datetime.utcnow().isoformat()
}
}
)
response = {
'statusCode': 200,
'body': 'successfully created item!',
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
return response