

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

# 在多個 AWS 帳戶和 AWS 區域中管理 AWS Service Catalog 產品
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions"></a>

*Ram Kandaswamy，Amazon Web Services*

## 總結
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-summary"></a>

Amazon Web Services (AWS) Service Catalog 簡化並加速企業基礎設施即程式碼 (IaC) 範本的控管和分發。您可以使用 AWS CloudFormation 範本來定義產品所需的 AWS 資源集合 *（堆疊*)。AWS CloudFormation StackSets 可讓您透過單一操作，跨多個帳戶和 AWS 區域建立、更新或刪除堆疊，藉此擴充此功能。

AWS Service Catalog 管理員使用開發人員撰寫的 CloudFormation 範本來建立產品，並發佈它們。這些產品接著會與產品組合建立關聯，並套用限制來控管。若要將您的產品提供給其他 AWS 帳戶或組織單位 (OUs) 中的使用者，您通常會與他們[共用您的產品組合](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/catalogs_portfolios_sharing.html)。此模式說明管理以 AWS CloudFormation StackSets 為基礎的 AWS Service Catalog 產品方案的替代方法。 AWS CloudFormation StackSets 您可以使用堆疊集限制來設定可部署和使用產品的 AWS 區域和帳戶，而不是共用產品組合。透過使用此方法，您可以在多個帳戶、OUs 和 AWS 區域中佈建 AWS Service Catalog 產品，並從中央位置管理它們，同時滿足您的控管需求。 

此方法的優點：
+ 產品是從主要帳戶佈建和管理，不會與其他帳戶共用。
+ 此方法提供以特定產品為基礎的所有佈建產品 （堆疊） 的合併檢視。
+ 使用 AWS Service Management Connector 的組態比較容易，因為它只以一個帳戶為目標。
+ 查詢和使用來自 AWS Service Catalog 的產品更容易。

## 先決條件和限制
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-prereqs"></a>

**先決條件**
+ IaC 和版本控制的 AWS CloudFormation 範本
+ 用於佈建和管理 AWS 資源的多帳戶設定和 AWS Service Catalog 

**限制**
+ 此方法使用 AWS CloudFormation StackSets，且適用 StackSets 的限制：
  + StackSets 不支援透過巨集部署 CloudFormation 範本。如果您使用巨集來預先處理範本，您將無法使用 StackSets 型部署。
  + StackSets 可讓您取消堆疊與堆疊集的關聯，因此您可以鎖定特定堆疊來修正問題。不過，取消關聯的堆疊無法與堆疊集重新建立關聯。
+ AWS Service Catalog 會自動產生 StackSet 名稱。目前不支援自訂。

## Architecture
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-architecture"></a>

**目標架構**

![\[使用者使用 AWS CloudFormation 範本和 StackSets 管理 AWS Service Catalog 產品。 AWS CloudFormation StackSets\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/16458fcd-861d-4ed4-8b91-47e19289a6bb/images/97d23325-b5c6-4ca9-8288-8dec1650c975.png)


1. 使用者會建立 AWS CloudFormation 範本，以 JSON 或 YAML 格式佈建 AWS 資源。

1. CloudFormation 範本會在 AWS Service Catalog 中建立產品，並將其新增至產品組合。

1. 使用者會建立佈建產品，以在目標帳戶中建立 CloudFormation 堆疊。

1. 每個堆疊會佈建 CloudFormation 範本中指定的資源。

## 工具
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-tools"></a>

**AWS 服務**
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速且一致地佈建資源，以及在整個 AWS 帳戶和區域的生命週期中管理這些資源。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Service Catalog](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/introduction.html) 可協助您集中管理針對 AWS 核准的 IT 服務目錄。最終使用者可在機構所設的限制範圍內，迅速地只部署自己需要且經核准的 IT 服務。

## 史詩
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-epics"></a>

