

• 2026 年 4 月 30 日之後將不再提供 AWS Systems Manager CloudWatch Dashboard。客戶可以繼續使用 Amazon CloudWatch 主控台來檢視、建立和管理其 Amazon CloudWatch 儀表板，就像現在一樣。如需詳細資訊，請參閱 [Amazon CloudWatch Dashboard 文件](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](documents.md)
+ [共用 SSM 文件](documents-ssm-sharing.md)
+ [共用 SSM 文件的最佳實務](documents-ssm-sharing.md#best-practices-shared)

**若要在 Application Manager 中檢視範本程式庫**

1. 在 https：//[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 Infrastructure Composer，這是一種視覺化建立和修改範本的工具。如需詳細資訊，請參閱 *AWS CloudFormation User Guide* 中的 [Create templates visually with Infrastructure Composer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/infrastructure-composer-for-cloudformation.html)。如需有關範本結構和語法的資訊，請參閱 *AWS CloudFormation User Guide* 中的 [CloudFormation template sections](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)。

您也可以從多個範本程式碼片段建構範本。範本程式碼片段是可向您示範如何撰寫特定資源範本的範例。例如，您可以檢視 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體、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：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **Application Manager**。

1. 選擇 **CloudFormation 範本程式庫**，然後選擇**建立範本**或選擇現有範本，接著依次選擇**動作**、**複製**。

1. 對於 **Name** (名稱)，輸入範本的名稱，以協助您識別其建立的資源或堆疊的用途。

1. (選用) 對於 **Version name** (版本名稱)，輸入名稱或編號以識別範本版本。

1. 在 **Code editor** (程式碼編輯器) 區段中，選擇 **YAML** 或 **JSON**，然後輸入或複製並貼上您的範本程式碼。

1. (選用) 在 **Tags** (標籤) 區段中，將一個或多個標籤索引鍵名稱/值對套用到範本。

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 Tools for PowerShell如果您尚未安裝和設定 AWS CLI 或 。如需相關資訊，請參閱[安裝或更新 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：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在導覽窗格中，選擇 **Application Manager**。

1. 選擇 **CloudFormation 範本程式庫**

1. 選擇一個範本，然後選擇 **Actions** (動作)、**Edit** (編輯)。您無法變更範本的名稱，但您可以變更所有其他詳細資訊。

1. 選擇**儲存**。範本會存放在 Systems Manager 文件服務中。