首页 > 解决方案 > 未能在 DynamoDB 中设置 LIST 值

问题描述

我正在尝试在我的 DynamoDB 表中设置一个列表值,如下所示:

{
  "TableName": "my-table",
  "Key": {
    "uid": {
      "S": "id-value"
    }
  },
  "UpdateExpression": " SET #actions = :actions",
  "ExpressionAttributeNames": {
    "#actions": "actions"
  },
  "ExpressionAttributeValues": {
    ":actions": {
      "L": [
        "one",
        "two"
      ]
    }
  },
  "ReturnValues": "ALL_NEW"
}

当我运行它时,我收到以下错误:

{
  "message": "There were 8 validation errors:\n* InvalidParameterType: Expected params.ExpressionAttributeValues[':actions'].L[0] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in     params.ExpressionAttributeValues[':actions'].L[0]\n* UnexpectedParameter: Unexpected key '1' found in params.ExpressionAttributeValues[':actions'].L[0]\n* UnexpectedParameter: Unexpected key '2' found in     params.ExpressionAttributeValues[':actions'].L[0]\n* InvalidParameterType: Expected params.ExpressionAttributeValues[':actions'].L[1] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in     params.ExpressionAttributeValues[':actions'].L[1]\n* UnexpectedParameter: Unexpected key '1' found in params.ExpressionAttributeValues[':actions'].L[1]\n* UnexpectedParameter: Unexpected key '2' found in     params.ExpressionAttributeValues[':actions'].L[1]",
  "code": "MultipleValidationErrors",
  "errors": [
    {
      "message": "Expected params.ExpressionAttributeValues[':actions'].L[0] to be a structure",
      "code": "InvalidParameterType",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Unexpected key '0' found in params.ExpressionAttributeValues[':actions'].L[0]",
      "code": "UnexpectedParameter",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Unexpected key '1' found in params.ExpressionAttributeValues[':actions'].L[0]",
      "code": "UnexpectedParameter",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Unexpected key '2' found in params.ExpressionAttributeValues[':actions'].L[0]",
      "code": "UnexpectedParameter",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Expected params.ExpressionAttributeValues[':actions'].L[1] to be a structure",
      "code": "InvalidParameterType",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Unexpected key '0' found in params.ExpressionAttributeValues[':actions'].L[1]",
      "code": "UnexpectedParameter",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Unexpected key '1' found in params.ExpressionAttributeValues[':actions'].L[1]",
      "code": "UnexpectedParameter",
      "time": "2018-12-19T15:21:49.307Z"
    },
    {
      "message": "Unexpected key '2' found in params.ExpressionAttributeValues[':actions'].L[1]",
      "code": "UnexpectedParameter",
      "time": "2018-12-19T15:21:49.307Z"
    }
  ],
  "time": "2018-12-19T15:21:49.308Z"
}

我知道可以使用 list_append 添加单个条目,但我需要设置整个列表...我做错了什么?

是否可以在单个查询中设置整个表?

提前致谢

标签: amazon-dynamodb

解决方案


原来缺少值的类型。这是正确的结构:

{
  "TableName": "my-table",
  "Key": {
    "uid": {
      "S": "id-value"
    }
  },
  "UpdateExpression": " SET #actions = :actions",
  "ExpressionAttributeNames": {
    "#actions": "actions"
  },
  "ExpressionAttributeValues": {
    ":actions": {
      "L": [
        {
          "S": "one"
        },
        {
          "S": "two"
        }
      ]
    }
  },
  "ReturnValues": "ALL_NEW"
}

推荐阅读