Question:
I have orchestrated a data pipe line using AWS Step function.
In last state I want to send a custom notification. I’m using an Intrinsic function States.Format to format my message and subject. It works fine for Context object element. Here, I have tested that in Message parameter.
But it doesn’t work with input JSON. This is my input JSON
{
“job-param”:{
“pipe-line-name”:”My pipe line name”, “other-keys”:”other values”
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 |
"Success State": { "Type": "Task", "Resource": "arn:aws:states:::sns:publish", "Parameters": { "Message.$": "States.Format('Execution Id:{}, completed successfully!', $.Execution.Id)", "Subject.$": "States.Format('[INFO] {} completed successfully!', $.job-param.pipe-line-name)", "TopicArn": "arn:aws:sns:us-east-1:************:sns-topic" }, "End": true } |
While saving this state machine, it gives me following error message:
The value for the field ‘Subject.$’ must be a valid JSON Path
I checked Input and Result path. They have this value. I can directly use this value as parameter. This is working fine. But I can’t format with other string.
1 2 |
"Subject.$": "$.job-param.pipe-line-name" |
Alternate approach would be to call lambda to customize and trigger SNS. But I want to avoid that.
Can I request some suggestions to fix this error?
Thanks in advance!
Answer:
If you want to use any name with -
in your JSON then you can write your JSON Path like this:
1 2 |
"Subject.$": "States.Format('[INFO] {} completed successfully!', $['job-param']['pipe-line-name'])", |
But it would be easier if you change your input JSON and replace
-
with _
:
1 2 |
"Subject.$": "States.Format('[INFO] {} completed successfully!', $.job_param.pipe_line_name)", |