【问题标题】:CloudFormation Update support for "Refer to Resources in Another Stack"CloudFormation 更新支持“参考另一个堆栈中的资源”
【发布时间】:2016-07-29 10:09:45
【问题描述】:

我正在使用来自Walkthrough: Refer to Resources in Another Stack 的示例来引用另一个堆栈中的资源(我认为这非常有用,应该是一个开箱即用的功能)。但是,该示例似乎不适用于更新,即如果将新输出添加到引用的堆栈中。

有趣的是,lambda 函数甚至没有根据日志和指标调用,因此它似乎不是可以在代码中修复的问题。我确实认为代码应该根据Replacing a Custom Resource During an Update在更新时使用不同的PhysicalResourceId

注意:这是来自unanswered AWS Forum thread的交叉帖子

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-lambda


    【解决方案1】:

    事实证明,CloudFormation 仅在其属性之一发生更改时才更新自定义资源。一旦发生这种情况,自定义资源应该发出它已更改的信号。所以

    替换:

    response.send(event, context, response.SUCCESS, responseData);
    

    var crypto = require('crypto');
    var hash = crypto.createHash('md5').update(JSON.stringify(responseData)).digest('hex');
    response.send(event, context, response.SUCCESS, responseData, hash);
    

    这将在更新期间导致以下事件:

    15:08:16 UTC+0200  UPDATE_COMPLETE     Custom::NetworkInfo  NetworkInfo 
    15:08:15 UTC+0200  UPDATE_IN_PROGRESS  Custom::NetworkInfo  NetworkInfo  Requested update required the provider to create a new physical resource
    15:08:08 UTC+0200  UPDATE_IN_PROGRESS  Custom::NetworkInfo  NetworkInfo
    

    这仍然需要更改属性。我想出的最好的方法是将伪随机参数传递给自定义资源:

    {
      "Parameters": {
        "Random": {
          "Description": "Random value to force stack-outputs update",
          "Type": "String"
        }
      },
      "Resources": {
        "NetworkInfo": {
          "Type": "Custom::NetworkInfo",
          "Properties": {
            "ServiceToken": { "Fn::GetAtt" : ["LookupStackOutputs", "Arn"] },
            "Random": { "Ref": "Random" },
            "StackName": { "Ref": "NetworkStackName" }
          }
        }
      }
    }
    

    未知参数(即Random)会被 lambda 函数简单地忽略。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 2021-06-27
      • 2016-06-09
      • 2020-12-02
      相关资源
      最近更新 更多