

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# CloudFormation 使用示例 AWS CLI
<a name="cli_2_cloudformation_code_examples"></a>

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 CloudFormation。 AWS Command Line Interface 

*操作*是大型程序的代码摘录，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `activate-type`
<a name="cloudformation_ActivateType_cli_2_topic"></a>

以下代码示例演示了如何使用 `activate-type`。

**AWS CLI**  
**激活类型**  
以下 `activate-type` 示例激活公有第三方扩展，使其可用于堆栈模板。  

```
aws cloudformation activate-type \
    --region us-west-2 \
    --type RESOURCE \
    --type-name Example::Test::1234567890abcdef0 \
    --type-name-alias Example::Test::Alias
```
输出：  

```
{
    "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Alias"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ActivateType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/activate-type.html)*中的。

### `batch-describe-type-configurations`
<a name="cloudformation_BatchDescribeTypeConfigurations_cli_2_topic"></a>

以下代码示例演示了如何使用 `batch-describe-type-configurations`。

**AWS CLI**  
**批量描述类型配置**  
以下 `batch-describe-type-configurations` 示例配置特定类型的数据。  

```
aws cloudformation batch-describe-type-configurations \
    --region us-west-2 \
    --type-configuration-identifiers TypeArn="arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Type,TypeConfigurationAlias=MyConfiguration"
```
输出：  

```
{
    "Errors": [],
    "UnprocessedTypeConfigurations": [],
    "TypeConfigurations": [
        {
            "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Type",
            "Alias": "MyConfiguration",
            "Configuration": "{\n        \"Example\": {\n            \"ApiKey\": \"examplekey\",\n            \"ApplicationKey\": \"examplekey1\",\n            \"ApiURL\": \"exampleurl\"\n            }\n}",
            "LastUpdated": "2021-10-01T15:25:46.210000+00:00",
            "TypeArn": "arn:aws:cloudformation:us-east-1:123456789012:type/resource/Example-Test-Type"
        }
    ]
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[BatchDescribeTypeConfigurations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/batch-describe-type-configurations.html)*中的。

### `cancel-update-stack`
<a name="cloudformation_CancelUpdateStack_cli_2_topic"></a>

以下代码示例演示了如何使用 `cancel-update-stack`。

**AWS CLI**  
**取消正在进行的堆栈更新**  
以下 `cancel-update-stack` 命令会取消 `myteststack` 堆栈上的堆栈更新：  

```
aws cloudformation cancel-update-stack --stack-name myteststack
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CancelUpdateStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/cancel-update-stack.html)*中的。

### `continue-update-rollback`
<a name="cloudformation_ContinueUpdateRollback_cli_2_topic"></a>

以下代码示例演示了如何使用 `continue-update-rollback`。

**AWS CLI**  
**重试更新回滚**  
以下 `continue-update-rollback` 示例从之前失败的堆栈更新中恢复回滚操作。  

```
aws cloudformation continue-update-rollback \
    --stack-name my-stack
```
此命令不生成任何输出。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ContinueUpdateRollback](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/continue-update-rollback.html)*中的。

### `create-change-set`
<a name="cloudformation_CreateChangeSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `create-change-set`。

**AWS CLI**  
**创建更改集**  
以下 `create-change-set` 示例创建一个具有 `CAPABILITY_IAM` 功能的更改集。该文件`template.yaml`是当前文件夹中的一个 AWS CloudFormation 模板，用于定义包含 IAM 资源的堆栈。  

```
aws cloudformation create-change-set \
    --stack-name my-application \
    --change-set-name my-change-set \
    --template-body file://template.yaml \
    --capabilities CAPABILITY_IAM
```
输出：  

```
{
    "Id": "arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784",
    "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-application/d0a825a0-e4cd-xmpl-b9fb-061c69e99204"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateChangeSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-change-set.html)*中的。

### `create-generated-template`
<a name="cloudformation_CreateGeneratedTemplate_cli_2_topic"></a>

以下代码示例演示了如何使用 `create-generated-template`。

**AWS CLI**  
**根据扫描的资源创建生成的模板**  
以下 `create-generated-template` 示例根据扫描的资源创建一个名为 `MyTemplate` 的生成模板。  

```
aws cloudformation create-generated-template \
    --generated-template-name MyTemplate \
    --resources file://resources.json
```
`resources.json` 的内容：  

```
[
    {
        "ResourceType": "AWS::EKS::Cluster",
        "LogicalResourceId":"MyCluster",
        "ResourceIdentifier": {
            "ClusterName": "MyAppClusterName"
        }
    },
    {
        "ResourceType": "AWS::AutoScaling::AutoScalingGroup",
        "LogicalResourceId":"MyASG",
        "ResourceIdentifier": {
            "AutoScalingGroupName": "MyAppASGName"
        }
    },
    {
        "ResourceType": "AWS::EKS::Nodegroup",
        "LogicalResourceId":"MyNodegroup",
        "ResourceIdentifier": {
            "NodegroupName": "MyAppNodegroupName"
        }
    },
    {
        "ResourceType": "AWS::IAM::Role",
        "LogicalResourceId":"MyRole",
        "ResourceIdentifier": {
            "RoleId": "arn:aws::iam::123456789012:role/MyAppIAMRole"
        }
    }
]
```
输出：  

```
{
  "Arn":
    "arn:aws:cloudformation:us-east-1:123456789012:generatedtemplate/7fc8512c-d8cb-4e02-b266-d39c48344e48",
  "Name": "MyTemplate"
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*[中的 “使用使用 IaC 生成器扫描的资源创建 CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-create-template-from-scanned-resources.html)”。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateGeneratedTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-generated-template.html)*中的。

### `create-stack-instances`
<a name="cloudformation_CreateStackInstances_cli_2_topic"></a>

以下代码示例演示了如何使用 `create-stack-instances`。

**AWS CLI**  
**创建堆栈实例**  
以下 `create-stack-instances` 示例在两个账户和四个区域中创建堆栈集的实例。容错设置可确保在所有账户和地区尝试更新，即使某些堆栈无法创建。  

```
aws cloudformation create-stack-instances \
    --stack-set-name my-stack-set \
    --accounts 123456789012 223456789012 \
    --regions us-east-1 us-east-2 us-west-1 us-west-2 \
    --operation-preferences FailureToleranceCount=7
```
输出：  

```
{
    "OperationId": "d7995c31-83c2-xmpl-a3d4-e9ca2811563f"
}
```
使用 `create-stack-set` 命令创建堆栈。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateStackInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-stack-instances.html)*中的。

### `create-stack-refactor`
<a name="cloudformation_CreateStackRefactor_cli_2_topic"></a>

以下代码示例演示了如何使用 `create-stack-refactor`。

**AWS CLI**  
**为堆栈重构操作创建堆栈定义**  
以下 `create-stack-refactor` 示例为堆栈重构创建堆栈定义。  

```
aws cloudformation create-stack-refactor \
    --stack-definitions \
      StackName=Stack1,TemplateBody@=file://template1-updated.yaml \
      StackName=Stack2,TemplateBody@=file://template2-updated.yaml
```
输出：  

```
{
    "StackRefactorId": "9c384f70-4e07-4ed7-a65d-fee5eb430841"
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户*指南》中的[堆栈重构](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateStackRefactor](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-stack-refactor.html)*中的。

### `create-stack-set`
<a name="cloudformation_CreateStackSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `create-stack-set`。

**AWS CLI**  
**创建堆栈集**  
以下`create-stack-set`示例使用指定的 YAML 文件模板创建堆栈集。 `template.yaml`是当前文件夹中用于定义堆栈的 AWS CloudFormation 模板。  

```
aws cloudformation create-stack-set \
    --stack-set-name my-stack-set \
    --template-body file://template.yaml \
    --description "SNS topic"
```
输出：  

```
{
    "StackSetId": "my-stack-set:8d0f160b-d157-xmpl-a8e6-c0ce8e5d8cc1"
}
```
使用 `create-stack-instances` 命令将堆栈实例添加到堆栈集中。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateStackSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-stack-set.html)*中的。

### `create-stack`
<a name="cloudformation_CreateStack_cli_2_topic"></a>

以下代码示例演示了如何使用 `create-stack`。

**AWS CLI**  
**创建 AWS CloudFormation 堆栈**  
以下 `create-stacks` 命令将使用 `sampletemplate.json` 模板创建名为 `myteststack` 的堆栈：  

```
aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters ParameterKey=KeyPairName,ParameterValue=TestKey ParameterKey=SubnetIDs,ParameterValue=SubnetID1\\,SubnetID2
```
输出：  

```
{
    "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896"
}
```
有关更多信息，请参阅*AWS CloudFormation 用户指南*中的堆栈。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-stack.html)*中的。

