This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

CAST supports DynamoDB via its com.castsoftware.nodejs extension. Details about how this support is provided for Node.js JavaScript source code is discussed below.

Objects

IconDescription

Node.js DynamoDB Endpoint

Node.jsDynamoDB Table

DynamoDB API

Link TypeFunction api v2

Commands from SDK V3

imported from '@aws-sdk/client-dynamodb'

No Link

createGlobalTable

createTable

-

useSelectLink

createBackup

getItem

batchGetItem

transactWriteItems

batchWriteItem

restoreTableToPointInTime

CreateTableCommand

BatchGetItemCommand

GetItemCommand

useDeleteLink

deleteTable

deleteItem

transactWriteItems

batchWriteItem

DeleteTableCommand
DeleteItemCommand

useUpdateLink

transactWriteItems

batchWriteItem

updateItem

updateTable

putItem

restoreTableToPointInTime

restoreTableFromBackup

PutItemCommand
UpdateItemCommand
UpdateCommand

DocumentClient

Link TypeFunction api v2

Commands from SDK V3

imported from '@aws-sdk/client-dynamodb'

useSelectLink
  • batchGet
  • transactGet
  • get
  • scan
  • query
  • batchWrite
  • transactWrite
-
useDeleteLink
  • batchWrite
  • transactWrite
  • delete
-
useUpdateLink
  • put
  • update
  • batchWrite
  • transactWrite
-

Code samples

API v2 sample

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

var AWS = require("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 database "myDatabase":

/* 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
});

What results can you expect?

Api v3 sample

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

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

const {CreateTableCommand} = require("@aws-sdk/client-dynamodb");
const {PutItemCommand } = require("@aws-sdk/client-dynamodb");
const {DeleteTableCommand } = require("@aws-sdk/client-dynamodb");

// 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();