使用 Application Manager 管理 AWS CloudFormation 範本 - AWS Systems Manager

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Application Manager 管理 AWS CloudFormation 範本

Application Manager是 中的工具 AWS Systems Manager,包含範本程式庫和其他工具,可協助您管理 AWS CloudFormation 範本。此區段包含下列資訊:

使用範本程式庫

Application Manager 範本程式庫提供的工具可協助您檢視、建立、編輯、刪除和複製範本。您也可以直接從範本程式庫佈建堆疊。範本會以類型 CloudFormation 的 Systems Manager (SSM) 文件形式存放。透過將範本儲存為 SSM 文件,您可以使用版本控制來處理範本的不同版本。您也可以設定許可及共享範本。成功佈建堆疊之後,Application Manager 和 CloudFormation 中會提供堆疊和範本。

開始之前

我們建議您先閱讀下列主題,以進一步了解 SSM 文件,然後再開始使用 Application Manager 中的 CloudFormation 範本。

若要在 Application Manager 中檢視範本程式庫
  1. 在 https://https://console.aws.amazon.com/systems-manager/ 開啟 AWS Systems Manager 主控台。

  2. 在導覽窗格中,選擇 Application Manager

  3. 選擇 CloudFormation 範本程式庫

建立範本

下列程序說明如何在 Application Manager 中建立 CloudFormation 範本。當您建立範本時,您可以在 JSON 或 YAML 中輸入範本的堆疊詳細資訊。如果您不熟悉 JSON 或 YAML,您可以使用 AWS Infrastructure Composer,這是一種視覺化建立和修改範本的工具。如需詳細資訊,請參閱AWS CloudFormation 《 使用者指南》中的使用 Infrastructure Composer 以視覺化方式建立範本。如需範本結構和語法的相關資訊,請參閱AWS CloudFormation 《 使用者指南》中的AWS CloudFormation 範本區段

您也可以從多個範本程式碼片段建構範本。範本程式碼片段是可向您示範如何撰寫特定資源範本的範例。例如,您可以檢視 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體、Amazon Simple Storage Service (Amazon S3) 網域、 AWS CloudFormation 映射等程式碼片段。程式碼片段會依資源分組。您可以在《AWS CloudFormation 使用者指南》中的一般範本程式碼片段區段中尋找一般用途 AWS CloudFormation 程式碼片段。

在 Application Manager (主控台) 中建立 CloudFormation 範本

利用以下程序,使用 AWS Management Console在 Application Manager 中建立 CloudFormation 範本。

若要在 Application Manager 中建立 CloudFormation 範本
  1. 在 https://https://console.aws.amazon.com/systems-manager/ 開啟 AWS Systems Manager 主控台。

  2. 在導覽窗格中,選擇 Application Manager

  3. 選擇 CloudFormation 範本程式庫,然後選擇建立範本或選擇現有範本,然後選擇動作複製

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

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

  6. Code editor (程式碼編輯器) 區段中,選擇 YAMLJSON,然後輸入或複製並貼上您的範本程式碼。

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

  8. (選用) 在許可區段中,輸入 AWS 帳戶 ID 並選擇新增帳戶。此動作會提供範本的讀取許可。帳戶擁有者可以佈建和複製範本,但無法編輯或刪除範本。

  9. 選擇建立。範本會存放在 Systems Manager (SSM) 文件服務中。

在 Application Manager (命令列) 中建立 CloudFormation 範本

在 JSON 或 YAML 中建立 CloudFormation 範本的內容之後,您可以使用 AWS Command Line Interface (AWS CLI) 或 AWS Tools for PowerShell 將範本儲存為 SSM 文件。將每個範例資源預留位置取代為您自己的資訊。

開始之前

AWS Tools for PowerShell如果您尚未安裝和設定 AWS CLI 或 。如需相關資訊,請參閱安裝或更新 AWS CLI的最新版本安裝 AWS Tools for PowerShell

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"
            }
        ]
    }

編輯範本

利用以下程序,在 Application Manager 中編輯 CloudFormation 範本。佈建使用已更新範本的堆疊之後,即可在 CloudFormation 中使用範本變更。

若要在 Application Manager 中編輯 CloudFormation 範本
  1. 在 https://https://console.aws.amazon.com/systems-manager/ 開啟 AWS Systems Manager 主控台。

  2. 在導覽窗格中,選擇 Application Manager

  3. 選擇 CloudFormation 範本程式庫

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

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