Skip to main content
 首页 » 编程设计

python之使用 AWS cloudformation 启动 EC2 实例时如何知道实例已准备就绪

2024年10月01日8sharpest

在使用 AWS cloudformation 创建堆栈后,我现在正在使用我的脚本 (Python) 发送检查实例状态的请求。 但这似乎不是一个好的解决方案。然后我尝试使用 cfn-signal 检查实例的状态,结果发现当收到信号时,cloudformation 堆栈已成功创建,但 EC2 实例仍在检查中。

使用 AWS cloudformatoin 启动 EC2 实例时如何知道实例已准备就绪

请您参考如下方法:

您可以为此使用 AWS 的 WaitCondition。基本上,WaitCondition 与 CloudFormation 模板一起使用以确保所需资源正在运行。

更多详情 click here

以下片段摘自上述文章

What is WaitCondition and who needs it?

WaitCondition can be considered as a timed semaphore which pauses the execution of yourCloudFormation template and waits for a number of success signals before it continues a stack creation operation. There are scenarios where you need to pause the execution of your CloudFormation stack, such as resource dependencies or user experience. Some scenarios also include:

- As a part of user experience, you want to pause completion of CloudFormation template and display of the output section until all resources are properly provisioned and in working state.

- There are resource dependencies where some additional scripts and packages on your instance must be properly configured before other AWS resources can contact them. For example, for successful backend configuration, a front end application should be in running state.

- An environment in which Active Directory should be in a running state before other instances perform authentication.

- A NAT instance should be in working state before private subnet instances try to fetch packages from the outside world.