我有一个 DynamoDB 表,我试图从表中获取一列。更具体地说,我只想要列中的不同值。
我正在使用 AWS Amplify 并设置了一个 API 来查询 DynamoDB 表。
API中的get方法如下。在哪里
- tableName - 是一个包含表名的变量。
- Listing_Location 是我要从表中检索的列。
app.get(path, function (req, res) {
if (userIdPresent) {
req.body['userId'] = req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH;
}
var queryItemParams = {
TableName: tableName,
ProjectionExpression: "#listing_location",
ExpressionAttributeNames = {
'#listing_location': 'Listing_Location'
}
};
dynamodb.scan(queryItemParams, (err, data) => {
if (err) {
res.statusCode = 500;
res.json({ error: 'Could not fetch listing locations : ' + err });
} else {
res.json(data.Items);
}
});
});
我从前端 React 应用程序发出以下获取请求,其中 apiName 是具有 API 名称的变量。path 是发出 get 请求的 api 端点。我正在导入这样的 API
import { Amplify, API } from 'aws-amplify';
getAllLocations = () => {
console.log("in getAllLocations");
API.get(apiName, path).then(response => {
console.log(response);
});
}
你能帮我理解我做错了什么吗?