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

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

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

问题

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

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

  1. import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";
  2. const client = new DynamoDBClient({ region: "us-east-1" });
  3. export async function handler(event, context, callback) {
  4. const params = {
  5. TableName: "Amenities"
  6. };
  7. try {
  8. const command = new ScanCommand(params);
  9. const data = await client.send(command);
  10. return data.Items;
  11. } catch (err) {
  12. return {
  13. statusCode: 500,
  14. body: JSON.stringify({
  15. message: "从DynamoDB检索数据时出错"
  16. })
  17. };
  18. }
  19. }
英文:

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?

  1. import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";
  2. const client = new DynamoDBClient({ region: "us-east-1" });
  3. export async function handler(event, context, callback) {
  4. const params = {
  5. TableName: "Amenities"
  6. };
  7. try {
  8. const command = new ScanCommand(params);
  9. const data = await client.send(command);
  10. return data.Items
  11. } catch (err) {
  12. return {
  13. statusCode: 500,
  14. body: JSON.stringify({
  15. message: "Error retrieving data from DynamoDB"
  16. })
  17. };
  18. }
  19. }

答案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:

确定