-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
46 lines (42 loc) · 1.13 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { PutItemCommand, DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { marshall } = require('@aws-sdk/util-dynamodb');
const ddb = new DynamoDBClient();
exports.handler = async (event) => {
try {
const data = getData();
await Promise.allSettled(data.map(async (item) => {
await addToDb(item);
}));
} catch (err) {
console.error(err);
}
};
const addToDb = async (item) => {
await ddb.send(new PutItemCommand({
TableName: process.env.TABLE_NAME,
Item: marshall({
pk: item.url,
sk: 'article',
GSI1PK: 'article',
GSI1SK: item.title,
title: item.title,
links: {
url: item.url,
...item.devUrl && { devUrl: item.devUrl },
...item.mediumUrl && { mediumUrl: item.mediumUrl },
...item.hashnodeUrl && { hashnodeUrl: item.hashnodeUrl }
}
})
}));
};
const getData = () => {
return [
{
title: '<title of article>',
devUrl: '<url of article on dev.to>',
url: '<relative url of article on your blog>',
mediumUrl: '<url of article on medium>',
hashnodeUrl: '<url of article on hashnode>'
}
]
};