jdiablo
jdiablo

Reputation: 29

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"
      })
    };
  }
}

Upvotes: 1

Views: 251

Answers (1)

Nigel
Nigel

Reputation: 36

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.

Upvotes: 2

Related Questions