python - Boto3 CloudFormation 状态

标签 python amazon-web-services boto3 aws-cloudformation

是否可以获取 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/

相关文章:

amazon-web-services - AWS Lambda : An error occurred (403) when calling the HeadObject operation: Forbidden

python - 如何使用 github-flask 为 {+path} 提供 URL 参数?

javascript - Pycurl 脚本

amazon-web-services - AWS 和自动缩放 cassandra

amazon-web-services - 事件完成后触发 AWS lambda

python - 与 DynamoDB 库 Boto3 的事务

python - 使用自定义变量消息通过 AWS Lambda/Python 以 JSON 形式发送 Apple 推送通知

python - 如何在 Python 中实现 "also if"?

python - Django 模型日期字段中的可选年/月/日

python - boto3 aws 检查 s3 存储桶是否已加密