【发布时间】:2017-11-24 06:26:11
【问题描述】:
我正在使用 API 网关,并且有一个将数据传递给 Step Function 的服务。
Steps 函数需要以下格式的 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
}
但是,Step Function 所需的 JSON 略有不同。如何在无需手动显式添加每个阶段的情况下将所有阶段变量转换为 JSON 格式?
谢谢
【问题讨论】:
标签: json amazon-web-services aws-api-gateway vtl