### `deactivate-type`
<a name="cloudformation_DeactivateType_cli_2_topic"></a>

以下代码示例演示了如何使用 `deactivate-type`。

**AWS CLI**  
**停用类型**  
以下 `deactivate-type` 示例停用先前在此账户和区域中激活的公有扩展。  

```
aws cloudformation deactivate-type \
    --region us-west-2 \
    --type MODULE \
    --type-name Example::Test::Type::MODULE
```
此命令不生成任何输出。  
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeactivateType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/deactivate-type.html)*中的。

### `delete-change-set`
<a name="cloudformation_DeleteChangeSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `delete-change-set`。

**AWS CLI**  
**删除更改集**  
以下 `delete-change-set` 示例通过指定更改集名称和堆栈名称来删除更改集。  

```
aws cloudformation delete-change-set \
    --stack-name my-stack \
    --change-set-name my-change-set
```
此命令不生成任何输出。  
以下 `delete-change-set` 示例通过指定更改集的完整 ARN 来删除更改集。  

```
aws cloudformation delete-change-set \
    --change-set-name arn:aws:cloudformation:us-east-2:123456789012:changeSet/my-change-set/4eca1a01-e285-xmpl-8026-9a1967bfb4b0
```
此命令不生成任何输出。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeleteChangeSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/delete-change-set.html)*中的。

### `delete-generated-template`
<a name="cloudformation_DeleteGeneratedTemplate_cli_2_topic"></a>

以下代码示例演示了如何使用 `delete-generated-template`。

**AWS CLI**  
**删除生成的模板**  
以下 `delete-generated-template` 示例删除指定的模板。  

```
aws cloudformation delete-generated-template \
    --generated-template-name MyTemplate
```
此命令不生成任何输出。  
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的[利用现有资源生成模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeleteGeneratedTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/delete-generated-template.html)*中的。

### `delete-stack-instances`
<a name="cloudformation_DeleteStackInstances_cli_2_topic"></a>

以下代码示例演示了如何使用 `delete-stack-instances`。

**AWS CLI**  
**删除堆栈实例**  
以下 `delete-stack-instances` 示例删除两个区域中两个账户的堆栈集实例，并终止堆栈。  

```
aws cloudformation delete-stack-instances \
    --stack-set-name my-stack-set \
    --accounts 123456789012 567890123456 \
    --regions us-east-1 us-west-1 \
    --no-retain-stacks
```
输出：  

```
{
    "OperationId": "ad49f10c-fd1d-413f-a20a-8de6e2fa8f27"
}
```
使用 `delete-stack-set` 命令删除空堆栈集。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeleteStackInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/delete-stack-instances.html)*中的。

### `delete-stack-set`
<a name="cloudformation_DeleteStackSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `delete-stack-set`。

**AWS CLI**  
**删除堆栈集**  
以下命令删除指定的空堆栈集。堆栈集必须为空。  

```
aws cloudformation delete-stack-set \
    --stack-set-name my-stack-set
```
此命令不生成任何输出。  
使用 `delete-stack-instances` 命令从堆栈集中删除实例。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeleteStackSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/delete-stack-set.html)*中的。

### `delete-stack`
<a name="cloudformation_DeleteStack_cli_2_topic"></a>

以下代码示例演示了如何使用 `delete-stack`。

**AWS CLI**  
**删除堆栈**  
以下 `delete-stack` 示例删除指定的堆栈。  

```
aws cloudformation delete-stack \
    --stack-name my-stack
```
此命令不生成任何输出。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeleteStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/delete-stack.html)*中的。

### `deploy`
<a name="cloudformation_Deploy_cli_2_topic"></a>

以下代码示例演示了如何使用 `deploy`。

**AWS CLI**  
以下命令会将名为 `template.json` 的模板部署到名为 `my-new-stack` 的堆栈中：  

```
aws cloudformation deploy --template-file /path_to_template/template.json --stack-name my-new-stack --parameter-overrides Key1=Value1 Key2=Value2 --tags Key1=Value1 Key2=Value2
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [Deploy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/deploy.html)。

### `deregister-type`
<a name="cloudformation_DeregisterType_cli_2_topic"></a>

以下代码示例演示了如何使用 `deregister-type`。

**AWS CLI**  
**取消注册类型版本**  
以下`deregister-type`示例将指定类型的版本从 CloudFormation 注册表中移除，使其无法再用于 CloudFormation 操作。  

```
aws cloudformation deregister-type \
    --type RESOURCE \
    --type-name My::Logs::LogGroup \
    --version-id 00000002
```
此命令不生成任何输出。  
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DeregisterType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/deregister-type.html)*中的。

### `describe-account-limits`
<a name="cloudformation_DescribeAccountLimits_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-account-limits`。

**AWS CLI**  
**获取有关您账户限制的信息**  
以下命令检索当前账户的区域限制列表。  

```
aws cloudformation describe-account-limits
```
输出：  

```
{
    "AccountLimits": [
        {
            "Name": "StackLimit",
            "Value": 200
        },
        {
            "Name": "StackOutputsLimit",
            "Value": 60
        },
        {
            "Name": "ConcurrentResourcesLimit",
            "Value": 2500
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeAccountLimits](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-account-limits.html)*中的。

### `describe-change-set`
<a name="cloudformation_DescribeChangeSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-change-set`。

**AWS CLI**  
**获取有关更改集的信息**  
以下 `describe-change-set` 示例显示由更改集名称和堆栈名称指定的更改集的详细信息。  

```
aws cloudformation describe-change-set \
    --change-set-name my-change-set \
    --stack-name my-stack
```
以下 `describe-change-set` 示例显示由更改集的完整 ARN 指定的更改集的详细信息：  

```
aws cloudformation describe-change-set \
    --change-set-name arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784
```
输出：  

```
{
    "Changes": [
        {
            "Type": "Resource",
            "ResourceChange": {
                "Action": "Modify",
                "LogicalResourceId": "function",
                "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
                "ResourceType": "AWS::Lambda::Function",
                "Replacement": "False",
                "Scope": [
                    "Properties"
                ],
                "Details": [
                    {
                        "Target": {
                            "Attribute": "Properties",
                            "Name": "Timeout",
                            "RequiresRecreation": "Never"
                        },
                        "Evaluation": "Static",
                        "ChangeSource": "DirectModification"
                    }
                ]
            }
        }
    ],
    "ChangeSetName": "my-change-set",
    "ChangeSetId": "arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/4eca1a01-e285-xmpl-8026-9a1967bfb4b0",
    "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
    "StackName": "my-stack",
    "Description": null,
    "Parameters": null,
    "CreationTime": "2019-10-02T05:20:56.651Z",
    "ExecutionStatus": "AVAILABLE",
    "Status": "CREATE_COMPLETE",
    "StatusReason": null,
    "NotificationARNs": [],
    "RollbackConfiguration": {},
    "Capabilities": [
        "CAPABILITY_IAM"
    ],
    "Tags": null
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeChangeSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-change-set.html)*中的。

### `describe-generated-template`
<a name="cloudformation_DescribeGeneratedTemplate_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-generated-template`。

**AWS CLI**  
**描述生成的模板**  
以下 `describe-generated-template` 示例描述了指定的模板。  

```
aws cloudformation describe-generated-template \
    --generated-template-name MyTemplate
```
输出：  

```
{
    "GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedTemplate/7d881acf-f307-4ded-910e-f8fb49b96894",
    "GeneratedTemplateName": "MyTemplate",
    "Resources": [
        {
            "ResourceType": "AWS::EC2::SecurityGroup",
            "LogicalResourceId": "EC2SecurityGroup",
            "ResourceIdentifier": {
                "Id": "sg-1234567890abcdef0"
            },
            "ResourceStatus": "COMPLETE",
            "ResourceStatusReason": "Resource Template complete",
            "Warnings": []
        },
        {
            "ResourceType": "AWS::EC2::Instance",
            "LogicalResourceId": "EC2Instance",
            "ResourceIdentifier": {
                "InstanceId": "i-1234567890abcdef0"
            },
            "ResourceStatus": "COMPLETE",
            "ResourceStatusReason": "Resource Template complete",
            "Warnings": []
        },
        {
            "ResourceType": "AWS::EC2::KeyPair",
            "LogicalResourceId": "EC2KeyPairSshkeypair",
            "ResourceIdentifier": {
                "KeyName": "sshkeypair"
            },
            "ResourceStatus": "COMPLETE",
            "ResourceStatusReason": "Resource Template complete",
            "Warnings": []
        }
    ],
    "Status": "COMPLETE",
    "StatusReason": "All resources complete",
    "CreationTime": "2025-09-23T19:38:06.435000+00:00",
    "LastUpdatedTime": "2025-09-23T19:38:10.798000+00:00",
    "Progress": {
        "ResourcesSucceeded": 3,
        "ResourcesFailed": 0,
        "ResourcesProcessing": 0,
        "ResourcesPending": 0
    },
    "TemplateConfiguration": {
        "DeletionPolicy": "RETAIN",
        "UpdateReplacePolicy": "RETAIN"
    },
    "TotalWarnings": 0
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的[利用现有资源生成模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeGeneratedTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-generated-template.html)*中的。

### `describe-publisher`
<a name="cloudformation_DescribePublisher_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-publisher`。

**AWS CLI**  
**描述发布者**  
以下 `describe-publisher` 示例配置发布者的信息。  

```
aws cloudformation describe-publisher \
    --region us-west-2 \
    --publisher-id 000q6TfUovXsEMmgKowxDZLlwqr2QUsh
```
输出：  

```
{
    "PublisherId": "000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c",
    "PublisherStatus": "VERIFIED",
    "IdentityProvider": "AWS_Marketplace",
    "PublisherProfile": "https://aws.amazon.com/marketplace/seller-profile?id=2c5dc1f0-17cd-4259-8e46-822a83gdtegd"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribePublisher](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-publisher.html)*中的。

### `describe-resource-scan`
<a name="cloudformation_DescribeResourceScan_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-resource-scan`。

**AWS CLI**  
**描述资源扫描**  
以下 `describe-resource-scan` 示例描述具有所指定扫描 ID 的资源扫描。  

```
aws cloudformation describe-resource-scan --region \
    --resource-scan-id arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60
```
输出：  

```
{
    "ResourceScanId": "arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60",
    "Status": "COMPLETE",
    "StartTime": "2025-08-21T03:10:38.485000+00:00",
    "EndTime": "2025-08-21T03:20:28.485000+00:00",
    "PercentageCompleted": 100.0,
    "ResourceTypes": [
        "AWS::CloudFront::CachePolicy",
        "AWS::CloudFront::OriginRequestPolicy",
        "AWS::EC2::DHCPOptions",
        "AWS::EC2::InternetGateway",
        "AWS::EC2::KeyPair",
        "AWS::EC2::NetworkAcl",
        "AWS::EC2::NetworkInsightsPath",
        "AWS::EC2::NetworkInterface",
        "AWS::EC2::PlacementGroup",
        "AWS::EC2::Route",
        "AWS::EC2::RouteTable",
        "AWS::EC2::SecurityGroup",
        "AWS::EC2::Subnet",
        "AWS::EC2::SubnetCidrBlock",
        "AWS::EC2::SubnetNetworkAclAssociation",
        "AWS::EC2::SubnetRouteTableAssociation",
        ...
    ],
    "ResourcesRead": 676
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的[利用现有资源生成模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeResourceScan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-resource-scan.html)*中的。

### `describe-stack-drift-detection-status`
<a name="cloudformation_DescribeStackDriftDetectionStatus_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-drift-detection-status`。

**AWS CLI**  
**检查偏离检测操作的状态**  
以下 `describe-stack-drift-detection-status` 示例显示偏离检测操作的状态。运行 `detect-stack-drift` 命令获取该 ID。  

```
aws cloudformation describe-stack-drift-detection-status \
    --stack-drift-detection-id 1a229160-e4d9-xmpl-ab67-0a4f93df83d4
```
输出：  

```
{
    "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
    "StackDriftDetectionId": "1a229160-e4d9-xmpl-ab67-0a4f93df83d4",
    "StackDriftStatus": "DRIFTED",
    "DetectionStatus": "DETECTION_COMPLETE",
    "DriftedStackResourceCount": 1,
    "Timestamp": "2019-10-02T05:54:30.902Z"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackDriftDetectionStatus](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-drift-detection-status.html)*中的。

### `describe-stack-events`
<a name="cloudformation_DescribeStackEvents_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-events`。

**AWS CLI**  
**描述堆栈事件**  
以下 `describe-stack-events` 示例显示指定堆栈的 2 个最新事件。  

```
aws cloudformation describe-stack-events \
    --stack-name my-stack \
    --max-items 2

{
    "StackEvents": [
        {
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "EventId": "4e1516d0-e4d6-xmpl-b94f-0a51958a168c",
            "StackName": "my-stack",
            "LogicalResourceId": "my-stack",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2019-10-02T05:34:29.556Z",
            "ResourceStatus": "UPDATE_COMPLETE"
        },
        {
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "EventId": "4dd3c810-e4d6-xmpl-bade-0aaf8b31ab7a",
            "StackName": "my-stack",
            "LogicalResourceId": "my-stack",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2019-10-02T05:34:29.127Z",
            "ResourceStatus": "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS"
        }
    ],
    "NextToken": "eyJOZXh0VG9XMPLiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyfQ=="
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackEvents](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-events.html)*中的。

### `describe-stack-instance`
<a name="cloudformation_DescribeStackInstance_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-instance`。

**AWS CLI**  
**描述堆栈实例**  
以下命令描述指定账户和区域中指定堆栈集的实例。堆栈集在当前区域和账户中，实例在账户 `123456789012` 中的 `us-west-2` 区域中：  

```
aws cloudformation describe-stack-instance \
    --stack-set-name my-stack-set \
    --stack-instance-account 123456789012 \
    --stack-instance-region us-west-2
```
输出：  

```
{
    "StackInstance": {
        "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743",
        "Region": "us-west-2",
        "Account": "123456789012",
        "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/StackSet-enable-config-e6cac20f-xmpl-46e9-8314-53e0d4591532/4287f9a0-e615-xmpl-894a-12b31d3117be",
        "ParameterOverrides": [],
        "Status": "OUTDATED",
        "StatusReason": "ResourceLogicalId:ConfigBucket, ResourceType:AWS::S3::Bucket, ResourceStatusReason:You have attempted to create more buckets than allowed (Service: Amazon S3; Status Code: 400; Error Code: TooManyBuckets; Request ID: F7F21CXMPL580224; S3 Extended Request ID: egd/Fdt89BXMPLyiqbMNljVk55Yqqvi3NYW2nKLUVWhUGEhNfCmZdyj967lhriaG/dWMobSO40o=)."
    }
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackInstance](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-instance.html)*中的。

### `describe-stack-refactor`
<a name="cloudformation_DescribeStackRefactor_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-refactor`。

**AWS CLI**  
**描述堆栈重构操作**  
以下 `describe-stack-refactor` 示例描述了具有所指定堆栈重构 ID 的堆栈重构操作。  

```
aws cloudformation describe-stack-refactor \
    --stack-refactor-id 9c384f70-4e07-4ed7-a65d-fee5eb430841
```
输出：  

```
{
    "StackRefactorId": "9c384f70-4e07-4ed7-a65d-fee5eb430841",
    "StackIds": [
        "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack1/3e6a1ff0-94b1-11f0-aa6f-0a88d2e03acf",
        "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack2/5da91650-94b1-11f0-81cf-0a23500e151b"
    ],
    "ExecutionStatus": "AVAILABLE",
    "Status": "CREATE_COMPLETE"
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户*指南》中的[堆栈重构](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackRefactor](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-refactor.html)*中的。

### `describe-stack-resource-drifts`
<a name="cloudformation_DescribeStackResourceDrifts_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-resource-drifts`。

**AWS CLI**  
**获取有关偏离堆栈定义的资源的信息**  
以下命令显示有关指定堆栈中偏离资源的信息。使用 `detect-stack-drift` 命令启动偏离检测：  

```
aws cloudformation describe-stack-resource-drifts \
    --stack-name my-stack
```
输出显示了一个经过修改的 AWS Lambda 函数： out-of-band  

```
{
    "StackResourceDrifts": [
        {
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "function",
            "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
            "ResourceType": "AWS::Lambda::Function",
            "ExpectedProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":128,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":900,\"TracingConfig\":{\"Mode\":\"Active\"}}",
            "ActualProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":256,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":22,\"TracingConfig\":{\"Mode\":\"Active\"}}",
            "PropertyDifferences": [
                {
                    "PropertyPath": "/MemorySize",
                    "ExpectedValue": "128",
                    "ActualValue": "256",
                    "DifferenceType": "NOT_EQUAL"
                },
                {
                    "PropertyPath": "/Timeout",
                    "ExpectedValue": "900",
                    "ActualValue": "22",
                    "DifferenceType": "NOT_EQUAL"
                }
            ],
            "StackResourceDriftStatus": "MODIFIED",
            "Timestamp": "2019-10-02T05:54:44.064Z"
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackResourceDrifts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-resource-drifts.html)*中的。

### `describe-stack-resource`
<a name="cloudformation_DescribeStackResource_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-resource`。

**AWS CLI**  
**获取有关堆栈资源的信息**  
以下 `describe-stack-resource` 示例显示指定堆栈中名为 `MyFunction` 的资源的详细信息。  

```
aws cloudformation describe-stack-resource \
    --stack-name MyStack \
    --logical-resource-id MyFunction
```
输出：  

```
{
    "StackResourceDetail": {
        "StackName": "MyStack",
        "StackId": "arn:aws:cloudformation:us-east-2:123456789012:stack/MyStack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
        "LogicalResourceId": "MyFunction",
        "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
        "ResourceType": "AWS::Lambda::Function",
        "LastUpdatedTimestamp": "2019-10-02T05:34:27.989Z",
        "ResourceStatus": "UPDATE_COMPLETE",
        "Metadata": "{}",
        "DriftInformation": {
            "StackResourceDriftStatus": "IN_SYNC"
        }
    }
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-resource.html)*中的。

### `describe-stack-resources`
<a name="cloudformation_DescribeStackResources_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-resources`。

**AWS CLI**  
**获取有关堆栈资源的信息**  
以下 `describe-stack-resources` 示例显示指定堆栈中的资源详细信息。  

```
aws cloudformation describe-stack-resources \
    --stack-name my-stack
```
输出：  

```
{
    "StackResources": [
        {
            "StackName": "my-stack",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "bucket",
            "PhysicalResourceId": "my-stack-bucket-1vc62xmplgguf",
            "ResourceType": "AWS::S3::Bucket",
            "Timestamp": "2019-10-02T04:34:11.345Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "StackName": "my-stack",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "function",
            "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
            "ResourceType": "AWS::Lambda::Function",
            "Timestamp": "2019-10-02T05:34:27.989Z",
            "ResourceStatus": "UPDATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "StackName": "my-stack",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "functionRole",
            "PhysicalResourceId": "my-functionRole-HIZXMPLEOM9E",
            "ResourceType": "AWS::IAM::Role",
            "Timestamp": "2019-10-02T04:34:06.350Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-resources.html)*中的。

### `describe-stack-set-operation`
<a name="cloudformation_DescribeStackSetOperation_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-set-operation`。

**AWS CLI**  
**获取有关堆栈集操作的信息**  
以下 describe-stack-set-operation `示例显示了对指定堆栈集执行更新操作的详细信息。  

```
aws cloudformation describe-stack-set-operation \
    --stack-set-name enable-config \
    --operation-id 35d45ebc-ed88-xmpl-ab59-0197a1fc83a0
```
输出：  

```
{
    "StackSetOperation": {
        "OperationId": "35d45ebc-ed88-xmpl-ab59-0197a1fc83a0",
        "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743",
        "Action": "UPDATE",
        "Status": "SUCCEEDED",
        "OperationPreferences": {
            "RegionOrder": [
                "us-east-1",
                "us-west-2",
                "eu-west-1",
                "us-west-1"
            ],
            "FailureToleranceCount": 7,
            "MaxConcurrentCount": 2
        },
        "AdministrationRoleARN": "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole",
        "ExecutionRoleName": "AWSCloudFormationStackSetExecutionRole",
        "CreationTimestamp": "2019-10-03T16:28:44.377Z",
        "EndTimestamp": "2019-10-03T16:42:08.607Z"
    }
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackSetOperation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-set-operation.html)*中的。

### `describe-stack-set`
<a name="cloudformation_DescribeStackSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stack-set`。

**AWS CLI**  
**获取有关堆栈集的信息**  
以下 describe-stack-set `示例显示有关指定堆栈集的详细信息。  

```
aws cloudformation describe-stack-set \
    --stack-set-name my-stack-set
```
输出：  

```
{
    "StackSet": {
        "StackSetName": "my-stack-set",
        "StackSetId": "my-stack-set:296a3360-xmpl-40af-be78-9341e95bf743",
        "Description": "Create an Amazon SNS topic",
        "Status": "ACTIVE",
        "TemplateBody": "AWSTemplateFormatVersion: '2010-09-09'\nDescription: An AWS SNS topic\nResources:\n  topic:\n    Type: AWS::SNS::Topic",
        "Parameters": [],
        "Capabilities": [],
        "Tags": [],
        "StackSetARN": "arn:aws:cloudformation:us-west-2:123456789012:stackset/enable-config:296a3360-xmpl-40af-be78-9341e95bf743",
        "AdministrationRoleARN": "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole",
        "ExecutionRoleName": "AWSCloudFormationStackSetExecutionRole"
    }
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStackSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-set.html)*中的。

### `describe-stacks`
<a name="cloudformation_DescribeStacks_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-stacks`。

**AWS CLI**  
**描述 AWS CloudFormation 堆栈**  
以下 `describe-stacks` 命令显示 `myteststack` 堆栈的摘要信息：  

```
aws cloudformation describe-stacks --stack-name myteststack
```
输出：  

```
{
    "Stacks":  [
        {
            "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896",
            "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
            "Tags": [],
            "Outputs": [
                {
                    "Description": "Name of S3 bucket to hold website content",
                    "OutputKey": "BucketName",
                    "OutputValue": "myteststack-s3bucket-jssofi1zie2w"
                }
            ],
            "StackStatusReason": null,
            "CreationTime": "2013-08-23T01:02:15.422Z",
            "Capabilities": [],
            "StackName": "myteststack",
            "StackStatus": "CREATE_COMPLETE",
            "DisableRollback": false
        }
    ]
}
```
有关更多信息，请参阅*AWS CloudFormation 用户指南*中的堆栈。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeStacks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stacks.html)*中的。

### `describe-type-registration`
<a name="cloudformation_DescribeTypeRegistration_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-type-registration`。

**AWS CLI**  
**显示类型注册信息**  
以下 `describe-type-registration` 示例显示有关指定类型注册的信息，包括该类型的当前状态、类型和版本。  

```
aws cloudformation describe-type-registration \
    --registration-token a1b2c3d4-5678-90ab-cdef-EXAMPLE11111
```
输出：  

```
{
    "ProgressStatus": "COMPLETE",
    "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup",
    "Description": "Deployment is currently in DEPLOY_STAGE of status COMPLETED; ",
    "TypeVersionArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup/00000001"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeTypeRegistration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-type-registration.html)*中的。

### `describe-type`
<a name="cloudformation_DescribeType_cli_2_topic"></a>

以下代码示例演示了如何使用 `describe-type`。

**AWS CLI**  
**显示类型信息**  
以下 `describe-type` 示例显示指定类型的信息。  

```
aws cloudformation describe-type \
    --type-name My::Logs::LogGroup \
    --type RESOURCE
```
输出：  

```
{
    "SourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs.git",
    "Description": "Customized resource derived from AWS::Logs::LogGroup",
    "TimeCreated": "2019-12-03T23:29:33.321Z",
    "Visibility": "PRIVATE",
    "TypeName": "My::Logs::LogGroup",
    "LastUpdated": "2019-12-03T23:29:33.321Z",
    "DeprecatedStatus": "LIVE",
    "ProvisioningType": "FULLY_MUTABLE",
    "Type": "RESOURCE",
    "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup/00000001",
    "Schema": "[details omitted]"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DescribeType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-type.html)*中的。

### `detect-stack-drift`
<a name="cloudformation_DetectStackDrift_cli_2_topic"></a>

以下代码示例演示了如何使用 `detect-stack-drift`。

**AWS CLI**  
**检测偏离的资源**  
以下 `detect-stack-drift` 示例对指定堆栈启动偏离检测。  

```
aws cloudformation detect-stack-drift \
    --stack-name my-stack
```
输出：  

```
{
    "StackDriftDetectionId": "1a229160-e4d9-xmpl-ab67-0a4f93df83d4"
}
```
然后，您可以将此 ID 与 `describe-stack-resource-drifts` 命令一起使用来描述偏离的资源。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DetectStackDrift](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/detect-stack-drift.html)*中的。

### `detect-stack-resource-drift`
<a name="cloudformation_DetectStackResourceDrift_cli_2_topic"></a>

以下代码示例演示了如何使用 `detect-stack-resource-drift`。

**AWS CLI**  
**检测资源的偏离**  
以下 `detect-stack-resource-drift` 示例检查名为 `MyStack` 的堆栈中名为 `MyFunction` 的资源是否偏离：  

```
aws cloudformation detect-stack-resource-drift \
   --stack-name MyStack \
   --logical-resource-id MyFunction
```
输出显示了一个经过修改的 AWS Lambda 函数： out-of-band  

```
{
    "StackResourceDrift": {
        "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/MyStack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
        "LogicalResourceId": "MyFunction",
        "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
        "ResourceType": "AWS::Lambda::Function",
        "ExpectedProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":128,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":900,\"TracingConfig\":{\"Mode\":\"Active\"}}",
        "ActualProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":256,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":22,\"TracingConfig\":{\"Mode\":\"Active\"}}",
        "PropertyDifferences": [
            {
                "PropertyPath": "/MemorySize",
                "ExpectedValue": "128",
                "ActualValue": "256",
                "DifferenceType": "NOT_EQUAL"
            },
            {
                "PropertyPath": "/Timeout",
                "ExpectedValue": "900",
                "ActualValue": "22",
                "DifferenceType": "NOT_EQUAL"
            }
        ],
        "StackResourceDriftStatus": "MODIFIED",
        "Timestamp": "2019-10-02T05:58:47.433Z"
    }
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DetectStackResourceDrift](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/detect-stack-resource-drift.html)*中的。

### `detect-stack-set-drift`
<a name="cloudformation_DetectStackSetDrift_cli_2_topic"></a>

以下代码示例演示了如何使用 `detect-stack-set-drift`。

**AWS CLI**  
**检测堆栈集及其所有关联堆栈实例的偏离**  
以下 `detect-stack-set-drift` 示例在指定的堆栈集（包括与该堆栈集关联的所有堆栈实例）上启动偏离检测操作，并返回一个可用于跟踪偏离操作状态的操作 ID。  

```
aws cloudformation detect-stack-set-drift \
    --stack-set-name stack-set-drift-example
```
输出：  

```
{
    "OperationId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的 “[检测堆栈集中的非托管配置更改](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-drift.html)”。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[DetectStackSetDrift](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/detect-stack-set-drift.html)*中的。

### `estimate-template-cost`
<a name="cloudformation_EstimateTemplateCost_cli_2_topic"></a>

以下代码示例演示了如何使用 `estimate-template-cost`。

**AWS CLI**  
**估算模板成本**  
以下 `estimate-template-cost` 示例为当前文件夹中名为 `template.yaml` 的模板生成成本估算。  

```
aws cloudformation estimate-template-cost \
    --template-body file://template.yaml
```
输出：  

```
{
    "Url": "http://calculator.s3.amazonaws.com/calc5.html?key=cloudformation/7870825a-xmpl-4def-92e7-c4f8dd360cca"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[EstimateTemplateCost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/estimate-template-cost.html)*中的。

### `execute-change-set`
<a name="cloudformation_ExecuteChangeSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `execute-change-set`。

**AWS CLI**  
**执行更改集**  
以下 `execute-change-set` 示例执行由更改集名称和堆栈名称指定的更改集。  

```
aws cloudformation execute-change-set \
    --change-set-name my-change-set \
    --stack-name my-stack
```
以下 `execute-change-set` 示例执行由更改集的完整 ARN 指定的更改集。  

```
aws cloudformation execute-change-set \
    --change-set-name arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ExecuteChangeSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/execute-change-set.html)*中的。

### `execute-stack-refactor`
<a name="cloudformation_ExecuteStackRefactor_cli_2_topic"></a>

以下代码示例演示了如何使用 `execute-stack-refactor`。

**AWS CLI**  
**完成堆栈重构操作**  
以下 `execute-stack-refactor` 示例完成具有所指定堆栈重构 ID 的堆栈重构操作。  

```
aws cloudformation execute-stack-refactor \
    --stack-refactor-id 9c384f70-4e07-4ed7-a65d-fee5eb430841
```
此命令不生成任何输出。  
有关更多信息，请参阅《*AWS CloudFormation 用户*指南》中的[堆栈重构](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ExecuteStackRefactor](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/execute-stack-refactor.html)*中的。

### `get-stack-policy`
<a name="cloudformation_GetStackPolicy_cli_2_topic"></a>

以下代码示例演示了如何使用 `get-stack-policy`。

**AWS CLI**  
**查看堆栈策略**  
以下 `get-stack-policy` 示例显示指定堆栈的堆栈策略。使用 `set-stack-policy` 命令将策略附加到堆栈。  

```
aws cloudformation get-stack-policy \
    --stack-name my-stack
```
输出：  

```
{
    "StackPolicyBody": "{\n  \"Statement\" : [\n    {\n      \"Effect\" : \"Allow\",\n      \"Action\" : \"Update:*\",\n      \"Principal\": \"*\",\n      \"Resource\" : \"*\"\n    },\n    {\n      \"Effect\" : \"Deny\",\n      \"Action\" : \"Update:*\",\n      \"Principal\": \"*\",\n      \"Resource\" : \"LogicalResourceId/bucket\"\n    }\n  ]\n}\n"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[GetStackPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/get-stack-policy.html)*中的。

### `get-template-summary`
<a name="cloudformation_GetTemplateSummary_cli_2_topic"></a>

以下代码示例演示了如何使用 `get-template-summary`。

**AWS CLI**  
**显示模板摘要**  
以下命令显示有关指定模板文件的资源和元数据的摘要信息。  

```
aws cloudformation get-template-summary \
   --template-body file://template.yaml
```
输出：  

```
{
    "Parameters": [],
    "Description": "A VPC and subnets.",
    "ResourceTypes": [
        "AWS::EC2::VPC",
        "AWS::EC2::Subnet",
        "AWS::EC2::Subnet",
        "AWS::EC2::RouteTable",
        "AWS::EC2::VPCEndpoint",
        "AWS::EC2::SubnetRouteTableAssociation",
        "AWS::EC2::SubnetRouteTableAssociation",
        "AWS::EC2::VPCEndpoint"
    ],
    "Version": "2010-09-09"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[GetTemplateSummary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/get-template-summary.html)*中的。

### `get-template`
<a name="cloudformation_GetTemplate_cli_2_topic"></a>

以下代码示例演示了如何使用 `get-template`。

**AWS CLI**  
**查看 AWS CloudFormation 堆栈的模板正文**  
以下 `get-template` 命令显示 `myteststack` 堆栈的模板：  

```
aws cloudformation get-template --stack-name myteststack
```
输出：  

```
{
    "TemplateBody": {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Outputs": {
            "BucketName": {
                "Description": "Name of S3 bucket to hold website content",
                "Value": {
                    "Ref": "S3Bucket"
                }
            }
        },
        "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
        "Resources": {
            "S3Bucket": {
                "Type": "AWS::S3::Bucket",
                "Properties": {
                    "AccessControl": "PublicRead"
                }
            }
        }
    }
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[GetTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/get-template.html)*中的。

### `list-change-sets`
<a name="cloudformation_ListChangeSets_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-change-sets`。

**AWS CLI**  
**列出更改集**  
以下 `list-change-sets` 示例显示指定堆栈的待处理更改集列表。  

```
aws cloudformation list-change-sets \
   --stack-name my-stack
```
输出：  

```
{
    "Summaries": [
        {
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "StackName": "my-stack",
            "ChangeSetId": "arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/70160340-7914-xmpl-bcbf-128a1fa78b5d",
            "ChangeSetName": "my-change-set",
            "ExecutionStatus": "AVAILABLE",
            "Status": "CREATE_COMPLETE",
            "CreationTime": "2019-10-02T05:38:54.297Z"
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListChangeSets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-change-sets.html)*中的。

### `list-exports`
<a name="cloudformation_ListExports_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-exports`。

**AWS CLI**  
**列出导出**  
以下 `list-exports` 示例显示当前区域堆栈的导出列表。  

```
aws cloudformation list-exports
```
输出：  

```
{
    "Exports": [
        {
            "ExportingStackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800",
            "Name": "private-vpc-subnet-a",
            "Value": "subnet-07b410xmplddcfa03"
        },
        {
            "ExportingStackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800",
            "Name": "private-vpc-subnet-b",
            "Value": "subnet-075ed3xmplebd2fb1"
        },
        {
            "ExportingStackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800",
            "Name": "private-vpc-vpcid",
            "Value": "vpc-011d7xmpl100e9841"
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListExports](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-exports.html)*中的。

### `list-generated-templates`
<a name="cloudformation_ListGeneratedTemplates_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-generated-templates`。

**AWS CLI**  
**列出生成的模板**  
以下 `list-generated-templates` 示例列出所有生成的模板。  

```
aws cloudformation list-generated-templates
```
输出：  

```
{
    "Summaries": [
        {
            "GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedtemplate/7fc8512c-d8cb-4e02-b266-d39c48344e48",
            "GeneratedTemplateName": "MyTemplate",
            "Status": "COMPLETE",
            "StatusReason": "All resources complete",
            "CreationTime": "2025-09-23T20:13:24.283000+00:00",
            "LastUpdatedTime": "2025-09-23T20:13:28.610000+00:00",
            "NumberOfResources": 4
        },
        {
            "GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedTemplate/f10dd1c4-edc6-4823-8153-ab6112b8d051",
            "GeneratedTemplateName": "MyEC2InstanceTemplate",
            "Status": "COMPLETE",
            "StatusReason": "All resources complete",
            "CreationTime": "2024-08-08T19:35:49.790000+00:00",
            "LastUpdatedTime": "2024-08-08T19:35:52.207000+00:00",
            "NumberOfResources": 3
        },
        {
            "GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedTemplate/e5a1c89f-7ce2-41bd-9bdf-75b7c852e3ca",
            "GeneratedTemplateName": "MyEKSNodeGroupTemplate",
            "Status": "COMPLETE",
            "StatusReason": "All resources complete",
            "CreationTime": "2024-07-16T20:39:27.883000+00:00",
            "LastUpdatedTime": "2024-07-16T20:39:35.766000+00:00",
            "NumberOfResources": 4
        }
    ]
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的[利用现有资源生成模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListGeneratedTemplates](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-generated-templates.html)*中的。

### `list-imports`
<a name="cloudformation_ListImports_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-imports`。

**AWS CLI**  
**列出导入**  
以下 `list-imports` 示例列出导入指定导出的堆栈。使用 `list-exports` 命令获取可用的导出列表。  

```
aws cloudformation list-imports \
    --export-name private-vpc-vpcid
```
输出：  

```
{
    "Imports": [
        "my-database-stack"
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListImports](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-imports.html)*中的。

### `list-resource-scan-related-resources`
<a name="cloudformation_ListResourceScanRelatedResources_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-resource-scan-related-resources`。

**AWS CLI**  
**列出资源扫描中的相关资源**  
以下 `list-resource-scan-related-resources` 示例列出所指定资源扫描中与 `resources.json` 内资源相关的资源。  

```
aws cloudformation list-resource-scan-related-resources \
    --resource-scan-id arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60 \
    --resources file://resources.json
```
`resources.json` 的内容：  

```
[
    {
        "ResourceType": "AWS::EKS::Cluster",
        "ResourceIdentifier": {
            "ClusterName": "MyAppClusterName"
        }
    },
    {
        "ResourceType": "AWS::AutoScaling::AutoScalingGroup",
        "ResourceIdentifier": {
            "AutoScalingGroupName": "MyAppASGName"
        }
    }
]
```
输出：  

```
{
    "RelatedResources": [
        {
            "ResourceType": "AWS::EKS::Nodegroup",
            "ResourceIdentifier": {
                "NodegroupName": "MyAppNodegroupName"
            },
            "ManagedByStack": false
        },
        {
            "ResourceType": "AWS::IAM::Role",
            "ResourceIdentifier": {
                "RoleId": "arn:aws::iam::123456789012:role/MyAppIAMRole"
            },
            "ManagedByStack": false
        }
    ]
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*[中的 “使用使用 IaC 生成器扫描的资源创建 CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-create-template-from-scanned-resources.html)”。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListResourceScanRelatedResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-resource-scan-related-resources.html)*中的。

### `list-resource-scan-resources`
<a name="cloudformation_ListResourceScanResources_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-resource-scan-resources`。

**AWS CLI**  
**列出资源扫描中的资源**  
以下 `list-resource-scan-resources` 示例列出所指定资源扫描中的资源，并按资源标识符进行筛选。  

```
aws cloudformation list-resource-scan-resources \
    --resource-scan-id arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60 \
    --resource-identifier MyApp
```
输出：  

```
{
    "Resources": [
        {
            "ResourceType": "AWS::EKS::Cluster",
            "ResourceIdentifier": {
                "ClusterName": "MyAppClusterName"
            },
            "ManagedByStack": false
        },
        {
            "ResourceType": "AWS::AutoScaling::AutoScalingGroup",
            "ResourceIdentifier": {
                "AutoScalingGroupName": "MyAppASGName"
            },
            "ManagedByStack": false
        }
    ]
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*[中的 “使用使用 IaC 生成器扫描的资源创建 CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-create-template-from-scanned-resources.html)”。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListResourceScanResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-resource-scan-resources.html)*中的。

### `list-stack-instances`
<a name="cloudformation_ListStackInstances_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stack-instances`。

**AWS CLI**  
**列出堆栈的实例**  
以下 `list-stack-instances` 示例列出根据指定堆栈集创建的实例。  

```
aws cloudformation list-stack-instances \
    --stack-set-name enable-config
```
示例输出包括有关由于错误而无法更新的堆栈的详细信息：  

```
{
    "Summaries": [
        {
            "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743",
            "Region": "us-west-2",
            "Account": "123456789012",
            "StackId": "arn:aws:cloudformation:ap-northeast-1:123456789012:stack/StackSet-enable-config-35a6ac50-d9f8-4084-86e4-7da34d5de4c4/a1631cd0-e5fb-xmpl-b474-0aa20f14f06e",
            "Status": "CURRENT"
        },
        {
            "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743",
            "Region": "us-west-2",
            "Account": "123456789012",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/StackSet-enable-config-e6cac20f-xmpl-46e9-8314-53e0d4591532/eab53680-e5fa-xmpl-ba14-0a522351f81e",
            "Status": "OUTDATED",
            "StatusReason": "ResourceLogicalId:ConfigDeliveryChannel, ResourceType:AWS::Config::DeliveryChannel, ResourceStatusReason:Failed to put delivery channel 'StackSet-enable-config-e6cac20f-xmpl-46e9-8314-53e0d4591532-ConfigDeliveryChannel-1OJWJ7XD59WR0' because the maximum number of delivery channels: 1 is reached. (Service: AmazonConfig; Status Code: 400; Error Code: MaxNumberOfDeliveryChannelsExceededException; Request ID: d14b34a0-ef7c-xmpl-acf8-8a864370ae56)."
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStackInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-instances.html)*中的。

### `list-stack-refactor-actions`
<a name="cloudformation_ListStackRefactorActions_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stack-refactor-actions`。

**AWS CLI**  
**列出堆栈重构操作的详细操作**  
以下 `list-stack-refactor-actions` 示例列出具有所指定堆栈重构 ID 的堆栈重构操作的详细操作。  

```
aws cloudformation list-stack-refactor-actions \
    --stack-refactor-id 9c384f70-4e07-4ed7-a65d-fee5eb430841
```
输出：  

```
{
    "StackRefactorActions": [
        {
            "Action": "MOVE",
            "Entity": "RESOURCE",
            "PhysicalResourceId": "MyTestLambdaRole",
            "Description": "No configuration changes detected.",
            "Detection": "AUTO",
            "TagResources": [],
            "UntagResources": [],
            "ResourceMapping": {
                "Source": {
                    "StackName": "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack1/3e6a1ff0-94b1-11f0-aa6f-0a88d2e03acf",
                    "LogicalResourceId": "MyLambdaRole"
                },
                "Destination": {
                    "StackName": "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack2/5da91650-94b1-11f0-81cf-0a23500e151b",
                    "LogicalResourceId": "MyLambdaRole"
                }
            }
        },
        {
            "Action": "MOVE",
            "Entity": "RESOURCE",
            "PhysicalResourceId": "MyTestFunction",
            "Description": "Resource configuration changes will be validated during refactor execution.",
            "Detection": "AUTO",
            "TagResources": [
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "Stack2"
                },
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "MyFunction"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack2/5da91650-94b1-11f0-81cf-0a23500e151b"
                }
            ],
            "UntagResources": [
                "aws:cloudformation:stack-name",
                "aws:cloudformation:logical-id",
                "aws:cloudformation:stack-id"
            ],
            "ResourceMapping": {
                "Source": {
                    "StackName": "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack1/3e6a1ff0-94b1-11f0-aa6f-0a88d2e03acf",
                    "LogicalResourceId": "MyFunction"
                },
                "Destination": {
                    "StackName": "arn:aws:cloudformation:us-east-1:123456789012:stack/Stack2/5da91650-94b1-11f0-81cf-0a23500e151b",
                    "LogicalResourceId": "MyFunction"
                }
            }
        }
    ]
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户*指南》中的[堆栈重构](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStackRefactorActions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-refactor-actions.html)*中的。

### `list-stack-resources`
<a name="cloudformation_ListStackResources_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stack-resources`。

**AWS CLI**  
**列出堆栈中的资源**  
以下命令显示指定堆栈中的资源列表。  

```
aws cloudformation list-stack-resources \
    --stack-name my-stack
```
输出：  

```
{
    "StackResourceSummaries": [
        {
            "LogicalResourceId": "bucket",
            "PhysicalResourceId": "my-stack-bucket-1vc62xmplgguf",
            "ResourceType": "AWS::S3::Bucket",
            "LastUpdatedTimestamp": "2019-10-02T04:34:11.345Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "LogicalResourceId": "function",
            "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
            "ResourceType": "AWS::Lambda::Function",
            "LastUpdatedTimestamp": "2019-10-02T05:34:27.989Z",
            "ResourceStatus": "UPDATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "LogicalResourceId": "functionRole",
            "PhysicalResourceId": "my-functionRole-HIZXMPLEOM9E",
            "ResourceType": "AWS::IAM::Role",
            "LastUpdatedTimestamp": "2019-10-02T04:34:06.350Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStackResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-resources.html)*中的。

### `list-stack-set-operation-results`
<a name="cloudformation_ListStackSetOperationResults_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stack-set-operation-results`。

**AWS CLI**  
**列出堆栈集操作结果**  
以下命令显示对指定堆栈集中的实例执行更新操作的结果。  

```
aws cloudformation list-stack-set-operation-results \
    --stack-set-name enable-config \
    --operation-id 35d45ebc-ed88-xmpl-ab59-0197a1fc83a0
```
输出：  

```
{
    "Summaries": [
        {
            "Account": "223456789012",
            "Region": "us-west-2",
            "Status": "SUCCEEDED",
            "AccountGateResult": {
                "Status": "SKIPPED",
                "StatusReason": "Function not found: arn:aws:lambda:eu-west-1:223456789012:function:AWSCloudFormationStackSetAccountGate"
            }
        },
        {
            "Account": "223456789012",
            "Region": "ap-south-1",
            "Status": "CANCELLED",
            "StatusReason": "Cancelled since failure tolerance has exceeded"
        }
    ]
}
```
**注意：**除非您创建账户门禁函数，否则 `AccountGateResult` 的 `SKIPPED` 状态有望成功操作。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStackSetOperationResults](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-set-operation-results.html)*中的。

