我正在使用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