Is it possible to use Fn::ImportValue inside Fn::GetAtt. 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".
The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template. For more information about GetAtt return values for a particular resource, refer to the documentation for that resource in the Resource and property reference.
The intrinsic function Fn::ImportValue returns the value of an output exported by another stack. You typically use this function to create cross-stack references. In the following example template snippets, Stack A exports VPC security group values and Stack B imports them.
To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.
GetAtt is essentially the same as the 2nd function of Ref above, it also returns an attribute of the resource that you created within your resource, but while ref returns only a default attribute, GetAtt allows you to choose from different attributes to return.
As it currently stands, it's not possible to have "Fn::ImportValue" inside of "Fn::GetAtt" block. 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:
"Resources" : {
"XApiResource": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"RestApiId": {"Fn::ImportValue" : "RestApi"},
"ParentId": {"Fn::ImportValue" : "RestApiRootResourceId"},
"PathPart": "apiPath"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With