How to add Current Date in putItem in VTL

2019-08-04 13:54发布

问题:

{
  "version": "2017-02-28",
  "operation": "PutItem",
  "key": {
    "id": $util.dynamodb.toDynamoDBJson($util.autoId()),
    "createdDate":$core_v2_utility.CurrentDate
  },
  "attributeValues": $util.dynamodb.toMapValuesJson($ctx.args.input),
  "condition": {
    "expression": "attribute_not_exists(#id)",
    "expressionNames": {
      "#id": "id",
      "#createdDate":"createdDate",
    },
   },
}

I have been trying to add a createDate into DynamoDB using VTL.I am finding error with $core_v2_utility.CurrentDate

回答1:

AWS AppSync does not have a $core_v2_utility.CurrentDate. Did you mean to use one of the time helpers? $util.time.nowFormatted("yyyy-MM-dd HH:mm:ssZ") gives you the current date and time in UTC.