更新堆栈w。 "替换:有条件的&#34 ;;它会取代吗?

时间:2017-04-18 12:28:58

标签: amazon-cloudformation

刚刚更新了我们的一些CF模板,并打算更新它所引用的堆栈。我添加了一些默认值并添加了CloudWatch警报,我还要将实例从m4.xlarge降级为m4.large。

我已经降级了EC2-GUI中的实例,它很顺利。然后我根据原始模板(即m4.xlarge)将其恢复为默认状态。 但是,当我修改模板中的实例类型的默认值时,它不会反映我何时将修改后的模板上传到CloudFormation。 这意味着默认值仍然是m4.xlarge,我必须使用下拉菜单选择模板中指定的m4.large。

如果我没有更改我得到的实例类型: "替换:错误"但如果我更新实例类型,我会得到"替换:有条件"。

如果我在" Changeset Details"然后"细节"我明白了:

[
  {
    "resourceChange": {
      "logicalResourceId": "CPUAlarm",
      "action": "Add",
      "physicalResourceId": null,
      "resourceType": "AWS::CloudWatch::Alarm",
      "replacement": null,
      "details": [],
      "scope": []
    },
    "type": "Resource"
  },
  {
    "resourceChange": {
      "logicalResourceId": "myInstanceName",
      "action": "Modify",
      "physicalResourceId": "<masked>",
      "resourceType": "AWS::EC2::Instance",
      "replacement": "Conditional",
      "details": [
        {
          "target": {
            "name": null,
            "requiresRecreation": "Never",
            "attribute": "Tags"
          },
          "causingEntity": null,
          "evaluation": "Dynamic",
          "changeSource": "DirectModification"
        },
        {
          "target": {
            "name": null,
            "requiresRecreation": "Never",
            "attribute": "Tags"
          },
          "causingEntity": "Project",
          "evaluation": "Static",
          "changeSource": "ParameterReference"
        },
        {
          "target": {
            "name": null,
            "requiresRecreation": "Never",
            "attribute": "Tags"
          },
          "causingEntity": null,
          "evaluation": "Static",
          "changeSource": null
        },
        {
          "target": {
            "name": "InstanceType",
            "requiresRecreation": "Conditionally",
            "attribute": "Properties"
          },
          "causingEntity": "InstanceType",
          "evaluation": "Static",
          "changeSource": "ParameterReference"
        },
        {
          "target": {
            "name": "InstanceType",
            "requiresRecreation": "Conditionally",
            "attribute": "Properties"
          },
          "causingEntity": null,
          "evaluation": "Dynamic",
          "changeSource": "DirectModification"
        }
      ],
      "scope": [
        "Properties",
        "Tags"
      ]
    },
    "type": "Resource"
  },
  {

所以我能看到的是: &#34; name&#34;:&#34; InstanceType&#34;,&#34; requiresRecreation&#34;:&#34; Conditional&#34;,是唯一具有更严格价值的值,因此整个stack gets&#34; Replacement:Conditional&#34;。

根据AWS: &#34;在某些情况下,AWS CloudFormation只有在您执行更改集后才能确定值。 AWS CloudFormation将这些更改标记为动态评估。例如,如果您引用有条件替换的更新资源,则AWS CloudFormation无法确定对更新资源的引用是否会发生更改。&#34;

来源: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets-samples.html#using-cfn-updating-stacks-changesets-samples-directly-editing-a-template

AFAIK&#34;更换:有条件的&#34; &#39;可能&#39;替换资源,即创建一个新的physicalResourceID,这反过来迫使我改变相关的SG等,但也可能不会这样做,对吗?

感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

通常不建议在CloudFormation之外修改通过CloudFormation创建的资源。对于您的上一个问题,Replacement: Conditional可能会或可能不会根据您尝试做的事情来替换资源。只要您在编辑EC2实例的实例类型的特定方案中例如时怀疑,查看AWS CloudFormation文档总是有帮助的,这里是什么文档状态:

  
      
  • 更新要求:Amazon EBS支持的实例的一些中断
  •   
  • 更新要求:替换实例存储支持的实例
  •   

参考:http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-instancetype