[英]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.