我正在使用API网关并具有将数据传递到Step Function的服务。是否有可能将所有阶段变量添加到嵌套JSON结构中的正文映射模板中?
步骤功能需要在以下格式JSON输入:
{
"input":"",
"stateMachineArn": "arn:aws:states:eu-west-1:xxxxxxxxxxxx:stateMachine:StateMachine-1"
}
我目前通过阶段变量以手动方式即
#set($data = $util.escapeJavaScript($input.json('$')))
{
"input": "{
\"input\": $data,
\"stageVariables\" : {
\"clientId\": \"${stageVariables.clientId}\",
\"clientSecret\": \"${stageVariables.clientSecret}\",
\"password\": \"${stageVariables.password}\" },
"stateMachineArn": "arn:aws:states:eu-west-1:xxxxxxxxxxxx:stateMachine:StateMachine-1"
}
我知道你可以使用默认映射模板像这样循环通过舞台变量并生成一个JSON:
"stage-variables" : {
#foreach($key in $stageVariables.keySet())
"$key" : "$util.escapeJavaScript($stageVariables.get($key))"
#if($foreach.hasNext),#end
#end
}
但是,步骤功能所需的JSON稍有不同。如何将所有阶段变量转换为我的JSON格式,而无需手动显式添加每个变量?
谢谢
感谢您的回复@JackKohn,请参阅我发布的问题的答案。亲切的问候。 – cyorkston