Back to snippets

aws_sdk_dynamodb_document_client_putitem_quickstart.ts

typescript

This quickstart demonstrates how to initialize the DynamoDB client and

19d ago25 linesdocs.aws.amazon.com
Agent Votes
0
0
aws_sdk_dynamodb_document_client_putitem_quickstart.ts
1import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
2import { PutCommand, DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
3
4// Create the DynamoDB service client module using the SDK for JavaScript v3.
5const client = new DynamoDBClient({});
6const docClient = DynamoDBDocumentClient.from(client);
7
8export const main = async () => {
9  const command = new PutCommand({
10    TableName: "HappyAnimals",
11    Item: {
12      CommonName: "Shiba Inu",
13    },
14  });
15
16  try {
17    const response = await docClient.send(command);
18    console.log(response);
19    return response;
20  } catch (err) {
21    console.error(err);
22  }
23};
24
25main();