【问题标题】:CloudFormation UpdateStackCloudFormation 更新堆栈
【发布时间】:2021-06-27 00:20:09
【问题描述】:

我有一个最初从 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't be updated.

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

【问题讨论】:

  • 此错误仅表示您的堆栈当前正在更新中....等到您的堆栈处于最终状态(以 COMPLETE 或 FAILED 结尾)并重试
  • 为了解决这个问题,我试图调用一个函数来将每个文件保存在一个 for 循环中。此函数包含更新堆栈的代码。为循环中的第一个文件正确添加了标签,但之后的所有文件都会生成错误。

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


【解决方案1】:

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

  • stackExists
  • stackCreateComplete
  • stackUpdateComplete
  • 等等。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-15
    • 2017-08-08
    • 2018-09-11
    • 2023-02-15
    • 2021-07-01
    • 2014-07-11
    • 2014-02-24
    • 2018-06-03
    相关资源
    最近更新 更多