-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.mjs
More file actions
26 lines (23 loc) · 815 Bytes
/
lambda.mjs
File metadata and controls
26 lines (23 loc) · 815 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
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient, PutCommand } from '@aws-sdk/lib-dynamodb';
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);
export const handler = async event => {
const records = event.Records;
const emails = records.reduce((acc, it) => {
const body = JSON.parse(it.body);
const message = JSON.parse(body.Message);
const bouncedRecipients = message.bounce.bouncedRecipients.map(
r => r.emailAddress,
);
return [...acc, ...bouncedRecipients];
}, []);
const pResult = emails.map(email => {
const command = new PutCommand({
TableName: process.env.TABLE_NAME,
Item: { email },
});
return docClient.send(command);
});
await Promise.all(pResult);
};