Support of DynamoDB for Node.js - TypeScript

Objects

Icon Description
NodeJS AWS DynamoDB Database
NodeJS AWS DynamoDB Table

Supported libraries

Library import path Versions
AWS SDK for JavaScript v2 aws-sdk 2.0.1 to 2.1692.0
AWS SDK for JavaScript v3 @aws-sdk/client-dynamodb 3.0.0 to 3.927.0
AWS SDK for JavaScript v3 - Helper Library @aws-sdk/lib-dynamodb 3.8.0 to 3.927.0

From API V2

Link Type from
aws-sdk.DynamoDB
from
aws-sdk.DocumentClient
useSelectLink createBackup
getItem
batchGetItem
transactWriteItems
batchWriteItem
restoreTableToPointInTime
batchGet
transactGet
get
scan
query
batchWrite
transactWrite
useDeleteLink deleteTable
deleteItem
transactWriteItems
batchWriteItem
batchWrite
transactWrite
delete
useUpdateLink transactWriteItems
batchWriteItem
updateItem
updateTable
createBackup
putItem
restoreTableToPointInTime
restoreTableFromBackup
put
update
batchWrite
transactWrite

From API V3

Link Type Commands from SDK V3 imported from ‘@aws-sdk/client-dynamodb’ Commands from SDK V3 imported from ‘@aws-sdk/lib-dynamodb’
useSelectLink QueryCommand
ScanCommand
BatchGetItemCommand
GetItemCommand
CreateBackupCommand
TransactGetItemsCommand
GetCommand
BatchGetCommand
TransactGetCommand
useDeleteLink DeleteTableCommand
DeleteItemCommand
BatchWriteItemCommand
TransactWriteItemsCommand
DeleteCommand
BatchWriteCommand
TransactWriteCommand
useUpdateLink PutItemCommand
UpdateItemCommand
UpdateCommand
CreateBackupCommand
UpdateTableCommand
PutItemCommand
BatchWriteItemCommand
TransactWriteItemsCommand
UpdateCommand
BatchWriteCommand
PutCommand
TransactWriteCommand

Code samples

API V2 sample

These declarations will establish a connection to the database located on localhost:

import AWS from "aws-sdk";

AWS.config.update({
  region: "us-west-2",
  endpoint: "http://localhost:8000"
});

var dynamodb = new AWS.DynamoDB();

These declarations will create a useUpdateLink from code to the table “Music”.

/* This example adds a new item to the Music table. */

var params = {
  Item: {
    "AlbumTitle": {
      S: "Somewhat Famous"
    },
    "Artist": {
      S: "No One You Know"
    },
    "SongTitle": {
      S: "Call Me Today"
    }
  },
  ReturnConsumedCapacity: "TOTAL",
  TableName: "Music"
};

dynamodb.putItem(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

API V3 sample

These declarations will establish a connection to the database located on localhost, create two tables, and create links:

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { CreateTableCommand, PutItemCommand, DeleteTableCommand } from "@aws-sdk/client-dynamodb";

const REGION = "us-east-1";
const ddbClient = new DynamoDBClient({region: REGION,
                                      endpoint: "http://localhost:8000" });
export { ddbClient };

// Set the parameters
export const params_put = {
  TableName: "TABLE_NAME_2",
  Item: {
    CUSTOMER_ID: { N: "001" },
    CUSTOMER_NAME: { S: "Richard Roe" },
  },
};

export const create = async () => {
  try {
    const data = await ddbClient.send(new CreateTableCommand({TableName: "TABLE_NAME"}));
    console.log("Table Created", data);
    return data;
  } catch (err) {
    console.log("Error", err);
  }
};
create();

export const put_item = async () => {
  try {
    const data = await ddbClient.send(new PutItemCommand(params_put));
    console.log("Table Updated", data);
    return data;
  } catch (err) {
    console.log("Error", err);
  }
};
put_item();

export const delete_item = async () => {
  try {
    const data = await ddbClient.send(new DeleteTableCommand({TableName: "TABLE_NAME"}));
    console.log("Success, table deleted", data);
    return data;
  } catch (err) {
      console.log("Error", err);
    }
};
delete_item();