【问题标题】:How to output the stack create successful info until all the resources are created in the stack如何输出堆栈创建成功信息,直到堆栈中创建所有资源
【发布时间】:2019-09-09 21:20:44
【问题描述】:

我正在尝试使用aws cloudformation create-stack --stack-name ... --template-body file://... 创建一个堆栈来创建一个堆栈。我一执行命令,它就会输出堆栈 ID。但堆栈所需的资源仍在创建中。

我想在创建所有资源之前输出一些消息。

我不想在循环中描述堆栈。并输出消息,直到得到堆栈创建完成信号。

【问题讨论】:

    标签: amazon-cloudformation


    【解决方案1】:

    在初始创建堆栈请求之后,您需要请求另一个:

     aws cloudformation wait stack-create-complete --stack-name $STACK_ID_FROM_CREATE_STACK
    

    来自 aws 文档http://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/stack-create-complete.html

    等到堆栈状态为 CREATE_COMPLETE。它将每 30 次投票 秒,直到达到成功状态。这将退出 120 次检查失败后返回代码 255。

    【讨论】:

    • 你知道如果堆栈进入 CREATE_FAILED 会发生什么吗?该命令是否仍需要 60 分钟(30 秒 * 120)才能失败,或者一旦堆栈进入 CREATE_FAILED 状态就会失败?
    • 我经常面临 Rate Exceeded 异常。有没有办法配置轮询间隔?
    【解决方案2】:

    在运行aws cloudformation create-stack 之后,我还需要在我的 bash 脚本中等待。我对使用 aws cloudformation wait stack-create-complete 命令犹豫不决,因为它最多只能轮询 60 分钟(120 次 30 秒)。另外,我不想运行测试来查看如果堆栈最终处于“CREATE_COMPLETE”以外的状态会如何表现。因此,我在 bash 中编写了自己的等待如下:

    aws --region ${AWS_REGION} --profile ${AWS_PROFILE} cloudformation create-stack --template-body ${STACK_TEMPLATE} --stack-name ${STACK_NAME}
    if [[ $? -eq 0 ]]; then
        # Wait for create-stack to finish
        echo  "Waiting for create-stack command to complete"
        CREATE_STACK_STATUS=$(aws --region ${AWS_REGION} --profile ${AWS_PROFILE} cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].StackStatus' --output text)
        while [[ $CREATE_STACK_STATUS == "REVIEW_IN_PROGRESS" ]] || [[ $CREATE_STACK_STATUS == "CREATE_IN_PROGRESS" ]]
        do
            # Wait 30 seconds and then check stack status again
            sleep 30
            CREATE_STACK_STATUS=$(aws --region ${AWS_REGION} --profile ${AWS_PROFILE} cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].StackStatus' --output text)
        done
    fi
    

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 2013-04-03
      • 2015-06-16
      • 1970-01-01
      相关资源
      最近更新 更多