如何在json中将字符串内部函数放在字符串中

时间:2017-10-03 09:29:55

标签: json amazon-web-services amazon-cloudformation

"整合":{" IntegrationHttpMethod" :" GET"," Type" :" HTTP"," Uri" :" http:// {" Fn :: GetAtt" :[" MyEC2Instance"," PublicIp" ]}:8080 / rest"

2 个答案:

答案 0 :(得分:0)

我会查看Sub函数。如果您想将{"Fn::GetAtt" : [ "MyEC2Instance", "PublicIp" ] }的结果放在示例字符串中,可以使用

完成
"MyGatewayMethod": {
  "Type": "AWS::ApiGateway::Method",
  "Properties": {

    ...

    "Integration": {
      "Type": "HTTP",
      "IntegrationHttpMethod": "GET",
      "Uri": { "Fn::Sub":"http://${MyEC2Instance.PublicIp}:8080/rest" }
    }
  }
}

Sub方法可用于替换GetAtt值和Ref值。

答案 1 :(得分:0)

感谢。我用这个函数Fn :: Join

解决了它

“Integration”:{“IntegrationResponses”:[{“StatusCode”:200}],“IntegrationHttpMethod”:“GET”,“Type”:“HTTP”,“Uri”:{“Fn :: Join”: [“”,[“http://”,{“Fn :: GetAtt”:[“MyEC2Instance”,“PublicIp”]},“:8080 / rest”]]}}

}           }