-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.txt
More file actions
57 lines (47 loc) · 1.57 KB
/
a.txt
File metadata and controls
57 lines (47 loc) · 1.57 KB
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
https://github.com/archanareddyse/lambda/blob/master/lambda%20code.txt
--------------------------------------------------------------------------------
import boto3
from uuid import uuid4
import urllib.parse
def lambda_handler(event, context):
s3 = boto3.client("s3")
dynamodb = boto3.resource('dynamodb')
for record in event['Records']:
bucket_name = record['s3']['bucket']['name']
object_key = urllib.parse.unquote_plus(record['s3']['object']['key']) # decode filename
# Since size is not available in event, you must get it from S3
response = s3.head_object(Bucket=bucket_name, Key=object_key)
size = response['ContentLength']
event_name = record['eventName']
event_time = record['eventTime']
dynamo_table = dynamodb.Table('newtable')
dynamo_table.put_item(
Item={
'unique': str(uuid4()),
'Bucket': bucket_name,
'Object': object_key,
'Size': size,
'Event': event_name,
'EventTime': event_time
}
)
return {
'statusCode': 200,
'body': 'File metadata saved to DynamoDB'
}
------------------------------------------------------------------------------------------------------------------------------------
SNS ACCesspolicy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowS3ToPublish",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "*"
}
]
}