查看更改集
创建更改集之后,您可在执行之前查看提议的更改。您可以使用 CloudFormation 控制台、Amazon CLI 或 CloudFormation API 查看更改集。CloudFormation 控制台提供了更改摘要以及 JSON 格式的更改详细列表。Amazon CLI 和 Amazon CloudFormation API 以 JSON 格式返回详细的更改列表。
查看更改集 (Amazon CLI)
-
要获取更改集的 ID,请运行 change-sets 命令。
指定具有您要查看的更改集的堆栈的堆栈 ID,如下例中所示:
aws cloudformation list-change-sets \ --stack-name
arn:aws:cloudformation:us-east-1:123456789012:stack/SampleStack/1a2345b6-0000-00a0-a123-00abc0abc000
CloudFormation 返回更改集列表,类似于以下内容:
{ "Summaries": [ { "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/SampleStack/1a2345b6-0000-00a0-a123-00abc0abc000", "Status": "CREATE_COMPLETE", "ChangeSetName": "SampleChangeSet", "CreationTime": "2020-11-18T20:44:05.889Z", "StackName": "SampleStack", "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet/1a2345b6-0000-00a0-a123-00abc0abc000" }, { "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/SampleStack/1a2345b6-0000-00a0-a123-00abc0abc000", "Status": "CREATE_COMPLETE", "ChangeSetName": "SampleChangeSet-conditional", "CreationTime": "2020-11-18T21:15:56.398Z", "StackName": "SampleStack", "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/SampleStack/1a2345b6-0000-00a0-a123-00abc0abc000", "Status": "CREATE_COMPLETE", "ChangeSetName": "SampleChangeSet-replacement", "CreationTime": "2020-11-18T21:03:37.706Z", "StackName": "SampleStack", "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet-replacement/1a2345b6-0000-00a0-a123-00abc0abc000" } ] }
-
运行 describe-change-set 命令,指定您要查看的更改集的 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/SampleStack/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": "SampleStack", "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 实例的标签。有关各字段的说明,请参阅《Amazon CloudFormation API 参考》中的Change
数据类型。有关更改集的其他示例,请参阅示例更改集。
查看更改集中的属性级别更改(Amazon 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",