首页 > 解决方案 > 使用带有解析器映射模板的 AppSync 在 DynamoDB 中存储数组(已编辑)

问题描述

我在使用 AppSync 在 PutItem 上的 DynamoDB 中存储数组时遇到了一些问题,这让我抓狂:P

问题是我从 GraphQl 传递的数组在我运行时消失了$util.dynamodb.toMapValuesJson。我究竟做错了什么?

我真的坚持这一点,非常感谢我能得到的任何帮助!

这是模板:

  #set($failing_list = [ "foo", 123, { "bar" : "baz" } ])

  {
    "version" : "2017-02-28",
    "operation" : "PutItem",
    "key": {
      "userId": { "S": "$ctx.args.input.email" },
      "createdAt": { "N": "$util.time.nowEpochMilliSeconds()" }
    },
    "data" : {
      "test": $util.dynamodb.toMapValuesJson({
        "working_list": [ "foo", 123, { "bar" : "baz" } ],
        "failing_list": $failing_list
      })
    }
  }

这是结果:

  {
    version: '2017-02-28',
    operation: 'PutItem',
    key: {
      userId: { S: 'xxxxxxxxxxxx' },
      createdAt: { N: '1531521284789' }
    },
    data: {
      test: {
        working_list: {
          L: [ { S: 'foo' }, { N: '123' }, { M: { bar: { S: 'baz' } } } ]
        },
        failing_list: {
          M: { L: { L: [ { M: { map: { M: {} } } }, { M: { map: { M: {} } } }, { M: { map: { M: {} } } } ] } }
        }
      }
   }
  }

标签: amazon-dynamodbaws-appsync

解决方案


推荐阅读