【发布时间】:2014-05-25 23:55:54
【问题描述】:
使用 Boto 检查 CloudFormation 堆栈是否存在且未处于损坏状态的最佳方法是什么?破碎是指失败和回滚状态。
我不想使用try/except 解决方案,因为 boto 将其记录为错误,而在我的场景中,它会将异常日志发送到警报系统。
目前我有以下解决方案:
1) 使用boto.cloudformation.connection.CloudFormationConnection.describe_stacks()
valid_states = '''\
CREATE_IN_PROGRESS
CREATE_COMPLETE
UPDATE_IN_PROGRESS
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
UPDATE_COMPLETE'''.splitlines()
def describe_stacks():
result = []
resp = cf_conn.describe_stacks()
result.extend(resp)
while resp.next_token:
resp = cf_conn.describe_stacks(next_token=resp.next_token)
result.extend(resp)
return result
stacks = [stack for stack in describe_stacks() if stack.stack_name == STACK_NAME and stack.stack_status in valid_states]
exists = len(stacks) >= 1
这很慢,因为我有很多堆栈。
2) 使用boto.cloudformation.connection.CloudFormationConnection.list_stacks()
def list_stacks(filters):
result = []
resp = cf_conn.list_stacks(filters)
result.extend(resp)
while resp.next_token:
resp = cf_conn.list_stacks(filters, next_token=resp.next_token)
result.extend(resp)
return result
stacks = [stack for stack in list_stacks(valid_states) if stack.stack_name == STACK_NAME]
exists = len(stacks) >= 1
这需要很长时间,因为摘要会保留 90 天,而且我有很多堆栈。
问题:检查给定堆栈是否存在且未处于故障或回滚状态的理想解决方案是什么?
【问题讨论】:
-
如果 list_stacks 接受 stack_names 过滤器列表,那就太好了。你有没有找到解决这个问题的方法?
-
@bdrx:不,我没有,自从我发布这个问题的那一周以来,我也没有寻找其他解决方案。
标签: python amazon-web-services boto amazon-cloudformation