是否可以获取 CloudFormation 堆栈的状态?如果是这样,怎么办?
我正在创建一个堆栈:
client = boto3.client('cloudformation',)
response = client.create_stack(
StackName=stackname,
...
)
我可以在 CloudFormation Web UI 中看到堆栈已成功创建。
我尝试通过以下方式获取状态:
print(client.describe_stacks(stack_name_or_id=hostname))
但这会引发异常:
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "stack_name_or_id", must be one of: StackName, NextToken
所以我尝试等待堆栈部署并捕获异常:
while True:
time.sleep(5)
try:
print(client.describe_stacks(stack_name_or_id=stackname))
except botocore.exceptions.ParamValidationError:
pass
但我根本没有得到任何回应; print
语句永远不会被调用。
最佳答案
错误信息:
Unknown parameter in input: "stack_name_or_id", must be one of: StackName, NextToken
清楚地表明您正在传递无效的参数名称; stack_name_or_id
。
在 Boto3 describe_stacks ,预期参数为:StackName
response = client.describe_stacks(
StackName='string',
NextToken='string'
)
对于正在运行的堆栈,您可以传递堆栈名称或堆栈 ID。但对于已删除的堆栈,您必须传递堆栈 ID。
client.describe_stacks(StackName='mystack')
{u'Stacks': [{u'StackId': 'arn:aws:cloudformation:us-east-1:.......
'content-type': 'text/xml',
'date': 'Thu, 22 Jun 2017 14:54:46 GMT'}}}
关于python - Boto3 CloudFormation 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44701794/