I want to get a list of stacks based on a give set of states. I am aware of a solution using the boto3 client for cloudformation, e.g. from the documentation:
response = client.list_stacks(
NextToken='string',
StackStatusFilter=[
'CREATE_IN_PROGRESS'|'CREATE_FAILED'|'CREATE_COMPLETE'|
'ROLLBACK_IN_PROGRESS'|'ROLLBACK_FAILED'|'ROLLBACK_COMPLETE'|
'DELETE_IN_PROGRESS'|'DELETE_FAILED'|'DELETE_COMPLETE'|
'UPDATE_IN_PROGRESS'|'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS'|
'UPDATE_COMPLETE'|'UPDATE_ROLLBACK_IN_PROGRESS'|'UPDATE_ROLLBACK_FAILED'|
'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'|'UPDATE_ROLLBACK_COMPLETE'|
'REVIEW_IN_PROGRESS',
]
)
(side note: I think the |
should be ,
, but anyway)
However, I understand that the "recommended" way is using boto3 resources to access the AWS services. Unfortunately, the boto3 cloudformation resource has not method to list and filter stacks (see the documentation).
I would like to avoid looping over all stacks and check each retrieved stack object for its status.
The only way I found so far, is the work around by accessing the client of the resource, though it feels a bit hacky and there is no way to filter for instance on the stackname.
cf = boto3.Session().resource('cloudformation')
cf.meta.client.list_stacks(StackStatusFilter=['ROLLBACK_COMPLETE'])
Question: Any idea how I could get something like list_stacks(StackStatusFilter=..)
for cf
, which is a cloudformation.ServiceResource
object that allows to filter on the status and the stackname?