-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.ts
33 lines (30 loc) · 877 Bytes
/
write.ts
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
import router from '../lib/router'
import { DynamoDB } from 'aws-sdk'
import { v4 as uuid } from 'uuid'
const dynamo = new DynamoDB.DocumentClient()
export const handler = router({
api: {
proxyV2: async (event) => {
if (event.requestContext.http.method === 'POST') {
if (event.body) {
const body = JSON.parse(event.body)
if (body && body.item && typeof body.item === 'string') {
const Item = {
id: uuid(),
item: body.item
}
await dynamo.put({ TableName: process.env.AWS_DYNAMODB_TABLE_NAME!, Item }).promise()
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(Item)
}
}
}
}
return {
statusCode: 400
}
}
}
})