英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论