Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate constant string with jsonpath

Tags:

I have AWS step machine and one of the step is used to notify failure using SNS service. I want to select some metadata from input json into outgoing message. So i am trying to concatenate constant string with jsonpath like below

"Notify Failure": {       "Type": "Task",       "Resource": "arn:aws:states:::sns:publish",       "Parameters": {         "Message.$": "A job submitted through Step Functions failed for document id $.document_id",         "Subject":"Job failed",         "TopicArn": "arn:aws:sns:us-west-2:xxxxxxx:xxxxxxxx"       },       "End": true     } 

where document_id is one of the property in input json

However when i try save state machine defination i get error

There is a problem with your ASL definition, please review it and try again The value for the field 'Message.$' must be a valid JSONPath

like image 295
LP13 Avatar asked Jan 18 '19 23:01

LP13


2 Answers

I was able to solve a similar issue using:

"Message.$": "States.Format('A job submitted through Step Functions failed for document id {}', $.document_id)", 

Described in a AWS News Blog post.

like image 197
Alex Avatar answered Oct 05 '22 02:10

Alex


The JSONPath implementation referenced from the AWS Step Functions documentation supports String concatenation via $.concat($..prop) but sadly this does not work when deployed to AWS, suggesting that AWS uses a different implementation.

Therefore there is no way to do string concatenation with JSONPath in AWS.

like image 42
timxyz Avatar answered Oct 05 '22 04:10

timxyz