

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

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

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

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

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

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

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

**适用于 PowerShell V4 的工具**  
**示例 1：验证指定模板的内容。输出详细说明了模板的功能、描述和参数。**  

```
Test-CFNTemplate -TemplateBody "{TEMPLATE CONTENT HERE}"
```
**示例 2：验证通过 Amazon S3 URL 访问的指定模板。输出详细说明了模板的功能、描述和参数。**  

```
Test-CFNTemplate -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [ValidateTemplate](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：验证指定模板的内容。输出详细说明了模板的功能、描述和参数。**  

```
Test-CFNTemplate -TemplateBody "{TEMPLATE CONTENT HERE}"
```
**示例 2：验证通过 Amazon S3 URL 访问的指定模板。输出详细说明了模板的功能、描述和参数。**  

```
Test-CFNTemplate -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [ValidateTemplate](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------