

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 使用 Application Manager 管理 CloudFormation 模板
<a name="application-manager-working-templates-overview"></a>

Application Manager 是 AWS Systems Manager 中的一项工具，包括一个模板库和其他工具，可帮助您管理 AWS CloudFormation 模板。本节包含以下信息：

**Topics**
+ [使用模板库](#application-manager-working-stacks-template-library-working)
+ [创建模板](#application-manager-working-stacks-creating-template)
+ [编辑模板](#application-manager-working-stacks-editing-template)

## 使用模板库
<a name="application-manager-working-stacks-template-library-working"></a>

这些 Application Manager 模板库提供了帮助您查看、创建、编辑、删除和克隆模板的工具。您也可以直接从模板库配置堆栈。模板存储为 `CloudFormation` 类型的 Systems Manager (SSM) 文档。通过将模板存储为 SSM 文档，您可以使用版本控件来操作不同版本的模板。您也可以设置权限和共享模板。成功配置堆栈后，将在 Application Manager 和 CloudFormation 中提供堆栈和模板。

**开始前的准备工作**  
我们建议您阅读以下主题，以了解有关 SSM 文档的详细信息，然后再开始使用 Application Manager 中的 CloudFormation 模板。
+ [AWS Systems Manager 文档](documents.md)
+ [共享 SSM 文档](documents-ssm-sharing.md)
+ [共享 SSM 文档的最佳做法](documents-ssm-sharing.md#best-practices-shared)

**查看 Application Manager 中的模板库**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，请选择 **Application Manager**。

1. 选择 **CloudFormation 模板库**。

## 创建模板
<a name="application-manager-working-stacks-creating-template"></a>

以下过程介绍如何在 Application Manager 中创建 CloudFormation 模板。创建模板时，可以在 JSON 或 YAML 中输入模板的堆栈详细信息。如果您不熟悉 JSON 或 YAML，可以使用 AWS 基础架构编辑器，此工具可用于通过可视化方式创建和修改模板。有关更多信息，请参阅《*AWS CloudFormation 用户指南*》中的[使用基础设施编辑器直观地创建模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/infrastructure-composer-for-cloudformation.html)。有关模板结构和语法的更多信息，请参阅《AWS CloudFormation 用户指南》中的 [CloudFormation 模板部分](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)**。

您还可以利用多个模板片段构建模板。模板片段提供一些示例，以说明如何为特定资源编写模板。例如，您可以查看用于 Amazon Elastic Compute Cloud (Amazon EC2) 实例、Amazon Simple Compute Service (Amazon S3) 域、Amazon Simple Storage Service (Amazon S3) 域、CloudFormation映射等的片段。片段按资源分组。可以在*AWS CloudFormation用户指南*的[通用模板片段](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-general.html)部分中，可以找到通用 CloudFormation 片段。

### 在 Application Manager（操作台）中创建 CloudFormation 模板
<a name="application-manager-working-stacks-creating-template-console"></a>

通过使用 AWS 管理控制台，使用以下过程在 Application Manager 中创建 CloudFormation 模板。

**在 Application Manager 中创建 CloudFormation 模板**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，请选择 **Application Manager**。

1. 选择 **CloudFormation 模板库**，然后选择**创建模板**或选择现有模板，然后再选择**操作**、**克隆**。

1. 对于**名称**，输入模板名称，以帮助您识别模板创建的资源或堆栈的用途。

1. （可选）对于**版本名称**，输入名称或编号以标识模板版本。

1. 在**代码编辑器**部分中，选择 **YAML** 或者 **JSON**，然后输入或复制并粘贴模板代码。

1. （可选）在**文档标签**部分，将一个或多个标签键名称/值对应用于文档。

1. （可选）在**权限**部分中，输入 AWS 账户 ID 并选择**添加帐户**。此操作提供对模板的读取权限。帐户所有者可以配置和克隆模板，但无法编辑或删除模板。

1. 选择**创建**。模板保存在 Systems Manager (SSM) 文档服务中。

### 在 Application Manager 中创建 CloudFormation 模板（命令行）
<a name="application-manager-working-stacks-creating-template-cli"></a>

在 JSON 或 YAML 中创建 CloudFormation 模板的内容后，您可以使用AWS Command Line Interface (AWS CLI） 或 AWS Tools for PowerShell 将模板另存为 SSM 文档。将每个*示例资源占位符*替换为您自己的信息。

**开始前的准备工作**  
安装并配置 AWS CLI 或 AWS Tools for PowerShell（如果尚未执行该操作）。有关信息，请参阅[安装或更新 AWS CLI 的最新版本](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)以及[安装 AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html)。

------
#### [ Linux & macOS ]

```
aws ssm create-document \
    --content file://path/to/template_in_json_or_yaml \
    --name "a_name_for_the_template" \
    --document-type "CloudFormation" \
    --document-format "JSON_or_YAML" \
    --tags "Key=tag-key,Value=tag-value"
```

------
#### [ Windows ]

```
aws ssm create-document ^
    --content file://C:\path\to\template_in_json_or_yaml ^
    --name "a_name_for_the_template" ^
    --document-type "CloudFormation" ^
    --document-format "JSON_or_YAML" ^
    --tags "Key=tag-key,Value=tag-value"
```

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

```
$json = Get-Content -Path "C:\path\to\template_in_json_or_yaml | Out-String
New-SSMDocument `
    -Content $json `
    -Name "a_name_for_the_template" `
    -DocumentType "CloudFormation" `
    -DocumentFormat "JSON_or_YAML" `
    -Tags "Key=tag-key,Value=tag-value"
```

------

如果成功，该命令将返回类似于以下内容的响应。

```
{
    "DocumentDescription": {
        "Hash": "c1d9640f15fbdba6deb41af6471d6ace0acc22f213bdd1449f03980358c2d4fb",
        "HashType": "Sha256",
        "Name": "MyTestCFTemplate",
        "Owner": "428427166869",
        "CreatedDate": "2021-06-04T09:44:18.931000-07:00",
        "Status": "Creating",
        "DocumentVersion": "1",
        "Description": "My test template",
        "PlatformTypes": [],
        "DocumentType": "CloudFormation",
        "SchemaVersion": "1.0",
        "LatestVersion": "1",
        "DefaultVersion": "1",
        "DocumentFormat": "YAML",
        "Tags": [
            {
                "Key": "Templates",
                "Value": "Test"
            }
        ]
    }
```

## 编辑模板
<a name="application-manager-working-stacks-editing-template"></a>

使用以下过程在 Application Manager 中编辑 CloudFormation 模板。配置使用更新后模板的堆栈后，将在 CloudFormation 中提供模板更改。

**在 Application Manager 中编辑 CloudFormation 模板的步骤**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，请选择 **Application Manager**。

1. 选择 **CloudFormation 模板库**

1. 选择模板，然后依次选择**操作**、**编辑**。您无法更改模板的名称，但您可以更改其他所有详细信息。

1. 选择**保存**。模板将保存在 Systems Manager 文档服务中。