-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
30 lines (24 loc) · 802 Bytes
/
logger.js
File metadata and controls
30 lines (24 loc) · 802 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
const AWS = require('aws-sdk')
const DynamoDB = new AWS.DynamoDB.DocumentClient()
const insertOnDynamoDB = async params => {
const createNewObjectOnDynamoDBMethod = 'put'
return DynamoDB[createNewObjectOnDynamoDBMethod](params).promise()
}
const setupParamsForDynamoDB = params => {
const uuid = require('uuid')
return {
TableName: process.env.dynamoTable,
Item: {
id: uuid.v1(),
customerId: params.customerId,
invoiceFile: params.invoiceFile,
createdAt: Date.now()
}
}
}
module.exports.handle = async event => {
const { customerId, invoiceFile } = JSON.parse(event.Records[0].Sns.Message)
const paramsToInserOnDynamoDB = setupParamsForDynamoDB({ customerId, invoiceFile })
await insertOnDynamoDB(paramsToInserOnDynamoDB)
return customerId
}