Search code examples
amazon-web-servicesamazon-dynamodbaws-sdk-js-v3

How to use the functions in the aws-sdk-js-v3?


I am trying to use one of the functions given in the @aws-sdk/lib-dynamodb documentation. It is called unmarshallOutput.

How do I make use of this function in my code?

import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";

const client = new DynamoDBClient({ region: "us-east-1" });

export async function handler(event, context, callback) {
  const params = {
    TableName: "Amenities"
  };

  try {
    const command = new ScanCommand(params);
    const data = await client.send(command);
    return data.Items
  } catch (err) {
    return {
      statusCode: 500,
      body: JSON.stringify({
        message: "Error retrieving data from DynamoDB"
      })
    };
  }
}

Solution

  • There are two ScanCommands, one in client-dynamodb and one in lib-dynamodb. You need to import the ScanCommand from lib-dynamodb, not client-dynamodb.