【问题标题】:Amazon DynamoDB Client - SDK V3.0: SerializationException in queryAmazon DynamoDB 客户端 - 开发工具包 V3.0:查询中的 SerializationException
【发布时间】:2021-06-10 23:31:51
【问题描述】:

最近我使用最新的 AWS SDK 版本 3 更新了我的代码

我有如下在dynamodb中查询的功能:

const query = async ( _eventId, _roomId) => {
  var params = {
    TableName: 'myTable',
    IndexName: 'p_key-status-index',
    KeyConditionExpression: 'p_key = :p_key AND #status = :status',
    FilterExpression: 'contains(room_id, :room_id)',
    ExpressionAttributeNames: marshall({
      '#status': 'status'
    }),
    ExpressionAttributeValues: marshall({
      ':p_key':  _eventId,
      ':room_id': _roomId,
      ':status': true
    })
  };

  console.log('getRegSeat :: params: ' + JSON.stringify(params));

  try {
    let res = await dynamoClient.send(new QueryCommand(params));
    console.log('res: ', res);

    return true
  } catch (e) {
    console.log('Error: ' + e);
  }
};

我收到一个错误

Error: SerializationException: Start of structure or map found where not expected

欢迎提出任何建议。

【问题讨论】:

    标签: node.js amazon-web-services amazon-dynamodb


    【解决方案1】:

    我发现了问题:

    ExpressionAttributeNames 不适用于marshall

    我的修复:我删除了marshall,一切都像魅力一样工作。

    ExpressionAttributeNames: {
          '#status': 'status'
        }
    

    我不知道这是错误还是 AWS 的设计。如果是设计的话,就是这么不协调的设计,对于我这样的新人来说有点迷茫。

    【讨论】:

    • 完美,我也遇到了同样的问题,谢谢!
    【解决方案2】:

    您能提供给我们 _eventId 和 _roomId 吗?可能有一些特殊字符需要处理什么的

    【讨论】:

    • eventId 和 roomId 中没有特殊字符。例如:eventId='EVENT#001', roomId='A_001'
    • @francophong 你能用不带# 字符的eventId 进行测试吗,它可以解释为与#status = :status 相同吗?
    猜你喜欢
    • 2023-04-09
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多