### 跨帳戶佈建產品
<a name="provision-products-across-accounts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立組合。 | 產品組合是一種容器，其中包含一或多個根據特定條件分組在一起的產品。將產品組合用於您的產品，可協助您在產品集中套用常見的限制條件。若要建立產品組合，請遵循 [AWS Service Catalog 文件](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/portfoliomgmt-create.html)中的指示。如果您使用的是 AWS CLI，以下是範例命令：<pre>aws servicecatalog create-portfolio --provider-name my-provider --display-name my-portfolio</pre>如需詳細資訊，請參閱 [AWS CLI 文件](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/servicecatalog/create-portfolio.html)。 | AWS Service Catalog、IAM | 
| 建立 CloudFormation 範本。 | 建立描述 資源的 CloudFormation 範本。適用時，應參數化資源屬性值。 | AWS CloudFormation、JSON/YAML | 
| 建立具有版本資訊的產品。 | 當您在 AWS Service Catalog 中發佈 CloudFormation 範本時，範本會變成產品。提供選用版本詳細資訊參數的值，例如版本標題和描述；這有助於稍後查詢產品。若要建立產品，請遵循 [AWS Service Catalog 文件](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/productmgmt-cloudresource.html)中的指示。如果您使用的是 AWS CLI，範例命令為：<pre>aws servicecatalog create-product --cli-input-json file://create-product-input.json</pre>其中 `create-product-input.json`是傳遞產品參數的檔案。如需此檔案的範例，請參閱*其他資訊*一節。如需詳細資訊，請參閱 [AWS CLI 文件](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/servicecatalog/create-product.html)。 | AWS Service Catalog | 
| 套用限制條件。 | 將堆疊集限制條件套用至產品組合，以設定產品部署選項，例如多個 AWS 帳戶、區域和許可。如需說明，請參閱 [AWS Service Catalog 文件](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/constraints-stackset.html)。 | AWS Service Catalog | 
| 新增 許可。 | 提供許可給使用者，讓他們可以啟動產品組合中的產品。如需主控台說明，請參閱 [AWS Service Catalog 文件](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/catalogs_portfolios_users.html)。如果您使用的是 AWS CLI，以下是範例命令：<pre>aws servicecatalog associate-principal-with-portfolio \<br />    --portfolio-id port-2s6abcdefwdh4 \<br />    --principal-arn arn:aws:iam::444455556666:role/Admin \<br />    --principal-type IAM</pre>如需詳細資訊，請參閱 [AWS CLI 文件](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/servicecatalog/associate-principal-with-portfolio.html)。 | AWS Service Catalog、IAM | 
| 佈建 產品。 | 佈建的產品是產品的資源執行個體。根據 CloudFormation 範本佈建產品會啟動 CloudFormation 堆疊及其基礎資源。根據堆疊集限制，以適用的 AWS 區域和帳戶為目標來佈建產品。在 AWS CLI 中，以下是範例命令：<pre>aws servicecatalog provision-product \<br />    --product-id prod-abcdfz3syn2rg \<br />    --provisioning-artifact-id pa-abc347pcsccfm \<br />    --provisioned-product-name "mytestppname3"</pre>如需詳細資訊，請參閱 [AWS CLI 文件](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/servicecatalog/provision-product.html)。 | AWS Service Catalog | 

## 相關資源
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-resources"></a>

**參考**
+ [AWS Service Catalog 概觀](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/what-is_concepts.html)
+ [使用 AWS CloudFormation StackSets](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/using-stacksets.html)

**教學課程和影片**
+ [AWS re：Invent 2019：自動化一切：選項和最佳實務 ](https://www.youtube.com/watch?v=bGBVPIpQMYk)（影片）

## 其他資訊
<a name="manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions-additional"></a>

當您使用 `create-product`命令時， `cli-input-json` 參數會指向指定資訊的檔案，例如產品擁有者、支援電子郵件和 CloudFormation 範本詳細資訊。以下是此類檔案的範例：

```
{
   "Owner": "Test admin",
      "SupportDescription": "Testing",
         "Name": "SNS",
            "SupportEmail": "example@example.com",
            "ProductType": "CLOUD_FORMATION_TEMPLATE",
               "AcceptLanguage": "en",
                  "ProvisioningArtifactParameters": {
                     "Description": "SNS product",
                        "DisableTemplateValidation": true,
                           "Info": {
                              "LoadTemplateFromURL": "<url>"
                     },
                           "Name": "version 1"
}
```