0

我有一个 DynamoDB 表,我试图从表中获取一列。更具体地说,我只想要列中的不同值。

我正在使用 AWS Amplify 并设置了一个 API 来查询 DynamoDB 表。

API中的get方法如下。在哪里

  1. tableName - 是一个包含表名的变量。
  2. 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);
    });
  }

你能帮我理解我做错了什么吗?

4

1 回答 1

0

不敢相信我犯了这个错误

ExpressionAttributeNames = { 

应该

ExpressionAttributeNames : { 
于 2020-06-23T11:39:46.563 回答