简体   繁体   English

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

[英]AWS Cloudformation Fn::ImportValue inside Fn::GetAtt

Is it possible to use Fn::ImportValue inside Fn::GetAtt. 是否可以在Fn :: GetAtt中使用Fn :: ImportValue。 Currently, I'm trying to do the following 目前,我正在尝试执行以下操作

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

But I'm facing an error. 但我面临一个错误。 "Template error: every Fn::GetAtt object requires two non-empty parameters, the resource name and the resource attribute". “模板错误:每个Fn :: GetAtt对象都需要两个非空参数,即资源名称和资源属性”。

As it currently stands, it's not possible to have "Fn::ImportValue" inside of "Fn::GetAtt" block. 就目前看来,“Fn :: GetAtt”块内的“Fn :: ImportValue”是不可能的。 The best explanation I have for this is that resource for which you want to get attribute value is not in a scope of your current template. 我对此的最佳解释是,您想要获取属性值的资源不在当前模板的范围内。

What you can try to do is to export all attribute values you are interested in from 'parent' template. 您可以尝试执行的操作是从“父”模板导出您感兴趣的所有属性值。

So your parent template would look like this: 所以你的父模板看起来像这样:

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

And now in your child template you can reference your API root resource id from parent template: 现在,在您的子模板中,您可以从父模板引用API根资源ID:

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

Though it's a bit complex, the syntax looks correct, so the problem is probably that the first parameter resolves to an empty value (since the second one is clearly a string that you stated). 虽然它有点复杂,但语法看起来是正确的,所以问题可能是第一个参数解析为空值(因为第二个参数显然是你所说的字符串)。

You could try figuring out if that is the case by removing any parts of the stack that fail, creating an output to the stack, and seeing if it has a value. 您可以通过删除堆栈中任何失败的部分,创建输出到堆栈,并查看它是否有值来尝试确定是否是这种情况。

Something like: 就像是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Cloudformation中使用DependsOn和Fn :: ImportValue - Using DependsOn with Fn::ImportValue in Cloudformation Cloudformation:一起使用 Fn::Join 和 Fn:GetAtt - Cloudformation: Using Fn::Join and Fn:GetAtt together CloudFormation:Fn::GetAtt:不适用于 AWS::RDS::DBInstance 上的 Endpoint.Address - CloudFormation: Fn::GetAtt: not working for Endpoint.Address on AWS::RDS::DBInstance Cloudformation 模板中的组合 Fn::Select + Fn::Split + Fn:GetAtt - Combination Fn::Select + Fn::Split + Fn:GetAtt in Cloudformation template 在cloudformation模板之间创建Fn :: GetAtt引用 - Create Fn::GetAtt references between cloudformation templates Fn:GetAtt for AWS :: RDS :: DBSubnetGroup对象 - Fn:GetAtt for AWS::RDS::DBSubnetGroup object AWS Fn::ImportValue !Sub 不接受值 - AWS Fn::ImportValue !Sub not accepting value CommaDelimitedList、fn:if 和 fn:select 的 AWS Cloudformation 组合 - AWS Cloudformation combination of CommaDelimitedList, fn:if and fn:select CloudFormation YAML 结合 FN::GETAtt 和 !Ref 以列出 id - CloudFormation YAML combining FN::GEtAtt and !Ref to list ids AWS cloudformation 错误:模板验证错误:模板错误:资源 NotificationsTopic 不支持 Fn::GetAtt 中的属性类型 Arn - AWS cloudformation error: Template validation error: Template error: resource NotificationsTopic does not support attribute type Arn in Fn::GetAtt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM