

# 查看 CloudFormation 堆栈的更改集
<a name="using-cfn-updating-stacks-changesets-view"></a>

创建更改集之后，您可在执行之前查看提议的更改。您可以使用 CloudFormation 控制台、AWS CLI 或 CloudFormation API 查看更改集。CloudFormation 控制台提供了更改摘要以及 JSON 格式的更改详细列表。AWS CLI 和 AWS CloudFormation API 以 JSON 格式返回详细的更改列表。

------
#### [ View a change set (console) ]

**查看更改集**

1. 通过以下网址打开 CloudFormation 控制台：[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/)。

1. 在屏幕顶部的导航栏中，选择您的 AWS 区域。

1. 在**堆栈**页面上，选择包含您要查看的更改集的堆栈名称。

1. 在导航窗格中，选择 **Change Sets (更改集)** 以查看堆栈的更改集的列表。

1. 选择要查看的更改集的名称。

   CloudFormation 控制台将您引导到更改集的详细信息页面，在其中您可以查看创建更改集的时间、其状态、用于生成更改集的输入，以及更改摘要。

   在**更改**部分中，每一行表示 CloudFormation 将添加、修改或删除的资源。
   + **添加** – CloudFormation 在您将资源添加到堆栈的模板上时创建资源。
   + **修改** – CloudFormation 在您更改堆栈模板中资源的属性时修改资源。
   + **删除** – CloudFormation 在您删除堆栈模板中的资源时删除资源。
**注意**  
修改可能会导致中断或替换（重新创建）资源。有关资源更新行为的更多信息，请参阅[理解堆栈资源的更新行为](using-cfn-updating-stacks-update-behaviors.md)。

   要重点查看特定更改，请使用筛选视图。例如，筛选特定资源类型，如 `AWS::EC2::Instance`。要筛选特定资源，请指定其逻辑或物理 ID，例如 `myWebServer` 或 `i-123abcd4`。

1. 在**更改**部分中，选择**属性级别更改**列中的**查看详细信息**，以查看资源的属性值更改。

1. CloudFormation 控制台将引导您打开资源的属性级别更改页面，您可以在其中查看执行更改集之前的资源模板配置，以及执行更改集之后将会具有的模板配置。

   **属性级别更改**部分的表格显示了受影响属性的**路径**、**更改类型**、**更改前值**和**更改后值**。在该表格中，选中要在模板的**更改前**和**更改后**视图中突出显示的每项更改的复选框，以查看将在属性级别进行的具体更改。
   + **添加** – 添加的属性以绿色突出显示。
   + **修改** – 修改后的属性以蓝色突出显示。
   + **移除** – 已删除的属性以红色突出显示。

------
#### [ View a change set for nested stack (console) ]

**查看嵌套堆栈的更改集（控制台）**

1. 通过以下网址打开 CloudFormation 控制台：[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/)。

1. 在屏幕顶部的导航栏中，选择您的 AWS 区域。

1. 在**堆栈**页面上，选择包含您要查看的更改集的堆栈名称。

1. 在导航窗格中，选择**更改集**以查看堆栈的更改集列表。

1. 选择要查看的更改集的名称。

   CloudFormation 控制台将您引导到更改集的详细信息页面，在其中您可以查看创建更改集的时间、其状态、用于生成更改集的输入，以及更改摘要。

   在**更改**部分中，每一行表示 CloudFormation 将添加、修改、删除或显示动态状态的资源。
   + **添加** – CloudFormation 在您将资源添加到堆栈的模板上时创建资源。
   + **修改** – CloudFormation 在您更改堆栈模板中资源的属性时修改资源。
   + **删除** – CloudFormation 在您删除堆栈模板中的资源时删除资源。
   + **动态** – CloudFormation 无法从嵌套堆栈的模板中确定确切的资源更改操作。
**注意**  
修改可能会导致中断或替换（重新创建）资源。有关资源更新行为的更多信息，请参阅[理解堆栈资源的更新行为](using-cfn-updating-stacks-update-behaviors.md)。

   要重点查看特定更改，请使用筛选视图。例如，筛选特定资源类型，如 **AWS::CloudFormation::Stack**。要筛选特定资源，请指定其逻辑或物理 ID，例如 **DeadLetterQueue** 或 **NestedStack**。

1. 在**更改**部分中，选择要查看的嵌套更改集的**查看嵌套更改集**。

   CloudFormation 控制台会将您引导到嵌套更改集的详细信息页面。您可以选择**转到根更改集**以查看根更改集，也可以选择**查看父更改集**以查看父更改集。有关更多信息，请参阅[嵌套堆栈的更改集](change-sets-for-nested-stacks.md)。
**注意**  
为嵌套堆栈创建更改集时，CloudFormation 属性级的更改集无法解析跨堆栈引用。如果子堆栈中的资源引用了父堆栈的输出，而父堆栈已被修改，则更改集可以标记这些资源以便进行有条件替换

------

**查看更改集 (AWS CLI)**

1. 要获取更改集的 ID，请运行 [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/list-change-sets.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/list-change-sets.html) 命令。

   指定具有您要查看的更改集的堆栈名称，如下例中所示：

   ```
   aws cloudformation list-change-sets --stack-name MyStack
   ```

   CloudFormation 返回更改集列表，类似于以下内容：

   ```
   {
       "Summaries": [
           {
               "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/1a2345b6-0000-00a0-a123-00abc0abc000",
               "Status": "CREATE_COMPLETE",
               "ChangeSetName": "SampleChangeSet",
               "CreationTime": "2020-11-18T20:44:05.889Z",
               "StackName": "MyStack",
               "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet/1a2345b6-0000-00a0-a123-00abc0abc000"
           },
           {
               "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/1a2345b6-0000-00a0-a123-00abc0abc000",
               "Status": "CREATE_COMPLETE",
               "ChangeSetName": "SampleChangeSet-conditional",
               "CreationTime": "2020-11-18T21:15:56.398Z",
               "StackName": "MyStack",
               "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet-conditional/1a2345b6-0000-00a0-a123-00abc0abc000"
           },
           {
               "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/1a2345b6-0000-00a0-a123-00abc0abc000",
               "Status": "CREATE_COMPLETE",
               "ChangeSetName": "SampleChangeSet-replacement",
               "CreationTime": "2020-11-18T21:03:37.706Z",
               "StackName": "MyStack",
               "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet-replacement/1a2345b6-0000-00a0-a123-00abc0abc000"
           }
       ]
   }
   ```

1. 运行 [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-change-set.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-change-set.html) 命令，指定您要查看的更改集的 ID。例如：

   ```
   aws cloudformation describe-change-set \
     --change-set-name arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet/1a2345b6-0000-00a0-a123-00abc0abc000
   ```

   CloudFormation 返回有关指定更改集的信息。

   ```
   {
       "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/1a2345b6-0000-00a0-a123-00abc0abc000",
       "Status": "CREATE_COMPLETE",
       "ChangeSetName": "SampleChangeSet-direct",
       "Parameters": [
           {
               "ParameterValue": "testing",
               "ParameterKey": "Purpose"
           },
           {
               "ParameterValue": "ellioty-useast1",
               "ParameterKey": "KeyPairName"
           },
           {
               "ParameterValue": "t2.micro",
               "ParameterKey": "InstanceType"
           }
       ],
       "Changes": [
           {
               "ResourceChange": {
                   "ResourceType": "AWS::EC2::Instance",
                   "PhysicalResourceId": "i-1abc23d4",
                   "Details": [
                       {
                           "ChangeSource": "DirectModification",
                           "Evaluation": "Static",
                           "Target": {
                               "Attribute": "Tags",
                               "RequiresRecreation": "Never"
                           }
                       }
                   ],
                   "Action": "Modify",
                   "Scope": [
                       "Tags"
                   ],
                   "LogicalResourceId": "MyEC2Instance",
                   "Replacement": "False"
               },
               "Type": "Resource"
           }
       ],
       "CreationTime": "2020-11-18T23:35:25.813Z",
       "Capabilities": [],
       "StackName": "MyStack",
       "NotificationARNs": [],
       "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet-direct/9edde307-960d-4e6e-ad66-b09ea2f20255"
   }
   ```

   将 `--include-property-values` 与 **describe-change-set** 结合使用可列出属性级别的更改。

   `Changes` 键列出对资源的更改。如果您要执行此更改集，CloudFormation 将更新 `i-1abc23d4` EC2 实例的标签。有关各字段的说明，请参阅《AWS CloudFormation API 参考》**中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_Change.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_Change.html) 数据类型。

   有关更改集的其他示例，请参阅[CloudFormation 堆栈的更改集示例](using-cfn-updating-stacks-changesets-samples.md)。

