-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathput-item.js
35 lines (31 loc) · 1.14 KB
/
put-item.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
// This is an example of a simple PutCommand using the higher level DocumentClient for Amazon DynamoDB
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, PutCommand } = require("@aws-sdk/lib-dynamodb");
async function putItems() {
const client = new DynamoDBClient({ region: "us-west-2" });
const ddbDocClient = DynamoDBDocumentClient.from(client);
return await ddbDocClient.send(
new PutCommand({
TableName: "RetailDatabase",
Item: {
pk: "[email protected]", // Partition Key
sk: "metadata", // Sort Key
name: "Jim Bob",
first_name: "Jim",
last_name: "Roberts",
address: {
road: "456 Nowhere Lane",
city: "Langely",
state: "WA",
pcode: "98260",
country: "USA",
},
username: "jrob",
},
})
);
}
putItems()
.then((data) =>
console.log("PutCommand succeeded with HTTP code:", JSON.stringify(data.$metadata.httpStatusCode, null, 2)))
.catch((error) => console.error(JSON.stringify(error, null, 2)));