### `list-stack-set-operations`
<a name="cloudformation_ListStackSetOperations_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stack-set-operations`。

**AWS CLI**  
**列出堆栈集操作**  
以下 `list-stack-set-operations` 示例显示指定堆栈集的最新操作列表。  

```
aws cloudformation list-stack-set-operations \
    --stack-set-name my-stack-set
```
输出：  

```
{
    "Summaries": [
        {
            "OperationId": "35d45ebc-ed88-xmpl-ab59-0197a1fc83a0",
            "Action": "UPDATE",
            "Status": "SUCCEEDED",
            "CreationTimestamp": "2019-10-03T16:28:44.377Z",
            "EndTimestamp": "2019-10-03T16:42:08.607Z"
        },
        {
            "OperationId": "891aa98f-7118-xmpl-00b2-00954d1dd0d6",
            "Action": "UPDATE",
            "Status": "FAILED",
            "CreationTimestamp": "2019-10-03T15:43:53.916Z",
            "EndTimestamp": "2019-10-03T15:45:58.925Z"
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStackSetOperations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-set-operations.html)*中的。

### `list-stack-sets`
<a name="cloudformation_ListStackSets_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stack-sets`。

**AWS CLI**  
**列出堆栈集**  
以下 `list-stack-sets` 示例显示当前区域和账户中的堆栈集列表。  

```
aws cloudformation list-stack-sets
```
输出：  

```
{
    "Summaries": [
        {
            "StackSetName": "enable-config",
            "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743",
            "Description": "Enable AWS Config",
            "Status": "ACTIVE"
        }
    ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStackSets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-sets.html)*中的。

### `list-stacks`
<a name="cloudformation_ListStacks_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-stacks`。

**AWS CLI**  
**列出 AWS CloudFormation 堆栈**  
以下 `list-stacks` 命令显示具有 `CREATE_COMPLETE` 状态的所有堆栈的摘要信息：  

```
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE
```
输出：  

```
[
    {
        "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896",
        "TemplateDescription": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
        "StackStatusReason": null,
        "CreationTime": "2013-08-26T03:27:10.190Z",
        "StackName": "myteststack",
        "StackStatus": "CREATE_COMPLETE"
    }
]
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListStacks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stacks.html)*中的。

### `list-type-registrations`
<a name="cloudformation_ListTypeRegistrations_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-type-registrations`。

**AWS CLI**  
**列出某一类型已完成的注册**  
以下 `list-type-registrations` 示例显示指定类型的已完成类型注册的列表。  

```
aws cloudformation list-type-registrations \
    --type RESOURCE \
    --type-name My::Logs::LogGroup \
    --registration-status-filter COMPLETE
```
输出：  

```
{
    "RegistrationTokenList": [
        "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
        "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
        "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333"
    ]
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListTypeRegistrations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-type-registrations.html)*中的。

### `list-type-versions`
<a name="cloudformation_ListTypeVersions_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-type-versions`。

**AWS CLI**  
**列出扩展的版本**  
以下 `list-type-versions` 示例返回有关扩展版本的摘要信息。  

```
aws cloudformation list-type-versions \
  --endpoint https://example.com \
  --region us-west-2 \
  --type RESOURCE \
  --type-name My::Resource::Example \
  --publisher-id 123456789012
```
此命令不生成任何输出。  
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListTypeVersions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-type-versions.html)*中的。

### `list-types`
<a name="cloudformation_ListTypes_cli_2_topic"></a>

以下代码示例演示了如何使用 `list-types`。

**AWS CLI**  
**列出账户中的私有资源类型**  
以下`list-types`示例显示当前在当前 AWS 账户中注册的私有资源类型的列表。  

```
aws cloudformation list-types
```
输出：  

```
{
    "TypeSummaries": [
        {
            "Description": "WordPress blog resource for internal use",
            "LastUpdated": "2019-12-04T18:28:15.059Z",
            "TypeName": "My::WordPress::BlogExample",
            "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-WordPress-BlogExample",
            "DefaultVersionId": "00000005",
            "Type": "RESOURCE"
        },
        {
            "Description": "Customized resource derived from AWS::Logs::LogGroup",
            "LastUpdated": "2019-12-04T18:28:15.059Z",
            "TypeName": "My::Logs::LogGroup",
            "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup",
            "DefaultVersionId": "00000003",
            "Type": "RESOURCE"
        }
    ]
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ListTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-types.html)*中的。

### `package`
<a name="cloudformation_Package_cli_2_topic"></a>

以下代码示例演示了如何使用 `package`。

**AWS CLI**  
以下命令将通过将本地构件上传到 S3 存储桶 `bucket-name` 来导出一个名为 `template.json` 的模板，并将导出的模板写入 `packaged-template.json`：  

```
aws cloudformation package --template-file /path_to_template/template.json --s3-bucket bucket-name --output-template-file packaged-template.json --use-json
```
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [Package](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/package.html)。

### `publish-type`
<a name="cloudformation_PublishType_cli_2_topic"></a>

以下代码示例演示了如何使用 `publish-type`。

**AWS CLI**  
**发布扩展**  
以下`publish-type`示例将指定的扩展作为该区域的公共扩展发布到 CloudFormation 注册表。  

```
aws cloudformation publish-type \
  --region us-west-2 \
  --type RESOURCE \
  --type-name Example::Test::1234567890abcdef0
