aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.34k stars 3.76k forks source link

(stepfunctions-tasks): DynamoDB attribute map synth output #21149

Open sirirako opened 1 year ago

sirirako commented 1 year ago

Describe the bug

sfntask.DynamoAttributeValue.mapFromJsonPath --> $.$.M

const addNewDocVersion2 = new sfntask.DynamoPutItem(this, 'addNewDocVersion2', { table: props.formtable, item: { Id: sfntask.DynamoAttributeValue.fromString(sfn.JsonPath.stringAt('$.Item.Id.S')), sk: sfntask.DynamoAttributeValue.fromString(sfn.JsonPath.format('v{}',sfn.JsonPath.stringAt('$.latest_version.latest_version.N'))), BusinessRule: sfntask.DynamoAttributeValue.mapFromJsonPath(sfn.JsonPath.stringAt('$.Item.BusinessRule.M')), Status: sfntask.DynamoAttributeValue.fromString('BusinessRuleProcessed'), Updated: sfntask.DynamoAttributeValue.fromNumber(businessRuleTS), Table: sfntask.DynamoAttributeValue.listFromJsonPath(sfn.JsonPath.stringAt('$.Item.Table.L')), KeyValue: sfntask.DynamoAttributeValue.mapFromJsonPath(sfn.JsonPath.stringAt('$.Item.KeyValue.M')), }, resultPath: JsonPath.DISCARD })

It turns into:

  "Parameters": {
    "Item": {
      "Id": {
        "S.$": "$.Item.Id.S"
      },
      "sk": {
        "S.$": "States.Format('v{}', $.latest_version.latest_version.N)"
      },
      "BusinessRule": {
        "M.$.$": "$.Item.BusinessRule.M"
      },
      "Status": {
        "S": "BusinessRuleProcessed"
      },
      "Updated": {
        "N": "1657831854044"
      },
      "Table": {
        "L.$": "$.Item.Table.L"
      },
      "KeyValue": {
        "M.$.$": "$.Item.KeyValue.M"
      }
    },

Expected Behavior

sfntask.DynamoAttributeValue.mapFromJsonPath Should be $.M

Current Behavior

sfntask.DynamoAttributeValue.mapFromJsonPath should not be $.$.M

Reproduction Steps

 const addNewDocVersion2 = new sfntask.DynamoPutItem(this, 'addNewDocVersion2', {
    table: props.formtable,
    item: {
      Id: sfntask.DynamoAttributeValue.fromString(sfn.JsonPath.stringAt('$.Item.Id.S')),
      sk: sfntask.DynamoAttributeValue.fromString(sfn.JsonPath.format('v{}',sfn.JsonPath.stringAt('$.latest_version.latest_version.N'))),
      BusinessRule: sfntask.DynamoAttributeValue.mapFromJsonPath(sfn.JsonPath.stringAt('$.Item.BusinessRule.M')),
      Status: sfntask.DynamoAttributeValue.fromString('BusinessRuleProcessed'),
      Updated: sfntask.DynamoAttributeValue.fromNumber(businessRuleTS),
      Table: sfntask.DynamoAttributeValue.listFromJsonPath(sfn.JsonPath.stringAt('$.Item.Table.L')),
      KeyValue: sfntask.DynamoAttributeValue.mapFromJsonPath(sfn.JsonPath.stringAt('$.Item.KeyValue.M')),
    },
    resultPath: JsonPath.DISCARD
  })

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.31.2

Framework Version

No response

Node.js Version

v14.17.6

OS

Mac OS

Language

Typescript

Language Version

TypeScript 4.7.4

Other information

No response

indrora commented 1 year ago

Looks to be a dupe of #12456

kaizencc commented 1 year ago

This looks to be a separate issue and is pretty weird. Here is where we are adding at least one $. I bet we don't want to always add $ in to avoid duplicates, but I haven't looked into it further.

https://github.com/aws/aws-cdk/blob/fcb311d615422b76f18b6be60dd466b315fcd6b0/packages/%40aws-cdk/aws-stepfunctions-tasks/lib/dynamodb/shared-types.ts#L212

anahitpo commented 7 months ago

Any updates on this one? Still not working properly. Any workaround suggestions?