

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

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

# 将 `GetTemplate` 与 CLI 配合使用
<a name="cloudformation_example_cloudformation_GetTemplate_section"></a>

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

------
#### [ CLI ]

**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)*中的。

------
#### [ PowerShell ]

**适用于 PowerShell V4 的工具**  
**示例 1：返回与指定堆栈关联的模板。**  

```
Get-CFNTemplate -StackName "myStack"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [GetTemplate](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：返回与指定堆栈关联的模板。**  

```
Get-CFNTemplate -StackName "myStack"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetTemplate](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------