-
Notifications
You must be signed in to change notification settings - Fork 0
/
orderup-put.mjs
35 lines (31 loc) · 926 Bytes
/
orderup-put.mjs
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
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
const client = new DynamoDBClient({});
const dynamo = DynamoDBDocumentClient.from(client);
const tableName = 'OrderUpDB';
export const handler = async (event) => {
try {
const requestJSON = JSON.parse(event.body);
await dynamo.send(
new PutCommand({
TableName: tableName,
Item: {
id: requestJSON.id,
pie: requestJSON.pie,
quantity: requestJSON.quantity,
customerName: requestJSON.customerName,
deliveryDate: requestJSON.deliveryDate,
},
})
);
return {
statusCode: 200,
body: JSON.stringify({ message: `Received order ${requestJSON.id}` }),
};
} catch (error) {
return {
statusCode: 400,
body: JSON.stringify({ error: error.message }),
};
}
};