aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(stepfunctions): allow intrinsic functions for JsonPath.list_at

Open koups496 opened this issue 4 years ago • 5 comments

Description

Currently the Step functions JsonPath.list_at values must either be exactly equal to '$' or start with '$.'. But this doesn't allow intrinsic functions and can thereby also start with 'States.Array'.


        task = sfn_tasks.BatchSubmitJob(self, id,
                                        job_definition_arn=self.job_definition.job_definition_arn,
                                        job_name=id,
                                        job_queue_arn=self.job_queue.job_queue_arn,
                                        container_overrides={
                                            "command" : sfn.JsonPath.list_at("States.Array('StaticValue1',$.DynamicValue2,'StaticValue3')")
                                  }

                                        )

https://github.com/aws/aws-cdk/blob/919605a781ac02393559fd96cbd8c136f87bce14/packages/%40aws-cdk/aws-stepfunctions/lib/fields.ts#L228-L232

Use Case

allow intrinsic functions and can thereby also start with 'States.Array'

Proposed Solution

From: https://github.com/aws/aws-cdk/blob/919605a781ac02393559fd96cbd8c136f87bce14/packages/%40aws-cdk/aws-stepfunctions/lib/fields.ts#L228-L232

To:

function validateDataPath(path: string) {
  if (path !== '$' 
    && !path.startsWith('$.')
    && ['Format','Array'].every(fn => !path.startsWith(`States.${fn}`))) {
    throw new Error("Data JSON path values must either be exactly equal to '$' or start with '$.'");
  }
}

Other information

No response

Acknowledge

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

koups496 avatar Dec 08 '21 19:12 koups496

Marking this as effort small because the fix proposed is small, but it looks like the reason why we haven't yet supported ASL intrinsic functions as a whole is because there likely is some design work involved in getting that support right.

It's on my radar, hence the p1, but I haven't gotten to it yet.

kaizencc avatar Dec 13 '21 19:12 kaizencc

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Dec 13 '22 20:12 github-actions[bot]

Can this issue be looked into? I happened to run across the same issue and the only solution I could find was replacing the code with suggested solution.

StephenTondelM avatar Dec 21 '22 20:12 StephenTondelM

For those still facing this issue, it seems that using JsonPath.objectAt pointing to the array's Json Path does the trick. That may be better than having to tune the CDK's code.

pesama avatar Dec 24 '23 09:12 pesama

For those still facing this issue, it seems that using JsonPath.objectAt pointing to the array's Json Path does the trick. That may be better than having to tune the CDK's code.

Do you want to elaborate?

rotem1850 avatar Nov 24 '24 13:11 rotem1850