```
输出：  

```
{
    "PublicTypeArn":"arn:aws:cloudformation:us-west-2::type/resource/000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c/Example-Test-1234567890abcdef0/1.0.0"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[PublishType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/publish-type.html)*中的。

### `register-publisher`
<a name="cloudformation_RegisterPublisher_cli_2_topic"></a>

以下代码示例演示了如何使用 `register-publisher`。

**AWS CLI**  
**注册发布者**  
以下 `register-publisher` 示例注册发布者并接受条款和条件参数。  

```
aws cloudformation register-publisher \
  --region us-west-2 \
  --accept-terms-and-conditions
```
输出：  

```
{
    "PublisherId": "000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[RegisterPublisher](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/register-publisher.html)*中的。

### `register-type`
<a name="cloudformation_RegisterType_cli_2_topic"></a>

以下代码示例演示了如何使用 `register-type`。

**AWS CLI**  
**注册资源类型**  
以下 `register-type` 示例会将指定的资源类型注册为用户账户中的私有资源类型。  

```
aws cloudformation register-type \
    --type-name My::Organization::ResourceName \
    --schema-handler-package s3://bucket_name/my-organization-resource_name.zip \
    --type RESOURCE
```
输出：  

```
{
    "RegistrationToken": "f5525280-104e-4d35-bef5-8f1f1example"
}
```
有关更多信息，请参阅《*类型开发CloudFormation 命令行界面用户指南》*中的[注册资源提供者](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-register.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[RegisterType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/register-type.html)*中的。

### `set-stack-policy`
<a name="cloudformation_SetStackPolicy_cli_2_topic"></a>

以下代码示例演示了如何使用 `set-stack-policy`。

**AWS CLI**  
**应用堆栈策略**  
以下 `set-stack-policy` 示例禁用指定堆栈中指定的资源更新。`stack-policy.json` 是一个 JSON 文档，可定义允许对堆栈中的资源执行的操作。  

```
aws cloudformation set-stack-policy \
    --stack-name my-stack \
    --stack-policy-body file://stack-policy.json
```
输出：  

```
{
  "Statement" : [
    {
      "Effect" : "Allow",
      "Action" : "Update:*",
      "Principal": "*",
      "Resource" : "*"
    },
    {
      "Effect" : "Deny",
      "Action" : "Update:*",
      "Principal": "*",
      "Resource" : "LogicalResourceId/bucket"
    }
  ]
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[SetStackPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/set-stack-policy.html)*中的。

### `set-type-configuration`
<a name="cloudformation_SetTypeConfiguration_cli_2_topic"></a>

以下代码示例演示了如何使用 `set-type-configuration`。

**AWS CLI**  
**配置数据**  
以下`set-type-configuration`示例指定了给定账户和区域中已注册 CloudFormation 扩展的配置数据。  

```
aws cloudformation set-type-configuration \
    --region us-west-2 \
    --type RESOURCE \
    --type-name Example::Test::Type \
    --configuration-alias default \
    --configuration "{\"CredentialKey\": \"testUserCredential\"}"
```
输出：  

```
{
    "ConfigurationArn": "arn:aws:cloudformation:us-west-2:123456789012:type-configuration/resource/Example-Test-Type/default"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[SetTypeConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/set-type-configuration.html)*中的。

### `set-type-default-version`
<a name="cloudformation_SetTypeDefaultVersion_cli_2_topic"></a>

以下代码示例演示了如何使用 `set-type-default-version`。

**AWS CLI**  
**设置类型的默认版本**  
以下 `set-type-default-version` 示例会将指定的类型版本设置为该类型的默认版本。  

```
aws cloudformation set-type-default-version \
    --type RESOURCE \
    --type-name My::Logs::LogGroup \
    --version-id 00000003
```
此命令不生成任何输出。  
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[SetTypeDefaultVersion](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/set-type-default-version.html)*中的。

### `signal-resource`
<a name="cloudformation_SignalResource_cli_2_topic"></a>

以下代码示例演示了如何使用 `signal-resource`。

**AWS CLI**  
**发出资源信号**  
以下 `signal-resource` 示例发出信号 `success`，表示在名为 `my-stack` 的堆栈中满足名为 `MyWaitCondition` 的等待条件。  

```
aws cloudformation signal-resource \
    --stack-name my-stack \
    --logical-resource-id MyWaitCondition \
    --unique-id 1234 \
    --status SUCCESS
```
此命令不生成任何输出。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[SignalResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/signal-resource.html)*中的。

### `start-resource-scan`
<a name="cloudformation_StartResourceScan_cli_2_topic"></a>

以下代码示例演示了如何使用 `start-resource-scan`。

**AWS CLI**  
**启动资源扫描**  
以下 `start-resource-scan` 示例启动一个资源扫描，这会扫描当前账户和区域中的所有现有资源。  

```
aws cloudformation start-resource-scan
```
输出：  

```
{
    "ResourceScanId":
      "arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60"
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的 “[使用 CloudFormation IaC 生成器启动资源扫描](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-start-resource-scan.html)”。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[StartResourceScan](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/start-resource-scan.html)*中的。

### `stop-stack-set-operation`
<a name="cloudformation_StopStackSetOperation_cli_2_topic"></a>

以下代码示例演示了如何使用 `stop-stack-set-operation`。

**AWS CLI**  
**停止堆栈集操作**  
以下 `stop-stack-set-operation` 示例停止正在对指定堆栈集进行的更新操作。  

```
aws cloudformation stop-stack-set-operation \
    --stack-set-name my-stack-set \
    --operation-id 1261cd27-490b-xmpl-ab42-793a896c69e6
```
此命令不生成任何输出。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[StopStackSetOperation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/stop-stack-set-operation.html)*中的。

### `test-type`
<a name="cloudformation_TestType_cli_2_topic"></a>

以下代码示例演示了如何使用 `test-type`。

**AWS CLI**  
**测试扩展**  
以下`test-type`示例测试已注册的扩展，以确保其满足在注册 CloudFormation 表中发布的所有必要要求。  

```
aws cloudformation test-type \
    --arn arn:aws:cloudformation:us-west-2:123456789012:type/resource/Sample-Test-Resource123/00000001
```
输出：  

```
{
    "TypeVersionArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Sample-Test-Resource123/00000001"
}
```
有关更多信息，请参阅[《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 注册表](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/registry.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[TestType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/test-type.html)*中的。

### `update-stack-instances`
<a name="cloudformation_UpdateStackInstances_cli_2_topic"></a>

以下代码示例演示了如何使用 `update-stack-instances`。

**AWS CLI**  
**更新堆栈实例**  
以下 `update-stack-instances` 示例使用最新设置重试两个区域中两个账户的堆栈实例的更新。指定的容错设置可确保在所有账户和地区尝试更新，即使某些堆栈无法更新。  

```
aws cloudformation update-stack-instances \
    --stack-set-name my-stack-set \
    --accounts 123456789012 567890123456 \
    --regions us-east-1 us-west-2 \
    --operation-preferences FailureToleranceCount=3
```
输出：  

```
{
    "OperationId": "103ebdf2-21ea-xmpl-8892-de5e30733132"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[UpdateStackInstances](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/update-stack-instances.html)*中的。

### `update-stack-set`
<a name="cloudformation_UpdateStackSet_cli_2_topic"></a>

以下代码示例演示了如何使用 `update-stack-set`。

**AWS CLI**  
**更新堆栈集**  
以下 `update-stack-set` 示例为指定堆栈集中的堆栈实例添加键名称为 `Owner` 和值为 `IT` 的标签。  

```
aws cloudformation update-stack-set \
    --stack-set-name my-stack-set \
    --use-previous-template \
    --tags Key=Owner,Value=IT
```
输出：  

```
{
    "OperationId": "e2b60321-6cab-xmpl-bde7-530c6f47950e"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[UpdateStackSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/update-stack-set.html)*中的。

### `update-stack`
<a name="cloudformation_UpdateStack_cli_2_topic"></a>

以下代码示例演示了如何使用 `update-stack`。

**AWS CLI**  
**更新 AWS CloudFormation 堆栈**  
以下 `update-stack` 命令更新 `mystack` 堆栈的模板和输入参数：  

```
aws cloudformation update-stack --stack-name mystack --template-url https://s3.amazonaws.com/sample/updated.template --parameters ParameterKey=KeyPairName,ParameterValue=SampleKeyPair ParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,SampleSubnetID2
```
以下 `update-stack` 命令更新 `mystack` 堆栈的 `SubnetIDs` 参数值：如果您没有指定参数值，则将使用模板中指定的默认值：  

```
aws cloudformation update-stack --stack-name mystack --template-url https://s3.amazonaws.com/sample/updated.template --parameters ParameterKey=KeyPairName,UsePreviousValue=true ParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,UpdatedSampleSubnetID2
```
以下 `update-stack` 命令向 `mystack` 堆栈添加两个堆栈通知主题：  

```
aws cloudformation update-stack --stack-name mystack --use-previous-template --notification-arns "arn:aws:sns:use-east-1:123456789012:mytopic1" "arn:aws:sns:us-east-1:123456789012:mytopic2"
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的[AWS CloudFormation 堆栈更新](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[UpdateStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/update-stack.html)*中的。

### `update-termination-protection`
<a name="cloudformation_UpdateTerminationProtection_cli_2_topic"></a>

以下代码示例演示了如何使用 `update-termination-protection`。

**AWS CLI**  
**启用终止保护**  
以下 `update-termination-protection` 示例在指定堆栈上启用终止保护。  

```
aws cloudformation update-termination-protection \
    --stack-name my-stack \
    --enable-termination-protection
```
输出：  

```
{
    "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204"
}
```
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[UpdateTerminationProtection](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/update-termination-protection.html)*中的。

### `validate-template`
<a name="cloudformation_ValidateTemplate_cli_2_topic"></a>

以下代码示例演示了如何使用 `validate-template`。

**AWS CLI**  
**验证 AWS CloudFormation 模板**  
以下 `validate-template` 命令验证 `sampletemplate.json` 模板：  

```
aws cloudformation validate-template --template-body file://sampletemplate.json
```
输出：  

```
{
    "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
    "Parameters": [],
    "Capabilities": []
}
```
有关更多信息，请参阅《*AWS CloudFormation 用户指南》*中的使用 AWS CloudFormation 模板。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[ValidateTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/validate-template.html)*中的。