如何使用aws-sdk-js-v3中的函数?

huangapple go评论57阅读模式
英文:

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

问题

我正在尝试使用@aws-sdk/lib-dynamodb文档中提供的一个函数。它被称为unmarshallOutput

我如何在我的代码中使用这个函数?

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: "从DynamoDB检索数据时出错"
      })
    };
  }
}
英文:

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

答案1

得分: 1

有两个ScanCommands,一个在client-dynamodb中,另一个在lib-dynamodb中。你需要从lib-dynamodb中导入ScanCommand,而不是从client-dynamodb中。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月10日 01:27:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75688076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定