

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

# 將 AWS Service Catalog 產品複製到不同的 AWS 帳戶和 AWS 區域
<a name="copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions"></a>

*Sachin Vighe 和 Santosh Kale，Amazon Web Services*

## 總結
<a name="copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions-summary"></a>

AWS Service Catalog 是一項區域服務，這表示 AWS Service Catalog [產品組合和產品](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/what-is_concepts.html)只能在建立它們的 AWS 區域中顯示。如果您在新區域中設定 [AWS Service Catalog 中樞](https://aws.amazon.com/about-aws/whats-new/2020/06/aws-service-catalog-now-supports-sharing-portfolios-across-an-organization-from-a-delegated-member-account/)，則必須重新建立現有的產品，這可能會是耗時的程序。

此模式的方法透過描述如何將來源 AWS 帳戶或區域中的 AWS Service Catalog 中樞中的產品複製到目的地帳戶或區域中的新中樞，協助簡化此程序。如需 AWS Service Catalog 中樞和語音模型的詳細資訊，請參閱 [AWS Service Catalog 中樞和語音模型：如何將 AWS Service Catalog 的部署和管理自動化至 AWS 管理和控管部落格上的許多帳戶](https://aws.amazon.com/blogs/mt/aws-service-catalog-hub-and-spoke-model-how-to-automate-the-deployment-and-management-of-service-catalog-to-many-accounts/)。 

模式也提供跨帳戶或其他區域複製 AWS Service Catalog 產品所需的個別程式碼套件。透過使用此模式，您的組織可以節省時間、在新的 AWS Service Catalog 中樞中提供現有和先前的產品版本、將手動錯誤的風險降至最低，以及將方法擴展到多個帳戶或區域。

**注意**  
此模式的 *Epics* 區段提供兩種複製 產品的選項。您可以使用選項 1 跨帳戶複製產品，或選擇選項 2 跨區域複製產品。

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

**先決條件**
+ 作用中的 AWS 帳戶
+ 來源帳戶或區域中現有的 AWS Service Catalog 產品。
+ 目的地帳戶或區域中現有的 AWS Service Catalog 中樞。
+ 如果您想要跨帳戶複製產品，您必須共用，然後將包含產品的 AWS Service Catalog 產品組合匯入目的地帳戶。如需詳細資訊，請參閱 AWS Service Catalog 文件中的[共用和匯入產品組合](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/catalogs_portfolios_sharing.html)。

**限制**
+ 您要跨區域或帳戶複製的 AWS Service Catalog 產品不能屬於多個產品組合。

## Architecture
<a name="copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions-architecture"></a>

下圖顯示將 AWS Service Catalog 產品從來源帳戶複製到目的地帳戶。

![\[區域 1 中的跨帳戶角色、區域 2 中的 Lambda 執行角色和 Lambda 函數。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7ede5d17-89eb-4455-928f-6953d145ac9f/images/26738220-1ed2-4f84-911b-3c88e954b60e.png)


 下圖顯示將 AWS Service Catalog 產品從來源區域複製到目的地區域。

![\[使用區域 2 中的 Lambda scProductCopy 函數複製的產品。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7ede5d17-89eb-4455-928f-6953d145ac9f/images/0a936792-3bdc-45c2-ba05-17e828615061.png)


**技術堆疊**
+ Amazon CloudWatch
+ AWS Identity and Access Management (IAM)
+ AWS Lambda
+ AWS Service Catalog

**自動化和擴展**

您可以使用 Lambda 函數來擴展此模式的方法，該函數可根據收到的請求數量或您需要複製的 AWS Service Catalog 產品數量進行擴展。如需詳細資訊，請參閱 AWS Lambda [Lambda 文件中的 Lambda 函數擴展](https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html)。

## 工具
<a name="copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions-tools"></a>
+ [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 Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，可協助您執行程式碼，而不需要佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [AWS Service Catalog](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/introduction.html) 可協助您集中管理針對 AWS 核准的 IT 服務目錄。最終使用者可在機構所設的限制範圍內，迅速地只部署自己需要且經核准的 IT 服務。

**Code**

您可以使用 ` cross-account-copy`套件 （已連接） 跨帳戶複製 AWS Service Catalog 產品，或使用 `cross-region-copy`套件 （已連接） 跨區域複製產品。

`cross-account-copy` 套件包含下列檔案：
+ `copyconf.properties` – 包含區域和 AWS 帳戶 ID 參數的組態檔案，用於跨帳戶複製產品。
+ `scProductCopyLambda.py` – 用於跨帳戶複製產品的 Python 函數。
+ `createDestAccountRole.sh` – 在目的地帳戶中建立 IAM 角色的指令碼。
+ `createSrcAccountRole.sh` – 在來源帳戶中建立 IAM 角色的指令碼。
+ `copyProduct.sh` – 用來建立和叫用 Lambda 函數以跨帳戶複製產品的指令碼。

`cross-region-copy` 套件包含下列檔案：
+ `copyconf.properties` – 包含區域和 AWS 帳戶 ID 參數的組態檔案，用於跨區域複製產品。
+ `scProductCopyLambda.py` – 跨區域複製產品的 Python 函數。
+ `copyProduct.sh` – 用來建立 IAM 角色，以及建立和叫用 Lambda 函數以跨區域複製產品的指令碼。

## 史詩
<a name="copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions-epics"></a>

### 選項 1 – 跨帳戶複製 AWS Service Catalog 產品
<a name="option-1-ndash-copy-aws-service-catalog-products-across-accounts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新組態檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions.html) | AWS 管理員、AWS 系統管理員、雲端管理員 | 
| 在目的地帳戶中設定 AWS CLI 的登入資料。 | 執行 `aws configure`命令並提供下列值，以設定您的登入資料來存取目的地帳戶中的 AWS CLI：<pre>$aws configure <br />AWS Access Key ID [None]: <your_access_key_id> <br />AWS Secret Access Key [None]: <your_secret_access_key> <br />Default region name [None]: Region<br />Default output format [None]:</pre>如需詳細資訊，請參閱 AWS Command Line Interface 文件中的[組態基本概念](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html)。  | AWS 管理員、AWS 系統管理員、雲端管理員 | 
| 在來源帳戶中設定 AWS CLI 的登入資料。 | 執行 `aws configure`命令並提供下列值，以設定您的登入資料來存取來源帳戶中的 AWS CLI： <pre>$aws configure<br />AWS Access Key ID [None]: <your_access_key_id><br />AWS Secret Access Key [None]: <your_secret_access_key><br />Default region name [None]: Region<br />Default output format [None]:</pre>如需詳細資訊，請參閱 AWS 命令列界面文件中[的組態基本](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html)概念。  | AWS 管理員、AWS 系統管理員、雲端管理員 | 
| 在目的地帳戶中建立 Lambda 執行角色。 | 在您的目的地帳戶中執行`createDestAccountRole.sh `指令碼。指令碼會實作下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions.html) | AWS 管理員、AWS 系統管理員、雲端管理員 | 
| 在來源帳戶中建立跨帳戶 IAM 角色。 | 在您的來源帳戶中執行`createSrcAccountRole.sh `指令碼。指令碼會實作下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions.html) | AWS 管理員、AWS 系統管理員、雲端管理員 | 
| 在目的地帳戶中執行 copyProduct 指令碼。 | 在目的地帳戶中執行`copyProduct.sh `指令碼。指令碼會實作下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions.html) | AWS 管理員、AWS 系統管理員、雲端管理員 | 

### 選項 2 – 將 AWS Service Catalog 產品從來源區域複製到目的地區域
<a name="option-2-ndash-copy-aws-service-catalog-products-from-a-source-region-to-a-destination-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新組態檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions.html) | AWS 系統管理員、雲端管理員、AWS 管理員 | 
| 設定 AWS CLI 的登入資料。 | 執行 `aws configure`命令並提供下列值，以設定您的登入資料來存取您環境中的 AWS CLI：<pre>$aws configure<br />AWS Access Key ID [None]: <your_access_key_id><br />AWS Secret Access Key [None]: <your_secret_access_key><br />Default region name [None]: Region<br />Default output format [None]:</pre>如需詳細資訊，請參閱 AWS 命令列界面文件中[的組態基本](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html)概念。  | AWS 管理員、AWS 系統管理員、雲端管理員 | 
| 執行 copyProduct 指令碼。 | 在目的地區域中執行`copyProduct.sh`指令碼。指令碼會實作下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions.html) | AWS 管理員、AWS 系統管理員、雲端管理員 | 

## 相關資源
<a name="copy-aws-service-catalog-products-across-different-aws-accounts-and-aws-regions-resources"></a>
+ [建立 Lambda 執行角色](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html) (AWS Lambda 文件）
+ [建立 Lambda 函數](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-awscli.html) (AWS Lambda 文件）
+ [AWS Service Catalog API 參考](https://docs.aws.amazon.com/servicecatalog/latest/dg/API_Operations_AWS_Service_Catalog.html)
+ [AWS Service Catalog 文件](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/what-is_concepts.html)

## 附件
<a name="attachments-7ede5d17-89eb-4455-928f-6953d145ac9f"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/7ede5d17-89eb-4455-928f-6953d145ac9f/attachments/attachment.zip)