-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
28 lines (28 loc) · 844 Bytes
/
index.js
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
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
exports.handler = async (event) => {
//const bucket = event.Records[0].s3.bucket.name;
const mid = event.Records[0].Sns.MessageId;
const message = JSON.parse(event.Records[0].Sns.Message);
const eventtime = event.Records[0].Sns.Timestamp;
const bucket = message.Records[0].s3.bucket.name;
const key = decodeURIComponent(
message.Records[0].s3.object.key.replace(/\+/g, " ")
);
const params = {
TableName : 'lambdatest',
/* Item properties will depend on your application concerns */
Item: {
mid: mid,
eventtime: eventtime,
bucketname: bucket,
filename: key
}
}
try {
await docClient.put(params).promise();
return { body: 'Successfully created item!' }
} catch (err) {
return { error: err }
}
};