通过映射模板将 SourceIp 附加到 AWS Step Function 输入

问题描述 投票:0回答:1

我一直在尝试在触发之前通过映射模板将 sourceIp 添加到我的步骤函数输入中。

基本上,

之前:

{
"input": "{\"uuid\":\"12345\",\"domain\":\"stackoverflow.com\"}",
"stateMachineArn": "arn:aws:states:us-east-1:xxx:xxxx"
}

之后:

{
"input": "{\"uuid\":\"12345\",\"domain\":\"stackoverflow.com\,\"sourceIp\":\"0.0.0.0\"}",
"stateMachineArn": "arn:aws:states:us-east-1:xxx:xxxx"
}

我尝试了多种映射模板配置,但这是我能得到的最接近的配置,chatGPT 坚持认为应该有效

#set($elem = $util.parseJson($input.json('$')))
#set($source = $context.identity.sourceIp)

#set($inputValue = $elem.get("input"))
#set($updatedInput = $util.parseJson($inputValue).put("source", $source))
#set($updatedInputString = $util.escapeJavaScript($util.toJson($updatedInput)))

{
  "input": "$updatedInputString",
  "stateMachineArn": "$elem.stateMachineArn"
}

结果如下:

 {
   "input": "",
   "stateMachineArn": "arn:aws:states:us-east-1:xxx:xxxx"
 }

我对此束手无策,希望得到任何意见。

谢谢!

mapping aws-api-gateway
1个回答
0
投票

可能不是最漂亮的,但它适合我的情况。希望对其他人有帮助!

#set($elem = $util.parseJson($input.json('$')))
#set($secondElem = $util.parseJson($elem.input))
#set($sourceIp = $context.identity.sourceIp)


{
  "input": "{\"uuid\": \"$secondElem.uuid\",\"domain\": \"$secondElem.domain\",\"source\": \"$sourceIp\"}",
  "stateMachineArn": "$elem.stateMachineArn"
}
© www.soinside.com 2019 - 2024. All rights reserved.