-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (47 loc) · 1.42 KB
/
index.js
File metadata and controls
55 lines (47 loc) · 1.42 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
// index.js
const dataProcessingService = require('./services/dataProcessing.js')
const { getConsoleMetadata } = require('./utils.js')
const LOG_TYPE = 'API_CALL'
const FILE_PATH = 'index.js'
exports.handler = async event => {
const failures = []
for (const record of event.Records) {
try {
// let consoleMetadata = getConsoleMetadata(
// LOG_TYPE,
// true,
// FILE_PATH,
// 'lambda.handler()'
// )
// console.log(`${ consoleMetadata } record.body: `, record.body)
const extractedInboundEmail = JSON.parse(record.body)
// consoleMetadata = getConsoleMetadata(
// LOG_TYPE,
// true,
// FILE_PATH,
// 'lambda.handler()'
// )
// console.log(`${ consoleMetadata } Extracted email data: `, extractedInboundEmail)
await dataProcessingService.processInboundEmailData(extractedInboundEmail)
} catch (error) {
const consoleMetadata = getConsoleMetadata(
LOG_TYPE,
false,
FILE_PATH,
'lambda.handler()'
)
console.error(
`${ consoleMetadata } Email processing failed for messageId ${record.messageId}: `,
error
)
failures.push({ itemIdentifier: record.messageId })
}
}
// SQS deletes records that aren't listed as failures
const body = { batchItemFailures: failures }
const response = {
statusCode: 200,
body
}
return response
}