CloudFormation 更新堆栈

时间:2021-03-31 00:42:21

标签: node.js amazon-web-services aws-lambda amazon-cloudformation

我有一个最初从 CloudFormation 模板创建的堆栈。当我将文件保存到我的 s3 存储桶时,我需要在 node.js 中添加一些动态标签。这是我的代码。

let date = new Date();
let currentDate = date.toISOString();

let cloudFormationParams = {
    StackName: 'name-of-stack-created-from-cloud-formation', 
    Tags: [
      {
        Key: 'CurrentDate',
        Value: currentDate
      },
      /* more items */
    ],
    UsePreviousTemplate: true 
  };

  await cloudformation.updateStack(cloudFormationParams, (err, data) => {
    if (err) {
        console.log(err, err.stack); // an error occurred
        return { status: "error" }
    } else {
        console.log(data);           // successful response

    }
}).promise();

这给了我错误 "ValidationError","errorMessage":"Stack: is in UPDATE_IN_PROGRESS state and can not be updated.

谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:1)

Nodejs 提供了 wait_for 方法,允许您在代码中等待,如果感兴趣的话,堆栈处于该状态。您可以等待的可能状态是:

  • stackExists
  • stackCreateComplete
  • stackUpdateComplete
  • 等等。

因此,您可以在对堆栈执行进一步操作之前将 execute(...)wait_for 添加到您的代码中。