Reputation: 13
Is there a way to check undefined resource attribute (returned by Fn::GetAtt) within CloudFormation template?
I would like to include specified resource's attributes in the stack's outputs using Fn::GetAtt only if those attributes are defined.
For example, creating stack using the following template gives me an error:
"Attribute: StreamArn was not found for resource: MyTestStack-DDBTable-1C0T2MJZA1J0I. Rollback requested by user."
because the stream specification is not included in the resource properties of this specific table.
Of course, the simple way to fix this is just to remove StreamArn from the stack outputs list. However, I still would like to know how to check whether the attribute is defined for specified resource or not.
Any suggestions would be highly appreciated.
{
"Resources":{
"DDBTable":{
"Type":"AWS::DynamoDB::Table",
"Properties":{
"AttributeDefinitions":[
{
"AttributeName":"ArtistId",
"AttributeType":"S"
},
{
"AttributeName":"Concert",
"AttributeType":"S"
},
{
"AttributeName":"TicketSales",
"AttributeType":"S"
}
],
"GlobalSecondaryIndexes":[
{
"IndexName":"GSI",
"KeySchema":[
{
"AttributeName":"TicketSales",
"KeyType":"HASH"
}
],
"Projection":{
"ProjectionType":"KEYS_ONLY"
},
"ProvisionedThroughput":{
"ReadCapacityUnits":5,
"WriteCapacityUnits":5
}
}
],
"KeySchema":[
{
"AttributeName":"ArtistId",
"KeyType":"HASH"
},
{
"AttributeName":"Concert",
"KeyType":"RANGE"
}
],
"ProvisionedThroughput":{
"ReadCapacityUnits":5,
"WriteCapacityUnits":5
}
}
}
},
"Outputs":{
"DDBTablePhysicalID":{
"Value":{
"Ref":"DDBTable"
}
},
"DDBTableArn":{
"Value":{
"Fn::GetAtt":[
"DDBTable",
"Arn"
]
}
},
"DDBTableStreamArn":{
"Value":{
"Fn::GetAtt":[
"DDBTable",
"StreamArn"
]
}
}
}
}
Upvotes: 1
Views: 522
Reputation: 238071
only if those attributes are defined.
Its not supported in plain CFN. You have to do it by defining your own macro or custom resource in the form of a lambda fuction.
Upvotes: 0