Fn :: GetAtt中的AWS Cloudformation Fn :: ImportValue

时间:2017-11-26 14:07:34

标签: amazon-web-services amazon-cloudformation

是否可以在Fn :: GetAtt中使用Fn :: ImportValue。目前,我正在尝试执行以下操作

    "ParentId": {
       "Fn::GetAtt": [
          {
            "Fn::ImportValue": {
               "Fn::Sub": "${ParentStack}:RestApi"
             }
          },
          "RootResourceId"
       ]
    }

但我面临一个错误。 "模板错误:每个Fn :: GetAtt对象都需要两个非空参数,即资源名称和资源属性"。

2 个答案:

答案 0 :(得分:5)

目前看来,不可能拥有" Fn :: ImportValue"在" Fn :: GetAtt"块。我对此的最佳解释是,您想要获取属性值的资源不在当前模板的范围内。

您可以尝试做的是导出您感兴趣的所有属性值来自父母'模板。

所以你的父模板看起来像这样:

"Outputs" : {
  "RestApi": {
    "Value" : { "Ref": "RestApi" },
    "Export" : { "Name": "RestApi" }
  },
  "RestApiRootResourceId": {
    "Value" : { "Fn::GetAtt": ["RestApi", "RootResourceId"] },
    "Export" : { "Name" : "RestApiRootResourceId" }
  }
}

现在,在您的子模板中,您可以从父模板中引用API根资源ID:

"Resources" : {
  "XApiResource": {
    "Type": "AWS::ApiGateway::Resource",
    "Properties": {
      "RestApiId": {"Fn::ImportValue" : "RestApi"},
      "ParentId": {"Fn::ImportValue" : "RestApiRootResourceId"},
      "PathPart": "apiPath"
    }
  }
}

答案 1 :(得分:1)

虽然它有点复杂,但语法看起来是正确的,所以问题可能是第一个参数解析为空值(因为第二个参数显然是你所说的字符串)。

您可以尝试通过删除堆栈中任何失败的部分,创建堆栈输出以及查看它是否具有值来确定是否是这种情况。

类似的东西:

"Outputs" : {
    "ParentStack" : {
        "Value" : "Fn::Ref": "ParentStack"
    },
    "ParentStackRestAPI" : {
        "Value" : "Fn::Sub": "${ParentStack}:RestApi"
    },
    "ImportedValue" : {
        "Value" : "Fn::ImportValue": {
            "Fn::Sub": "${ParentStack}:RestApi"
        }
    }
}
相关问题