我有一个很长但重复的 json 格式的状态机定义,我正在尝试使用状态机块的 DefinitionSubstitutions 属性将一些公共块提取到 AWS SAM 模板中。例如,我有一个 Retry
政策,如下所示:
{
"StartAt": "Generate Config",
"States": {
"Generate Config": {
"Type": "Task",
"Resource": "${GenerateConfigFunctionArn}",
"Retry": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"IntervalSeconds": 15,
"MaxAttempts": 5,
"BackoffRate": 1.5
}
],
"Next": "Process basins"
},
...
我想像这样将重试块提取到 AWS SAM 模板中:
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
}
]
...
所以上面变成:
{
"StartAt": "Generate Config",
"States": {
"Generate Config": {
"Type": "Task",
"Resource": "${GenerateConfigFunctionArn}",
"Retry": "${RetryPolicy}",
"Next": "Process basins"
},
...
但是,当我运行 aws deploy
时出现错误:
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
我不明白我做错了什么。