I have a very long but repetitive State Machine definition in json format and I am trying to extract some of the common blocks into the AWS SAM template using the DefinitionSubstitutions property of the State Machine block. For example, I have a Retry
policy like so:
{
"StartAt": "Generate Config",
"States": {
"Generate Config": {
"Type": "Task",
"Resource": "${GenerateConfigFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"IntervalSeconds": 15,
"MaxAttempts": 5,
"BackoffRate": 1.5
}
],
"Next": "Process basins"
},
...
I would like to extract the retry block into the AWS SAM template like so:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
PredictiveAnalyticsPipelineOrchestration:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: stateMachine/definition.asl.json
DefinitionSubstitutions:
GenerateConfigFunctionArn: !GetAtt GenerateConfigFunction.Arn
RetryPolicy: |
[
{
"ErrorEquals": [
"States.ALL"
],
"IntervalSeconds": 10,
"MaxAttempts": 2,
"BackoffRate": 1.5
}
]
...
So the above becomes:
{
"StartAt": "Generate Config",
"States": {
"Generate Config": {
"Type": "Task",
"Resource": "${GenerateConfigFunctionArn}",
"Retry": "${RetryPolicy}",
"Next": "Process basins"
},
...
However, when I run aws deploy
I get an error:
Resource handler returned message: "Invalid State Machine Definition:
'INVALID_JSON_DESCRIPTION: Illegal unquoted character ((CTRL-CHAR, code 10)):
has to be escaped using backslash to be included in string value
I don't understand what I am doing wrong.