**查看更改集中的属性级别更改（AWS CLI）**
+ 以下命令列出了与 `AWS::EC2::NetworkInterface` 资源的一个更改集相关的属性级别更改，包括移除 `Ipv4Prefixes` 属性、修改该资源的 `Description` 并添加一个 `Tag`：

  ```
  aws cloudformation describe-change-set --include-property-values \
    --change-set-name arn:aws:cloudformation:us-east-1:123456789012:changeSet/ExampleChangeSet/9f7b541b-126b-44f7-998e-932174557841
  ```

  下面是示例输出。

  ```
  "ChangeSetName": "ExampleChangeSet",
      "ChangeSetId": "arn:aws:cloudformation:us-east-1:803642222207:changeSet/ExampleChangeSet/9f7b541b-126b-44f7-998e-932174557841",
      "StackId": "arn:aws:cloudformation:us-east-1:803642222207:stack/ExampleStack/ab664180-f686-11ee-9e29-12cd92393671",
      "StackName": "ExampleStack",
      "Description": null,
      "Parameters": null,
      "CreationTime": "2024-04-09T18:04:59.935000+00:00",
      "ExecutionStatus": "AVAILABLE",
      "Status": "CREATE_COMPLETE",
      "StatusReason": null,
      "NotificationARNs": [],
      "RollbackConfiguration": {
          "RollbackTriggers": []
      },
      "Capabilities": [],
      "Tags": null,
      "ParentChangeSetId": null,
      "IncludeNestedStacks": true,
      "RootChangeSetId": null,
      "OnStackFailure": null,
   {
      "Changes": [
          {
              "Type": "Resource",
              "ResourceChange": {
                  "Action": "Modify",
                  "LogicalResourceId": "EC2NetworkInterface00eni067fd35b649a05b7100Tpyls",
                  "PhysicalResourceId": "eni-067fd35b649a05b71",
                  "ResourceType": "AWS::EC2::NetworkInterface",
                  "Replacement": "False",
                  "Scope": [
                      "Properties",
                      "Tags"
                  ],
                  "Details": [
                      {
                          "Target": {
                              "Attribute": "Properties",
                              "Name": "Ipv4Prefixes",
                              "RequiresRecreation": "Never",
                              "Path": "/Properties/Ipv4Prefixes",
                              "BeforeValue": "[]",
                              "AttributeChangeType": "Remove"
                          },
                          "Evaluation": "Static",
                          "ChangeSource": "DirectModification"
                      },
                      {
                          "Target": {
                              "Attribute": "Properties",
                              "Name": "Description",
                              "RequiresRecreation": "Never",
                              "Path": "/Properties/Description",
                              "BeforeValue": "",
                              "AfterValue": "Description",
                              "AttributeChangeType": "Modify"
                          },
                          "Evaluation": "Static",
                          "ChangeSource": "DirectModification"
                      },
                      {
                          "Target": {
                              "Attribute": "Tags",
                              "RequiresRecreation": "Never",
                              "Path": "/Properties/Tags/0",
                              "AfterValue": "{\"Key\":\"Test\",\"Value\":\"Test\"}",
                              "AttributeChangeType": "Add"
                          },
                          "Evaluation": "Static",
                          "ChangeSource": "DirectModification"
                      }
                  ],
                  "BeforeContext": "{\"Properties\":{\"Description\":\"\",\"PrivateIpAddress\":\"172.31.76.2\",\"PrivateIpAddresses\":[{\"PrivateIpAddress\":\"172.31.76.2\",\"Primary\":\"true\"}],\"SecondaryPrivateIpAddressCount\":\"0\",\"Ipv6PrefixCount\":\"0\",\"Ipv4Prefixes\":[],\"Ipv4PrefixCount\":\"0\",\"GroupSet\":[\"sg-05a45689b1059e82d\"],\"Ipv6Prefixes\":[],\"SubnetId\":\"subnet-455e8969\",\"SourceDestCheck\":\"true\",\"InterfaceType\":\"interface\",\"Tags\":[]},\"UpdateReplacePolicy\":\"Retain\",\"DeletionPolicy\":\"Retain\"}",
                  "AfterContext": "{\"Properties\":{\"Description\":\"Description\",\"PrivateIpAddress\":\"172.31.76.2\",\"PrivateIpAddresses\":[{\"PrivateIpAddress\":\"172.31.76.2\",\"Primary\":\"true\"}],\"SecondaryPrivateIpAddressCount\":\"0\",\"Ipv6PrefixCount\":\"0\",\"Ipv4PrefixCount\":\"0\",\"GroupSet\":[\"sg-05a45689b1059e82d\"],\"Ipv6Prefixes\":[],\"SubnetId\":\"subnet-455e8969\",\"SourceDestCheck\":\"true\",\"InterfaceType\":\"interface\",\"Tags\":[{\"Value\":\"Test\",\"Key\":\"Test\"}]},\"UpdateReplacePolicy\":\"Retain\",\"DeletionPolicy\":\"Retain\"}"
              }
          }
      ],
      "ChangeSetName": "ExampleChangeSet",
      "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/ExampleChangeSet/9f7b541b-126b-44f7-998e-932174557841",
      "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/ExampleStack/ab664180-f686-11ee-9e29-12cd92393671",
  ```