

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

# 遷移與現代化
<a name="migration-modernization-pattern-list"></a>

**Topics**
+ [遷移](migration-pattern-list.md)
+ [現代化](modernization-pattern-list.md)
+ [大型主機](mainframe-pattern-list.md)

# 遷移
<a name="migration-pattern-list"></a>

**Topics**
+ [使用 Microsoft Excel 和 Python 為 AWS DMS 任務建立 AWS CloudFormation 範本](create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python.md)
+ [開始使用自動化產品組合探索](get-started-with-automated-portfolio-discovery.md)
+ [將內部部署 Cloudera 工作負載遷移至 AWS 上的 Cloudera 資料平台](migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws.md)
+ [解決將 Microsoft SQL Server 遷移至 AWS 雲端後的連線錯誤](resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud.md)
+ [重新啟動 RHEL 來源伺服器後，在不停用 SELinux 的情況下自動重新啟動 AWS 複寫代理程式](restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server.md)
+ [重新架構師](migration-rearchitect-pattern-list.md)
+ [重新託管](migration-rehost-pattern-list.md)
+ [重新定位](migration-relocate-pattern-list.md)
+ [平台重建](migration-replatform-pattern-list.md)
+ [依工作負載的遷移模式](migration-migration-patterns-by-workload-pattern-list.md)
+ [更多模式](migration-more-patterns-pattern-list.md)

# 使用 Microsoft Excel 和 Python 為 AWS DMS 任務建立 AWS CloudFormation 範本
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python"></a>

*Venkata Naveen Koppula，Amazon Web Services*

## 總結
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python-summary"></a>

此模式概述使用 Microsoft Excel 和 Python 為 [AWS Database Migration Service](https://aws.amazon.com/dms/) (AWS DMS) 自動建立 AWS CloudFormation 範本的步驟。

使用 AWS DMS 遷移資料庫通常需要建立 AWS CloudFormation 範本來佈建 AWS DMS 任務。先前，建立 AWS CloudFormation 範本需要 JSON 或 YAML 程式設計語言的知識。使用此工具，您只需具備 Excel 的基本知識，以及如何使用終端機或命令視窗執行 Python 指令碼。

做為輸入，工具會採用 Excel 工作手冊，其中包含要遷移的資料表名稱、AWS DMS 端點的 Amazon Resource Name (ARNs)，以及 AWS DMS 複寫執行個體。然後，該工具會為所需的 AWS DMS 任務產生 AWS CloudFormation 範本。

如需詳細步驟和背景資訊，請參閱 [ AWS 資料庫部落格中的部落格文章使用 Microsoft Excel 建立 AWS DMS 任務的 AWS CloudFormation 範本](https://aws.amazon.com/blogs/database/create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel/)。

## 先決條件和限制
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Microsoft Excel 2016 版或更新版本
+ Python 2.7 版或更新版本
+ **xlrd** Python 模組 （安裝在命令提示中，使用 命令：**pip install xlrd**)
+ AWS DMS 來源和目標端點和 AWS DMS 複寫執行個體

**限制**
+ 結構描述、資料表和關聯資料欄的名稱會在目的地端點轉換為小寫字元。
+ 此工具不會處理 AWS DMS 端點和複寫執行個體的建立。
+ 目前， 工具只支援每個 AWS DMS 任務的一個結構描述。

## Architecture
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python-architecture"></a>

**來源技術堆疊**
+ 內部部署資料庫
+ Microsoft Excel

**目標技術堆疊**
+ AWS CloudFormation 範本
+ AWS 雲端中的資料庫 

**架構**

![\[使用 Excel 和 Python 為 AWS DMS 自動建立 CloudFormation 範本的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/778c7c1e-2647-496f-8afd-52ff1ef02489/images/8fe1550d-8966-41aa-a480-5f7bef20629f.png)


## 工具
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python-tools"></a>
+ [Pycharm IDE](https://aws.amazon.com/pycharm/)，或任何支援 Python 3.6 版的整合式開發環境 (IDE)
+ Microsoft Office 2016 （適用於 Microsoft Excel)

## 史詩
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python-epics"></a>

### 設定網路、AWS DMS 複寫執行個體和端點
<a name="configure-the-network-aws-dms-replication-instance-and-endpoints"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 如有必要，請請求提高服務配額。 | 視需要請求提高 AWS DMS 任務的服務配額。 | 一般 AWS | 
| 設定 AWS 區域、虛擬私有雲端 (VPCs)、CIDR 範圍、可用區域和子網路。 |  | 一般 AWS | 
| 設定 AWS DMS 複寫執行個體。 | AWS DMS 複寫執行個體可以連線到內部部署和 AWS 資料庫。 | 一般 AWS | 
| 設定 AWS DMS 端點。 | 設定來源和目標資料庫的端點。 | 一般 AWS | 

### 準備 AWS DMS 任務和標籤的工作表
<a name="prepare-the-worksheets-for-aws-dms-tasks-and-tags"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定資料表清單。 | 列出遷移中涉及的所有資料表。 | 資料庫 | 
| 準備任務工作表。 | 使用您設定的資料表清單準備 Excel 工作表。 | General AWS、Microsoft Excel | 
| 準備標籤工作表。 | 詳細說明要連接到 AWS DMS 任務的 AWS 資源標籤。 | General AWS、Microsoft Excel | 

### 下載並執行 工具
<a name="download-and-run-the-tool"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 GitHub 儲存庫下載並擷取範本產生工具。 | GitHub 儲存庫：https：//https://github.com/aws-samples/dms-cloudformation-templates-generator/ |  | 
| 執行 工具。 | 請遵循「參考和說明」下列出的部落格文章中的詳細指示。 |  | 

## 相關資源
<a name="create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python-resources"></a>
+ [使用 Microsoft Excel 為 AWS DMS 任務建立 AWS CloudFormation 範本 （部落格文章）](https://aws.amazon.com/blogs/database/create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel/)
+ [DMS CloudFormation 範本產生器 (GitHub 儲存庫）](https://github.com/aws-samples/dms-cloudformation-templates-generator/tree/v1.0)
+ [Python 文件](https://www.python.org/)
+ [xlrd 描述和下載](https://pypi.org/project/xlrd/)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/)
+ [AWS CloudFormation 文件](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/)

# 開始使用自動化產品組合探索
<a name="get-started-with-automated-portfolio-discovery"></a>

*Pratik Chunawala 和 Rodolfo Jr. Cerrada，Amazon Web Services*

## 總結
<a name="get-started-with-automated-portfolio-discovery-summary"></a>

將應用程式和伺服器遷移至 Amazon Web Services (AWS) 雲端時，評估產品組合和收集中繼資料是一項重大挑戰，特別是對於具有 300 多個伺服器的大型遷移。使用自動化產品組合探索工具可協助您收集應用程式的相關資訊，例如使用者數量、使用頻率、相依性，以及應用程式基礎設施的相關資訊。在規劃遷移波紋時，此資訊至關重要，因此您可以正確排定優先順序，並將具有類似特徵的應用程式分組。使用探索工具可簡化產品組合團隊與應用程式擁有者之間的通訊，因為產品組合團隊可以驗證探索工具的結果，而不是手動收集中繼資料。此模式討論選擇自動化探索工具的重要考量，以及如何在環境中部署和測試工具的資訊。

此模式包含 範本，這是建立自己高階活動檢查清單的起點。檢查清單旁邊是負責、負責、諮詢、告知 (RACI) 矩陣的範本。您可以使用此 RACI 矩陣來判斷誰負責檢查清單中的每個任務。

## 史詩
<a name="get-started-with-automated-portfolio-discovery-epics"></a>

### 選取探索工具
<a name="select-a-discovery-tool"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 判斷探索工具是否適合您的使用案例。 | 探索工具可能不是適合您使用案例的最佳解決方案。考慮選取、購買、準備和部署探索工具所需的時間量。在您的環境中為無代理程式探索工具設定掃描設備，或將代理程式安裝到所有範圍內工作負載，可能需要 4-8 週的時間。部署後，您必須允許 4 到 12 週的時間，讓探索工具透過掃描應用程式工作負載和執行應用程式堆疊分析來收集中繼資料。如果您遷移的伺服器少於 100 個，您可能可以手動收集中繼資料，並比使用自動探索工具部署和收集中繼資料所需的時間更快地分析相依性。 | 遷移負責人，遷移工程師 | 
| 選取探索工具。 | 檢閱[其他資訊](#get-started-with-automated-portfolio-discovery-additional)區段中**選取自動探索工具的考量**事項。判斷為您的使用案例選擇探索工具的適當條件，然後根據這些條件評估每個工具。如需自動化探索工具的完整清單，請參閱[探索、規劃和建議遷移工具](https://aws.amazon.com/prescriptive-guidance/migration-tools/migration-discovery-tools/)。 | 遷移負責人，遷移工程師 | 

### 準備安裝
<a name="prepare-for-installation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備部署前檢查清單。 | 建立您在部署工具之前必須完成的任務檢查清單。如需範例，請參閱 Flexera 文件網站上的[部署前檢查清單](https://docs.flexera.com/foundationcloudscape/ug/Content/helplibrary/FCGS_Predeployment.htm)。 | 組建主管、遷移工程師、遷移主管、網路管理員 | 
| 準備網路需求。 | 佈建工具執行和存取目標伺服器所需的連接埠、通訊協定、IP 地址和路由。如需詳細資訊，請參閱 探索工具的安裝指南。如需範例，請參閱 Flexera 文件網站上的[部署需求](https://docs.flexera.com/foundationcloudscape/help/RCDeployReq.htm)。 | 遷移工程師、網路管理員、雲端架構師 | 
| 準備帳戶和登入資料需求。 | 識別存取目標伺服器和安裝所有工具元件所需的登入資料。 | 雲端管理員、一般 AWS、遷移工程師、遷移主管、網路管理員、AWS 管理員 | 
| 準備您要安裝工具的設備。 | 確定您要安裝工具元件的設備符合工具的規格和平台需求。 | 遷移工程師、遷移主管、網路管理員 | 
| 準備變更訂單。 | 根據您組織中的變更管理程序，準備所需的任何變更訂單，並確保這些變更訂單獲得核准。 | 組建潛在客戶、遷移潛在客戶 | 
| 將需求傳送給利益相關者。 | 將部署前檢查清單和網路需求傳送給利益相關者。在繼續部署之前，利益相關者應該檢閱、評估和準備必要的要求。 | 組建潛在客戶、遷移潛在客戶 | 

### 部署 工具
<a name="deploy-the-tool"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載安裝程式。 | 下載安裝程式或虛擬機器映像。虛擬機器映像通常採用開放虛擬化格式 (OVF)。 | 組建潛在客戶、遷移潛在客戶 | 
| 將檔案解壓縮。 | 如果您使用的是 安裝程式，則必須在內部部署伺服器上下載並執行安裝程式。 | 組建潛在客戶、遷移潛在客戶 | 
| 在伺服器上部署 工具。 | 在目標內部部署伺服器上部署探索工具，如下所示：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/get-started-with-automated-portfolio-discovery.html) | 組建領導、遷移領導、網路管理員 | 
| 登入 探索工具。 | 遵循畫面上的提示，並登入以開始使用 工具。 | 遷移潛在客戶、建置潛在客戶 | 
| 啟用產品。 | 輸入您的授權金鑰。 | 組建潛在客戶、遷移潛在客戶 | 
| 設定工具。 | 輸入存取目標伺服器所需的任何登入資料，例如 Windows、VMware、Simple Network Management Protocol (SNMP) 和 Secure Shell Protocol (SSH) 或資料庫的登入資料。 | 組建潛在客戶、遷移潛在客戶 | 

### 測試工具
<a name="test-the-tool"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選取測試伺服器。 | 識別一組可用來測試探索工具的非生產子網路或 IP 地址。這可協助您快速驗證掃描、快速識別任何錯誤並進行疑難排解，以及將您的測試與生產環境隔離。 | 組建領導、遷移領導、網路管理員 | 
| 開始掃描選取的測試伺服器。 | 對於無代理程式探索工具，請在探索工具主控台中輸入所選測試伺服器的子網路或 IP 地址，然後開始掃描。對於代理程式型探索工具，請在選取的測試伺服器上安裝代理程式。 | 組建領導、遷移領導、網路管理員 | 
| 檢閱掃描結果。 | 檢閱測試伺服器的掃描結果。如果發現任何錯誤，請疑難排解並修正錯誤。記錄錯誤和解決方案。您可以在未來參考此資訊，也可以將此資訊新增至您的產品組合 Runbook。 | 組建領導、遷移領導、網路管理員 | 
| 重新掃描測試伺服器。 | 重新掃描完成後，請重複掃描，直到沒有錯誤為止。 | 組建領導、遷移領導、網路管理員 | 

## 相關資源
<a name="get-started-with-automated-portfolio-discovery-resources"></a>

**AWS resources**
+ [AWS 雲端 遷移的應用程式產品組合評估指南](https://docs.aws.amazon.com/prescriptive-guidance/latest/application-portfolio-assessment-guide/introduction.html)
+ [探索、規劃和建議遷移工具](https://aws.amazon.com/prescriptive-guidance/migration-tools/migration-discovery-tools/)

**常用所選探索工具的部署指南**
+ [部署 RN150 虛擬設備](https://docs.flexera.com/foundationcloudscape/ug/Content/helplibrary/FCGS_QSG_DeployRN150.htm) (Flexera 文件）
+ [收集器安裝](https://www.modelizeit.com/documentation/ADC-Gatherer-Install.html) (modelizeIT 文件）
+ [內部部署分析伺服器安裝 ](https://www.modelizeit.com/documentation/RejuvenApptor-Install.html)(modelizeIT 文件）

## 其他資訊
<a name="get-started-with-automated-portfolio-discovery-additional"></a>

**選取自動化探索工具的考量事項**

每個探索工具都有優點和限制。為您的使用案例選取適當的工具時，請考慮下列事項：
+ 選取探索工具，可收集您實現產品組合評估目標所需的大部分中繼資料，如果不是全部。
+ 識別您需要手動收集的任何中繼資料，因為工具不支援它。
+ 將探索工具需求提供給利益相關者，讓他們可以根據其內部安全和合規需求來檢閱和評估工具，例如伺服器、網路和憑證需求。
  + 此工具是否需要您在範圍內工作負載中安裝 代理程式？
  + 工具是否需要您在環境中設定虛擬設備？
+ 判斷您的資料駐留需求。有些組織不想將資料存放在環境之外。若要解決此問題，您可能需要在內部部署環境中安裝工具的一些元件。
+ 確定工具支援範圍內工作負載的作業系統 (OS) 和作業系統版本。
+ 判斷您的產品組合是否包含大型主機、中範圍和舊版伺服器。大多數探索工具可以將這些工作負載偵測為相依性，但有些工具可能無法取得裝置詳細資訊，例如使用率和伺服器相依性。Device42 和modernizeIT 探索工具都支援大型主機和中階伺服器。

## 附件
<a name="attachments-8c9d84de-e84a-4b0c-bcaa-389cd90be1f0"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/8c9d84de-e84a-4b0c-bcaa-389cd90be1f0/attachments/attachment.zip)

# 將內部部署 Cloudera 工作負載遷移至 AWS 上的 Cloudera 資料平台
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws"></a>

*Battulga Purevragchaa 和 Nidhi Gupta，Amazon Web Services*

*Nijjwol Lamsal， Cloudera， Inc.*

## 總結
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-summary"></a>

此模式說明將內部部署 Cloudera 分散式 Hadoop (CDH)、Hortonworks 資料平台 (HDP) 和 Cloudera 資料平台 (CDP) 工作負載遷移至 CDP Public Cloud on AWS 的高階步驟。我們建議您與 Cloudera Professional Services 和系統整合商 (SI) 合作實作這些步驟。

Cloudera 客戶想要將內部部署 CDH、HDP 和 CDP 工作負載移至雲端的原因有很多。一些典型原因包括：
+ 簡化新資料平台範例的採用，例如資料湖區或資料網格
+ 提高業務敏捷性、普及現有資料資產的存取和推論
+ 降低總擁有成本 (TCO)
+ 增強工作負載彈性
+ 提供更高的可擴展性；相較於舊版內部部署安裝基礎，可大幅縮短佈建資料服務的時間
+ 淘汰舊版硬體；大幅減少硬體重新整理週期
+ 利用pay-as-you-go定價透過 Cloudera 授權模型 (CCU) 擴展到 AWS 上的 Cloudera 工作負載
+ 利用更快的部署和改善與持續整合和持續交付 (CI/CD) 平台的整合
+ 針對多個工作負載使用單一統一平台 (CDP)

Cloudera 支援所有主要工作負載，包括Machine Learning、資料工程、資料倉儲、操作資料庫、串流處理 (CSP)，以及資料安全和控管。Cloudera 已在內部部署提供這些工作負載多年，您可以使用 CDP Public Cloud 搭配 Workload Manager 和 Replication Manager，將這些工作負載遷移至 AWS 雲端。 

Cloudera 共用資料體驗 (SDX) 提供跨這些工作負載的共用中繼資料目錄，以促進一致的資料管理和操作。SDX 也包含可防範威脅的全方位精細安全性，以及稽核和搜尋功能的統一控管，以符合支付卡產業資料安全標準 (PCI DSS) 和 GDPR 等標準。 

**CDP 遷移一目了然**


|  |  | 
| --- |--- |
|    工作負載 | 來源工作負載 | CDH、HDP 和 CDP 私有雲端 | 
| --- |--- |--- |
| 來源環境 | Windows，Linux內部部署、主機代管或任何非 AWS 環境 | 
| 目的地工作負載 | AWS 上的 CDP 公有雲端 | 
| 目的地環境 | 部署模型：客戶帳戶操作模型：客戶/Cloudera 控制平面 | 
| ** **** ****移轉** | 遷移策略 (7R) | 重新託管、轉換或重構 | 
| 這是工作負載版本中的升級嗎？ | 是 | 
| 遷移持續時間 | 部署：約 1 週可建立客戶帳戶、虛擬私有雲端 (VPC) 和 CDP 公有雲端客戶受管環境。遷移持續時間：1-4 個月，取決於工作負載的複雜性和大小。 | 
| **成本** | 在 AWS 上執行工作負載的成本 | 在高層級上，CDH 工作負載遷移至 AWS 的成本假設您會在 AWS 上建立新的環境。它包括考慮人員時間和精力，以及為新環境佈建運算資源和授權軟體。Cloudera 雲端消費型定價模式可讓您靈活地利用爆量和自動擴展功能。如需詳細資訊，請參閱 Cloudera 網站上的 [CDP 公有雲端服務費率](https://www.cloudera.com/products/pricing/cdp-public-cloud-service-rates.html)。Cloudera Enterprise [Data Hub](https://www.cloudera.com/products/enterprise-data-hub.html) 是以 Amazon Elastic Compute Cloud (Amazon EC2) 為基礎，並緊密建立傳統叢集的模型。Data Hub 可以[自訂](https://docs.cloudera.com/data-hub/cloud/create-cluster-aws/topics/mc-creating-a-cluster.html)，但這會影響成本。[CDP 公有雲端資料倉儲](https://docs.cloudera.com/data-warehouse/cloud/index.html)、[Cloudera Machine Learning](https://docs.cloudera.com/machine-learning/cloud/product/topics/ml-product-overview.html) 和 [Cloudera Data Engineering (CDE)](https://docs.cloudera.com/data-engineering/cloud/index.html) 是以容器為基礎，可設定為自動擴展。 | 
| ** **** ****基礎設施協議和架構** | 系統要求 | 請參閱[先決條件](#migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-prereqs)一節。 | 
| SLA | 請參閱 [CDP 公有雲端的 Cloudera 服務水準協議。](https://www.cloudera.com/legal/terms-and-conditions/cdp-public-cloud-sla.html) | 
| DR | 請參閱 Cloudera 文件中的[災難復原](https://docs.cloudera.com/cdp-reference-architectures/latest/cdp-ra-operations/topics/cdp-ra-abstract.html)。 | 
| 授權和操作模型 （適用於目標 AWS 帳戶） | 使用自有授權 (BYOL) 模型 | 
| ** ****合規** | 安全要求 | 請參閱 [Cloudera 文件中的 Cloudera 安全性概觀](https://docs.cloudera.com/cdp-private-cloud-base/7.1.6/security-overview/topics/cm-security-overview.html)。 | 
| 其他[合規認證](https://aws.amazon.com/compliance/programs) | 請參閱 Cloudera 網站上有關[一般資料保護法規 (GDPR](https://www.cloudera.com/solutions/lower-business-risks/general-data-protection-regulation.html)) 合規和 [CDP 信任中心](https://www.cloudera.com/products/trust-center.html)的資訊。 | 

## 先決條件和限制
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-prereqs"></a>

**先決條件**
+ [AWS 帳戶需求](https://docs.cloudera.com/cdp-public-cloud/cloud/requirements-aws/topics/mc-requirements-aws.html)，包括帳戶、資源、服務和許可，例如 AWS Identity and Access Management (IAM) 角色和政策設定
+ 從 Cloudera [網站部署 CDP 的先決條件](https://docs.cloudera.com/cdp-public-cloud/cloud/getting-started/topics/cdp-set_up_cdp_prerequisites.html) 

遷移需要下列角色和專業知識：


| 
| 
| Role | 技能和責任 | 
| --- |--- |
| 遷移潛在客戶 | 確保執行支援、團隊協作、規劃、實作和評估 | 
| Cloudera 中小企業 | CDH、HDP 和 CDP 管理、系統管理和架構方面的專業技能 | 
| AWS 架構師 | AWS 服務、聯網、安全和架構的技能 | 

## Architecture
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-architecture"></a>

建置適當的架構是確保遷移和效能符合您期望的關鍵步驟。為了滿足此手冊的假設，AWS 雲端中的目標資料環境，無論是在虛擬私有雲端 (VPC) 託管執行個體或 CDP 上，在作業系統和軟體版本以及主要機器規格方面，都必須與來源環境相當。

下圖 （透過 [Cloudera 共享資料體驗資料表](https://www.cloudera.com/content/dam/www/marketing/resources/datasheets/cloudera-sdx-datasheet.pdf?daqp=true)的許可而重新產生） 顯示 CDP 環境的基礎設施元件，以及層或基礎設施元件如何互動。

![\[CDP 環境元件\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bb47435e-2638-425c-ac37-7d55053452ac/images/91d62277-7fde-4ec6-8e2b-86a446e2f6ee.png)


架構包含下列 CDP 元件：
+ Data Hub 是一項服務，用於啟動和管理採用 Cloudera Runtime 技術的工作負載叢集。您可以使用 Data Hub 中的叢集定義，為自訂使用案例佈建和存取工作負載叢集，並定義自訂叢集組態。如需詳細資訊，請參閱 [Cloudera 網站](https://docs.cloudera.com/data-hub/cloud/index.html)。
+ 資料流程和串流可解決企業在處理資料時面臨的主要挑戰。它會管理下列項目：
  + 處理大量和大規模的即時資料串流
  + 追蹤串流資料的資料來源和歷程
  + 管理和監控邊緣應用程式和串流來源

  如需詳細資訊，請參閱 [Cloudera 網站上的 Cloudera DataFlow](https://www.cloudera.com/products/dataflow.html) 和 [CSP](https://www.cloudera.com/products/stream-processing.html)。
+ 資料工程包括資料整合、資料品質和資料控管，可協助組織建置和維護資料管道和工作流程。如需詳細資訊，請參閱 [Cloudera 網站](https://docs.cloudera.com/data-engineering/cloud/index.html)。了解 [Spot 執行個體的支援，以協助節省 AWS for Cloudera Data Engineering 工作負載的成本](https://docs.cloudera.com/data-engineering/cloud/cost-management/topics/cde-spot-instances.html)。
+ 資料倉儲** **可讓您建立獨立的資料倉儲和資料封送，以自動擴展以滿足工作負載需求。此服務為每個資料倉儲和資料智慧提供隔離的運算執行個體和自動化最佳化，並協助您在符合 SLAs 時節省成本。如需詳細資訊，請參閱 [Cloudera 網站](https://docs.cloudera.com/data-warehouse/cloud/index.html)。了解如何[管理 AWS 上 Cloudera Data Warehouse 的成本](https://docs.cloudera.com/data-warehouse/cloud/planning/topics/dw-manage-cloud-costs.html)和[自動擴展](https://docs.cloudera.com/data-warehouse/cloud/auto-scaling/topics/dw-public-cloud-autoscaling-overview.html)。
+ CDP 中的操作資料庫為可擴展、高效能應用程式提供了可靠且靈活的基礎。它提供即時、始終可用、可擴展的資料庫，可在統一的操作和倉儲平台上提供傳統的結構化資料以及新的非結構化資料。如需詳細資訊，請參閱 [Cloudera 網站](https://www.cloudera.com/products/operational-db.html)。
+ Machine Learning 是一種雲端原生機器學習平台，可將自助式資料科學和資料工程功能合併到企業資料雲端內的單一可攜式服務。它可在資料上的任何地方進行可擴展的機器學習和人工智慧 (AI) 部署。如需詳細資訊，請參閱 [Cloudera 網站](https://docs.cloudera.com/machine-learning/cloud/index.html)。

**AWS 上的 CDP**

下圖 （採用 Cloudera 網站的許可） 顯示 AWS 上 CDP 的高階架構。CDP 實作[自己的安全模型](https://docs.cloudera.com/runtime/7.1.0/cdp-security-overview/topics/security-management-console-security.html)來管理帳戶和資料流程。這些透過使用[跨帳戶角色](https://docs.cloudera.com/cdp-public-cloud/cloud/requirements-aws/topics/mc-aws-req-credential.html)與 [IAM](https://aws.amazon.com/iam/) 整合。 

![\[AWS 高階架構上的 CDP\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bb47435e-2638-425c-ac37-7d55053452ac/images/54420517-38b4-4e82-bd19-9ded50ed009c.png)


CDP 控制平面位於 Cloudera 主帳戶中自己的 VPC。每個客戶帳戶都有自己的子帳戶和唯一的 VPC。跨帳戶 IAM 角色和 SSL 技術會將進出控制平面的管理流量路由到位於每個客戶 VPC 內網際網路可路由公有子網路上的客戶服務。在客戶的 VPC 上，Cloudera 共享資料體驗 (SDX) 以統一的控管和合規提供企業級安全性，讓您可以更快地從資料中取得洞見。SDX 是併入所有 Cloudera 產品的設計理念。如需適用於 AWS 的 [SDX](https://docs.cloudera.com/cdp-public-cloud/cloud/overview/topics/cdp-services.html) 和 CDP 公有雲端網路架構的詳細資訊，請參閱 Cloudera 文件。 [https://docs.cloudera.com/cdp-public-cloud/cloud/aws-refarch/topics/cdp-pc-aws-refarch-overview.html](https://docs.cloudera.com/cdp-public-cloud/cloud/aws-refarch/topics/cdp-pc-aws-refarch-overview.html)

## 工具
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Elastic Kubernetes Service (Amazon EKS)](https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html) 可協助您在 AWS 上執行 Kubernetes，而無需安裝或維護您自己的 Kubernetes 控制平面或節點。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**自動化和工具**
+ 如需其他工具，您可以使用 [Cloudera Backup Data Recovery (BDR)](https://docs.cloudera.com/documentation/enterprise/6/6.3/topics/cm_bdr_tutorials.html)、[AWS Snowball](https://aws.amazon.com/snowball/) 和 [AWS Snowmobile](https://aws.amazon.com/snowmobile/)，協助將資料從內部部署 CDH、HDP 和 CDP 遷移到 AWS 託管的 CDP。
+ 對於新的部署，我們建議您使用適用於 [CDP 的 AWS 合作夥伴解決方案](https://aws.amazon.com/solutions/partners/terraform-modules/cdp-public-cloud/)。

## 史詩
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-epics"></a>

### 準備遷移
<a name="prepare-for-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 與 Cloudera 團隊互動。 | Cloudera 會與客戶一起追求標準化的參與模式，並可與您的系統整合商 (SI) 合作，以推廣相同的方法。請聯絡 Cloudera 客戶團隊，讓他們可以提供指引和必要的技術資源，以開始專案。聯絡 Cloudera 團隊可確保所有必要的團隊都能在日期接近時準備遷移。 您可以聯絡 Cloudera Professional Services，以較低成本和最高效能快速地將 Cloudera 部署從試行移至生產環境。如需方案的完整清單，請參閱 [Cloudera 網站](https://www.cloudera.com/about/services-and-support/professional-services.html)。 | 遷移潛在客戶 | 
| 在 AWS 上為您的 VPC 建立 CDP 公有雲端環境。 | 使用 Cloudera Professional Services 或您的 SI，在 AWS 上的 VPC 中規劃和部署 CDP 公有雲端。 | Cloudera SME 雲端架構師 | 
| 排定優先順序並評估工作負載以進行遷移。 | 評估所有現場部署工作負載，以判斷最容易遷移的工作負載。非關鍵任務的應用程式最好先移動，因為它們對您的客戶的影響最小。在您成功遷移其他工作負載之後，請儲存任務關鍵工作負載以供上次使用。暫時性 (CDP Data Engineering) 工作負載比持久性 (CDP Data Warehouse) 工作負載更容易遷移。在遷移時考慮資料磁碟區和位置也很重要。挑戰可能包括持續將資料從內部部署環境複寫到雲端，以及變更資料擷取管道以將資料直接匯入雲端。 | 遷移潛在客戶 | 
| 討論 CDH、HDP、CDP 和舊版應用程式遷移活動。 | 考慮並開始規劃下列 Cloudera Workload Manager 活動：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws.html) | 遷移潛在客戶 | 
| 完成 Cloudera Replication Manager 要求和建議。 | 使用 Cloudera Professional Services 和您的 SI 準備將工作負載遷移到 AWS 上的 CDP 公有雲端環境。了解下列要求和建議可協助您避免在安裝 Replication Manager 服務期間和之後的常見問題。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws.html) | 遷移潛在客戶 | 

### 將 CDP 遷移至 AWS
<a name="migrate-cdp-to-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Cloudera Workload Manager 遷移開發/測試環境的第一個工作負載。 | 您的 SI 可協助您將第一個工作負載遷移至 AWS 雲端。這應該是非面向客戶或關鍵任務的應用程式。開發/測試遷移的理想候選項目是具有雲端可輕鬆擷取資料的應用程式，例如 CDP Data Engineering 工作負載。這是一種暫時性工作負載，與 CDP Data Warehouse 工作負載等持續性工作負載相比，存取它的使用者通常較少，而 CDP Data Warehouse 工作負載可能有許多需要不間斷存取的使用者。Data Engineering 工作負載並非持久性，如果發生錯誤，這可將業務影響降至最低。不過，這些任務對於生產報告至關重要，因此請先排定低影響資料工程工作負載的優先順序。 | 遷移潛在客戶 | 
| 視需要重複遷移步驟。 | Cloudera Workload Manager 可協助識別最適合雲端的工作負載。它提供諸如雲端效能評分、目標環境的大小/容量計劃，以及複寫計劃的指標。遷移的最佳候選項目是季節性工作負載、臨機操作報告，以及不會耗用許多資源的間歇性任務。Cloudera Replication Manager 會將資料從內部部署移至雲端，以及從雲端移至內部部署。使用 Workload Manager 主動最佳化資料倉儲、資料工程和機器學習的工作負載、應用程式、效能和基礎設施容量。如需如何現代化資料倉儲的完整指南，請參閱 [Cloudera 網站](https://www.cloudera.com/content/dam/www/marketing/resources/webinars/modern-data-warehouse-fundamentals.png.landing.html)。 | Cloudera 中小企業 | 

## 相關資源
<a name="migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws-resources"></a>

Cloudera 文件：
+ [向 CDP、Cloudera Manager 和 Replication Manager 註冊傳統叢集：](https://docs.cloudera.com/replication-manager/cloud/operations/topics/rm-requirements-for-bdr-cdh-clusters.html)
  + [管理主控台](https://docs.cloudera.com/management-console/cloud/overview/topics/mc-management-console.html)
  + [Replication Manager hive 複寫](https://docs.cloudera.com/replication-manager/cloud/core-concepts/topics/rm-replication-of-data-using-hive.html)
+ [Sentry 複寫](https://docs.cloudera.com/replication-manager/cloud/core-concepts/topics/rm-sentry-policy-replication.html) 
+ [Sentry 許可](https://docs.cloudera.com/replication-manager/cloud/core-concepts/topics/rm-sentry-ranger-permissions.html)
+ [Data Hub 叢集規劃檢查清單](https://docs.cloudera.com/data-hub/cloud/cluster-planning/topics/dh-cluster-checklist.html)
+ [Workload Manager 架構](https://docs.cloudera.com/workload-manager/cloud/configuration/topics/wm-public-architecture-wm.html)
+ [複寫管理員需求](https://docs.cloudera.com/replication-manager/cloud/index.html)
+ [Cloudera 資料平台可觀測性](https://www.cloudera.com/products/observability.html)
+ [AWS 需求](https://docs.cloudera.com/cdp-public-cloud/cloud/requirements-aws/topics/mc-requirements-aws.html)

AWS 文件：
+ [雲端資料遷移](https://aws.amazon.com/cloud-data-migration/)

# 解決將 Microsoft SQL Server 遷移至 AWS 雲端後的連線錯誤
<a name="resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud"></a>

*Premkumar Chelladurai，Amazon Web Services*

## 總結
<a name="resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud-summary"></a>

將 Windows Server 2008 R2、2012 或 2012 R2 上執行的 Microsoft SQL Server 遷移至 Amazon Web Services (AWS) Cloud 上的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體後，SQL Server 的連線會失敗，並出現下列錯誤： 
+ `[Microsoft][ODBC SQL Server Driver][DBNETLIB] General Network error`
+ `ERROR [08S01] [Microsoft][SQL Native Client]Communication link failure. System.Data.SqlClient.SqlException: A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)`
+ `TCP Provider: The semaphore timeout period has expired`

此模式說明如何透過在作業系統 (OS) 和在 Windows Server 2008 R2、2012 或 2012 R2 上執行的 SQL Server 網路介面層級關閉 Windows Scalable Networking Pack (SNP) 功能來解決這些錯誤R2。

## 先決條件和限制
<a name="resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud-prereqs"></a>

**先決條件**
+ Windows Server 的管理員權限。
+ 如果您使用 AWS Application Migration Service 做為遷移工具，則需要下列其中一個 Windows Server 版本：
  + Windows Server 2008 R2 Service Pack 1、2012 或 2012 R2
+ 如果您使用 CloudEndure Migration 做為遷移工具，則需要下列其中一個 Windows Server 版本：
  + Windows Server 2003 R2 Service Pack 3、2008、2008 R2 Service Pack 1、2012 或 2012 R2

## 工具
<a name="resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud-tools"></a>
+ [Amazon EC2](https://docs.aws.amazon.com/ec2/index.html) – Amazon Elastic Compute Cloud (Amazon EC2) 在 AWS 雲端中提供可擴展的運算容量。您可以使用 Amazon EC2 視需要啟動任意數量或任意數量的虛擬伺服器，也可以向外擴展或向內擴展。 
+ [Windows Server](https://docs.microsoft.com/en-us/windows-server/) – Windows Server 是建置連線應用程式、網路和 Web 服務基礎設施的平台。

## 史詩
<a name="resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud-epics"></a>

### 在作業系統和彈性網路介面層級關閉 SNP 功能
<a name="turn-off-snp-features-at-the-os-and-elastic-network-interface-levels"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在作業系統層級關閉 SNP 功能。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud.html) | AWS 管理員、AWS 系統管理員、遷移工程師、雲端管理員 | 
| 在彈性網路介面層級關閉 SNP 功能。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud.html) | AWS 管理員、雲端管理員、AWS 系統管理員 | 

## 相關資源
<a name="resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud-resources"></a>
+ [如何疑難排解進階網路效能功能，例如 RSS 和 NetDMA](https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/troubleshoot-network-performance-features-rss-netdma)

# 重新啟動 RHEL 來源伺服器後，在不停用 SELinux 的情況下自動重新啟動 AWS 複寫代理程式
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server"></a>

*Anil Kunapareddy、Venkatramana Chintha 和 Shanmugam Shanker，Amazon Web Services*

## 總結
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-summary"></a>

AWS Application Migration Service 有助於簡化、加速和自動化 Red Hat Enterprise Linux (RHEL) 工作負載遷移至 Amazon Web Services (AWS) 雲端。若要將來源伺服器新增至 Application Migration Service，請在伺服器上安裝 AWS 複寫代理程式。

Application Migration Service 提供即時、非同步的區塊層級複寫。這表示在整個複寫過程中，您可以繼續正常的 IT 操作。這些 IT 操作可能需要您在遷移期間重新啟動或重新啟動 RHEL 來源伺服器。如果發生這種情況，AWS 複寫代理程式不會自動重新啟動，而且您的資料複寫將會停止。一般而言，您可以將 Security-Enhanced Linux (SELinux) 設定為**停用**或**寬鬆**模式，以自動重新啟動 AWS Replication Agent。不過，您組織的安全政策可能禁止停用 SELinux，而且您可能也必須[重新標記檔案](https://access.redhat.com/solutions/3176)。

此模式說明如何在 RHEL 來源伺服器在遷移期間重新啟動或重新啟動時，在不關閉 SELinux 的情況下自動重新啟動 AWS 複寫代理程式。 

## 先決條件和限制
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 您希望遷移至 AWS 雲端的現場部署 RHEL 工作負載。 
+ 從 Application Migration Service 主控台初始化的 Application Migration Service。只有在您第一次使用此服務時，才需要初始化。如需說明，請參閱 [Application Migration Service 文件](https://docs.aws.amazon.com/mgn/latest/ug/mandatory-setup.html)。
+ Application Migration Service 的現有 [AWS Identity and Access Management (IAM) 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)。如需詳細資訊，請參閱 [Application Migration Service 文件](https://docs.aws.amazon.com/mgn/latest/ug/mgn-policies.html)。

**版本**
+ RHEL 第 7 版或更新版本

## 工具
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-tools"></a>

**AWS 服務**
+ [AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 是一種高度自動化lift-and-shift（重新託管） 解決方案，可簡化、加速和降低將應用程式遷移至 AWS 的成本。

**Linux 命令**

下表提供您將在 RHEL 來源伺服器上執行的 Linux 命令清單。這些也會在此模式的 epics 和故事中說明。 


| 
| 
| 命令 | Description | 
| --- |--- |
| `#systemctl –version` | 識別系統版本。 | 
| `#systemctl list-units --type=service` | 列出 RHEL 伺服器上可用的所有作用中服務。 | 
| `#systemctl list-units --type=service \| grep running` | 列出目前在 RHEL 伺服器上執行的所有服務。 | 
| `#systemctl list-units --type=service \| grep failed` | 列出 RHEL 伺服器重新啟動或重新啟動後無法載入的所有服務。 | 
| `restorecon -Rv /etc/rc.d/init.d/aws-replication-service` | 將內容變更為 `aws-replication-service`。 | 
| `yum install policycoreutils*` | 安裝 SELinux 系統操作所需的政策核心公用程式。 | 
| `ausearch -c "insmod" --raw \| audit2allow -M my-modprobe` | 搜尋稽核日誌並建立 政策的模組。 | 
| `semodule -i my-modprobe.pp` | 啟用政策。 | 
| `cat my-modprobe.te` | 顯示 `my-modprobe.te` 檔案的內容。 | 
| `semodule -l \| grep my-modprobe` | 檢查政策是否已載入 SELinux 模組。 | 

## 史詩
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-epics"></a>

### 安裝 AWS 複寫代理程式並重新啟動 RHEL 來源伺服器
<a name="install-the-aws-replication-agent-and-reboot-the-rhel-source-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用存取金鑰和私密存取金鑰建立 Application Migration Service 使用者。 | 若要安裝 AWS 複寫代理程式，您必須使用所需的 AWS 登入資料建立 Application Migration Service 使用者。如需說明，請參閱 [Application Migration Service 文件](https://docs.aws.amazon.com/mgn/latest/ug/credentials.html)。 | 遷移工程師 | 
| 安裝 AWS 複寫代理程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server.html) | 遷移工程師 | 
| 重新啟動或重新啟動 RHEL 來源伺服器。 | 當 RHEL 來源伺服器**的資料複寫狀態**顯示在[遷移儀表板](https://docs.aws.amazon.com/mgn/latest/ug/migration-dashboard.html)上**停滯**時，請重新啟動或重新啟動 RHEL 來源伺服器。 | 遷移工程師 | 
| 檢查資料複寫狀態。 | 等待一小時，然後在遷移儀表板上再次檢查**資料複寫狀態**。它應該處於**運作**狀態。 | 遷移工程師 | 

### 檢查 RHEL 來源伺服器上的 AWS 複寫代理程式狀態
<a name="check-aws-replication-agent-status-on-the-rhel-source-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別系統版本。 | 開啟 RHEL 來源伺服器的命令列界面，並執行下列命令來識別系統版本：`#systemctl –version` | 遷移工程師 | 
| 列出所有作用中的服務。 | 若要列出 RHEL 伺服器上可用的所有作用中服務，請執行 命令：`#systemctl list-units --type=service` | 遷移工程師 | 
| 列出所有執行中的服務。 | 若要列出目前在 RHEL 伺服器上執行的所有服務，請使用 命令：`#systemctl list-units --type=service \| grep running` | 遷移工程師 | 
| 列出所有無法載入的服務。 | 若要列出 RHEL 伺服器重新啟動或重新啟動後無法載入的所有服務，請執行 命令：`#systemctl list-units --type=service \| grep failed` | 遷移工程師 | 

### 建立並執行 SELinux 模組
<a name="create-and-run-the-selinux-module"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 變更安全內容。 | 在 RHEL 來源伺服器的命令列界面中，執行下列命令，將安全內容變更為 AWS 複寫服務：`restorecon -Rv /etc/rc.d/init.d/aws-replication-service` | 遷移工程師 | 
| 安裝核心公用程式。 | 若要安裝 SELinux 系統操作所需的核心公用程式及其政策，請執行 命令：`yum install policycoreutils*` | 遷移工程師 | 
| 搜尋稽核日誌並建立 政策的模組。 | 執行 命令：`ausearch -c "insmod" --raw \| audit2allow -M my-modprobe` | 遷移工程師 | 
| 顯示 my-modprobe-te 檔案的內容。 | `my-modprobe.te` 檔案是由 **audit2allow **命令產生。它包含 SELinux 網域、政策來源目錄和子目錄，並指定與網域相關聯的存取向量規則和轉換。若要顯示檔案的內容，請執行 命令：`cat my modprobe.te` | 遷移工程師 | 
| 啟用政策。 | 若要插入模組並將政策套件設為作用中，請執行 命令：`semodule -i my-modprobe.pp` | 遷移工程師 | 
| 檢查是否已載入模組。 | 執行 命令：`semodule -l \| grep my-modprobe`載入 SELinux 模組後，您不再需要在遷移期間將 SELinux 設定為**已停用**或**寬鬆**模式。 | 遷移工程師 | 
| 重新啟動或重新啟動 RHEL 來源伺服器，並確認資料複寫狀態。 | 開啟 AWS Migration Service 主控台，導覽至**資料複寫進度**，然後重新啟動或重新啟動 RHEL 來源伺服器。資料複寫現在應在 RHEL 來源伺服器重新啟動後自動恢復。 | 遷移工程師 | 

## 相關資源
<a name="restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server-resources"></a>
+ [應用程式遷移服務文件](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)
+ [技術訓練資料](https://docs.aws.amazon.com/mgn/latest/ug/mgn-training.html)
+ [故障診斷 AWS 複寫代理程式問題](https://docs.aws.amazon.com/mgn/latest/ug/Troubleshooting-Agent-Issues.html)
+ [Application Migration Service 政策](https://docs.aws.amazon.com/mgn/latest/ug/mgn-policies.html)

# 重新架構師
<a name="migration-rearchitect-pattern-list"></a>

**Topics**
+ [將 Oracle 的 VARCHAR2(1) 資料類型轉換為 Amazon Aurora PostgreSQL 的布林資料類型](convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.md)
+ [在 Aurora PostgreSQL 相容中建立應用程式使用者和角色](create-application-users-and-roles-in-aurora-postgresql-compatible.md)
+ [使用 PostgreSQL 相容 Aurora 全域資料庫模擬 Oracle DR](emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database.md)
+ [從 SQL Server 遷移至 PostgreSQL 時，實作 PII 資料的 SHA1 雜湊](implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.md)
+ [使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.md)
+ [在 Aurora PostgreSQL 相容中使用檔案編碼將 BLOB 檔案載入 TEXT](load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL AWS CLI CloudFormation](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.md)
+ [使用 AWS DMS，以 SSL 模式將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.md)
+ [將 Oracle SERIALLY\$1REUSABLE pragma 套件遷移至 PostgreSQL](migrate-oracle-serially-reusable-pragma-packages-into-postgresql.md)
+ [將 Oracle 外部資料表遷移至 Amazon Aurora PostgreSQL 相容](migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible.md)
+ [將函數型索引從 Oracle 遷移至 PostgreSQL](migrate-function-based-indexes-from-oracle-to-postgresql.md)
+ [使用延伸模組將 Oracle 原生函數遷移至 PostgreSQL](migrate-oracle-native-functions-to-postgresql-using-extensions.md)
+ [使用 AWS DMS 將 Db2 資料庫從 Amazon EC2 遷移至 Aurora MySQL 相容](migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫從 Amazon EC2 遷移至 Amazon DocumentDB](migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms.md)
+ [將內部部署 ThoughtSpot Falcon 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift.md)
+ [使用 Oracle GoldenGate 從 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.md)
+ [使用 AWS DMS 將 Oracle 分割的資料表遷移至 PostgreSQL](migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms.md)
+ [從 Amazon RDS for Oracle 遷移至 Amazon RDS for MySQL](migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql.md)
+ [使用 AWS DMS 和 AWS SCT 從 Amazon EC2 上的 IBM Db2 遷移至 Aurora PostgreSQL 相容 Amazon EC2](migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms.md)
+ [使用具體化視觀表和 AWS DMS，從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms.md)
+ [使用 AWS DMS 和 AWS SCT 從 Oracle on Amazon EC2 遷移至 Amazon RDS for MySQL](migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for MariaDB](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 和 AWS SCT 將內部部署 Oracle 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [使用 Oracle 旁觀者和 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Amazon Redshift](migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct.md)
+ [將資料從現場部署 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql.md)
+ [使用 AWS DMS 從 SAP ASE 遷移至 Amazon RDS for SQL Server](migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms.md)
+ [使用 AWS DMS 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms.md)
+ [使用 AWS SCT 資料擷取代理程式將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents.md)
+ [將舊版應用程式從 Oracle Pro\$1C 遷移至 ECPG](migrate-legacy-applications-from-oracle-pro-c-to-ecpg.md)
+ [將虛擬產生的資料欄從 Oracle 遷移至 PostgreSQL](migrate-virtual-generated-columns-from-oracle-to-postgresql.md)
+ [在 Aurora PostgreSQL 相容上設定 Oracle UTL\$1FILE 功能](set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible.md)
+ [從 Oracle 遷移到 Amazon Aurora PostgreSQL 後驗證資料庫物件](validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql.md)

# 將 Oracle 的 VARCHAR2(1) 資料類型轉換為 Amazon Aurora PostgreSQL 的布林資料類型
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql"></a>

*Naresh Damera，Amazon Web Services*

## 總結
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-summary"></a>

從 Amazon Relational Database Service (Amazon RDS) for Oracle 遷移至 Amazon Aurora PostgreSQL 相容版本期間，您可能會在驗證 AWS Database Migration Service () 中的遷移時遇到資料不符的情況AWS DMS。若要防止此不相符，您可以將 VARCHAR2(1) 資料類型轉換為布林資料類型。

VARCHAR2 資料類型存放可變長度文字字串，而 VARCHAR2(1) 表示字串長度為 1 個字元或 1 個位元組。如需 VARCHAR2 的詳細資訊，請參閱 [Oracle 內建資料類型](https://docs.oracle.com/database/121/SQLRF/sql_elements001.htm#SQLRF30020) (Oracle 文件）。

在此模式中，在範例來源資料表欄中，VARCHAR2(1) 資料為 **Y**，表示*是*，或 **N**，表示*否*。 此模式包含使用 AWS DMS 和 AWS Schema Conversion Tool (AWS SCT) 將此資料類型從 VARCHAR2(1) 中的 **Y** 和 **N** 值轉換為布林值中的 **true** 或 **false** 值的指示。

**目標對象**

對於使用 將 Oracle 資料庫遷移至 Aurora PostgreSQL 相容資料庫的使用者，建議使用此模式 AWS DMS。當您完成遷移時，請遵循[將 Oracle 轉換為 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.ToPostgreSQL.html) (AWS SCT 文件） 中的建議。

## 先決條件和限制
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 確認您的環境已為 Aurora 做好準備，包括設定登入資料、許可和安全群組。如需詳細資訊，請參閱[設定 Amazon Aurora 的環境](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_SettingUp_Aurora.html) (Aurora 文件）。
+ 來源 Amazon RDS for Oracle 資料庫，其中包含具有 VARCHAR2(1) 資料的資料表資料欄。
+ 目標 Amazon Aurora PostgreSQL 相容資料庫執行個體。如需詳細資訊，請參閱[建立資料庫叢集並連線至 Aurora PostgreSQL 資料庫叢集上的資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html#CHAP_GettingStarted.AuroraPostgreSQL.CreateDBCluster) (Aurora 文件）。

**產品版本**
+ Amazon RDS for Oracle 12.1.0.2 版或更新版本。
+ AWS DMS 3.1.4 版或更新版本。如需詳細資訊，請參閱[使用 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)和[使用 PostgreSQL 資料庫做為 （文件） 的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)。AWS DMS 我們建議您使用最新版本的 AWS DMS ，以獲得最全面的版本和功能支援。
+ AWS Schema Conversion Tool (AWS SCT) 1.0.632 版或更新版本。我們建議您使用最新版本的 AWS SCT ，以獲得最全面的版本和功能支援。
+ Aurora 支援 Aurora PostgreSQL 相容資料庫引擎版本中列出的 PostgreSQL 版本 (Aurora 文件）。 [ PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html) 

## Architecture
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-architecture"></a>

**來源技術堆疊**

Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**

Amazon Aurora PostgreSQL 相容資料庫執行個體

**來源和目標架構**

![\[將資料類型從 VARCHAR2(1) 變更為布林值\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5d4dc568-20d8-4883-a942-21c81039d8e6/images/9fd82ae2-56e6-439c-b4cd-9e74fe77b480.png)


## 工具
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移到 AWS 雲端 或在雲端和內部部署設定的組合之間遷移。
+ [Amazon Relational Database Service (Amazon RDS) for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展 Oracle 關聯式資料庫 AWS 雲端。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 透過自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，支援異質資料庫遷移。

**其他服務**
+ [Oracle SQL Developer](https://docs.oracle.com/en/database/oracle/sql-developer/) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。在此模式中，您會使用此工具連線至 Amazon RDS for Oracle 資料庫執行個體並查詢資料。
+ [pgAdmin](https://www.pgadmin.org/docs/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。在此模式中，您會使用此工具連線至 Aurora 資料庫執行個體並查詢資料。

## 史詩
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料庫遷移報告。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.html) | DBA、開發人員 | 
| 在目標資料庫上停用外部金鑰限制條件。 | 在 PostgreSQL 中，外部金鑰是透過使用觸發程序來實作。在完全載入階段期間， 一次 AWS DMS 載入一個資料表。我們強烈建議您使用下列其中一種方法，在完全載入期間停用外部金鑰限制條件：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.html)如果無法停用外部金鑰限制，請為父資料表和子資料表特有的主要資料建立 AWS DMS 遷移任務。 | DBA、開發人員 | 
| 停用目標資料庫上的主索引鍵和唯一索引鍵。 | 使用下列命令，停用目標資料庫上的主索引鍵和限制條件。這有助於改善初始載入任務的效能。<pre>ALTER TABLE <table> DISABLE PRIMARY KEY;</pre><pre>ALTER TABLE <table> DISABLE CONSTRAINT <constraint_name>;</pre> | DBA、開發人員 | 
| 建立初始載入任務。 | 在 中 AWS DMS，建立初始載入的遷移任務。如需說明，請參閱[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。針對遷移方法，選擇**遷移現有資料**。此遷移方法在 API `Full Load`中** **呼叫。尚未啟動此任務。 | DBA、開發人員 | 
| 編輯初始載入任務的任務設定。 | 編輯任務設定以新增資料驗證。這些驗證設定必須在 JSON 檔案中建立。如需說明和範例，請參閱[指定任務設定](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.CustomizingTasks.TaskSettings.html)。新增下列驗證：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.html)若要驗證其餘的資料遷移，請在任務中啟用資料驗證。如需詳細資訊，請參閱[資料驗證任務設定](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.CustomizingTasks.TaskSettings.DataValidation.html)。 | AWS 管理員，DBA | 
| 建立進行中複寫任務。 | 在 中 AWS DMS，建立讓目標資料庫與來源資料庫保持同步的遷移任務。如需說明，請參閱[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。針對遷移方法，選擇**僅複寫資料變更**。尚未啟動此任務。 | DBA | 

### 測試遷移任務
<a name="test-the-migration-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立測試的範例資料。 | 在來源資料庫中，建立包含資料的範例資料表以供測試之用。 | 開發人員 | 
| 確認沒有衝突的活動。 | 使用 `pg_stat_activity`來檢查伺服器上可能影響遷移的任何活動。如需詳細資訊，請參閱[統計資料收集器 ](https://www.postgresql.org/docs/current/monitoring-stats.html)(PostgreSQL 文件）。 | AWS 管理員 | 
| 啟動 AWS DMS 遷移任務。 | 在 AWS DMS 主控台的**儀表板**頁面上，啟動您在上一個史詩中建立的初始載入和持續複寫任務。 | AWS 管理員 | 
| 監控任務和資料表載入狀態。 | 在遷移期間，監控[任務狀態](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html#CHAP_Tasks.Status)和[資料表狀態](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html#CHAP_Tasks.CustomizingTasks.TableState)。當初始載入任務完成時，在**資料表統計資料**索引標籤上：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.html) | AWS 管理員 | 
| 驗證遷移結果。 | 使用 pgAdmin 查詢目標資料庫上的資料表。成功的查詢表示資料已成功遷移。 | 開發人員 | 
| 在目標資料庫上新增主索引鍵和外部索引鍵。 | 在目標資料庫上建立主索引鍵和外部索引鍵。如需詳細資訊，請參閱 [ALTER TABLE](https://www.postgresql.org/docs/current/sql-altertable.html) (PostgreSQL 網站）。 | DBA | 
| 清除測試資料。 | 在來源和目標資料庫上，清除為單位測試而建立的資料。 | 開發人員 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 完成遷移。 | 使用實際來源資料重複上述史詩*測試遷移任務*。這會將資料從來源遷移到目標資料庫。 | 開發人員 | 
| 驗證來源和目標資料庫是否同步。 | 驗證來源和目標資料庫是否同步。如需詳細資訊和說明，請參閱[AWS DMS 資料驗證](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | 開發人員 | 
| 停止來源資料庫。 | 停止 Amazon RDS for Oracle 資料庫。如需說明，請參閱[暫時停止 Amazon RDS 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_StopInstance.html)。當您停止來源資料庫時， 中的初始載入和持續複寫任務 AWS DMS 會自動停止。停止這些任務不需要其他動作。 | 開發人員 | 

## 相關資源
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-resources"></a>

**AWS 參考**
+ [使用 AWS DMS 和 將 Oracle 資料庫遷移至 Aurora PostgreSQL AWS SCT](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct.html) (AWS 方案指引）
+ [將 Oracle 轉換為 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.ToPostgreSQL.html) (AWS SCT 文件）
+ [運作方式 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.html)(AWS DMS 文件）

**其他參考**
+ [布林資料類型 ](https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-boolean/)(PostgreSQL 文件）
+ [Oracle 內建資料類型](https://docs.oracle.com/database/121/SQLRF/sql_elements001.htm#SQLRF30020) (Oracle 文件）
+ [pgAdmin](https://www.pgadmin.org/) (pgAdmin 網站）
+ [SQL 開發人員](https://www.oracle.com/database/technologies/appdev/sql-developer.html) (Oracle 網站）

**教學課程和影片**
+ [入門 AWS DMS](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [簡介 AWS DMS](https://www.youtube.com/watch?v=ouia1Sc5QGo)（影片）
+ [了解 Amazon RDS](https://www.youtube.com/watch?v=eMzCI7S1P9M) （影片）

## 其他資訊
<a name="convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql-additional"></a>

**資料驗證指令碼**

下列資料驗證指令碼會將 **1** 轉換為 **Y**，並將 **0** 轉換為 **N**。 這有助於 AWS DMS 任務成功完成並通過資料表驗證。

```
{
"rule-type": "validation",
"rule-id": "5",
"rule-name": "5",
"rule-target": "column",
"object-locator": {
"schema-name": "ADMIN",
"table-name": "TEMP_CHRA_BOOL",
"column-name": "GRADE"
},
"rule-action": "override-validation-function",
"target-function": "case grade when '1' then 'Y' else 'N' end"
        }
```

指令碼中的 `case`陳述式會執行驗證。如果驗證失敗， 會在目標資料庫執行個體的 **public.awsdms\$1validation\$1failures\$1v1** 資料表中 AWS DMS 插入記錄。此記錄包含資料表名稱、錯誤時間，以及來源和目標資料表中不相符值的詳細資訊。

如果您未將此資料驗證指令碼新增至 AWS DMS 任務，且資料已插入目標資料表，則 AWS DMS 任務會將驗證狀態顯示為**不相符的記錄**。

在 AWS SCT 轉換期間， AWS DMS 遷移任務會將 VARCHAR2(1) 資料類型變更為布林值，並在資料`"NO"`欄上新增主索引鍵限制條件。

# 在 Aurora PostgreSQL 相容中建立應用程式使用者和角色
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible"></a>

*Abhishek Verma，Amazon Web Services*

## 總結
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-summary"></a>

當您遷移至 Amazon Aurora PostgreSQL 相容版本時，來源資料庫上存在的資料庫使用者和角色必須在 Aurora PostgreSQL 相容資料庫中建立。您可以使用兩種不同的方法，在 Aurora PostgreSQL 相容中建立使用者和角色：
+ 在目標中使用與來源資料庫中類似的使用者和角色。在此方法中，會從來源資料庫擷取使用者和角色的資料定義語言 (DDLs)。然後，它們會轉換並套用至目標 Aurora PostgreSQL 相容資料庫。例如，部落格文章[使用 SQL 將使用者、角色和授予從 Oracle 映射到 PostgreSQL](https://aws.amazon.com/blogs/database/use-sql-to-map-users-roles-and-grants-from-oracle-to-postgresql) 涵蓋使用從 Oracle 來源資料庫引擎擷取。
+ 使用在開發、管理和執行資料庫中其他相關操作時常用的標準化使用者和角色。這包括由個別使用者執行的唯讀、讀寫、開發、管理和部署操作。

此模式包含在標準化使用者和角色方法所需的 Aurora PostgreSQL 相容中建立使用者和角色所需的授予。使用者和角色建立步驟符合授予最低權限給資料庫使用者的安全政策。下表列出使用者、其對應的角色，以及其在資料庫上的詳細資訊。


| 
| 
| 使用者 | 角色 | 用途 | 
| --- |--- |--- |
| `APP_read` | `APP_RO` | 用於結構描述上的唯讀存取 `APP` | 
| `APP_WRITE` | `APP_RW` | 用於結構描述上的寫入和讀取操作 `APP` | 
| `APP_dev_user` | `APP_DEV` | 用於結構描述 上的開發用途`APP_DEV`，具有結構描述上的唯讀存取權 `APP` | 
| `Admin_User` | `rds_superuser` | 用於在資料庫上執行管理員操作 | 
| `APP` | `APP_DEP` | 用於在`APP`結構描述下建立物件，以及在`APP`結構描述中部署物件 | 

## 先決條件和限制
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-prereqs"></a>

**先決條件**
+ 作用中的 Amazon Web Services (AWS) 帳戶
+ PostgreSQL 資料庫、Amazon Aurora PostgreSQL 相容版本資料庫，或 PostgreSQL 資料庫的 Amazon Relational Database Service (Amazon RDS)

**產品版本**
+ PostgreSQL 的所有版本

## Architecture
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-architecture"></a>

**來源技術堆疊**
+ 任何資料庫

**目標技術堆疊**
+ Amazon Aurora PostgreSQL 相容

**目標架構**

下圖顯示 Aurora PostgreSQL 相容資料庫中的使用者角色和結構描述架構。

![\[Aurora PostgreSQL-Comaptible 資料庫的使用者角色和結構描述架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/80105a81-e3d1-4258-b3c1-77f3a5e78592/images/b95cb9bc-8bf7-47d1-92e7-66cfb37d7ce7.png)


                                                                                                                                    

**自動化和擴展**

此模式包含使用者、角色和結構描述建立指令碼，您可以執行多次，而不會影響來源或目標資料庫的現有使用者。

## 工具
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。

**其他服務**
+ [psql](https://www.postgresql.org/docs/current/app-psql.html) 是一種終端型前端工具，會隨每次 PostgreSQL 資料庫安裝一起安裝。它具有執行 SQL、PL-PGSQL 和作業系統命令的命令列界面。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。

## 史詩
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-epics"></a>

### 建立使用者和角色
<a name="create-the-users-and-roles"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立部署使用者。 | 部署使用者`APP`將用於在部署期間建立和修改資料庫物件。使用下列指令碼在結構描述 `APP_DEP`中建立部署使用者角色`APP`。驗證存取權，以確保此使用者只有在所需結構描述 中建立物件的權限`APP`。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-application-users-and-roles-in-aurora-postgresql-compatible.html) | DBA | 
| 建立唯讀使用者。 | 唯讀使用者`APP_read`將用於在結構描述 中執行唯讀操作`APP`。使用下列指令碼來建立唯讀使用者。驗證存取權，以確保此使用者僅具有讀取結構描述中物件的權限，`APP`並自動授予在結構描述中建立之任何新物件的讀取存取權`APP`。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-application-users-and-roles-in-aurora-postgresql-compatible.html) | DBA | 
| 建立讀取/寫入使用者。 | 讀取/寫入使用者`APP_WRITE`將用於對結構描述 執行讀取和寫入操作`APP`。使用下列指令碼來建立讀取/寫入使用者，並授予該`APP_RW`角色。驗證存取權，以確保此使用者僅對結構描述中的物件具有讀取和寫入權限，`APP`並自動為結構描述 中建立的任何新物件授予讀取和寫入存取權`APP`。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-application-users-and-roles-in-aurora-postgresql-compatible.html) |  | 
| 建立管理員使用者。 | 管理員使用者`Admin_User`將用於對資料庫執行管理員操作。這些操作的範例為 `CREATE ROLE`和 `CREATE DATABASE`。 `Admin_User`使用內建角色`rds_superuser`在資料庫上執行管理員操作。使用下列指令碼來建立和測試`Admin_User`資料庫中管理員使用者的權限。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-application-users-and-roles-in-aurora-postgresql-compatible.html) | DBA | 
| 建立開發使用者。 | 開發使用者`APP_dev_user`將有權在其本機結構描述中建立物件，`APP_DEV`並在結構描述 中建立讀取存取權`APP`。使用下列指令碼來建立和測試`APP_dev_user`資料庫中使用者的權限。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-application-users-and-roles-in-aurora-postgresql-compatible.html) | DBA | 

## 相關資源
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-resources"></a>

**PostgreSQL 文件**
+ [建立角色](https://www.postgresql.org/docs/9.1/sql-createrole.html)
+ [建立使用者](https://www.postgresql.org/docs/8.0/sql-createuser.html)
+ [預先定義的角色](https://www.postgresql.org/docs/14/predefined-roles.html)

 

## 其他資訊
<a name="create-application-users-and-roles-in-aurora-postgresql-compatible-additional"></a>

**PostgreSQL 14 增強功能**

PostgreSQL 14 提供一組預先定義的角色，可讓您存取某些常用的特權功能和資訊。管理員 （包括具有 `CREATE ROLE`權限的角色） 可以將這些角色或其環境中的其他角色授予使用者，讓他們能夠存取指定的功能和資訊。

管理員可以使用 `GRANT`命令授予使用者對這些角色的存取權。例如，若要將`pg_signal_backend`角色授予 `Admin_User`，您可以執行下列命令。

```
GRANT pg_signal_backend TO Admin_User;
```

此`pg_signal_backend`角色旨在允許管理員啟用信任的非超級使用者角色，將訊號傳送至其他後端。如需詳細資訊，請參閱 [PostgreSQL 14 增強](https://www.postgresql.org/docs/14/predefined-roles.html)功能。

**微調存取權**

在某些情況下，可能需要為使用者提供更精細的存取 （例如，資料表型存取或資料欄型存取）。在這種情況下，可以建立其他角色，將這些權限授予使用者。如需詳細資訊，請參閱 [PostgreSQL Grants](https://www.postgresql.org/docs/8.4/sql-grant.html)。

# 使用 PostgreSQL 相容 Aurora 全域資料庫模擬 Oracle DR
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database"></a>

*HariKrishna Boorgadda，Amazon Web Services*

## 總結
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database-summary"></a>

企業災難復原 (DR) 的最佳實務基本上包含設計和實作容錯硬體和軟體系統，這些系統可以承受災難 (*業務持續性） *並恢復正常操作 (*業務恢復*)，且介入最少，理想情況下不會遺失資料。建置容錯環境以滿足企業 DR 目標可能既昂貴又耗時，而且需要業務的強大承諾。

Oracle Database 提供三種不同的 DR 方法，相較於任何其他保護 Oracle 資料的方法，可提供最高層級的資料保護和可用性。
+ Oracle 零資料遺失復原設備
+ Oracle Active Data Guard
+ Oracle GoldenGate

此模式提供使用 Amazon Aurora 全域資料庫模擬 Oracle GoldenGate DR 的方法。參考架構跨三個 AWS 區域使用 Oracle GoldenGate 進行 DR。模式會逐步解說來源架構到以 Amazon Aurora PostgreSQL 相容版本為基礎的雲端原生 Aurora 全域資料庫。

Aurora 全域資料庫專為具有全域足跡的應用程式而設計。單一 Aurora 資料庫跨越多個 AWS 區域，最多可有五個次要區域。Aurora 全域資料庫提供下列功能：
+ 實體儲存層級複寫
+ 低延遲全域讀取
+ 從整個區域的中斷快速復原災難
+ 快速跨區域遷移
+ 跨區域的低複寫延遲
+ 對資料庫的效能影響Little-to-no 

如需 Aurora 全域資料庫功能和優點的詳細資訊，請參閱[使用 Amazon Aurora 全域資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html#aurora-global-database-overview)。如需意外和受管容錯移轉的詳細資訊，請參閱[在 Amazon Aurora 全域資料庫中使用容錯移轉](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-disaster-recovery.html#aurora-global-database-failover)。

## 先決條件和限制
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶 
+ 用於應用程式連線的 Java Database Connectivity (JDBC) PostgreSQL 驅動程式
+ 以 Amazon Aurora PostgreSQL 相容版本為基礎的 Aurora 全域資料庫
+ 基於 Aurora PostgreSQL 相容，遷移至 Aurora 全域資料庫的 Oracle Real Application Clusters (RAC) 資料庫

**Aurora 全域資料庫的限制**
+ 並非所有 AWS 區域都提供 Aurora 全域資料庫。如需支援區域的清單，請參閱 [Aurora PostgreSQL 的 Aurora 全域資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.Aurora_Fea_Regions_DB-eng.Feature.GlobalDatabase.html#Concepts.Aurora_Fea_Regions_DB-eng.Feature.GlobalDatabase.apg)。
+ 如需有關不支援的功能以及 Aurora 全域資料庫的其他限制的資訊，請參閱 [Amazon Aurora 全域資料庫的限制](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html#aurora-global-database.limitations)。

**產品版本**
+ Amazon Aurora PostgreSQL 相容版本 10.14 版或更新版本

## Architecture
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database-architecture"></a>

**來源技術堆疊**** **
+ Oracle RAC 四節點資料庫
+ Oracle GoldenGate

**來源架構******

下圖顯示使用 Oracle GoldenGate 複寫之不同 AWS 區域中具有四節點 Oracle RAC 的三個叢集。

![\[主要區域和兩個次要區域的 Oracle RAC。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/11d4265b-31af-4ebf-a766-24196193ee01/images/9fc740fc-d339-422e-beaf-1f65690c9d14.png)


**目標技術堆疊**
+ 以 Aurora PostgreSQL 相容為基礎的三個叢集 Amazon Aurora 全域資料庫，主要區域中有一個叢集，不同次要區域中有兩個叢集

**目標架構**

![\[主要區域和兩個次要區域的 Amazon Aurora。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/11d4265b-31af-4ebf-a766-24196193ee01/images/8e3deca9-03f2-437c-9341-795ac17e2b42.png)


## 工具
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [Amazon Aurora 全域資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html)橫跨多個 AWS 區域，提供低延遲的全域讀取，並從可能影響整個 AWS 區域的罕見中斷中快速復原。

## 史詩
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database-epics"></a>

### 使用讀取器資料庫執行個體新增區域
<a name="add-regions-with-reader-db-instances"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連接一或多個次要 Aurora 叢集。 | 在 AWS 管理主控台上，選擇 Amazon Aurora。選取主要叢集，選擇**動作**，然後從下拉式清單中選擇**新增區域**。 | DBA | 
| 選取執行個體類別。 | 您可以變更次要叢集的執行個體類別。不過，我們建議您保持與主要叢集執行個體類別相同的狀態。 | DBA | 
| 新增第三個區域。 | 重複此史詩中的步驟，在第三個區域中新增叢集。 | DBA | 

### 容錯移轉 Aurora 全域資料庫
<a name="fail-over-the-aurora-global-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Aurora 全域資料庫中移除主要叢集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database.html) | DBA | 
| 重新設定您的應用程式，將寫入流量轉向新提升的叢集。 | 使用新提升叢集的端點修改應用程式中的端點。 | DBA | 
| 停止對無法使用的叢集發出任何寫入操作。 | 停止應用程式和您移除之叢集的任何資料處理語言 (DML) 活動。 | DBA | 
| 建立新的 Aurora 全域資料庫。 | 現在，您可以使用新提升的叢集建立 Aurora 全域資料庫，做為主要叢集。 | DBA | 

### 啟動主要叢集
<a name="start-the-primary-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選取要從全域資料庫啟動的主要叢集。 | 在 Amazon Aurora 主控台的全域資料庫設定中，選擇主要叢集。 | DBA | 
| 啟動叢集。 | 在**動作**下拉式清單中，選擇**開始**。此程序可能需要一些時間。重新整理畫面以查看狀態，或在操作完成後檢查叢集目前狀態**的狀態**欄。 | DBA | 

### 清除資源
<a name="clean-up-the-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 刪除剩餘的次要叢集。 | 容錯移轉試行完成後，從全域資料庫中移除次要叢集。 | DBA | 
| 刪除主要叢集。 | 移除叢集。 | DBA | 

## 相關資源
<a name="emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database-resources"></a>
+ [使用 Amazon Aurora 全球資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html#aurora-global-database-detaching)
+ [使用 Amazon Aurora Global Database 的 Aurora PostgreSQL 災難復原解決方案](https://aws.amazon.com/blogs/database/aurora-postgresql-disaster-recovery-solutions-using-amazon-aurora-global-database/) （部落格文章）

# 從 SQL Server 遷移至 PostgreSQL 時，實作 PII 資料的 SHA1 雜湊
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql"></a>

*Rajkumar Raghuwanshi 和 Jagadish Kantubugata，Amazon Web Services*

## 總結
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-summary"></a>

此模式說明如何在從 SQL Server 遷移至 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL 相容時，為電子郵件地址實作安全雜湊演算法 1 (SHA1) 雜湊。電子郵件地址是*個人身分識別資訊* (PII) 的範例。PII 是當直接檢視或與其他相關資料配對時，可用來合理推斷個人身分的資訊。

此模式涵蓋在不同資料庫定序和字元編碼之間維持一致雜湊值的挑戰，並提供使用 PostgreSQL 函數和觸發程序的解決方案。雖然此模式著重於 SHA1 雜湊，但可以適應 PostgreSQL `pgcrypto`模組支援的其他雜湊演算法。一律考慮雜湊策略的安全性影響，並在處理敏感資料時諮詢安全專家。

## 先決條件和限制
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 來源 SQL Server 資料庫
+ Target PostgreSQL 資料庫 (Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容）
+ PL/pgSQL 編碼專業知識

**限制**
+ 此模式需要根據使用案例進行資料庫層級定序變更。
+ 尚未評估對大型資料集的效能影響。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 依區域的服務](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

**產品版本**
+ Microsoft SQL Server 2012 或更新版本

## Architecture
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-architecture"></a>

**來源技術堆疊 **
+ SQL Server
+ .NET Framework

**目標技術堆疊 **
+ PostgreSQL
+ `pgcrypto` 延伸模組

**自動化和擴展**
+ 請考慮實作雜湊函數作為預存程序，以便於維護。
+ 對於大型資料集，請評估效能，並考慮批次處理或索引策略。

## 工具
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管且符合 ACID 規範的關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移到 AWS 雲端 或在雲端和內部部署設定的組合之間遷移。
+ [Amazon Relational Database Service Amazon RDS for PostgreSQL ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)可協助您在 中設定、操作和擴展 PostgreSQL 關聯式資料庫 AWS 雲端。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 透過自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，支援異質資料庫遷移。

**其他工具**
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。
+ [SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/ssms/sql-server-management-studio-ssms) 是用於管理任何 SQL 基礎設施的整合環境。

## 最佳實務
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-best-practices"></a>
+ 使用適當的定序設定來處理目標資料庫端的特殊字元。
+ 使用各種電子郵件地址進行徹底測試，包括非 ASCII 字元的地址。
+ 在應用程式和資料庫層之間維持大小寫處理的一致性。
+ 使用雜湊值對查詢效能進行基準測試。

## 史詩
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-epics"></a>

### 分析來源雜湊實作
<a name="analyze-source-hashing-implementation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱 SQL Server 程式碼。 | 若要檢閱產生 SHA1 雜湊的 SQL Server 程式碼，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 資料工程師、DBA、應用程式開發人員 | 
| 記錄雜湊演算法和資料轉換。 | 若要記錄確切的雜湊演算法和資料轉換，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、資料工程師、DBA | 

### 建立 PostgreSQL 雜湊函數
<a name="create-postgresql-hashing-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立`pgcrypto`擴充功能。 | 若要建立`pgcrypto`擴充功能，請使用 `pgAdmin/psql`執行下列命令：<pre>CREATE EXTENSION pgcrypto;</pre> | DBA，資料工程師 | 
| 實作 PostgreSQL 函數。 | 實作下列 PostgreSQL 函數來複寫 SQL Server 雜湊邏輯。在高階，此函數使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html)<pre>CREATE OR REPLACE FUNCTION utility.hex_to_bigint ( <br />     par_val character varying, <br />     par_upper character varying DEFAULT 'lower'::character varying) <br />RETURNS bigint <br />LANGUAGE 'plpgsql' <br />AS $BODY$ <br />DECLARE <br />    retnumber bigint; <br />    digest_bytes bytea;<br />BEGIN <br />    if lower(par_upper) = 'upper' <br />    then <br />        digest_bytes := digest(upper(par_val), 'sha1');<br />    else <br />        digest_bytes := digest((par_val), 'sha1');<br />    end if; <br />    retnumber := ('x' || encode(substring(digest_bytes, length(digest_bytes)-10+1), 'hex'))::bit(64)::bigint; <br />    RETURN retnumber; <br />END; <br />$BODY$;</pre> | 資料工程師、DBA、應用程式開發人員 | 
| 測試函數。 | 若要測試函數，請使用 SQL Server 的範例資料來驗證相符的雜湊值。執行以下命令：<pre>select 'alejandro_rosalez@example.com' as Email, utility.hex_to_bigint('alejandro_rosalez@example.com','upper') as HashValue;<br /><br />--OUTPUT<br />/*<br />email 	        hashvalue<br />"alejandro_rosalez@example.com"	451397011176045063<br />*/<br /></pre> | 應用程式開發人員、DBA、資料工程師 | 

### 實作自動雜湊的觸發
<a name="implement-triggers-for-automatic-hashing"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在相關資料表上建立觸發條件。 | 若要在相關資料表上建立觸發，以在插入或更新時自動產生雜湊值，請執行下列命令：<pre>CREATE OR REPLACE FUNCTION update_email_hash() <br />RETURNS TRIGGER <br />AS $$ <br />BEGIN <br />    NEW.email_hash = utility.hex_to_bigint(NEW.email, 'upper'); <br />    RETURN NEW; <br />END; <br />$$ LANGUAGE plpgsql;</pre><pre>CREATE TRIGGER email_hash_trigger BEFORE INSERT OR UPDATE ON users FOR EACH ROW EXECUTE FUNCTION update_email_hash();</pre> | 應用程式開發人員、資料工程師、DBA | 

### 遷移現有資料
<a name="migrate-existing-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 開發遷移指令碼或使用 AWS DMS。 | 開發遷移指令碼或使用 AWS DMS 來填入現有資料的雜湊值 （包括存放在`BIGINT`來源系統中的雜湊值）。完成下列任務：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 資料工程師、應用程式開發人員、DBA | 
| 使用新的 PostgreSQL 雜湊函數。 | 若要使用新的 PostgreSQL 雜湊函數以確保一致性，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、DBA、DevOps 工程師 | 

### 更新應用程式查詢
<a name="update-application-queries"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別應用程式查詢。 | 若要識別使用雜湊值的應用程式查詢，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、DBA、資料工程師 | 
| 修改查詢。 | 如有必要，請修改查詢以使用新的 PostgreSQL 雜湊函數。請執行下列操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、DBA、資料工程師 | 

### 測試和驗證
<a name="test-and-validate"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行測試。 | 若要使用生產資料子集執行徹底測試，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、資料工程師、DBA | 
| 驗證雜湊值是否相符。 | 若要驗證 SQL Server 和 PostgreSQL 之間的雜湊值是否相符，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、資料工程師、DBA | 
| 驗證應用程式功能。 | 若要使用遷移的資料和新的雜湊實作來驗證應用程式功能，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.html) | 應用程式開發人員、DBA、資料工程師 | 

## 疑難排解
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 雜湊值不相符。 | 驗證來源和目標之間的字元編碼和定序。如需詳細資訊，請參閱在 [Amazon Aurora 和 Amazon RDS （部落格） 上管理 PostgreSQL 中的定序變更](https://aws.amazon.com/blogs/database/manage-collation-changes-in-postgresql-on-amazon-aurora-and-amazon-rds/)。AWS  | 

## 相關資源
<a name="implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql-resources"></a>

**AWS 部落格**
+ [在 Amazon Aurora 和 Amazon RDS 上的 PostgreSQL 中管理定序變更](https://aws.amazon.com/blogs/database/manage-collation-changes-in-postgresql-on-amazon-aurora-and-amazon-rds/)
+ [使用從 欄位學到的最佳實務和經驗，將 SQL Server 遷移至 Amazon Aurora PostgreSQL ](https://aws.amazon.com/blogs/database/migrate-sql-server-to-amazon-aurora-postgresql-using-best-practices-and-lessons-learned-from-the-field/)

**其他資源**
+ [PostgreSQL pgcrypto 模組](https://www.postgresql.org/docs/current/pgcrypto.html) (PostgreSQL 文件）
+ [PostgreSQL 觸發函數](https://www.postgresql.org/docs/current/plpgsql-trigger.html) (PostgreSQL 文件）
+ [SQL Server HASHBYTES 函數](https://docs.microsoft.com/en-us/sql/t-sql/functions/hashbytes-transact-sql) (Microsoft 文件）

# 使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct"></a>

*Pinesh Singal，Amazon Web Services*

## 總結
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-summary"></a>

許多遷移策略和方法會分多個階段執行，持續數週到數個月。在此期間，您可能會因為要遷移至 PostgreSQL 資料庫執行個體的來源 Oracle 資料庫執行個體中的修補或升級而遇到延遲。為了避免這種情況，建議您將剩餘的 Oracle 資料庫程式碼逐步遷移至 PostgreSQL 資料庫程式碼。

此模式為在初始遷移後執行大量交易且必須遷移至 PostgreSQL 資料庫的多 TB Oracle 資料庫執行個體提供無停機時間的增量遷移策略。您可以使用此模式的step-by-step方法，將 Amazon Relational Database Service (Amazon RDS) for Oracle 資料庫執行個體逐步遷移至 Amazon RDS for PostgreSQL 資料庫執行個體，而無需登入 Amazon Web Services (AWS) 管理主控台。

模式使用 [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 尋找來源 Oracle 資料庫中兩個結構描述之間的差異。然後，您可以使用 AWS Schema Conversion Tool (AWS SCT) 將 Amazon RDS for Oracle 資料庫結構描述物件轉換為 Amazon RDS for PostgreSQL 資料庫結構描述物件。然後，您可以在 Windows 命令提示字元中執行 Python 指令碼，為來源資料庫物件的增量變更建立 AWS SCT 物件。

**注意**  
遷移生產工作負載之前，建議您在測試或非生產環境中，針對此模式的方法執行概念驗證 (PoC)。

## 先決條件和限制
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 現有的 Amazon RDS for Oracle 資料庫執行個體。 
+ 現有的 Amazon RDS for PostgreSQL 資料庫執行個體。
+ AWS SCT，安裝並設定適用於 Oracle 和 PostgreSQL 資料庫引擎的 JDBC 驅動程式。如需詳細資訊，請參閱 [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html#CHAP_Installing.Procedure) 文件中的安裝 AWS SCT 和[安裝所需的資料庫驅動程式](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html#CHAP_Installing.JDBCDrivers)。 
+ Oracle SQL Developer，已安裝並設定。如需詳細資訊，請參閱 [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 文件。 
+ `incremental-migration-sct-sql.zip` 檔案 （已連接），下載到您的本機電腦。

**限制**
+ 來源 Amazon RDS for Oracle 資料庫執行個體的最低需求為：
  + Oracle 10.2 版和更新版本 （適用於 10.x 版）、11g 版 (11.2.0.3.v1 版和更新版本） 和最高 12.2 版，以及 Enterprise、Standard、Standard One 和 Standard Two 版 18c 版
+ 您目標 Amazon RDS for PostgreSQL 資料庫執行個體的最低需求為： 
  + PostgreSQL 9.4 版和更新版本 （適用於 9.x 版）、10.x 版和 11.x 版
+ 此模式使用 Oracle SQL Developer。如果您使用其他工具來尋找和匯出結構描述差異，結果可能會有所不同。
+ Oracle SQL Developer [產生的 SQL 指令碼](https://docs.oracle.com/database/121/AEUTL/sql_rep.htm#AEUTL191)可能會引發轉換錯誤，這表示您需要執行手動遷移。
+ 如果 AWS SCT 來源和目標測試連線失敗，請確定您已設定虛擬私有雲端 (VPC) 安全群組的 JDBC 驅動程式版本和傳入規則，以接受傳入流量。

**產品版本**
+ Amazon RDS for Oracle 資料庫執行個體 12.1.0.2 版 (10.2 版及更新版本）
+ Amazon RDS for PostgreSQL 資料庫執行個體 11.5 版 (9.4 版及更新版本）
+ Oracle SQL Developer 19.1 版及更新版本
+ AWS SCT 1.0.632 版及更新版本

## Architecture
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-architecture"></a>

**來源技術堆疊**
+ Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**
+ Amazon RDS for PostgreSQL 資料庫執行個體

**來源和目標架構**

下圖顯示 Amazon RDS for Oracle 資料庫執行個體遷移至 Amazon RDS for PostgreSQL 資料庫執行個體。

![\[從 Amazon RDS for Oracle 到 Amazon RDS for PostgreSQL 的遷移工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/c7eed517-e496-4e8e-a520-c1e43397419e/images/bfbbed5e-db13-4a22-99aa-1a17f00f5faf.png)


圖表顯示下列遷移工作流程：

1. 開啟 Oracle SQL Developer 並連線至來源和目標資料庫。

1. 產生[差異報告](https://docs.oracle.com/cd/E93130_01/rules_palette/Content/Diff%20Reports/Detailed_Diff_Reports.htm)，然後產生結構描述差異物件的 SQL 指令碼檔案。如需 diff 報告的詳細資訊，請參閱 Oracle 文件中的[詳細 diff 報告](https://docs.oracle.com/cd/E93130_01/rules_palette/Content/Diff%20Reports/Detailed_Diff_Reports.htm)。

1. 設定 AWS SCT 並執行 Python 程式碼。

1. SQL 指令碼檔案會從 Oracle 轉換為 PostgreSQL。

1. 在目標 PostgreSQL 資料庫執行個體上執行 SQL 指令碼檔案。 

**自動化和擴展**

您可以將單一程式中多個功能的其他參數和安全相關變更新增至 Python 指令碼，以自動化此遷移。

## 工具
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-tools"></a>
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) – AWS Schema Conversion Tool (AWS SCT) 會將您現有的資料庫結構描述從一個資料庫引擎轉換為另一個資料庫引擎。
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) – Oracle SQL Developer 是一種整合的開發環境 (IDE)，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。

**Code**

`incremental-migration-sct-sql.zip` 檔案 （已連接） 包含此模式的完整原始碼。

## 史詩
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-epics"></a>

### 建立來源資料庫結構描述差異的 SQL 指令碼檔案
<a name="create-the-sql-scripts-file-for-the-source-database-schema-differences"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Oracle SQL Developer 中執行資料庫差異。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.html) | DBA | 
| 產生 SQL 指令碼檔案。 | 選擇**產生指令碼**以產生 SQL 檔案中的差異。 這會產生 SQL 指令碼檔案，供 AWS SCT 用來將資料庫從 Oracle 轉換為 PostgreSQL。 | DBA | 

### 使用 Python 指令碼在 AWS SCT 中建立目標資料庫物件
<a name="use-the-python-script-to-create-the-target-db-objects-in-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Windows 命令提示字元設定 AWS SCT。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.html)<pre>#source_vendor,source_hostname,source_dbname,source_user,source_pwd,source_schema,source_port,source_sid,target_vendor,target_hostname,target_user,target_pwd,target_dbname,target_port<br /><br />ORACLE,myoracledb.cokmvis0v46q.us-east-1.rds.amazonaws.com,ORCL,orcl,orcl1234,orcl,1521,ORCL,POSTGRESQL,mypgdbinstance.cokmvis0v46q.us-east-1.rds.amazonaws.com,pguser,pgpassword,pgdb,5432</pre>4. 根據您的需求修改 AWS SCT 組態參數，然後將 SQL 指令碼檔案複製到`input`子目錄中的工作目錄。 | DBA | 
| 執行 Python 指令碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.html) | DBA | 
|  在 Amazon RDS for PostgreSQL 中建立物件 | 執行 SQL 檔案，並在 Amazon RDS for PostgreSQL 資料庫執行個體中建立物件。 | DBA | 

## 相關資源
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-resources"></a>
+ [Amazon RDS 上的 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 
+ [Amazon RDS 上的 PostgreSQL ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)
+ [使用 AWS SCT 使用者介面](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html)
+ [使用 Oracle 做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)

## 附件
<a name="attachments-c7eed517-e496-4e8e-a520-c1e43397419e"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/c7eed517-e496-4e8e-a520-c1e43397419e/attachments/attachment.zip)

# 在 Aurora PostgreSQL 相容中使用檔案編碼將 BLOB 檔案載入 TEXT
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible"></a>

*Bhanu Ganesh Gudivada 和 Jeevan Shetty，Amazon Web Services*

## 總結
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-summary"></a>

通常在遷移期間，在某些情況下，您必須處理從本機檔案系統的檔案載入的非結構化和結構化資料。資料也可能位於與資料庫字元集不同的字元集中。

這些檔案會保存以下類型的資料：
+ **中繼資料** – 此資料說明檔案結構。
+ **半結構化資料** – 這些是特定格式的文字字串，例如 JSON 或 XML。您可以對這類資料進行聲明，例如「一律以「＜」」或「不包含任何換行字元」。
+ **全文** – 此資料通常包含所有類型的字元，包括換行字元和引號字元。它也可能由 UTF-8 中的多位元組字元組成。
+ **二進位資料** – 此資料可能包含位元組或位元組組合，包括 null 和end-of-file標記。

載入這些資料類型的混合可能是一項挑戰。

此模式可與現場部署 Oracle 資料庫 、Amazon Web Services (AWS) 雲端上 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 Oracle 資料庫，以及 Oracle 資料庫的 Amazon Relational Database Service (Amazon RDS) 搭配使用。例如，此模式使用 Amazon Aurora PostgreSQL 相容版本。

在 Oracle Database 中，透過 `BFILE`（二進位檔案） 指標、`DBMS_LOB`套件和 Oracle 系統函數的協助，您可以從檔案載入並使用字元編碼轉換為 CLOB。由於 PostgreSQL 在遷移至 Amazon Aurora PostgreSQL 相容版本資料庫時不支援 BLOB 資料類型，因此這些函數必須轉換為 PostgreSQL 相容指令碼。

此模式提供兩種方法，可將檔案載入 Amazon Aurora PostgreSQL 相容資料庫中的單一資料庫資料欄：
+ 方法 1 – 您可以使用 `aws_s3`延伸的 `table_import_from_s3`函數搭配 編碼選項，從 Amazon Simple Storage Service (Amazon S3) 儲存貯體匯入資料。
+ 方法 2 – 您在資料庫外部編碼為十六進位，然後解碼以在`TEXT`資料庫中檢視。

我們建議您使用方法 1，因為 Aurora PostgreSQL 相容與`aws_s3`延伸模組直接整合。

此模式使用範例，將包含多位元組字元和不同格式的電子郵件範本，載入 Amazon Aurora PostgreSQL 相容資料庫。

## 先決條件和限制
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Amazon RDS 執行個體或 Aurora PostgreSQL 相容執行個體
+ 對 SQL 和關聯式資料庫管理系統 (RDBMS) 的基本了解
+ Amazon Simple Storage Service (Amazon S3) 儲存貯體。
+ Oracle 和 PostgreSQL 中的系統函數知識
+ RPM 套件 HexDump-XXD-0.1.1 （隨附於 Amazon Linux 2)
**注意**  
Amazon Linux 2 即將終止支援。如需詳細資訊，請參閱 [Amazon Linux 2 FAQs](https://aws.amazon.com/amazon-linux-2/faqs/)。

**限制**
+ 對於 `TEXT`資料類型，可儲存的最長字元字串約為 1 GB。

**產品版本**
+ Aurora 支援 Amazon Aurora PostgreSQL 更新中列出的 PostgreSQL 版本。 [ PostgreSQL ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/AuroraPostgreSQL.Updates.html)

## Architecture
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-architecture"></a>

**目標技術堆疊**
+ Aurora PostgreSQL 相容

**目標架構**

*方法 1 – 使用 aws\$1s3.table\$1import\$1from\$1s3*

從內部部署伺服器，包含多位元組字元和自訂格式的電子郵件範本的檔案會傳輸至 Amazon S3。此模式提供的自訂資料庫函數使用 `aws_s3.table_import_from_s3`函數搭配 `file_encoding` 將檔案載入資料庫，並以`TEXT`資料類型傳回查詢結果。

![\[從現場部署伺服器到 Aurora 資料庫 TEXT 輸出的四步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cbf63cac-dcea-4e18-ab4f-c4f6296f60e7/images/9c46b385-e8a0-4e50-b856-d522c44d79e3.png)


1. 檔案會傳輸至預備 S3 儲存貯體。

1. 檔案會上傳至 Amazon Aurora PostgreSQL 相容資料庫。

1. 使用 pgAdmin 用戶端，自訂函數`load_file_into_clob`會部署到 Aurora 資料庫。

1. 自訂函數會在內部`table_import_from_s3`搭配 file\$1encoding 使用 。函數的輸出是透過使用 `array_to_string`和 `array_agg`做為`TEXT`輸出來取得。

*方法 2 – 在資料庫外部編碼為十六進位，並解碼以檢視資料庫內的 TEXT*

來自內部部署伺服器或本機檔案系統的檔案會轉換為十六進位傾印。然後，檔案會匯入 PostgreSQL 做為`TEXT`欄位。

![\[使用十六進位傾印的三個步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cbf63cac-dcea-4e18-ab4f-c4f6296f60e7/images/563038ca-f890-4874-85df-d0f82d99800a.png)


1. 使用 `xxd -p`選項，將檔案轉換為命令列中的十六進位傾印。

1. 使用 `\copy`選項將十六進位傾印檔案上傳至 Aurora PostgreSQL 相容，然後將十六進位傾印檔案解碼為二進位檔案。

1. 將二進位資料編碼為傳回為 `TEXT`。

## 工具
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。

**其他工具**
+ [pgAdmin4](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理和開發平台。pgAdmin4 可用於 Linux、Unix、mac OS 和 Windows 來管理 PostgreSQL。  

## 史詩
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-epics"></a>

### 方法 1：將資料從 Amazon S3 匯入 Aurora PostgreSQL 相容
<a name="approach-1-import-data-from-amazon-s3-to-aurora-postgresql-compatible"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 EC2 執行個體。 | 如需啟動執行個體的指示，請參閱[啟動執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)。 | DBA | 
| 安裝 PostgreSQL 用戶端 pgAdmin 工具。 | 下載並安裝 [pgAdmin](https://www.pgadmin.org/download/)。 | DBA | 
| 建立 IAM 政策。 | 建立名為 的 AWS Identity and Access Management (IAM) 政策`aurora-s3-access-pol`，授予儲存檔案的 S3 儲存貯體存取權。使用下列程式碼，`<bucket-name>`將 取代為 S3 儲存貯體的名稱。<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Action": [<br />                "s3:GetObject",<br />                "s3:AbortMultipartUpload",<br />                "s3:DeleteObject",<br />                "s3:ListMultipartUploadParts",<br />                "s3:PutObject",<br />                "s3:ListBucket"<br />            ],<br />            "Resource": [<br />                "arn:aws:s3:::<bucket-name>/*",<br />                "arn:aws:s3:::<bucket-name>"<br />            ]<br />        }<br />    ]<br />}</pre> | DBA | 
| 建立 IAM 角色，以將物件從 Amazon S3 匯入 Aurora PostgreSQL 相容。 | 使用以下程式碼建立名為 的 IAM 角色`aurora-s3-import-role`與 [AssumeRole](https://docs.amazonaws.cn/en_us/STS/latest/APIReference/API_AssumeRole.html) 信任關係。 `AssumeRole` 允許 Aurora 代表您存取其他 AWS 服務。<pre>{<br />  "Version": "2012-10-17",		 	 	 <br />  "Statement": [<br />    {<br />      "Effect": "Allow","Principal": {<br />        "Service": "rds.amazonaws.com"<br />      },"Action": "sts:AssumeRole"<br />    }<br />  ]<br />}<br /></pre> | DBA | 
| 將 IAM 角色與叢集建立關聯。 | 若要將 IAM 角色與 Aurora PostgreSQL 相容資料庫叢集建立關聯，請執行下列 AWS CLI 命令。`<Account-ID>` 變更為託管 Aurora PostgreSQL 相容資料庫的 AWS 帳戶 ID。這可讓 Aurora PostgreSQL 相容資料庫存取 S3 儲存貯體。<pre>aws rds add-role-to-db-cluster --db-cluster-identifier aurora-postgres-cl<br />--feature-name s3Import --role-arn arn:aws:iam::<Account-ID>:role/aurora-s3-import-role</pre> | DBA | 
| 將範例上傳至 Amazon S3。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.html) | DBA、應用程式擁有者 | 
| 部署自訂 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.html) | 應用程式擁有者、DBA | 
| 執行自訂函數，將資料匯入資料庫。 | 執行下列 SQL 命令，將角括號中的項目取代為適當的值。<pre>select load_file_into_clob('aws-s3-import-test'::text,'us-west-1'::text,'employee.salary.event.notification.email.vm'::text);</pre>在執行 命令之前，將角括號中的項目取代為適當的值，如下列範例所示。<pre>Select load_file_into_clob('aws-s3-import-test'::text,'us-west-1'::text,'employee.salary.event.notification.email.vm'::text);</pre>命令會從 Amazon S3 載入檔案，並將輸出傳回為 `TEXT`。 | 應用程式擁有者、DBA | 

### 方法 2：將範本檔案轉換為本機 Linux 系統中的十六進位傾印
<a name="approach-2-convert-the-template-file-into-a-hex-dump-in-a-local-linux-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將範本檔案轉換為十六進位傾印。 | Hexdump 公用程式會以十六進位、小數、八進位或 ASCII 顯示二進位檔案的內容。`hexdump` 命令是 `util-linux`套件的一部分，並預先安裝在 Linux 發行版本中。Hexdump RPM 套件也是 Amazon Linux 2 的一部分。(：Amazon Linux 2 即將結束支援。 如需詳細資訊，請參閱 [Amazon Linux 2 FAQs](https://aws.amazon.com/amazon-linux-2/faqs/)。)若要將檔案內容轉換為十六進位傾印，請執行下列 shell 命令。<pre>xxd -p </path/file.vm> | tr -d '\n' > </path/file.hex></pre>將路徑和檔案取代為適當的值，如下列範例所示。<pre>xxd -p employee.salary.event.notification.email.vm | tr -d '\n' > employee.salary.event.notification.email.vm.hex</pre> | DBA | 
| 將 hexdump 檔案載入資料庫結構描述。 | 使用下列命令將 hexdump 檔案載入 Aurora PostgreSQL 相容資料庫。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.html) | DBA | 

## 相關資源
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-resources"></a>

**參考**
+ [使用 PostgreSQL 資料庫做為 AWS Database Migration Service 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)
+ [具有 PostgreSQL 相容性 (12.4) 遷移手冊的 Oracle Database 19c 到 Amazon Aurora](https://d1.awsstatic.com/whitepapers/Migration/oracle-database-amazon-aurora-postgresql-migration-playbook-12.4.pdf)
+ [建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)
+ [將 IAM 角色與 Amazon Aurora MySQL 資料庫叢集建立關聯](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.Authorizing.IAM.AddRoleToDBCluster.html)
+ [pgAdmin](https://www.pgadmin.org/)

**教學課程**
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [從 Oracle 遷移至 Amazon Aurora](https://aws.amazon.com/getting-started/projects/migrate-oracle-to-amazon-aurora/)

## 其他資訊
<a name="load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible-additional"></a>

**load\$1file\$1into\$1clob 自訂函數**

```
CREATE OR REPLACE FUNCTION load_file_into_clob(
    s3_bucket_name text,
    s3_bucket_region text,
    file_name text,
    file_delimiter character DEFAULT '&'::bpchar,
    file_encoding text DEFAULT 'UTF8'::text)
    RETURNS text
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
    blob_data BYTEA;
    clob_data TEXT;
    l_table_name CHARACTER VARYING(50) := 'file_upload_hex';
    l_column_name CHARACTER VARYING(50) := 'template';
    l_return_text TEXT;
    l_option_text CHARACTER VARYING(150);
    l_sql_stmt CHARACTER VARYING(500);
        
BEGIN
    
    EXECUTE format ('CREATE TEMPORARY TABLE %I (%I text, id_serial serial)', l_table_name, l_column_name);
    
    l_sql_stmt := 'select ''(format text, delimiter ''''' || file_delimiter || ''''', encoding ''''' || file_encoding ||  ''''')'' ';
    
    EXECUTE FORMAT(l_sql_stmt)
    INTO l_option_text;
    
    EXECUTE FORMAT('SELECT aws_s3.table_import_from_s3($1,$2,$6, aws_commons.create_s3_uri($3,$4,$5))')
    INTO l_return_text
    USING l_table_name, l_column_name, s3_bucket_name, file_name,s3_bucket_region,l_option_text;
    
    EXECUTE format('select array_to_string(array_agg(%I order by id_serial),E''\n'') from %I', l_column_name, l_table_name)
    INTO clob_data;
    
    drop table file_upload_hex;
    
    RETURN clob_data;
END;
$BODY$;
```

**電子郵件範本**

```
######################################################################################
##                                                                                    ##
##    johndoe Template Type: email                                                    ##
##    File: johndoe.salary.event.notification.email.vm                                ##
##    Author: Aimée Étienne    Date 1/10/2021                                                ##
##  Purpose: Email template used by EmplmanagerEJB to inform a johndoe they         ##
##        have been given access to a salary event                                    ##
##    Template Attributes:                                                             ##
##        invitedUser - PersonDetails object for the invited user                        ##
##        salaryEvent - OfferDetails object for the event the user was given access    ##
##        buyercollege - CompDetails object for the college owning the salary event    ##
##        salaryCoordinator - PersonDetails of the salary coordinator for the event    ##
##        idp - Identity Provider of the email recipient                                ##
##        httpWebRoot - HTTP address of the server                                    ##
##                                                                                    ##
######################################################################################

$!invitedUser.firstname $!invitedUser.lastname,

Ce courriel confirme que vous avez ete invite par $!salaryCoordinator.firstname $!salaryCoordinator.lastname de $buyercollege.collegeName a participer a l'evenement "$salaryEvent.offeringtitle" sur johndoeMaster Sourcing Intelligence.

Votre nom d'utilisateur est $!invitedUser.username

Veuillez suivre le lien ci-dessous pour acceder a l'evenement.

${httpWebRoot}/myDashboard.do?idp=$!{idp}

Si vous avez oublie votre mot de passe, utilisez le lien "Mot de passe oublie" situe sur l'ecran de connexion et entrez votre nom d'utilisateur ci-dessus.

Si vous avez des questions ou des preoccupations, nous vous invitons a communiquer avec le coordonnateur de l'evenement $!salaryCoordinator.firstname $!salaryCoordinator.lastname au ${salaryCoordinator.workphone}.

*******

johndoeMaster Sourcing Intelligence est une plateforme de soumission en ligne pour les equipements, les materiaux et les services.

Si vous avez des difficultes ou des questions, envoyez un courriel a support@johndoeMaster.com pour obtenir de l'aide.
```

# 使用 AWS SCT 和 AWS DMS 將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL AWS CLI CloudFormation
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation"></a>

*Pinesh Singal，Amazon Web Services*

## 總結
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-summary"></a>

此模式說明如何使用 [() 將 Oracle 資料庫執行個體的多 TB Amazon Relational Database Service (Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)) 遷移至 [Amazon RDS for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 資料庫執行個體AWS CLI。 AWS Command Line Interface 此方法提供最短的停機時間，不需要登入 AWS 管理主控台。

此模式使用 AWS Schema Conversion Tool (AWS SCT) 和 AWS Database Migration Service (AWS DMS) 主控台，有助於避免手動組態和個別遷移。解決方案會為多個資料庫設定一次性組態，並在 AWS DMS 中使用 AWS SCT 和 執行遷移 AWS CLI。

模式使用 AWS SCT 將資料庫結構描述物件從 Amazon RDS for Oracle 轉換為 Amazon RDS for PostgreSQL，然後使用 AWS DMS 遷移資料。在 中使用 Python 指令碼 AWS CLI，您可以使用 CloudFormation 範本建立 AWS SCT 物件和 AWS DMS 任務。

## 先決條件和限制
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 現有的 Amazon RDS for Oracle 資料庫執行個體。
+ 現有的 Amazon RDS for PostgreSQL 資料庫執行個體。 
+ 執行指令碼的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體或具有 Windows 或 Linux 作業系統的本機電腦。
+ 了解下列 AWS DMS 遷移任務類型：`full-load`、`cdc`、`full-load-and-cdc`。 如需詳細資訊，請參閱 AWS DMS 文件中的[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。 
+ AWS SCT，安裝並設定適用於 Oracle 和 PostgreSQL 資料庫引擎的 Java Database Connectivity (JDBC) 驅動程式。如需詳細資訊，請參閱 AWS SCT 文件中的[安裝和設定 AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html#CHAP_Installing.Procedure)。 
+ 來自已安裝 AWS SCT 資料夾`AWSSchemaConversionToolBatch.jar`的檔案，複製到您的工作目錄。
+ `cli-sct-dms-cft.zip` 檔案 （已連接），在您的工作目錄中下載並解壓縮。
+ 最新的 AWS DMS 複寫執行個體引擎版本。如需詳細資訊，請參閱 AWS 支援 文件和[AWS DMS 版本備註](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReleaseNotes.html)中的[如何建立 AWS DMS 複寫執行個體](https://aws.amazon.com/premiumsupport/knowledge-center/create-aws-dms-replication-instance/)。 
+ AWS CLI 第 2 版，安裝並設定您的存取金鑰 ID、私密存取金鑰，以及執行指令碼之 EC2 執行個體或作業系統的預設 AWS 區域 名稱。如需詳細資訊，請參閱 AWS CLI 文件中的[安裝或更新至最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)和[設定 的設定 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)。 
+ 熟悉 CloudFormation 範本。如需詳細資訊，請參閱 CloudFormation 文件中的 [CloudFormation 運作](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-overview.html)方式。 
+ Python 第 3 版，安裝在執行指令碼的 EC2 執行個體或作業系統上並進行設定。如需詳細資訊，請參閱 [Python 文件](https://docs.python.org/3/)。 

**限制**
+ 來源 Amazon RDS for Oracle 資料庫執行個體的最低需求為： 
  + 適用於 Enterprise、Standard、Standard One 和 Standard Two 版本的 Oracle 版本 12c (12.1.0.2、12.2.0.1)、18c (18.0.0.0) 和 19c (19.0.0.0)。
  + 雖然 Amazon RDS 支援 Oracle 18c (18.0.0.0)，但此版本處於棄用路徑，因為 Oracle 在end-of-support日期後不再提供 18c 的修補程式。如需詳細資訊，請參閱 [Amazon RDS 文件中的 Amazon RDS for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html#Oracle.Concepts.Deprecate.11204)。
  + 不再支援 Amazon RDS for Oracle 11g。
+ 您目標 Amazon RDS for PostgreSQL 資料庫執行個體的最低需求為： 
  + PostgreSQL 第 9 版 (9.5 和 9.6)、10.x、11.x、12.x 和 13.x

**產品版本**
+ Amazon RDS for Oracle 資料庫執行個體 12.1.0.2 版及更新版本
+ Amazon RDS for PostgreSQL 資料庫執行個體 11.5 版及更新版本
+ AWS CLI 第 2 版 
+ 的最新版本 AWS SCT
+ Python 3 的最新版本

## Architecture
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-architecture"></a>

**來源技術堆疊**
+ Amazon RDS for Oracle

**目標技術堆疊**
+ Amazon RDS for PostgreSQL

**來源和目標架構**

下圖顯示使用 AWS DMS 和 Python 指令碼將 Amazon RDS for Oracle 資料庫執行個體遷移至 Amazon RDS for PostgreSQL 資料庫執行個體。

![\[使用 AWS DMS 和 Python 將 RDS for Oracle 資料庫執行個體遷移至 RDS for PostgreSQL 資料庫執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5e041494-2e64-4f09-b6ec-0e0cba3a4972/images/77022e13-46fb-4aa8-ab49-85b0ca4c317a.png)


 

圖表顯示下列遷移工作流程：

1. Python 指令碼使用 AWS SCT 連線到來源和目標資料庫執行個體。

1. 使用者 AWS SCT 從 Python 指令碼開始，將 Oracle 程式碼轉換為 PostgreSQL 程式碼，並在目標資料庫執行個體上執行。

1. Python 指令碼會為來源和目標資料庫執行個體建立 AWS DMS 複寫任務。

1. 使用者部署 Python 指令碼來啟動 AWS DMS 任務，然後在資料遷移完成後停止任務。

**自動化和擴展**

您可以將參數和安全相關變更新增至 Python 指令碼，以提供其他功能，以自動化此遷移。 

## 工具
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-tools"></a>
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。
+ [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速且一致地佈建資源，以及在整個 AWS 帳戶 和 區域的生命週期中管理這些資源。此模式會使用 Python 指令碼將`.csv`輸入檔案轉換為`.json`輸入檔案。`.json` 檔案用於 AWS CLI 命令，以建立使用 Amazon Resource Name (ARNs)、遷移類型、任務設定和資料表映射建立多個 AWS DMS 複寫任務的 CloudFormation 堆疊。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端 或在雲端和內部部署設定的組合之間遷移。此模式使用 AWS DMS 在命令列上執行的 Python 指令碼來建立、啟動和停止任務，以及建立 CloudFormation 範本。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 透過自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，支援異質資料庫遷移。此模式需要安裝 AWS SCT 目錄中`AWSSchemaConversionToolBatch.jar`的檔案。

**Code**

`cli-sct-dms-cft.zip` 檔案 （已連接） 包含此模式的完整原始碼。

## 史詩
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-epics"></a>

### 在 中設定 AWS SCT 和建立資料庫物件 AWS CLI
<a name="configure-awssct-and-create-database-objects-in-the-cli"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  AWS SCT 設定 從 執行 AWS CLI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.html) | DBA | 
| 執行 `run_aws_sct.py` Python 指令碼。 | 使用以下命令執行 `run_aws_sct.py` Python 指令碼：`$ python run_aws_sct.py database_migration.txt`Python 指令碼會將資料庫物件從 Oracle 轉換為 PostgreSQL，並以 PostgreSQL 格式建立 SQL 檔案。指令碼也會建立 PDF 檔案 `Database migration assessment report`，為您提供資料庫物件的詳細建議和轉換統計資料。 | DBA | 
| 在 Amazon RDS for PostgreSQL 中建立物件。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.html) | DBA | 

### 使用 和 設定 AWS CLI 和建立 AWS DMS 任務 CloudFormation
<a name="configure-and-create-dms-tasks-by-using-the-cli-and-cfn"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 複寫執行個體。 | 登入 AWS 管理主控台，開啟 [AWS DMS 主控台](https://console.aws.amazon.com/dms/v2/)，並建立根據您的需求設定的複寫執行個體。如需詳細資訊，請參閱 AWS DMS 文件中的[建立複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.Creating.html)和 AWS 支援 文件中的[如何建立 AWS DMS 複寫執行個體](https://aws.amazon.com/premiumsupport/knowledge-center/create-aws-dms-replication-instance/)。 | DBA | 
| 建立來源端點。 | 在 AWS DMS 主控台上，選擇**端點**，然後根據您的需求建立 Oracle 資料庫的來源端點。 額外的連線屬性必須`numberDataTypeScale`具有 `-2`值。如需詳細資訊，請參閱 AWS DMS 文件中的[建立來源和目標端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)。 | DBA | 
| 建立目標端點。 | 在 AWS DMS 主控台上，選擇**端點**，然後根據您的需求建立 PostgreSQL 資料庫的目標端點。 如需詳細資訊，請參閱 AWS DMS 文件中的[建立來源和目標端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)。 | DevOps 工程師 | 
| 設定複 AWS DMS 寫詳細資訊以從 執行 AWS CLI。 | 使用下列格式，使用 AWS DMS 來源端點 ARN、目標端點 ARN 和複寫執行個體 ARN 設定 `dms-arn-list.txt` 檔案中的來源和目標端點和複寫詳細資訊：<pre>#sourceARN,targetARN,repARN<br />arn:aws:dms:us-east-1:123456789012:endpoint:EH7AINRUDZ5GOYIY6HVMXECMCQ<br />arn:aws:dms:us-east-1:123456789012:endpoint:HHJVUV57N7O3CQF4PJZKGIOYY5<br />arn:aws:dms:us-east-1:123456789012:rep:LL57N77AQQAHHJF4PJFHNEDZ5G</pre> | DBA | 
| 執行 `dms-create-task.py` Python 指令碼來建立 AWS DMS 任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.html) | DBA | 
| 確認 AWS DMS 任務已就緒。 | 在 AWS DMS 主控台上，檢查`Ready`狀態區段中的 AWS DMS 任務是否處於 **狀態**。 | DBA | 

### 使用 啟動和停止 AWS DMS 任務 AWS CLI
<a name="start-and-stop-the-dms-tasks-by-using-the-cli"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 AWS DMS 任務。 | 使用以下命令執行 `dms-start-task.py` Python 指令碼：<pre>$ python dms-start-task.py start '<cdc-start-datetime>'</pre>開始日期和時間必須是 `'DD-MON-YYYY'`或 `'YYYY-MM-DDTHH:MI:SS'` 格式 （例如 `'01-Dec-2019'`或 `'2018-03-08T12:12:12'`)。您可以在 AWS DMS 主控台 AWS DMS 的任務頁面上的**資料表統計資料**索引標籤中檢閱**任務**狀態。 | DBA | 
| 驗證資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.html)如需詳細資訊，請參閱 AWS DMS 文件中的[AWS DMS 資料驗證](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | DBA | 
| 停止 AWS DMS 任務。 | 使用下列命令執行 Python 指令碼：<pre>$ python dms-start-task.py stop</pre>AWS DMS 任務可能會停止`failed`狀態，視驗證狀態而定。如需詳細資訊，請參閱下一節。 | DBA | 

## 疑難排解
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| AWS SCT 來源和目標測試連線失敗。 | 設定 JDBC 驅動程式版本和 VPC 安全群組傳入規則，以接受傳入流量。 | 
| 來源或目標端點測試執行失敗。 | 檢查端點設定和複寫執行個體是否處於 `Available` 狀態。檢查端點連線狀態是否為 `Successful`。 如需詳細資訊，請參閱 AWS 支援 文件中的[如何對 AWS DMS 端點連線失敗進行疑難排解](https://aws.amazon.com/premiumsupport/knowledge-center/dms-endpoint-connectivity-failures/)。 | 
| 完全載入執行失敗。 | 檢查來源和目標資料庫是否有相符的資料類型和大小。 如需詳細資訊，請參閱 AWS DMS 文件中的 [中的遷移任務疑難排解 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Troubleshooting.html)。 | 
| 您遇到驗證執行錯誤。 | 檢查資料表是否具有主索引鍵，因為未驗證非主索引鍵資料表。如果資料表有主索引鍵和錯誤，請檢查來源端點中的額外連線屬性是否具有 `numberDataTypeScale=-2`。如需詳細資訊，請參閱 AWS DMS 文件中的[使用 Oracle 做為來源、OracleSettings 和故障診斷時的端點設定 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.ConnectionAttrib)。 [OracleSettings](https://docs.aws.amazon.com/dms/latest/APIReference/API_OracleSettings.html) [https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html#CHAP_Validating.Troubleshooting](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html#CHAP_Validating.Troubleshooting)  | 

## 相關資源
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation-resources"></a>
+ [安裝和設定 AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html#CHAP_Installing.Procedure)
+ [簡介 AWS DMS](https://www.youtube.com/watch?v=ouia1Sc5QGo)（影片）
+ [AWS CLI 和 PowerShell 的 CloudFormation 堆疊操作命令範例](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cli.html)
+ [導覽 的使用者介面 AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html)
+ [使用 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ [使用 連線至 Oracle 資料庫 AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)
+ [使用 PostgreSQL 資料庫做為 的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html) 
+ [資料遷移的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.html)
+ [資料遷移的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.html)
+ [cloudformation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/index.html) (AWS CLI 文件）
+ [create-stack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-stack.html) (AWS CLI 文件） 
+ [dms](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/dms/index.html) (AWS CLI 文件） 

## 附件
<a name="attachments-5e041494-2e64-4f09-b6ec-0e0cba3a4972"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/5e041494-2e64-4f09-b6ec-0e0cba3a4972/attachments/attachment.zip)

# 使用 AWS DMS，以 SSL 模式將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms"></a>

*Pinesh Singal，Amazon Web Services*

## 總結
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-summary"></a>

此模式提供將 Amazon Relational Database Service (Amazon RDS) for Oracle 資料庫執行個體遷移至 Amazon Web Services (AWS) 雲端上 Amazon RDS for PostgreSQL 資料庫的指引。為了加密資料庫之間的連線， 模式會在 Amazon RDS 和 AWS Database Migration Service (AWS DMS) 中使用憑證授權單位 (CA) 和 SSL 模式。

模式描述了線上遷移策略，對於具有大量交易的多 TB Oracle 來源資料庫而言，幾乎沒有停機時間。為了資料安全，模式會在傳輸資料時使用 SSL。

此模式使用 AWS Schema Conversion Tool (AWS SCT) 將 Amazon RDS for Oracle 資料庫結構描述轉換為 Amazon RDS for PostgreSQL 結構描述。然後， 模式會使用 AWS DMS 將資料從 Amazon RDS for Oracle 資料庫遷移至 Amazon RDS for PostgreSQL 資料庫。

## 先決條件和限制
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶 
+ 僅以 ***rds-ca-rsa2048-g1* **設定的 Amazon RDS 資料庫憑證授權單位 (CA) 
  + ***rds-ca-2019*** 憑證已於 2024 年 8 月過期。
  + ***rds-ca-2015*** 憑證已於 2020 年 3 月 5 日過期。
+ AWS SCT
+ AWS DMS
+ pgAdmin
+ SQL 工具 （例如 SQL Developer 或 SQL\$1Plus)

**限制**
+ Amazon RDS for Oracle 資料庫 – 企業版和標準二版的 Oracle 19c 最低需求。
+ Amazon RDS for PostgreSQL 資料庫 – 最低需求為 PostgreSQL 第 12 版及更新版本 （適用於 9.x 及更新版本）。

**產品版本**
+ Amazon RDS for Oracle 資料庫版本 12.1.0.2 執行個體
+ Amazon RDS for PostgreSQL 資料庫 11.5 版執行個體

## Architecture
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ 版本為 12.1.0.2.v18 的 Amazon RDS for Oracle 資料庫執行個體。

**目標技術堆疊**
+ AWS DMS
+ 具有 11.5 版的 Amazon RDS for PostgreSQL 資料庫執行個體。

**目標架構**

下圖顯示 Oracle （來源） 和 PostgreSQL （目標） 資料庫之間資料遷移架構的架構。架構包含下列項目：
+ 虛擬私有雲端 (VPC)
+ 可用區域
+ 私有子網路
+ Amazon RDS for Oracle 資料庫
+ AWS DMS 複寫執行個體
+ RDS for PostgreSQL 資料庫

若要加密來源和目標資料庫的連線，必須在 Amazon RDS 和 AWS DMS 中啟用 CA 和 SSL 模式。

![\[在 RDS for Oracle 和 AWS DMS 之間，以及在 AWS DMS 和 RDS for PostgreSQL 之間移動的資料。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7098e2a3-b456-4e14-8881-c97145aef483/images/55b50ff7-1e6a-4ff0-9bcd-2fd419d5316a.png)


## 工具
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-tools"></a>

**AWS 服務**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 可協助您在 AWS 雲端中設定、操作和擴展 Oracle 關聯式資料庫。
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。

**其他服務**
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。

## 最佳實務
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-best-practices"></a>

Amazon RDS 提供新的憑證授權機構憑證，做為 AWS 安全最佳實務。如需新憑證和支援之 AWS 區域的相關資訊，請參閱[使用 SSL/TLS 加密與資料庫執行個體或叢集的連線](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html)。

如果您的 RDS 執行個體目前在 CA 憑證 上`rds-ca-2019`，且您想要升級至 `rds-ca-rsa2048-g1`，請遵循透過[修改資料庫執行個體或叢集來更新 CA 憑證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL-certificate-rotation.html#UsingWithRDS.SSL-certificate-rotation-updating)，或透過[套用維護來更新 CA 憑證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL-certificate-rotation.html#UsingWithRDS.SSL-certificate-rotation-maintenance-update)中的指示。

## 史詩
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-epics"></a>

### 設定 Amazon RDS for Oracle 執行個體
<a name="configure-the-amazon-rds-for-oracle-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Oracle 資料庫執行個體。 | 登入您的 AWS 帳戶，開啟 AWS 管理主控台，然後導覽至 Amazon RDS 主控台。在 主控台上，選擇**建立資料庫**，然後選擇 **Oracle**。 | 一般 AWS、DBA | 
| 設定安全群組。 | 設定傳入和傳出安全群組。 | 一般 AWS | 
| 建立選項群組。 | 在與 Amazon RDS for Oracle 資料庫相同的 VPC 和安全群組中建立選項群組。在**選項**中，選擇 **SSL**。針對**連接埠**，選擇 **2484** （針對 SSL 連線）。 | 一般 AWS | 
| 設定 選項設定。 | 請使用下列設定：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 修改 RDS for Oracle 資料庫執行個體。 | 將 CA 憑證設定為 **rds-ca-rsa2048-g1**。在**選項群組**下，連接先前建立的選項群組。 | DBA、一般 AWS | 
| 確認 RDS for Oracle 資料庫執行個體可用。 | 確定 Amazon RDS for Oracle 資料庫執行個體已啟動並執行，而且可存取資料庫結構描述。若要連線至 RDS for Oracle 資料庫，請使用`sqlplus`命令列中的 命令。<pre>$ sqlplus orcl/****@myoracledb.cokmvis0v46q.us-east-1.rds.amazonaws.com:1521/ORCL<br />SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 15 18:11:07 2019<br />Copyright (c) 1982, 2016, Oracle.  All rights reserved.<br />Last Successful login time: Mon Dec 16 2019 23:17:31 +05:30<br />Connected to:<br />Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production<br />With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options<br />SQL></pre> | DBA | 
| 在 RDS for Oracle 資料庫中建立物件和資料。 | 在結構描述中建立物件並插入資料。 | DBA | 

### 設定 Amazon RDS for PostgreSQL 執行個體
<a name="configure-the-amazon-rds-for-postgresql-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 RDS for PostgreSQL 資料庫。 | 在 Amazon RDS 主控台**建立資料庫**頁面上，選擇 **PostgreSQL** 以建立 Amazon RDS for PostgreSQL 資料庫執行個體。 | DBA、一般 AWS | 
| 設定安全群組。 | 設定傳入和傳出安全群組。 | 一般 AWS | 
| 建立參數群組。 | 如果您使用的是 PostgreSQL 11.x 版，請建立參數群組來設定 SSL 參數。在 PostgreSQL 第 12 版中，預設會啟用 SSL 參數群組。 | 一般 AWS | 
| 編輯參數。 | 將 `rds.force_ssl` 參數變更為 `1`（開啟）。根據預設， `ssl` 參數為 `1`（開啟）。透過將 `rds.force_ssl` 參數設定為 `1`，您可以強制所有連線僅透過 SSL 模式進行連線。 | 一般 AWS | 
| 修改 RDS for PostgreSQL 資料庫執行個體。 | 將 CA 憑證設定為 **rds-ca-rsa2048-g1**。根據您的 PostgreSQL 版本，連接預設參數群組或先前建立的參數群組。 | DBA、一般 AWS | 
| 確認 RDS for PostgreSQL 資料庫執行個體可用。 | 確定 Amazon RDS for PostgreSQL 資料庫已啟動並執行。`psql` 命令會從命令列使用`sslmode`集合 建立 SSL 連線。其中一個選項是在 參數群組`sslmode=1`中設定 ，並使用 `psql` 連線，而不在 命令中包含 `sslmode` 參數。下列輸出顯示已建立 SSL 連線。<pre>$ psql -h mypgdbinstance.cokmvis0v46q.us-east-1.rds.amazonaws.com -p 5432 "dbname=pgdb user=pguser"<br />Password for user pguser:<br />psql (11.3, server 11.5)<br />SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)<br />Type "help" for help.<br />pgdb=></pre>第二個選項是在參數群組`sslmode=1`中設定 ，並在`psql`命令中包含 `sslmode` 參數。下列輸出顯示已建立 SSL 連線。<pre>$ psql -h mypgdbinstance.cokmvis0v46q.us-east-1.rds.amazonaws.com -p 5432 "dbname=pgdb user=pguser sslmode=require"<br />Password for user pguser: <br />psql (11.3, server 11.5)<br />SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)<br />Type "help" for help.<br />pgdb=></pre> | DBA | 

### 設定和執行 AWS SCT
<a name="configure-and-run-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS SCT。 | 安裝最新版本的 AWS SCT 應用程式。 | 一般 AWS | 
| 使用 JDBC 驅動程式設定 AWS SCT。 | 下載適用於 Oracle ([ojdbc8.jar](https://download.oracle.com/otn-pub/otn_software/jdbc/233/ojdbc8.jar)) 和 PostgreSQL ([postgresql-42.2.5.jar) 的 Java Database Connectivity (JDBC](https://jdbc.postgresql.org/download/postgresql-42.2.19.jar)) 驅動程式。若要在 AWS SCT 中設定驅動程式，請選擇**設定**、**全域設定**、**驅動程式**。 | 一般 AWS | 
| 建立 AWS SCT 專案。 | 使用 Oracle 作為來源資料庫引擎和 Amazon RDS for PostgreSQL 作為目標資料庫引擎，建立 AWS SCT 專案和報告：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 驗證資料庫物件。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | DBA、一般 AWS | 

### 設定和執行 AWS DMS
<a name="configure-and-run-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立複寫執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 匯入憑證。 | 為您的 AWS 區域下載[憑證套件 (PEM)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#UsingWithRDS.SSL.CertificatesAllRegions)。套件同時包含`rds-ca-2019`中繼憑證和根憑證。套件也包含 `rds-ca-rsa2048-g1`、 `rds-ca-rsa4096-g1`和`rds-ca-ecc384-g1`根 CA 憑證。您的應用程式信任存放區只需要註冊根 CA 憑證。 | 一般 AWS | 
| 建立來源端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html)如需詳細資訊，請參閱[使用 Oracle 資料庫做為 AWS Database Migration Service 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。 | 一般 AWS | 
| 建立目標端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html)如需詳細資訊，請參閱[使用 PostgreSQL 資料庫做為 AWS Database Migration Service 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)。 | 一般 AWS | 
| 測試端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 建立遷移任務。 | 若要為完全載入和變更資料擷取 (CDC) 或資料驗證建立遷移任務，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 規劃生產執行。 | 與應用程式擁有者等利益相關者確認停機時間，以在生產系統中執行 AWS DMS。 | 遷移潛在客戶 | 
| 執行 遷移任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 驗證資料。 | 檢閱來源 Oracle 和目標 PostgreSQL 資料庫中的遷移任務結果和資料：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | DBA | 
| 停止遷移任務。 | 成功完成資料驗證後，請停止遷移任務。 | 一般 AWS | 

### 清除資源
<a name="clean-up-the-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 刪除 AWS DMS 任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 刪除 AWS DMS 端點。 | 選取您建立的來源和目標端點，選擇**動作**，然後選擇**刪除**。 | 一般 AWS | 
| 刪除 AWS DMS 複寫執行個體。 | 選擇複寫執行個體，選擇**動作**，然後選擇**刪除**。 | 一般 AWS | 
| 刪除 PostgreSQL 資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 一般 AWS | 
| 刪除 Oracle 資料庫。 | 在 Amazon RDS 主控台上，選取 Oracle 資料庫執行個體，選擇**動作**，然後選擇**刪除**。 | 一般 AWS | 

## 疑難排解
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| AWS SCT 來源和目標測試連線失敗。 | 設定 JDBC 驅動程式版本和 VPC 安全群組傳入規則，以接受傳入流量。 | 
| Oracle 來源端點測試執行失敗。 | 檢查端點設定以及複寫執行個體是否可用。 | 
| AWS DMS 任務完全載入執行失敗。 | 檢查來源和目標資料庫是否具有相符的資料類型和大小。 | 
| AWS DMS 驗證遷移任務會傳回錯誤。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.html) | 

## 相關資源
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-resources"></a>

**資料庫**
+ [Amazon RDS for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 
+ [Amazon RDS for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)

**SSL 資料庫連線**
+ [使用 SSL/TLS 加密與資料庫執行個體的連線](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html)
  + [搭配 RDS for Oracle 資料庫執行個體使用 SSL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Concepts.SSL.html)
  + [使用 SSL/TLS 保護 RDS for PostgreSQL 的連線](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.Security.html)
  + [下載特定 AWS 區域的憑證套件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#UsingWithRDS.SSL.CertificatesAllRegions)
    + [下載 CA-2019 根憑證](https://s3.amazonaws.com/rds-downloads/rds-ca-2019-root.pem) （已於 2024 年 8 月過期）
+ [使用選項群組](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html)
  + [將選項新增至 Oracle 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.Oracle.Options.html)
  + [Oracle Secure Sockets Layer](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.Oracle.Options.SSL.html)
+ [使用參數群組](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithParamGroups.html)
+ [PostgreSQL sslmode 連線參數](https://www.postgresql.org/docs/11/libpq-connect.html#LIBPQ-CONNECT-SSLMODE)
+ [從 JDBC 使用 SSL](https://jdbc.postgresql.org/documentation/ssl/)
+ [輪換您的 SSL/TLS 憑證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL-certificate-rotation.html)
  + [透過修改資料庫執行個體或叢集來更新您的 CA 憑證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL-certificate-rotation.html#UsingWithRDS.SSL-certificate-rotation-updating)
  + [套用維護來更新您的 CA 憑證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL-certificate-rotation.html#UsingWithRDS.SSL-certificate-rotation-maintenance-update)

**AWS SCT**
+ [AWS Schema Conversion Tool](https://aws.amazon.com/dms/schema-conversion-tool/)
+ [AWS Schema Conversion Tool使用者指南](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [使用 AWS SCT 使用者介面](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html)
+ [使用 Oracle 資料庫做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)

**AWS DMS**
+ [AWS Database Migration Service](https://aws.amazon.com/dms/)
+ [AWS Database Migration Service 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
  + [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
  + [使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)
+ [搭配 AWS Database Migration Service 使用 SSL](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.SSL.html)
+ [將執行關聯式資料庫的應用程式遷移至 AWS](https://d1.awsstatic.com/whitepapers/Migration/migrating-applications-to-aws.pdf)

## 其他資訊
<a name="migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms-additional"></a>

Amazon RDS Certificate Authority 憑證已於 2024 年 8 月`rds-ca-2019`過期。如果您使用或計劃使用 SSL 或 TLS 搭配憑證驗證來連線至 RDS 資料庫執行個體或多可用區域資料庫叢集，請考慮使用其中一個新的 CA 憑證：`rds-ca-rsa2048-g1`、 `rds-ca-rsa4096-g1`或 `rds-ca-ecc384-g1`。

# 將 Oracle SERIALLY\$1REUSABLE pragma 套件遷移至 PostgreSQL
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql"></a>

*Vinay Paladi，Amazon Web Services*

## 總結
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-summary"></a>

此模式提供step-by-step方法，將定義為 SERIALLY\$1REUSABLE pragma 的 Oracle 套件遷移至 Amazon Web Services (AWS) 上的 PostgreSQL。此方法會維護 SERIALLY\$1REUSABLE pragma 的功能。

PostgreSQL 不支援套件和 SERIALLY\$1REUSABLE pragma 的概念。若要在 PostgreSQL 中取得類似的功能，您可以為套件建立結構描述，並在結構描述內部署所有相關物件 （例如函數、程序和類型）。為了實現 SERIALLY\$1REUSABLE pragma 的功能，此模式中提供的範例包裝函式指令碼使用 [AWS Schema Conversion Tool (AWS SCT) 延伸套件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_ExtensionPack.html)。

如需詳細資訊，請參閱 Oracle 文件中的 [SERIALLY\$1REUSABLE Pragma](https://docs.oracle.com/cd/B13789_01/appdev.101/b10807/13_elems046.htm)。

## 先決條件和限制
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 最新版本的 AWS SCT 和必要的驅動程式
+ Amazon Aurora PostgreSQL 相容版本資料庫或 Amazon Relational Database Service (Amazon RDS) for PostgreSQL 資料庫 

**產品版本**
+ Oracle 資料庫 10g 版及更新版本

## Architecture
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-architecture"></a>

**來源技術堆疊**
+ 內部部署的 Oracle 資料庫

**目標技術堆疊**
+ [Aurora PostgreSQL 相容](https://aws.amazon.com/rds/aurora/details/postgresql-details/)或 Amazon RDS for PostgreSQL
+ AWS SCT

**遷移架構**

![\[使用 AWS SCT、.sql 檔案、手動轉換至 PostgreSQL 傳送至 AWS 的內部部署 Oracle 資料庫資料。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/fe3c45d2-6ea4-43b5-adb1-18f068f126b9/images/2dc90708-e300-4251-9d12-de97b6588b72.png)


## 工具
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-tools"></a>

**AWS 服務**
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管且符合 ACID 規範的關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。

**其他工具**
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。

## 史詩
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-epics"></a>

### 使用 AWS SCT 遷移 Oracle 套件
<a name="migrate-the-oracle-package-by-using-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS SCT。 | 設定來源資料庫的 AWS SCT 連線。如需詳細資訊，請參閱[使用 Oracle 資料庫做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)。 | DBA、開發人員 | 
| 轉換指令碼。 | 使用 AWS SCT 將目標資料庫選取為 Aurora PostgreSQL 相容，以轉換 Oracle 套件。 | DBA、開發人員 | 
| 儲存 .sql 檔案。 | 儲存 .sql 檔案之前，請將 AWS SCT 中的**專案設定**選項修改為**每個階段的單一檔案**。AWS SCT 會根據物件類型，將 .sql 檔案分成多個 .sql 檔案。 | DBA、開發人員 | 
| 變更程式碼。 | 開啟 AWS SCT 產生的`init`函數，並如*其他資訊*區段中的範例所示進行變更。它會新增變數來實現功能 `pg_serialize = 0`。 | DBA、開發人員 | 
| 測試轉換。 | 將`init`函數部署至 Aurora PostgreSQL 相容資料庫，並測試結果。 | DBA、開發人員 | 

## 相關資源
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-resources"></a>
+ [AWS Schema Conversion Tool](https://aws.amazon.com/dms/schema-conversion-tool/)
+ [Amazon RDS](https://aws.amazon.com/rds/)
+ [Amazon Aurora 功能](https://aws.amazon.com/rds/aurora/postgresql-features/)
+ [SERIALLY\$1REUSABLE Pragma](https://docs.oracle.com/cd/B28359_01/appdev.111/b28370/seriallyreusable_pragma.htm#LNPLS01346)

## 其他資訊
<a name="migrate-oracle-serially-reusable-pragma-packages-into-postgresql-additional"></a>

```
Source Oracle Code:

CREATE OR REPLACE PACKAGE test_pkg_var
IS
PRAGMA SERIALLY_REUSABLE;
PROCEDURE function_1
 (test_id number);
PROCEDURE function_2
 (test_id number
 );
END;

CREATE OR REPLACE PACKAGE BODY test_pkg_var
IS
PRAGMA SERIALLY_REUSABLE;
v_char VARCHAR2(20) := 'shared.airline';
v_num number := 123;

PROCEDURE function_1(test_id number)
IS
begin
dbms_output.put_line( 'v_char-'|| v_char);
dbms_output.put_line( 'v_num-'||v_num);
v_char:='test1';
function_2(0);
END;

PROCEDURE function_2(test_id number)
is
begin
dbms_output.put_line( 'v_char-'|| v_char);
dbms_output.put_line( 'v_num-'||v_num);
END;
END test_pkg_var;

Calling the above functions

set serveroutput on


EXEC test_pkg_var.function_1(1);


EXEC test_pkg_var.function_2(1);


Target Postgresql Code:


CREATE SCHEMA test_pkg_var;

CREATE OR REPLACE FUNCTION test_pkg_var.init(pg_serialize IN INTEGER DEFAULT 0)

RETURNS void
AS
$BODY$

DECLARE

BEGIN

if aws_oracle_ext.is_package_initialized( 'test_pkg_var' ) AND pg_serialize = 0

then

return;

end if;

PERFORM aws_oracle_ext.set_package_initialized( 'test_pkg_var' );

PERFORM aws_oracle_ext.set_package_variable( 'test_pkg_var', 'v_char', 'shared.airline.basecurrency'::CHARACTER

VARYING(100));

PERFORM aws_oracle_ext.set_package_variable('test_pkg_var', 'v_num', 123::integer);

END;

$BODY$

LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_pkg_var.function_1(pg_serialize int default 1)

RETURNS void
AS

$BODY$
DECLARE

BEGIN

PERFORM test_pkg_var.init(pg_serialize);

raise notice 'v_char%',aws_oracle_ext.get_package_variable( 'test_pkg_var', 'v_char');

raise notice 'v_num%',aws_oracle_ext.get_package_variable( 'test_pkg_var', 'v_num');

PERFORM aws_oracle_ext.set_package_variable( 'test_pkg_var', 'v_char', 'test1'::varchar);

PERFORM test_pkg_var.function_2(0);
END;

$BODY$
LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_pkg_var.function_2(IN pg_serialize integer default 1)

RETURNS void

AS

$BODY$

DECLARE

BEGIN

PERFORM test_pkg_var.init(pg_serialize);

raise notice 'v_char%',aws_oracle_ext.get_package_variable( 'test_pkg_var', 'v_char');

raise notice 'v_num%',aws_oracle_ext.get_package_variable( 'test_pkg_var', 'v_num');

END;
$BODY$
LANGUAGE plpgsql;


Calling the above functions

select test_pkg_var.function_1()

 select test_pkg_var.function_2()
```

# 將 Oracle 外部資料表遷移至 Amazon Aurora PostgreSQL 相容
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible"></a>

*anuradha chintha 和 Rakesh Raghav，Amazon Web Services*

## 總結
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-summary"></a>

外部資料表可讓 Oracle 查詢以一般檔案存放在資料庫外部的資料。您可以使用 ORACLE\$1LOADER 驅動程式來存取以 SQL\$1Loader 公用程式可載入的任何格式儲存的任何資料。您無法在外部資料表上使用資料處理語言 (DML)，但您可以使用外部資料表進行查詢、聯結和排序操作。

Amazon Aurora PostgreSQL 相容版本不提供類似於 Oracle 中外部資料表的功能。反之，您必須使用現代化來開發符合功能需求的可擴展解決方案，而且是無法的。

此模式提供使用 `aws_s3`擴充功能，將不同類型的 Oracle 外部資料表遷移至 Amazon Web Services (AWS) 雲端上的 Aurora PostgreSQL 相容版本的步驟。

我們建議在生產環境中實作此解決方案之前，先徹底測試此解決方案。

## 先決條件和限制
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ AWS 命令列界面 (AWS CLI)
+ 可用的 Aurora PostgreSQL 相容資料庫執行個體。
+ 具有外部資料表的現場部署 Oracle 資料庫
+ pg.Client API
+ 資料檔案 

**限制**
+ 此模式不提供可取代 Oracle 外部資料表的功能。不過，您可以進一步增強步驟和範本程式碼，以實現資料庫現代化目標。
+ 檔案不應包含在`aws_s3`匯出和匯入函數中以分隔符號傳遞的字元。

**產品版本**
+ 若要從 Amazon S3 匯入 RDS for PostgreSQL，資料庫必須執行 PostgreSQL 10.7 版或更新版本。

## Architecture
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-architecture"></a>

**來源技術堆疊**
+ Oracle

**來源架構**

![\[前往內部部署 Oracle 資料庫中目錄和資料表的資料檔案圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/555e69af-36fc-4ff5-b66c-af22b4cf262a/images/3fbc507d-b0fa-4e05-b999-043dc7327ed7.png)


**目標技術堆疊**
+ Amazon Aurora PostgreSQL 相容
+ Amazon CloudWatch
+ AWS Lambda
+ AWS Secrets Manager
+ Amazon Simple Notification Service (Amazon SNS)
+ Amazon Simple Storage Service (Amazon S3)

**目標架構**

下圖顯示解決方案的高階表示法。

![\[描述在圖表後面。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/555e69af-36fc-4ff5-b66c-af22b4cf262a/images/5421540e-d2e3-4361-89cc-d8415fcb21fd.png)


1. 檔案會上傳至 S3 儲存貯體。

1. Lambda 函數已啟動。

1. Lambda 函數會啟動資料庫函數呼叫。

1. Secrets Manager 提供資料庫存取的登入資料。

1. 根據資料庫函數，會建立 SNS 警示。

**自動化和擴展**

外部資料表的任何新增或變更都可以使用中繼資料維護來處理。

## 工具
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-tools"></a>
+ [Amazon Aurora PostgreSQL 相容](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) – Amazon Aurora PostgreSQL 相容版本是全受管、PostgreSQL 相容且 ACID 相容的關係資料庫引擎，結合了高階商業資料庫的速度和可靠性，以及開放原始碼資料庫的成本效益。
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) – AWS Command Line Interface (AWS CLI) 是管理 AWS 服務的統一工具。只需下載和設定一個工具，您就可以從命令列控制多個 AWS 服務，並透過指令碼將其自動化。
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) – Amazon CloudWatch 會監控 Amazon S3 資源和使用率。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) – AWS Lambda 是一種無伺服器運算服務，支援執行程式碼，無需佈建或管理伺服器、建立工作負載感知叢集擴展邏輯、維護事件整合，或管理執行時間。在此模式中，每當檔案上傳至 Amazon S3 時，Lambda 都會執行資料庫函數。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) – AWS Secrets Manager 是一種用於憑證儲存和擷取的服務。使用 Secrets Manager，您可以使用以程式設計方式呼叫 Secrets Manager 擷取秘密的 API，取代程式碼中的硬式編碼登入資料，包括密碼。
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 提供儲存層來接收和存放檔案，以供取用和往返 Aurora PostgreSQL 相容叢集傳輸。
+ [aws\$1s3](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html#aws_s3.table_import_from_s3) – `aws_s3`延伸模組整合 Amazon S3 和 Aurora PostgreSQL 相容。
+ [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) – Amazon Simple Notification Service (Amazon SNS) 會協調和管理發佈者和用戶端之間的訊息傳遞或傳送。在此模式中，Amazon SNS 用於傳送通知。

**Code**

每當檔案放入 S3 儲存貯體時，都必須從處理應用程式或 Lambda 函數建立和呼叫資料庫函數。如需詳細資訊，請參閱 程式碼 （已連接）。

## 史詩
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-epics"></a>

### 建立外部檔案
<a name="create-an-external-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將外部檔案新增至來源資料庫。 | 建立外部檔案，並將其移至 `oracle`目錄。 | DBA | 

### 設定目標 (Aurora PostgreSQL 相容）
<a name="configure-the-target-aurora-postgresql-compatible"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Aurora PostgreSQL 資料庫。 | 在 Amazon Aurora PostgreSQL 相容叢集中建立資料庫執行個體。 | DBA | 
| 建立結構描述、aws\$1s3 延伸模組和資料表。 | 在*其他資訊*區段`ext_tbl_scripts`中使用 下的程式碼。資料表包括實際資料表、預備資料表、錯誤和日誌資料表，以及可轉移。 | DBA、開發人員 | 
| 建立 資料庫函數。 | 若要建立資料庫函數，請使用*其他資訊*區段中函數下的`load_external_table_latest`程式碼。 | DBA、開發人員 | 

### 建立並設定 Lambda 函式
<a name="create-and-configure-the-lambda-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立角色。 | 建立具有存取 Amazon S3 和 Amazon Relational Database Service (Amazon RDS) 許可的角色。此角色將指派給 Lambda 以執行模式。 | DBA | 
| 建立 Lambda 函數。 | 建立從 Amazon S3 讀取檔案名稱的 Lambda 函數 （例如 `file_key = info.get('object', {}).get('key')`)，並使用檔案名稱做為輸入參數來呼叫資料庫函數 （例如 `curs.callproc("load_external_tables", [file_key])`)。根據函數呼叫結果，將會啟動 SNS 通知 （例如 `client.publish(TopicArn='arn:',Message='fileloadsuccess',Subject='fileloadsuccess')`)。根據您的業務需求，您可以視需要建立具有額外程式碼的 Lambda 函數。如需詳細資訊，請參閱 [Lambda 文件](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)。 | DBA | 
| 設定 S3 儲存貯體事件觸發。 | 設定機制，針對 S3 儲存貯體中的所有物件建立事件呼叫 Lambda 函數。 | DBA | 
| 建立秘密。 | 使用 Secrets Manager 建立資料庫登入資料的秘密名稱。在 Lambda 函數中傳遞秘密。 | DBA | 
| 上傳 Lambda 支援檔案。 | 上傳 .zip 檔案，其中包含 Lambda 支援套件和連接的 Python 指令碼，以連線至 Aurora PostgreSQL 相容。Python 程式碼會呼叫您在資料庫中建立的 函數。 | DBA | 
| 建立 SNS 主題。 | 建立 SNS 主題以傳送郵件，確保資料載入成功或失敗。 | DBA | 

### 新增與 Amazon S3 的整合
<a name="add-integration-with-amazon-s3"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 在 Amazon S3 主控台上，使用不包含正斜線的唯一名稱建立 S3 儲存貯體。S3 儲存貯體名稱全域唯一，且命名空間由所有 AWS 帳戶共用。 | DBA | 
| 建立 IAM 政策。 | 若要建立 AWS Identity and Access Management (IAM) 政策，請使用*其他資訊*區段`s3bucketpolicy_for_import`中 下的程式碼。 | DBA | 
| 建立角色。 | 為 Aurora PostgreSQL 相容建立兩個角色，一個用於匯入的角色，另一個用於匯出的角色。將對應的政策指派給角色。 | DBA | 
| 將角色連接至 Aurora PostgreSQL 相容叢集。 | 在**管理角色**下，將匯入和匯出角色連接至 Aurora PostgreSQL 叢集。 | DBA | 
| 為 Aurora PostgreSQL 相容建立支援物件。 | 對於資料表指令碼，請在*其他資訊*區段`ext_tbl_scripts`中使用 下的程式碼。對於自訂函數，請在*其他資訊*區段`load_external_Table_latest`中使用 下的程式碼。 | DBA | 

### 處理測試檔案
<a name="process-a-test-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將檔案上傳至 S3 儲存貯體。 | 若要將測試檔案上傳至 S3 儲存貯體，請使用主控台或在 AWS CLI 中使用下列命令。 <pre>aws s3 cp /Users/Desktop/ukpost/exttbl/"testing files"/aps s3://s3importtest/inputext/aps</pre>一旦上傳檔案，儲存貯體事件就會啟動 Lambda 函數，執行 Aurora PostgreSQL 相容函數。 | DBA | 
| 檢查資料以及日誌和錯誤檔案。 | Aurora PostgreSQL 相容函數會將檔案載入主資料表，並在 S3 儲存貯體中建立 `.log`和 `.bad` 檔案。 | DBA | 
| 監控解決方案。 | 在 Amazon CloudWatch 主控台中，監控 Lambda 函數。 | DBA | 

## 相關資源
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-resources"></a>
+ [Amazon S3 整合](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-s3-integration.html)
+ [Amazon S3](https://aws.amazon.com/s3/)
+ [使用 Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)
+ [AWS Lambda](https://aws.amazon.com/lambda/)
+ [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/)
+ [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/)
+ [設定 Amazon SNS 通知](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)

## 其他資訊
<a name="migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible-additional"></a>

**ext\$1table\$1scripts**

```
CREATE EXTENSION aws_s3 CASCADE;
CREATE TABLE IF NOT EXISTS meta_EXTERNAL_TABLE
(
    table_name_stg character varying(100) ,
    table_name character varying(100)  ,
    col_list character varying(1000)  ,
    data_type character varying(100)  ,
    col_order numeric,
    start_pos numeric,
    end_pos numeric,
    no_position character varying(100)  ,
    date_mask character varying(100)  ,
    delimeter character(1)  ,
    directory character varying(100)  ,
    file_name character varying(100)  ,
    header_exist character varying(5)
);
CREATE TABLE IF NOT EXISTS ext_tbl_stg
(
    col1 text
);
CREATE TABLE IF NOT EXISTS error_table
(
    error_details text,
    file_name character varying(100),
    processed_time timestamp without time zone
);
CREATE TABLE IF NOT EXISTS log_table
(
    file_name character varying(50) COLLATE pg_catalog."default",
    processed_date timestamp without time zone,
    tot_rec_count numeric,
    proc_rec_count numeric,
    error_rec_count numeric
);
sample insert scripts of meta data:
INSERT INTO meta_EXTERNAL_TABLE (table_name_stg, table_name, col_list, data_type, col_order, start_pos, end_pos, no_position, date_mask, delimeter, directory, file_name, header_exist) VALUES ('F_EX_APS_TRANSACTIONS_STG', 'F_EX_APS_TRANSACTIONS', 'source_filename', 'character varying', 2, 8, 27, NULL, NULL, NULL, 'databasedev', 'externalinterface/loaddir/APS', 'NO');
INSERT INTO meta_EXTERNAL_TABLE (table_name_stg, table_name, col_list, data_type, col_order, start_pos, end_pos, no_position, date_mask, delimeter, directory, file_name, header_exist) VALUES ('F_EX_APS_TRANSACTIONS_STG', 'F_EX_APS_TRANSACTIONS', 'record_type_identifier', 'character varying', 3, 28, 30, NULL, NULL, NULL, 'databasedev', 'externalinterface/loaddir/APS', 'NO');
INSERT INTO meta_EXTERNAL_TABLE (table_name_stg, table_name, col_list, data_type, col_order, start_pos, end_pos, no_position, date_mask, delimeter, directory, file_name, header_exist) VALUES ('F_EX_APS_TRANSACTIONS_STG', 'F_EX_APS_TRANSACTIONS', 'fad_code', 'numeric', 4, 31, 36, NULL, NULL, NULL, 'databasedev', 'externalinterface/loaddir/APS', 'NO');
INSERT INTO meta_EXTERNAL_TABLE (table_name_stg, table_name, col_list, data_type, col_order, start_pos, end_pos, no_position, date_mask, delimeter, directory, file_name, header_exist) VALUES ('F_EX_APS_TRANSACTIONS_STG', 'F_EX_APS_TRANSACTIONS', 'session_sequence_number', 'numeric', 5, 37, 42, NULL, NULL, NULL, 'databasedev', 'externalinterface/loaddir/APS', 'NO');
INSERT INTO meta_EXTERNAL_TABLE (table_name_stg, table_name, col_list, data_type, col_order, start_pos, end_pos, no_position, date_mask, delimeter, directory, file_name, header_exist) VALUES ('F_EX_APS_TRANSACTIONS_STG', 'F_EX_APS_TRANSACTIONS', 'transaction_sequence_number', 'numeric', 6, 43, 48, NULL, NULL, NULL, 'databasedev', 'externalinterface/loaddir/APS', 'NO');
```

**s3bucketpolicy\$1for 匯入**

```
---Import role policy
--Create an IAM policy to allow, Get,  and list actions on S3 bucket
 {
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "s3import",
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::s3importtest",
                "arn:aws:s3:::s3importtest/*"
            ]
        }
    ]
}
--Export Role policy
--Create an IAM policy to allow, put,  and list actions on S3 bucket
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "s3export",
            "Action": [
                "S3:PutObject",
                "s3:ListBucket"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::s3importtest/*"
            ]
        }
    ]
}
```

**資料庫函數 load\$1external\$1tables\$1latest 範例**

```
CREATE OR REPLACE FUNCTION public.load_external_tables(pi_filename text)
 RETURNS character varying
 LANGUAGE plpgsql
AS $function$
/* Loading data from S3 bucket into a APG table */
DECLARE
 v_final_sql TEXT;
 pi_ext_table TEXT;
 r refCURSOR;
 v_sqlerrm text;
 v_chunk numeric;
 i integer;
 v_col_list TEXT;
 v_postion_list CHARACTER VARYING(1000);
 v_len  integer;
 v_delim varchar;
 v_file_name CHARACTER VARYING(1000);
 v_directory CHARACTER VARYING(1000);
 v_table_name_stg CHARACTER VARYING(1000);
 v_sql_col TEXT;
 v_sql TEXT;
 v_sql1 TEXT;
 v_sql2 TEXT;
 v_sql3 TEXT;
 v_cnt integer;
 v_sql_dynamic TEXT;
 v_sql_ins TEXT;
 proc_rec_COUNT integer;
 error_rec_COUNT integer;
 tot_rec_COUNT integer;
 v_rec_val integer;
 rec record;
 v_col_cnt integer;
 kv record;
 v_val text;
 v_header text;
 j integer;
 ERCODE VARCHAR(5);
 v_region text;
 cr CURSOR FOR
 SELECT distinct DELIMETER,
   FILE_NAME,
   DIRECTORY
 FROM  meta_EXTERNAL_TABLE
 WHERE table_name = pi_ext_table
   AND DELIMETER IS NOT NULL;


 cr1 CURSOR FOR
   SELECT   col_list,
   data_type,
   start_pos,
   END_pos,
   concat_ws('',' ',TABLE_NAME_STG) as TABLE_NAME_STG,
   no_position,date_mask
 FROM  meta_EXTERNAL_TABLE
 WHERE table_name = pi_ext_table
 order by col_order asc;
cr2 cursor FOR
SELECT  distinct table_name,table_name_stg
   FROM  meta_EXTERNAL_TABLE
   WHERE upper(file_name) = upper(pi_filename);


BEGIN
 -- PERFORM utl_file_utility.init();
   v_region := 'us-east-1';
   /* find tab details from file name */


   --DELETE FROM  ERROR_TABLE WHERE file_name= pi_filename;
  -- DELETE FROM  log_table WHERE file_name= pi_filename;


 BEGIN


   SELECT distinct table_name,table_name_stg INTO strict pi_ext_table,v_table_name_stg
   FROM  meta_EXTERNAL_TABLE
   WHERE upper(file_name) = upper(pi_filename);
 EXCEPTION
   WHEN NO_DATA_FOUND THEN
    raise notice 'error 1,%',sqlerrm;
    pi_ext_table := null;
    v_table_name_stg := null;
      RAISE USING errcode = 'NTFIP' ;
    when others then
        raise notice 'error others,%',sqlerrm;
 END;
 j :=1 ;
  
for rec in  cr2
 LOOP




  pi_ext_table     := rec.table_name;
  v_table_name_stg := rec.table_name_stg;
  v_col_list := null;


 IF pi_ext_table IS NOT NULL
  THEN
    --EXECUTE concat_ws('','truncate table  ' ,pi_ext_table) ;
   EXECUTE concat_ws('','truncate table  ' ,v_table_name_stg) ;




       SELECT distinct DELIMETER INTO STRICT v_delim
       FROM  meta_EXTERNAL_TABLE
       WHERE table_name = pi_ext_table;


       IF v_delim IS NOT NULL THEN
     SELECT distinct DELIMETER,
       FILE_NAME,
       DIRECTORY ,
       concat_ws('',' ',table_name_stg),
       case  header_exist when 'YES' then 'CSV HEADER' else 'CSV' end as header_exist
     INTO STRICT v_delim,v_file_name,v_directory,v_table_name_stg,v_header
     FROM  meta_EXTERNAL_TABLE
     WHERE table_name = pi_ext_table
       AND DELIMETER IS NOT NULL;


     IF    upper(v_delim) = 'CSV'
     THEN
       v_sql := concat_ws('','SELECT aws_s3.table_import_FROM_s3 ( ''',
       v_table_name_stg,''','''',
       ''DELIMITER '''','''' CSV HEADER QUOTE ''''"'''''', aws_commons.create_s3_uri ( ''',
       v_directory,''',''',v_file_name,''', ''',v_region,'''))');
       ELSE
       v_sql := concat_ws('','SELECT aws_s3.table_import_FROM_s3(''',
           v_table_name_stg, ''','''', ''DELIMITER AS ''''^''''',''',','
          aws_commons.create_s3_uri
           ( ''',v_directory, ''',''',
           v_file_name, ''',',
            '''',v_region,''')
          )');
          raise notice 'v_sql , %',v_sql;
       begin
        EXECUTE  v_sql;
       EXCEPTION
         WHEN OTHERS THEN
           raise notice 'error 1';
         RAISE USING errcode = 'S3IMP' ;
       END;


       select count(col_list) INTO v_col_cnt
       from  meta_EXTERNAL_TABLE where table_name = pi_ext_table;






        -- raise notice 'v_sql 2, %',concat_ws('','update ',v_table_name_stg, ' set col1 = col1||''',v_delim,'''');


       execute concat_ws('','update ',v_table_name_stg, ' set col1 = col1||''',v_delim,'''');




       i :=1;
       FOR rec in cr1
       loop
       v_sql1 := concat_ws('',v_sql1,'split_part(col1,''',v_delim,''',', i,')',' as ',rec.col_list,',');
       v_sql2 := concat_ws('',v_sql2,rec.col_list,',');
   --    v_sql3 := concat_ws('',v_sql3,'rec.',rec.col_list,'::',rec.data_type,',');


       case
         WHEN upper(rec.data_type) = 'NUMERIC'
         THEN v_sql3 := concat_ws('',v_sql3,' case WHEN length(trim(split_part(col1,''',v_delim,''',', i,'))) =0
                THEN null
                 ELSE
                 coalesce((trim(split_part(col1,''',v_delim,''',', i,')))::NUMERIC,0)::',rec.data_type,' END as ',rec.col_list,',') ;
         WHEN UPPER(rec.data_type) = 'TIMESTAMP WITHOUT TIME ZONE' AND rec.date_mask = 'YYYYMMDD'
         THEN v_sql3 := concat_ws('',v_sql3,' case WHEN length(trim(split_part(col1,''',v_delim,''',', i,'))) =0
                THEN null
                 ELSE
                 to_date(coalesce((trim(split_part(col1,''',v_delim,''',', i,'))),''99990101''),''YYYYMMDD'')::',rec.data_type,' END as ',rec.col_list,',');
         WHEN UPPER(rec.data_type) = 'TIMESTAMP WITHOUT TIME ZONE' AND rec.date_mask =  'MM/DD/YYYY hh24:mi:ss'
         THEN v_sql3 := concat_ws('',v_sql3,' case WHEN length(trim(split_part(col1,''',v_delim,''',', i,'))) =0
                THEN null
                 ELSE
                 to_date(coalesce((trim(split_part(col1,''',v_delim,''',', i,'))),''01/01/9999 0024:00:00''),''MM/DD/YYYY hh24:mi:ss'')::',rec.data_type,' END as ',rec.col_list,',');
          ELSE
        v_sql3 := concat_ws('',v_sql3,' case WHEN length(trim(split_part(col1,''',v_delim,''',', i,'))) =0
                THEN null
                 ELSE
                  coalesce((trim(split_part(col1,''',v_delim,''',', i,'))),'''')::',rec.data_type,' END as ',rec.col_list,',') ;
       END case;


       i :=i+1;
       end loop;


         -- raise notice 'v_sql 3, %',v_sql3;


       SELECT trim(trailing ' ' FROM v_sql1) INTO v_sql1;
       SELECT trim(trailing ',' FROM v_sql1) INTO v_sql1;


       SELECT trim(trailing ' ' FROM v_sql2) INTO v_sql2;
       SELECT trim(trailing ',' FROM v_sql2) INTO v_sql2;


       SELECT trim(trailing ' ' FROM v_sql3) INTO v_sql3;
       SELECT trim(trailing ',' FROM v_sql3) INTO v_sql3;


       END IF;
      raise notice 'v_delim , %',v_delim;


     EXECUTE concat_ws('','SELECT COUNT(*) FROM ',v_table_name_stg)  INTO v_cnt;


    raise notice 'stg cnt , %',v_cnt;


    /* if upper(v_delim) = 'CSV' then
       v_sql_ins := concat_ws('', ' SELECT * from ' ,v_table_name_stg );
     else
      -- v_sql_ins := concat_ws('',' SELECT ',v_sql1,'  from (select col1 from ' ,v_table_name_stg , ')sub ');
       v_sql_ins := concat_ws('',' SELECT ',v_sql3,'  from (select col1 from ' ,v_table_name_stg , ')sub ');
       END IF;*/


v_chunk := v_cnt/100;




for i in 1..101
loop
     BEGIN
    -- raise notice 'v_sql , %',v_sql;
       -- raise notice 'Chunk number , %',i;
       v_sql_ins := concat_ws('',' SELECT ',v_sql3,'  from (select col1 from ' ,v_table_name_stg , ' offset ',v_chunk*(i-1), ' limit ',v_chunk,') sub ');


     v_sql := concat_ws('','insert into  ', pi_ext_table ,' ', v_sql_ins);
     -- raise notice 'select statement , %',v_sql_ins;
          -- v_sql := null;
     -- EXECUTE concat_ws('','insert into  ', pi_ext_table ,' ', v_sql_ins, 'offset ',v_chunk*(i-1), ' limit ',v_chunk );
     --v_sql := concat_ws('','insert into  ', pi_ext_table ,' ', v_sql_ins );


     -- raise notice 'insert statement , %',v_sql;


    raise NOTICE 'CHUNK START %',v_chunk*(i-1);
   raise NOTICE 'CHUNK END %',v_chunk;


     EXECUTE v_sql;


  EXCEPTION
       WHEN OTHERS THEN
       -- v_sql_ins := concat_ws('',' SELECT ',v_sql1, '  from (select col1 from ' ,v_table_name_stg , ' )sub ');
         -- raise notice 'Chunk number for cursor , %',i;


    raise NOTICE 'Cursor - CHUNK START %',v_chunk*(i-1);
   raise NOTICE 'Cursor -  CHUNK END %',v_chunk;
         v_sql_ins := concat_ws('',' SELECT ',v_sql3, '  from (select col1 from ' ,v_table_name_stg , ' )sub ');


         v_final_sql := REPLACE (v_sql_ins, ''''::text, ''''''::text);
        -- raise notice 'v_final_sql %',v_final_sql;
         v_sql :=concat_ws('','do $a$ declare  r refcursor;v_sql text; i numeric;v_conname text;  v_typ  ',pi_ext_table,'[]; v_rec  ','record',';
           begin






           open r for execute ''select col1 from ',v_table_name_stg ,'  offset ',v_chunk*(i-1), ' limit ',v_chunk,''';
           loop
           begin
           fetch r into v_rec;
           EXIT WHEN NOT FOUND;




           v_sql := concat_ws('''',''insert into  ',pi_ext_table,' SELECT ',REPLACE (v_sql3, ''''::text, ''''''::text) , '  from ( select '''''',v_rec.col1,'''''' as col1) v'');
            execute v_sql;


           exception
            when others then
          v_sql := ''INSERT INTO  ERROR_TABLE VALUES (concat_ws('''''''',''''Error Name: '''',$$''||SQLERRM||''$$,''''Error State: '''',''''''||SQLSTATE||'''''',''''record : '''',$$''||v_rec.col1||''$$),'''''||pi_filename||''''',now())'';


               execute v_sql;
             continue;
           end ;
           end loop;
           close r;
           exception
           when others then
         raise;
           end ; $a$');
      -- raise notice ' inside excp v_sql %',v_sql;
          execute v_sql;
      --  raise notice 'v_sql %',v_sql;
       END;
  END LOOP;
     ELSE


     SELECT distinct DELIMETER,FILE_NAME,DIRECTORY ,concat_ws('',' ',table_name_stg),
       case  header_exist when 'YES' then 'CSV HEADER' else 'CSV' end as header_exist
       INTO STRICT v_delim,v_file_name,v_directory,v_table_name_stg,v_header
     FROM  meta_EXTERNAL_TABLE
     WHERE table_name = pi_ext_table                  ;
     v_sql := concat_ws('','SELECT aws_s3.table_import_FROM_s3(''',
       v_table_name_stg, ''','''', ''DELIMITER AS ''''#'''' ',v_header,' '',','
      aws_commons.create_s3_uri
       ( ''',v_directory, ''',''',
       v_file_name, ''',',
        '''',v_region,''')
      )');
         EXECUTE  v_sql;


     FOR rec in cr1
     LOOP


      IF rec.start_pos IS NULL AND rec.END_pos IS NULL AND rec.no_position = 'recnum'
      THEN
        v_rec_val := 1;
      ELSE


       case
         WHEN upper(rec.data_type) = 'NUMERIC'
         THEN v_sql1 := concat_ws('',' case WHEN length(trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))) =0
                THEN null
                 ELSE
                 coalesce((trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1)))::NUMERIC,0)::',rec.data_type,' END as ',rec.col_list,',') ;
         WHEN UPPER(rec.data_type) = 'TIMESTAMP WITHOUT TIME ZONE' AND rec.date_mask = 'YYYYMMDD'
         THEN v_sql1 := concat_ws('','case WHEN length(trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))) =0
                THEN null
                 ELSE
                 to_date(coalesce((trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))),''99990101''),''YYYYMMDD'')::',rec.data_type,' END as ',rec.col_list,',');
         WHEN UPPER(rec.data_type) = 'TIMESTAMP WITHOUT TIME ZONE' AND rec.date_mask = 'YYYYMMDDHH24MISS'
         THEN v_sql1 := concat_ws('','case WHEN length(trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))) =0
                THEN null
                 ELSE
                 to_date(coalesce((trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))),''9999010100240000''),''YYYYMMDDHH24MISS'')::',rec.data_type,' END as ',rec.col_list,',');
          ELSE
        v_sql1 := concat_ws('',' case WHEN length(trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))) =0
                THEN null
                 ELSE
                  coalesce((trim(substring(COL1, ',rec.start_pos ,',', rec.END_pos,'-',rec.start_pos ,'+1))),'''')::',rec.data_type,' END as ',rec.col_list,',') ;
       END case;


      END IF;
      v_col_list := concat_ws('',v_col_list ,v_sql1);
     END LOOP;




           SELECT trim(trailing ' ' FROM v_col_list) INTO v_col_list;
           SELECT trim(trailing ',' FROM v_col_list) INTO v_col_list;


           v_sql_col   :=  concat_ws('',trim(trailing ',' FROM v_col_list) , ' FROM  ',v_table_name_stg,' WHERE col1 IS NOT NULL AND length(col1)>0 ');




           v_sql_dynamic := v_sql_col;


           EXECUTE  concat_ws('','SELECT COUNT(*) FROM ',v_table_name_stg) INTO v_cnt;




         IF v_rec_val = 1 THEN
             v_sql_ins := concat_ws('',' select row_number() over(order by ctid) as line_number ,' ,v_sql_dynamic) ;


         ELSE
               v_sql_ins := concat_ws('',' SELECT' ,v_sql_dynamic) ;
           END IF;


     BEGIN
       EXECUTE concat_ws('','insert into  ', pi_ext_table ,' ', v_sql_ins);
           EXCEPTION
              WHEN OTHERS THEN
          IF v_rec_val = 1 THEN
                  v_final_sql := ' select row_number() over(order by ctid) as line_number ,col1 from ';
                ELSE
                 v_final_sql := ' SELECT col1 from';
               END IF;
       v_sql :=concat_ws('','do $a$ declare  r refcursor;v_rec_val numeric := ',coalesce(v_rec_val,0),';line_number numeric; col1 text; v_typ  ',pi_ext_table,'[]; v_rec  ',pi_ext_table,';
             begin
             open r for execute ''',v_final_sql, ' ',v_table_name_stg,' WHERE col1 IS NOT NULL AND length(col1)>0 '' ;
             loop
             begin
             if   v_rec_val = 1 then
             fetch r into line_number,col1;
             else
             fetch r into col1;
             end if;


             EXIT WHEN NOT FOUND;
              if v_rec_val = 1 then
              select line_number,',trim(trailing ',' FROM v_col_list) ,' into v_rec;
              else
                select ',trim(trailing ',' FROM v_col_list) ,' into v_rec;
              end if;


             insert into  ',pi_ext_table,' select v_rec.*;
              exception
              when others then
               INSERT INTO  ERROR_TABLE VALUES (concat_ws('''',''Error Name: '',SQLERRM,''Error State: '',SQLSTATE,''record : '',v_rec),''',pi_filename,''',now());
               continue;
              end ;
               end loop;
             close r;
              exception
              when others then
              raise;
              end ; $a$');
         execute v_sql;


     END;


         END IF;


   EXECUTE concat_ws('','SELECT COUNT(*) FROM  ' ,pi_ext_table)   INTO proc_rec_COUNT;


   EXECUTE concat_ws('','SELECT COUNT(*) FROM  error_table WHERE file_name =''',pi_filename,''' and processed_time::date = clock_timestamp()::date')  INTO error_rec_COUNT;


   EXECUTE concat_ws('','SELECT COUNT(*) FROM ',v_table_name_stg)   INTO tot_rec_COUNT;


   INSERT INTO  log_table values(pi_filename,now(),tot_rec_COUNT,proc_rec_COUNT, error_rec_COUNT);


   raise notice 'v_directory, %',v_directory;


   raise notice 'pi_filename, %',pi_filename;


   raise notice 'v_region, %',v_region;


  perform aws_s3.query_export_to_s3('SELECT replace(trim(substring(error_details,position(''('' in error_details)+1),'')''),'','','';''),file_name,processed_time FROM  error_table WHERE file_name = '''||pi_filename||'''',
   aws_commons.create_s3_uri(v_directory, pi_filename||'.bad', v_region),
   options :='FORmat csv, header, delimiter $$,$$'
   );


raise notice 'v_directory, %',v_directory;


   raise notice 'pi_filename, %',pi_filename;


   raise notice 'v_region, %',v_region;


  perform aws_s3.query_export_to_s3('SELECT * FROM  log_table WHERE file_name = '''||pi_filename||'''',
   aws_commons.create_s3_uri(v_directory, pi_filename||'.log', v_region),
   options :='FORmat csv, header, delimiter $$,$$'
   );




   END IF;
 j := j+1;
 END LOOP;


       RETURN 'OK';
EXCEPTION
    WHEN  OTHERS THEN
  raise notice 'error %',sqlerrm;
   ERCODE=SQLSTATE;
   IF ERCODE = 'NTFIP' THEN
     v_sqlerrm := concat_Ws('',sqlerrm,'No data for the filename');
   ELSIF ERCODE = 'S3IMP' THEN
    v_sqlerrm := concat_Ws('',sqlerrm,'Error While exporting the file from S3');
   ELSE
      v_sqlerrm := sqlerrm;
   END IF;


 select distinct directory into v_directory from  meta_EXTERNAL_TABLE;




 raise notice 'exc v_directory, %',v_directory;


   raise notice 'exc pi_filename, %',pi_filename;


   raise notice 'exc v_region, %',v_region;


  perform aws_s3.query_export_to_s3('SELECT * FROM  error_table WHERE file_name = '''||pi_filename||'''',
   aws_commons.create_s3_uri(v_directory, pi_filename||'.bad', v_region),
   options :='FORmat csv, header, delimiter $$,$$'
   );
    RETURN null;
END;
$function$
```

# 將函數型索引從 Oracle 遷移至 PostgreSQL
<a name="migrate-function-based-indexes-from-oracle-to-postgresql"></a>

*Veeranjaneyulu Grandhi 和 Navakanth Talluri，Amazon Web Services*

## 總結
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-summary"></a>

索引是增強資料庫效能的常見方式。索引可讓資料庫伺服器比沒有索引時更快地尋找和擷取特定資料列。但索引也會為資料庫系統整體增加額外負荷，因此應該合理地使用它們。以函數為基礎的索引，以函數或表達式為基礎，可以涉及多個欄和數學表達式。以函數為基礎的索引可改善使用索引表達式的查詢效能。 

原本，PostgreSQL 不支援使用波動定義為穩定的函數建立以函數為基礎的索引。不過，您可以建立具有波動的類似函數，`IMMUTABLE`並在建立索引時使用它們。

`IMMUTABLE` 函數無法修改資料庫，並保證永遠傳回相同的結果與相同的引數。此類別可讓最佳化工具在查詢使用常數引數呼叫函數時預先評估函數。 

此模式有助於將 Oracle 函數型索引與 `to_char`、 `to_date`和 等函數搭配使用時遷移`to_number`至 PostgreSQL 對等項目。

## 先決條件和限制
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 Amazon Web Services (AWS) 帳戶
+ 具有接聽程式服務設定和執行的來源 Oracle 資料庫執行個體
+ 熟悉 PostgreSQL 資料庫

**限制**
+ 資料庫大小限制為 64 TB。
+ 用於建立索引的函數必須為 IMMUTABLE。

**產品版本**
+ 11g 版 (11.2.0.3.v1 版及更新版本） 及最高 12.2 版和 18c 版的所有 Oracle 資料庫版本
+ PostgreSQL 9.6 版及更新版本

## Architecture
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-architecture"></a>

**來源技術堆疊**
+ 內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體或 Amazon RDS for Oracle 資料庫執行個體上的 Oracle 資料庫

**目標技術堆疊**
+ 任何 PostgreSQL 引擎

## 工具
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-tools"></a>
+ **pgAdmin 4** 是 Postgres 的開放原始碼管理工具。pgAdmin 4 工具提供圖形界面，用於建立、維護和使用資料庫物件。
+ **Oracle SQL Developer** 是整合式開發環境 (IDE)，用於在傳統和雲端部署中開發和管理 Oracle 資料庫。

## 史詩
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-epics"></a>

### 使用預設函數建立以函數為基礎的索引
<a name="create-a-function-based-index-using-a-default-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 to\$1char 函數在資料欄上建立以函數為基礎的索引。 | 使用下列程式碼來建立以函數為基礎的索引。<pre>postgres=# create table funcindex( col1 timestamp without time zone);<br />CREATE TABLE<br />postgres=# insert into funcindex values (now());<br />INSERT 0 1<br />postgres=# select * from funcindex;<br />            col1<br />----------------------------<br /> 2022-08-09 16:00:57.77414<br />(1 rows)<br /> <br />postgres=# create index funcindex_idx on funcindex(to_char(col1,'DD-MM-YYYY HH24:MI:SS'));<br />ERROR:  functions in index expression must be marked IMMUTABLE</pre> PostgreSQL 不允許在沒有 `IMMUTABLE`子句的情況下建立以函數為基礎的索引。 | DBA、App 開發人員 | 
| 檢查函數的波動。 | 若要檢查函數波動，請使用*其他資訊*區段中的程式碼。   | DBA | 

### 使用包裝函式建立以函式為基礎的索引
<a name="create-function-based-indexes-using-a-wrapper-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立包裝函式。 | 若要建立包裝函式，請使用*其他資訊區段*中的程式碼。 | PostgreSQL 開發人員 | 
| 使用包裝函式建立索引。 | 使用*其他資訊*區段中的程式碼，在與應用程式相同的結構描述`IMMUTABLE`中建立具有 關鍵字的使用者定義函數，並在索引建立指令碼中參考它。如果在一般結構描述中建立使用者定義的函數 （從先前的範例），請更新顯示的 `search_path`。<pre>ALTER ROLE <ROLENAME> set search_path=$user, COMMON;</pre> | DBA、PostgreSQL 開發人員 | 

### 驗證索引建立
<a name="validate-index-creation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證索引建立。 | 驗證是否需要根據查詢存取模式建立索引。 | DBA | 
| 驗證索引是否可以使用。 | 若要檢查 PostgreSQL Optimizer 是否收取函數型索引，請使用 explain 或 explain analysis 執行 SQL 陳述式。使用*其他資訊*區段中的程式碼。如果可能，也請收集資料表統計資料。如果您注意到解釋計畫，PostgreSQL 最佳化工具已因為述詞條件而選擇以函數為基礎的索引。 | DBA | 

## 相關資源
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-resources"></a>
+ [以函數為基礎的索引 ](https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_indexes.htm#ADFNS00505)(Oracle 文件）
+ [運算式上的索引](https://www.postgresql.org/docs/9.4/indexes-expressional.html) (PostgreSQL 文件）
+ [PostgreSQL 波動](https://www.postgresql.org/docs/current/xfunc-volatility.html) (PostgreSQL 文件）
+ [PostgreSQL search\$1path](https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH) (PostgreSQL 文件）
+ [Oracle 資料庫 19c 至 Amazon Aurora PostgreSQL 遷移手冊](https://docs.aws.amazon.com/dms/latest/oracle-to-aurora-postgresql-migration-playbook/chap-oracle-aurora-pg.html) 

## 其他資訊
<a name="migrate-function-based-indexes-from-oracle-to-postgresql-additional"></a>

**建立包裝函式**

```
CREATE OR REPLACE FUNCTION myschema.to_char(var1 timestamp without time zone, var2 varchar) RETURNS varchar AS $BODY$ select to_char(var1, 'YYYYMMDD'); $BODY$ LANGUAGE sql IMMUTABLE;
```

**使用包裝函式建立索引**

```
postgres=# create function common.to_char(var1 timestamp without time zone, var2 varchar) RETURNS varchar AS $BODY$ select to_char(var1, 'YYYYMMDD'); $BODY$ LANGUAGE sql IMMUTABLE;
CREATE FUNCTION
postgres=# create index funcindex_idx on funcindex(common.to_char(col1,'DD-MM-YYYY HH24:MI:SS'));
CREATE INDEX
```

**檢查函數的波動**

```
SELECT DISTINCT p.proname as "Name",p.provolatile as "volatility" FROM pg_catalog.pg_proc p
 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
 LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
 WHERE n.nspname OPERATOR(pg_catalog.~) '^(pg_catalog)$' COLLATE pg_catalog.default AND p.proname='to_char'GROUP BY p.proname,p.provolatile
ORDER BY 1;
```

**驗證索引是否可以使用**

```
explain analyze <SQL>
 
 
postgres=# explain select col1 from funcindex where common.to_char(col1,'DD-MM-YYYY HH24:MI:SS') = '09-08-2022 16:00:57';
                                                       QUERY PLAN
------------------------------------------------------------------------------------------------------------------------
 Index Scan using funcindex_idx on funcindex  (cost=0.42..8.44 rows=1 width=8)
   Index Cond: ((common.to_char(col1, 'DD-MM-YYYY HH24:MI:SS'::character varying))::text = '09-08-2022 16:00:57'::text)
(2 rows)
```

# 使用延伸模組將 Oracle 原生函數遷移至 PostgreSQL
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions"></a>

*Pinesh Singal，Amazon Web Services*

## 總結
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-summary"></a>

此遷移模式提供step-by-step指引，透過修改 `aws_oracle_ext`和`orafce`擴充功能至 PostgreSQL () 原生內建程式碼，將 Amazon Relational Database Service (Amazon RDS`psql`) for Oracle 資料庫執行個體遷移至 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL 相容版本資料庫。這可節省處理時間。

模式說明離線手動遷移策略，多 TB Oracle 來源資料庫具有大量交易時不會停機。

遷移程序使用 AWS Schema Conversion Tool (AWS SCT) 搭配 `aws_oracle_ext`和 `orafce`延伸模組，將 Amazon RDS for Oracle 資料庫結構描述轉換為 Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫結構描述。然後，程式碼會手動變更為 PostgreSQL 支援的原生`psql`內建程式碼。這是因為延伸呼叫會影響 PostgreSQL 資料庫伺服器上的程式碼處理，而且並非所有延伸程式碼都完全抱怨或與 PostgreSQL 程式碼相容。

此模式主要著重於使用 AWS SCT 和擴充功能 `aws_oracle_ext` 和 手動遷移 SQL 程式碼`orafce`。您可以將已使用的延伸模組轉換為原生 PostgreSQL (`psql`) 內建。然後，您移除延伸模組的所有參考，並相應地轉換程式碼。

## 先決條件和限制
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶 
+ 作業系統 (Windows 或 Mac) 或 Amazon EC2 執行個體 （啟動和執行中） 
+ Orafce

**限制**

並非所有使用 `aws_oracle_ext`或 `orafce`擴充功能的 Oracle 函數都可以轉換為原生 PostgreSQL 函數。它可能需要手動重新作業，以便使用 PostgreSQL 程式庫進行編譯。

使用 AWS SCT 擴充功能的一個缺點是執行和擷取結果時效能緩慢。您可以從 Oracle `SYSDATE`函數遷移到所有三個代碼 (`aws_oracle_ext`、 和`psql`預設值） 之間的 PostgreSQL `NOW()`函數的簡易 [PostgreSQL EXPLAIN 計劃](https://www.postgresql.org/docs/current/sql-explain.html) （陳述式的執行計劃） 了解其成本`orafce`，如隨附文件中*效能比較檢查*一節所述。

**產品版本**
+ **Source：**Amazon RDS for Oracle 資料庫 10.2 和更新版本 （適用於 10.x)、11g (11.2.0.3.v1 和更新版本），以及 Enterprise Edition、Standard Edition、Standard Edition 1 和 Standard Edition 2 最多 12.2、18c 和 19c （和更新版本）
+ **目標**：Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫 9.4 及更新版本 （適用於 9.x)、10.x、11.x、12.x、13.x 及 14.x （及更新版本）
+ **AWS SCT**：最新版本 （此模式已使用 1.0.632 進行測試）
+ **Orafce**：最新版本 （此模式已使用 3.9.0 進行測試）

## Architecture
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-architecture"></a>

**來源技術堆疊**
+ 版本為 12.1.0.2.v18 的 Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**
+ 具有 11.5 版的 Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫執行個體

**資料庫遷移架構**

下圖代表來源 Oracle 和目標 PostgreSQL 資料庫之間的資料庫遷移架構。架構涉及 AWS Cloud、虛擬私有雲端 (VPC)、可用區域、私有子網路、Amazon RDS for Oracle 資料庫、AWS SCT、Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫、Oracle (`aws_oracle_ext` 和 `orafce`) 擴充功能，以及結構化查詢語言 (SQL) 檔案。

![\[程序會在下列清單中說明。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/158847bb-27ef-4915-a9ca-7d87073792c1/images/234b824a-bfe5-4ef0-9fa7-8401370b92a5.png)


1. 啟動 Amazon RDS for Oracle 資料庫執行個體 （來源資料庫）。

1. 使用 AWS SCT 搭配 `aws_oracle_ext`和 `orafce`延伸套件，將原始碼從 Oracle 轉換為 PostreSQL。

1. 轉換會產生 PostgreSQL 支援的遷移 .sql 檔案。

1. 手動將未轉換的 Oracle 延伸程式碼轉換為 PostgreSQL (`psql`) 程式碼。

1. 手動轉換會產生 PostgreSQL 支援的轉換後 .sql 檔案。

1. 在 Amazon RDS for PostgreSQL 資料庫執行個體 （目標資料庫） 上執行這些 .sql 檔案。

## 工具
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-tools"></a>

**工具**

*AWS 服務*
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) - AWS Schema Conversion Tool (AWS SCT) 會將您現有的資料庫結構描述從一個資料庫引擎轉換為另一個資料庫引擎。您可以轉換關聯式線上交易處理 (OLTP) 結構描述或資料倉儲結構描述。轉換後的結構描述適用於 Amazon RDS for MySQL 資料庫執行個體、Amazon Aurora 資料庫叢集、Amazon RDS for PostgreSQL 資料庫執行個體或 Amazon Redshift 叢集。轉換後的結構描述也可以與 Amazon EC2 執行個體上的資料庫搭配使用，或儲存為 Amazon S3 儲存貯體中的資料。

  AWS SCT 提供專案型使用者介面，可將來源資料庫的資料庫結構描述自動轉換為與您目標 Amazon RDS 執行個體相容的格式。 

  您可以使用 AWS SCT 從 Oracle 來源資料庫遷移至上述任何目標。您可以使用 AWS SCT 匯出來源資料庫物件定義，例如結構描述、檢視、預存程序和函數。 

  您可以使用 AWS SCT 將資料從 Oracle 轉換為 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL 相容版本。 

  在此模式中，您可以使用 AWS SCT，使用延伸模組 和 將 Oracle 程式碼轉換`aws_oracle_ext`並遷移至 PostgreSQL`orafce`，並手動將延伸程式碼遷移至`psql`預設或原生內建程式碼。
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_ExtensionPack.html) 延伸套件是一種附加元件模組，可模擬來源資料庫中存在的函數，而這些函數在將物件轉換為目標資料庫時需要。您需要轉換資料庫結構描述，才能安裝 AWS SCT 延伸套件。

  當您轉換資料庫或資料倉儲結構描述時，AWS SCT 會將額外的結構描述新增至目標資料庫。此結構描述會實作來源資料庫的 SQL 系統功能，當您將已轉換的結構描述寫入至目標資料庫時需要這些功能。這個額外的結構描述稱為延伸套件結構描述。

  OLTP 資料庫的延伸套件結構描述會根據來源資料庫命名。對於 Oracle 資料庫，延伸套件結構描述為 `AWS_ORACLE_EXT`。

*其他工具*
+ [Orafce](https://github.com/orafce/orafce) – Orafce 是實作 Oracle 相容函數、資料類型和套件的模組。這是具有 Berkeley 來源分佈 (BSD) 授權的開放原始碼工具，因此任何人都可以使用它。`orafce` 模組適用於從 Oracle 遷移到 PostgreSQL，因為它在 PostgreSQL 中實作了許多 Oracle 函數。

 

**Code**

如需從 Oracle 到 PostgreSQL 的所有常用和遷移程式碼清單，以避免使用 AWS SCT 延伸程式碼，請參閱隨附的文件。

## 史詩
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-epics"></a>

### 設定 Amazon RDS for Oracle 來源資料庫
<a name="configure-the-amazon-rds-for-oracle-source-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Oracle 資料庫執行個體。 | 從 Amazon RDS 主控台建立 Amazon RDS for Oracle 或 Aurora PostgreSQL 相容資料庫執行個體。 | 一般 AWS、DBA | 
| 設定安全群組。 | 設定傳入和傳出安全群組。 | 一般 AWS | 
| 建立資料庫。 | 使用所需的使用者和結構描述建立 Oracle 資料庫。 | 一般 AWS、DBA | 
| 建立物件。 | 在結構描述中建立物件和插入資料。 | DBA | 

### 設定 Amazon RDS for PostgreSQL 目標資料庫
<a name="configure-the-amazon-rds-for-postgresql-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 PostgreSQL 資料庫執行個體。 | 從 Amazon RDS 主控台建立 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL 資料庫執行個體。 | 一般 AWS、DBA | 
| 設定安全群組。 | 設定傳入和傳出安全群組。 | 一般 AWS | 
| 建立資料庫。 | 使用所需的使用者和結構描述建立 PostgreSQL 資料庫。 | 一般 AWS、DBA | 
| 驗證擴充功能。 | 確定`aws_oracle_ext``orafce`已在 PostgreSQL 資料庫中正確安裝和設定 和 。 | DBA | 
| 確認 PostgreSQL 資料庫可用。 | 確定 PostgreSQL 資料庫已啟動並執行。 | DBA | 

### 使用 AWS SCT 和擴充功能將 Oracle 結構描述遷移至 PostgreSQL
<a name="migrate-the-oracle-schema-into-postgresql-using-aws-sct-and-the-extensions"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS SCT。 | 安裝最新版本的 AWS SCT。 | DBA | 
| 設定 AWS SCT。 | 使用適用於 Oracle () 和 PostgreSQL () 的 Java Database Connectivity (JDBC`ojdbc8.jar`) 驅動程式設定 AWS SCT`postgresql-42.2.5.jar`。 | DBA | 
| 啟用 AWS SCT 延伸套件或範本。 | 在 AWS SCT **專案設定**下，使用 Oracle 資料庫結構描述的 `aws_oracle_ext`和 `orafce`擴充功能啟用內建函數實作。 | DBA | 
| 轉換結構描述。 | 在 AWS SCT 中，選擇**轉換結構描述**，將結構描述從 Oracle 轉換為 PostgreSQL，並產生 .sql 檔案。 | DBA | 

### 將 AWS SCT 延伸程式碼轉換為 psql 程式碼
<a name="convert-aws-sct-extension-code-to-psql-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 手動轉換程式碼。 | 手動將延伸支援程式碼的每一行轉換為`psql`預設內建程式碼，如附加文件中詳述。例如，將 `AWS_ORACLE_EXT.SYSDATE()`或 `ORACLE.SYSDATE()`變更為 `NOW()`。 | DBA | 
| 驗證程式碼 | （選用） 在 PostgreSQL 資料庫中暫時執行程式碼，以驗證每一行程式碼。 | DBA | 
| 在 PostgreSQL 資料庫中建立物件。 | 若要在 PostgreSQL 資料庫中建立物件，請執行由 AWS SCT 產生並在前兩個步驟中修改的 .sql 檔案。 | DBA | 

## 相關資源
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-resources"></a>
+ 資料庫
  + [Amazon RDS 上的 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)
  + [Amazon RDS 上的 PostgreSQL ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)
  + [使用 Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)
  + [PostgreSQL EXPLAIN 計畫](https://www.postgresql.org/docs/current/sql-explain.html)
+ AWS SCT
  + [AWS Schema Conversion Tool概觀](https://aws.amazon.com/dms/schema-conversion-tool/)
  + [AWS SCT 使用者指南](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
  + [使用 AWS SCT 使用者介面](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html)
  + [使用 Oracle 資料庫做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)
+ AWS SCT 的延伸模組
  + [使用 AWS SCT 延伸套件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_ExtensionPack.html)
  + [Oracle 功能 (en)](https://postgres.cz/wiki/Oracle_functionality_(en))
  + [PGXN 或afce](https://pgxn.org/dist/orafce/)
  + [GitHub 或afce](https://github.com/orafce/orafce)

## 其他資訊
<a name="migrate-oracle-native-functions-to-postgresql-using-extensions-additional"></a>

如需詳細資訊，請遵循詳細的命令搭配語法和範例，以手動轉換附加文件中的程式碼。

## 附件
<a name="attachments-158847bb-27ef-4915-a9ca-7d87073792c1"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/158847bb-27ef-4915-a9ca-7d87073792c1/attachments/attachment.zip)

# 使用 AWS DMS 將 Db2 資料庫從 Amazon EC2 遷移至 Aurora MySQL 相容
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms"></a>

*Pinesh Singal，Amazon Web Services*

## 總結
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-summary"></a>

將 [IBM Db2 for LUW 資料庫](https://www.ibm.com/docs/en/db2/11.5?topic=federation)遷移至 [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 之後，請考慮移至 Amazon Web Services (AWS) 雲端原生資料庫來重新架構資料庫。此模式涵蓋將 [Amazon](https://docs.aws.amazon.com/ec2/) EC[Db2](https://www.ibm.com/docs/en/db2/11.5)2 遷移至 AWS 上的 [Amazon Aurora MySQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraMySQL.html)資料庫。 EC2  

模式說明線上遷移策略，對於具有大量交易的多 TB Db2 來源資料庫，停機時間最短。 

此模式使用 [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 將 Db2 資料庫結構描述轉換為 Aurora MySQL 相容結構描述。然後， 模式會使用 [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 將資料從 Db2 資料庫遷移至 Aurora MySQL 相容資料庫。非由 AWS SCT 轉換的程式碼需要手動轉換。

## 先決條件和限制
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 具有虛擬私有雲端 (VPC) 的作用中 AWS 帳戶
+ AWS SCT
+ AWS DMS

**產品版本**
+ AWS SCT 最新版本
+ 適用於 Linux 的 Db2 11.1.4.4 版及更新版本

## Architecture
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ 安裝在 EC2 執行個體上的 DB2/Linux x86-64 位元 EC2  

**目標技術堆疊**
+ Amazon Aurora MySQL 相容版本資料庫執行個體

**來源和目標架構**

下圖顯示來源 Db2 與目標 Aurora MySQL 相容資料庫之間的資料遷移架構。AWS 雲端上的架構包含虛擬私有雲端 (VPC) （虛擬私有雲端）、可用區域、Db2 執行個體和 AWS DMS 複寫執行個體的公有子網路，以及 Aurora MySQL 相容資料庫的私有子網路。

![\[來源 Db2 與目標 Aurora MySQL 相容資料庫之間的資料遷移架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5abfccc4-148c-4794-8d80-e3c122679125/images/f30664f8-2d6a-4448-8d5c-cff3988a52c7.png)


## 工具
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-tools"></a>

**AWS 服務**
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。AWS SCT 支援 LUW 9.1、9.5、9.7、10.1、10.5、11.1 和 11.5 版的來源 IBM Db2。

## 最佳實務
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-best-practices"></a>

如需最佳實務，請參閱 [ AWS Database Migration Service 的最佳實務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.html)。

## 史詩
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-epics"></a>

### 設定來源 IBM Db2 資料庫
<a name="configure-the-source-ibm-db2-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon EC2 上建立 IBM Db2 資料庫。 Amazon EC2 | 您可以使用來自 AWS Marketplace 的 Amazon Machine Image (AMI)，或在 EC2Db2 執行個體上安裝 Db2 軟體，在 EC2 執行個體上建立 IBM Db2 資料庫。 EC2 透過選取與內部部署資料庫類似的 AMI for IBM Db2 （例如 [IBM Db2 v11.5.7 RHEL 7.9](https://aws.amazon.com/marketplace/pp/prodview-aclrjj4hq2ols?sr=0-1&ref_=beagle&applicationId=AWS-EC2-Console)) 來啟動 EC2 執行個體。 | DBA、一般 AWS | 
| 設定安全群組。 | 分別使用連接埠 22 和 50000 設定 SSH （安全殼層） 和 TCP 的 VPC 安全群組傳入規則。 | 一般 AWS | 
| 建立資料庫執行個體。 | 建立新的執行個體 （使用者） 和資料庫 （結構描述），或使用預設`db2inst1`執行個體和範例資料庫。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | DBA | 
| 確認 Db2 資料庫執行個體可用。 | 若要確認 Db2 資料庫執行個體已啟動並執行，請使用 `Db2pd -`命令。 | DBA | 

### 設定目標 Aurora MySQL 相容資料庫
<a name="configure-the-target-aurora-mysql-compatible-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Aurora MySQL 相容資料庫。 | 從 AWS RDS 服務建立具有 MySQL 相容性資料庫的 Amazon Aurora[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | DBA、一般 AWS | 
| 設定安全群組。 | 設定 SSH 和 TCP 連線的 VPC 安全群組傳入規則。 | 一般 AWS | 
| 確認 Aurora 資料庫可用。 | 若要確保 Aurora MySQL 相容資料庫已啟動並執行，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | DBA | 

### 設定和執行 AWS SCT
<a name="configure-and-run-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS SCT。 | 下載並安裝最新版本的 [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html) （最新版本 1.0.628)。 | 一般 AWS | 
| 設定 AWS SCT。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | 一般 AWS | 
| 建立 AWS SCT 專案。 | 建立 AWS SCT 專案和報告，使用 Db2 for LUW 做為來源資料庫引擎，並使用 Aurora MySQL 相容於目標資料庫引擎。若要識別連線至 Db2 for LUW 資料庫所需的權限，請參閱[使用 Db2 LUW 做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.DB2LUW.html)。 | 一般 AWS | 
| 驗證物件。 | 選擇**載入結構描述**，驗證物件。更新目標資料庫上任何不正確的物件：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | DBA、一般 AWS | 

### 設定和執行 AWS DMS
<a name="configure-and-run-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立複寫執行個體。 | 登入 AWS 管理主控台，導覽至 AWS DMS 服務，並使用您為來源和目標資料庫設定的 VPC 安全群組的有效設定來建立複寫執行個體。 | 一般 AWS | 
| 建立端點。 | 建立 Db2 資料庫的來源端點，並為 Aurora MySQL 相容資料庫建立目標端點：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | 一般 AWS | 
| 建立遷移任務。 | 為完全載入和 CDC 或資料驗證建立單一遷移任務或多個遷移任務：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | 一般 AWS | 
| 規劃生產執行。 | 與應用程式擁有者等利益相關者確認停機時間，以在生產系統中執行 AWS DMS。 | 遷移潛在客戶 | 
| 執行遷移任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | 一般 AWS | 
| 驗證資料。 | 檢閱來源 Db2 和目標 MySQL 資料庫中的遷移任務結果和資料：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | DBA | 
| 停止遷移任務。 | 成功完成資料驗證後，停止驗證遷移任務。 | 一般 AWS | 

## 疑難排解
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| AWS SCT 來源和目標測試連線失敗。 | 設定 JDBC 驅動程式版本和 VPC 安全群組傳入規則，以接受傳入流量。 | 
| Db2 來源端點測試執行失敗。 | 設定額外的連線設定 `CurrentLSN=<scan>;`。 | 
| AWSDMS 任務無法連線至 Db2 來源，並傳回下列錯誤。`database is recoverable if either or both of the database configuration parameters LOGARCHMETH1 and LOGARCHMETH2 are set to ON` | 若要避免錯誤，請執行下列命令：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.html) | 

## 相關資源
<a name="migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms-resources"></a>

**Amazon EC2**
+ [Amazon EC2](https://aws.amazon.com/ec2/)
+ [Amazon EC2 使用者指南](https://docs.aws.amazon.com/ec2/)

**資料庫**
+ [IBM Db2 資料庫](https://www.ibm.com/products/db2-database)
+ [Amazon Aurora](https://aws.amazon.com/rds/aurora/)
+ [使用 Amazon Aurora MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraMySQL.html)

**AWS SCT**
+ [AWS DMS 結構描述轉換](https://aws.amazon.com/dms/schema-conversion-tool/)
+ [AWS Schema Conversion Tool使用者指南](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [使用 AWS SCT 使用者介面](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html)
+ [使用 IBM Db2 LUW 做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.DB2LUW.html)

**AWS DMS**
+ [AWS Database Migration Service](https://aws.amazon.com/dms/)
+ [AWS Database Migration Service 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [資料遷移的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.html)
+ [資料遷移的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.html)
+ [AWS Database Migration Service 和 AWS Schema Conversion Tool 現在支援 IBM Db2 LUW 作為來源](https://aws.amazon.com/blogs/database/aws-database-migration-service-and-aws-schema-conversion-tool-now-support-ibm-db2-as-a-source/) （部落格文章）
+ [將執行關聯式資料庫的應用程式遷移至 AWS](https://d1.awsstatic.com/whitepapers/Migration/migrating-applications-to-aws.pdf)

# 使用 AWS DMS 將 Microsoft SQL Server 資料庫從 Amazon EC2 遷移至 Amazon DocumentDB
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms"></a>

*Umamaheswara Nooka，Amazon Web Services*

## 總結
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms-summary"></a>

此模式說明如何使用 AWS Database Migration Service (AWS DMS) 將 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上託管的 Microsoft SQL Server 資料庫遷移至 Amazon DocumentDB （具有 MongoDB 相容性） 資料庫。

AWS DMS 複寫任務會讀取 SQL Server 資料庫的資料表結構、在 Amazon DocumentDB 中建立對應的集合，以及執行完全載入遷移。

您也可以使用此模式將現場部署 SQL Server 或 Amazon Relational Database Service (Amazon RDS) for SQL Server 資料庫執行個體遷移至 Amazon DocumentDB。如需詳細資訊，請參閱 [AWS 規範指引網站上的將 Microsoft SQL Server 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-sql-server/welcome.html)指南。

## 先決條件和限制
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ EC2 執行個體上現有的 SQL Server 資料庫。
+ 修正 SQL Server 資料庫中指派給 AWS DMS 的資料庫 (**db\$1owner**) 角色。如需詳細資訊，請參閱 SQL Server 文件中的[資料庫層級角色](https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles?view=sql-server-ver15)。 
+ 熟悉使用 `mongodump`、`mongoexport`、 `mongorestore`和 `mongoimport`公用程式將[資料移入和移出 Amazon DocumentDB 叢集](https://docs.aws.amazon.com/documentdb/latest/developerguide/backup_restore-dump_restore_import_export_data.html)。
+ [Microsoft SQL Server Management Studio](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver15)，已安裝並設定。

**限制**
+ Amazon DocumentDB 中的叢集大小限制為 64 TB。如需詳細資訊，請參閱 Amazon DocumentDB 文件中的[叢集限制](https://docs.aws.amazon.com/documentdb/latest/developerguide/limits.html#limits-cluster)。 
+ AWS DMS 不支援將多個來源資料表合併為單一 Amazon DocumentDB 集合。
+ 如果 AWS DMS 在沒有主索引鍵的情況下處理來源資料表的任何變更，它會忽略來源資料表中的大型物件 (LOB) 資料欄。

## Architecture
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ Amazon EC2

**目標技術堆疊**
+ Amazon DocumentDB

**目標架構**

![\[AWS 雲端 architecture showing VPC with private DB subnet and components for SQL Server and DocumentDB.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f186220b-5a94-48b2-840d-f04aedf51651/images/00962b85-8b71-49df-b84a-3adcbc9ad3a3.png)


## 工具
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms-tools"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html) – AWS Database Migration Service (AWS DMS) 可協助您輕鬆安全地遷移資料庫。
+ [Amazon DocumentDB](https://docs.aws.amazon.com/documentdb/latest/developerguide/get-started-guide.html) – Amazon DocumentDB （與 MongoDB 相容） 是一種快速、可靠且全受管的資料庫服務。
+ [Amazon EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html) – Amazon Elastic Compute Cloud (Amazon EC2) 在 AWS 雲端中提供可擴展的運算容量。
+ [Microsoft SQL Server](https://docs.microsoft.com/en-us/sql/sql-server/?view=sql-server-ver15) – SQL Server 是一種關聯式資料庫管理系統。
+ [SQL Server Management Studio (SSMS)](https://docs.microsoft.com/en-us/sql/ssms/sql-server-management-studio-ssms?view=sql-server-ver15) – SSMS 是管理 SQL Server 的工具，包括存取、設定和管理 SQL Server 元件。

## 史詩
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms-epics"></a>

### 建立和設定 VPC
<a name="create-and-configure-a-vpc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC。 | 登入 AWS 管理主控台並開啟 Amazon VPC 主控台。建立具有 IPv4 CIDR 區塊範圍的虛擬私有雲端 (VPC)。 | 系統管理員 | 
| 建立安全群組和網路 ACLs。 | 在 Amazon VPC 主控台上，根據您的需求為您的 VPC 建立安全群組和網路存取控制清單 （網路 ACLs)。您也可以使用這些組態的預設設定。如需此案例和其他案例的詳細資訊，請參閱「相關資源」一節。 | 系統管理員 | 

### 建立和設定 Amazon DocumentDB 叢集
<a name="create-and-configure-the-amazon-documentdb-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  建立 Amazon DocumentDB 叢集。 | 開啟 Amazon DocumentDB 主控台，然後選擇「叢集」。選擇「建立」，並使用一個執行個體建立 Amazon DocumentDB 叢集。重要：請務必使用 VPC 的安全群組來設定此叢集。 | 系統管理員  | 
|  安裝 mongo shell。 | mongo Shell 是一個命令行公用程式，可以使用它來連線和查詢 Amazon DocumentDB 叢集。若要安裝它，請執行 "/etc/yum.repos.d/mongodb-org-3.6.repo" 命令來建立儲存庫檔案。執行「sudo yum install -y mongodb-org-shell」命令來安裝 mongo shell。若要加密傳輸中的資料，請下載 Amazon DocumentDB 的公有金鑰，然後連接至您的 Amazon DocumentDB 執行個體。如需這些步驟的詳細資訊，請參閱「相關資源」一節。 | 系統管理員  | 
| 在 Amazon DocumentDB 叢集中建立資料庫。 | 使用資料庫的名稱執行「使用」命令，在 Amazon DocumentDB 叢集中建立資料庫。 | 系統管理員  | 

### 建立和設定 AWS DMS 複寫執行個體
<a name="create-and-configure-the-aws-dms-replication-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 複寫執行個體。 | 開啟 AWS DMS 主控台，然後選擇「建立複寫執行個體」。輸入複寫任務的名稱和描述。選擇執行個體類別、引擎版本、儲存體、VPC、異地同步備份，並使其可公開存取。選擇「進階」索引標籤來設定網路和加密設定。指定維護設定，然後選擇「建立複寫執行個體」。 | 系統管理員  | 
| 設定 SQL Server 資料庫。 | 登入 Microsoft SQL Server 並新增傳入規則，以在來源端點和 AWS DMS 複寫執行個體之間進行通訊。使用複寫執行個體的私有 IP 地址做為來源。重要：複寫執行個體和目標端點應該位於相同的 VPC 上。如果來源和複寫執行個體VPCs 不同，請使用安全群組中的替代來源。 | 系統管理員  | 

### 在 AWS DMS 中建立和測試來源和目標端點
<a name="create-and-test-the-source-and-target-endpoints-in-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立來源和目標資料庫端點。 | 開啟 AWS DMS 主控台，然後選擇「連接來源和目標資料庫端點」。指定來源和目標資料庫的連線資訊。如有必要，請選擇「進階」索引標籤來設定「額外連線屬性」的值。在端點組態中下載並使用憑證套件。 | 系統管理員  | 
| 測試端點連線。 | 選擇「執行測試」來測試連線。透過驗證安全群組設定以及來自來源和目標資料庫執行個體的 AWS DMS 複寫執行個體連線，對任何錯誤訊息進行故障診斷。 | 系統管理員  | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 遷移任務。 | 在 AWS DMS 主控台上，選擇「任務」、「建立任務」。指定任務選項，包括來源和目的地端點名稱，以及複寫執行個體名稱。在「遷移類型」下，選擇「遷移現有資料」和「僅複寫資料變更」。選擇「開始任務」。 | 系統管理員  | 
| 執行 AWS DMS 遷移任務。 | 在「任務設定」下，指定資料表準備模式的設定，例如「不執行任何動作」、「目標上的捨棄資料表」、「截斷」和「在複寫中包含 LOB 資料欄」。設定 AWS DMS 將接受的最大 LOB 大小，然後選擇「啟用記錄」。將「進階設定」保留為預設值，然後選擇「建立任務」。 | 系統管理員  | 
| 監控遷移。 | 在 AWS DMS 主控台上，選擇「任務」，然後選擇您的遷移任務。選擇「任務監控」來監控您的任務。完成完全載入遷移並套用快取變更時，任務會停止。 | 系統管理員  | 

### 測試並驗證遷移
<a name="test-and-verify-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  使用 mongo shell 連線至 Amazon DocumentDB 叢集。 | 開啟 Amazon DocumentDB 主控台，選擇「叢集」下的叢集。在「連線和安全性」索引標籤中，選擇「使用 mongo shell 連線至此叢集」。 | 系統管理員  | 
| 驗證遷移的結果。 | 使用資料庫的名稱執行「使用」命令，然後執行「顯示集合」命令。使用資料庫的名稱執行 "db. .count()；" 命令。如果結果與您的來源資料庫相符，則遷移成功。 | 系統管理員  | 

## 相關資源
<a name="migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms-resources"></a>

**建立和設定 VPC**
+ [為您的 VPC 建立安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#CreatingSecurityGroups)
+ [建立網路 ACL](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)

** **

**建立和設定 Amazon DocumentDB 叢集**
+ [建立 Amazon DocumentDB 叢集](https://docs.aws.amazon.com/documentdb/latest/developerguide/get-started-guide.html#cloud9-cluster)
+ [安裝 Amazon DocumentDB 的 mongo shell](https://docs.aws.amazon.com/documentdb/latest/developerguide/get-started-guide.html#cloud9-mongoshell)
+ [連接至 Amazon DocumentDB 叢集](https://docs.aws.amazon.com/documentdb/latest/developerguide/get-started-guide.html#cloud9-connectcluster)

** **

**建立和設定 AWS DMS 複寫執行個體**
+ [使用公有和私有複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.html#CHAP_ReplicationInstance.PublicPrivate)

** **

**在 AWS DMS 中建立和測試來源和目標端點**
+ [使用 Amazon DocumentDB 做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/target.docdb.html)
+ [使用 SQL Server 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html)
+ [使用 AWS DMS 端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.html)

** **

**遷移資料**
+ [遷移至 Amazon DocumentDB](https://docs.aws.amazon.com/documentdb/latest/developerguide/docdb-migration.html)

** **

**其他資源**
+ [使用 SQL Server 做為 AWS DMS 來源的限制](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html#CHAP_Source.SQLServer.Limitations) 
+ [如何使用 Amazon DocumentDB 大規模建置和管理應用程式](https://aws.amazon.com/blogs/database/how-to-use-amazon-documentdb-with-mongodb-compatibility-to-build-and-manage-applications-at-scale/)

# 將內部部署 ThoughtSpot Falcon 資料庫遷移至 Amazon Redshift
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift"></a>

*Battulga Purevragchaa 和 Antony Prasad Thevaraj，Amazon Web Services*

## 摘要
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift-summary"></a>

內部部署資料倉儲需要大量的管理時間和資源，尤其是大型資料集。建置、維護和成長這些倉儲的財務成本也非常高。為了協助管理成本、降低擷取、轉換和載入 (ETL) 複雜性，並隨著資料成長提供效能，您必須持續選擇要載入的資料和要封存的資料。

透過將內部部署 [ThoughtSpot Falcon 資料庫](https://docs.thoughtspot.com/software/latest/data-caching)遷移至 Amazon Web Services (AWS) 雲端，除了降低整體基礎設施成本之外，您還可以存取雲端型資料湖和資料倉儲，以提高業務敏捷性、安全性和應用程式可靠性。Amazon Redshift 有助於大幅降低資料倉儲的成本和營運開銷。您也可以使用 Amazon Redshift Spectrum 來分析其原生格式的大量資料，而無需載入資料。

此模式說明將 ThoughtSpot Falcon 資料庫從現場部署資料中心遷移至 AWS 雲端上 Amazon Redshift 資料庫的步驟和程序。

## 先決條件和限制
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 在內部部署資料中心託管的 ThoughtSpot Falcon 資料庫

**產品版本**
+ ThoughtSpot 7.0.1 版 

## Architecture
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift-architecture"></a>

![\[將 ThoughtSpot Falcon 資料庫從內部部署資料中心遷移至 Amazon Redshift。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/b0ca29f4-b269-4b57-b386-738693a6b334/images/2b483990-1f30-439c-ba13-dc0cb0650360.png)


 

該圖顯示以下工作流程：

1. 資料託管在內部部署關聯式資料庫中。

1. AWS Schema Conversion Tool (AWS SCT) 會轉換與 Amazon Redshift 相容的資料定義語言 (DDL)。

1. 建立資料表之後，您可以使用 AWS Database Migration Service (AWS DMS) 遷移資料。

1. 資料會載入 Amazon Redshift。

1. 如果您使用 Redshift Spectrum 或已在 Amazon S3 中託管資料，資料會儲存在 Amazon S3) 中。

## 工具
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift-tools"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) – AWS Data Migration Service (AWS DMS) 可協助您快速且安全地將資料庫遷移至 AWS。
+ [Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html) – Amazon Redshift 是一種快速、全受管的 PB 級資料倉儲服務，可讓您使用現有的商業智慧工具有效率地分析所有資料，既簡單又經濟實惠。
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) – AWS Schema Conversion Tool (AWS SCT) 會將您現有的資料庫結構描述從一個資料庫引擎轉換為另一個資料庫引擎。

## 史詩
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別適當的 Amazon Redshift 組態。 | 根據您的需求和資料磁碟區識別適當的 Amazon Redshift 叢集組態。 如需詳細資訊，請參閱 [Amazon Redshift 文件中的 Amazon Redshift 叢集](https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html)。 | DBA | 
| 研究 Amazon Redshift 以評估是否符合您的需求。 | 使用 [Amazon Redshift FAQs](https://aws.amazon.com/redshift/faqs/)來了解和評估 Amazon Redshift 是否符合您的需求。 | DBA | 

### 準備目標 Amazon Redshift 叢集
<a name="prepare-the-target-amazon-redshift-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon Redshift 叢集。 | 登入 AWS 管理主控台，開啟 Amazon Redshift 主控台，然後在虛擬私有雲端 (VPC) 中建立 Amazon Redshift 叢集。 如需詳細資訊，請參閱 Amazon Redshift 文件中的[在 VPC 中建立叢集](https://docs.aws.amazon.com/redshift/latest/mgmt/getting-started-cluster-in-vpc.html)。 | DBA | 
| 為您的 Amazon Redshift 資料庫設計執行 PoC。 | 執行資料庫設計的概念驗證 (PoC)，以遵循 Amazon Redshift 最佳實務。 如需詳細資訊，請參閱[《Amazon Redshift 文件》中的為 Amazon Redshift 執行概念驗證](https://docs.aws.amazon.com/redshift/latest/dg/proof-of-concept-playbook.html)。 | DBA | 
| 建立資料庫使用者。 | 在 Amazon Redshift 資料庫中建立使用者，並授予適當的角色以存取結構描述和資料表。 如需詳細資訊，請參閱《Amazon Redshift 文件》中的[授予使用者或使用者群組的存取權限](https://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html)。 | DBA | 
| 將組態設定套用至目標資料庫。 | 根據您的需求將組態設定套用至 Amazon Redshift 資料庫。 如需啟用資料庫、工作階段和伺服器層級參數的詳細資訊，請參閱 Amazon Redshift 文件中的[組態參考](https://docs.aws.amazon.com/redshift/latest/dg/cm_chap_ConfigurationRef.html)。 | DBA | 

### 在 Amazon Redshift 叢集中建立物件
<a name="create-objects-in-the-amazon-redshift-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon Redshift 中使用 DDL 手動建立資料表。 | （選用） 如果您使用 AWS SCT，系統會自動建立資料表。不過，如果複寫 DDLs時發生失敗，您必須手動建立資料表 | DBA | 
| 為 Redshift Spectrum 建立外部資料表。 | 使用 Amazon Redshift Spectrum 的外部結構描述建立外部資料表。若要建立外部資料表，您必須是外部結構描述或[資料庫超級使用者的](https://docs.aws.amazon.com/redshift/latest/dg/r_superusers.html)擁有者。 如需詳細資訊，請參閱[《Amazon Redshift 文件》中的為 Amazon Redshift Spectrum 建立外部資料表](https://docs.aws.amazon.com/redshift/latest/dg/c-spectrum-external-tables.html)。 | DBA | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS DMS 遷移資料。 | 在 Amazon Redshift 資料庫中建立資料表的 DDL 之後，請使用 AWS DMS 將資料遷移至 Amazon Redshift。如需詳細步驟和說明，請參閱 [AWS DMS 文件中的使用 Amazon Redshift 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Redshift.html)。 | DBA | 
| 使用 COPY 命令載入資料。 | 使用 Amazon Redshift `COPY`命令將資料從 Amazon S3 載入至 Amazon Redshift。如需詳細資訊，請參閱[《Amazon Redshift 文件》中的使用 COPY 命令從 Amazon S3 載入](https://docs.aws.amazon.com/redshift/latest/dg/t_loading-tables-from-s3.html)。 | DBA | 

### 驗證 Amazon Redshift 叢集
<a name="validate-the-amazon-redshift-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標記錄。 | 驗證從來源系統載入的來源和目標記錄的資料表計數。 | DBA | 
| 實作效能調校的 Amazon Redshift 最佳實務。 | 實作資料表和資料庫設計的 Amazon Redshift 最佳實務。 如需詳細資訊，請參閱部落格文章 [Amazon Redshift 的前 10 大效能調校技術](https://aws.amazon.com/blogs/big-data/top-10-performance-tuning-techniques-for-amazon-redshift/)。 | DBA | 
| 最佳化查詢效能。 | Amazon Redshift 使用 SQL 型查詢與系統中的資料和物件互動。資料處理語言 (DML) 是 SQL 的子集，可用來檢視、新增、變更和刪除資料。DDL 是您用來新增、變更和刪除資料庫物件的 SQL 子集，例如資料表和檢視。如需詳細資訊，請參閱 Amazon Redshift 文件中的[調校查詢效能](https://docs.aws.amazon.com/redshift/latest/dg/c-optimizing-query-performance.html)。 | DBA | 
| 實作 WLM。 | 您可以使用工作負載管理 (WLM) 來定義多個查詢佇列，並在執行時間將查詢路由至適當的佇列。如需詳細資訊，請參閱《Amazon Redshift 文件》中的[實作工作負載管理](https://docs.aws.amazon.com/redshift/latest/dg/cm-c-implementing-workload-management.html)。 | DBA | 
| 使用並行擴展。 | 透過使用 並行擴展 功能，您可以支援幾乎無限制的並行使用者和並行查詢，並具有一致的快速查詢效能。如需詳細資訊，請參閱《Amazon Redshift 文件》中的[使用並行擴展](https://docs.aws.amazon.com/redshift/latest/dg/concurrency-scaling.html)。 | DBA | 
| 使用 Amazon Redshift 最佳實務進行資料表設計。 | 當您規劃資料庫時，某些重要的資料表設計決策可能會大幅影響整體查詢效能。如需選擇最適合的資料表設計選項的詳細資訊，請參閱 [Amazon Redshift 文件中的設計資料表的 Amazon Redshift 最佳實務](https://docs.aws.amazon.com/redshift/latest/dg/c_designing-tables-best-practices.html)。 | DBA | 
| 在 Amazon Redshift 中建立具體化視觀表。 | 具體化檢視包含根據一或多個基礎資料表上的 SQL 查詢預先計算的結果集。您可以發出`SELECT`陳述式，以與查詢資料庫中其他資料表或檢視相同的方式查詢具體化檢視。如需詳細資訊，請參閱[《Amazon Redshift 文件》中的在 Amazon Redshift 中建立具體化視](https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-overview.html)觀表。 | DBA | 
| 定義資料表之間的聯結。 | 若要在 ThoughtSpot 中同時搜尋多個資料表，您必須透過指定包含兩個資料表中相符資料的欄來定義資料表之間的聯結。這些欄代表聯結`foreign key`的 `primary key`和 。您可以在 Amazon Redshift 或 ThoughtSpot 中使用 `ALTER TABLE`命令來定義它們。如需詳細資訊，請參閱 Amazon Redshift 文件中的 [ALTER TABLE](https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_TABLE.html)。 | DBA | 

### 設定與 Amazon Redshift 的 ThoughtSpot 連線
<a name="set-up-thoughtspot-connection-to-amazon-redshift"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  新增 Amazon Redshift 連線。 | 將 Amazon Redshift 連線新增至您的內部部署 ThoughtSpot Falcon 資料庫。如需詳細資訊，請參閱 ThoughtSpot 文件中的[新增 Amazon Redshift 連線](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-add-connection.html)。 | DBA | 
| 編輯 Amazon Redshift 連線。 | 您可以 編輯 Amazon Redshift 連線來新增資料表和資料欄。如需詳細資訊，請參閱 ThoughtSpot 文件中的[編輯 Amazon Redshift 連線](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-edit-connection.html)。 | DBA | 
| 重新映射 Amazon Redshift 連線。 | 透過編輯新增 Amazon Redshift 連線時建立的來源映射 .yaml 檔案來修改連線參數。 例如，您可以將現有的資料表或資料欄重新映射至現有資料庫連線中的不同資料表或資料欄。ThoughtSpot 建議您在重新映射連線中的資料表或資料欄之前和之後檢查相依性，以確保它們視需要顯示。如需詳細資訊，請參閱 ThoughtSpot 文件中的[重新對應 Amazon Redshift 連線](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-remap-connection.html)。 | DBA | 
| 從 Amazon Redshift 連線刪除資料表。 | （選用） 如果您嘗試移除 Amazon Redshift 連線中的資料表，ThoughtSpot 會檢查相依性，並顯示相依物件的清單。您可以選擇列出的物件來刪除它們，或移除相依性。然後，您可以移除資料表。如需詳細資訊，請參閱 ThoughtSpot 文件中的[從 Amazon Redshift 連線刪除資料表](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-delete-table.html)。 | DBA | 
|  從 Amazon Redshift 連線刪除具有相依物件的資料表。 | （選用） 如果您嘗試刪除具有相依物件的資料表，操作會遭到封鎖。`Cannot delete` 視窗隨即出現，其中包含相依物件的連結清單。移除所有相依性後，您就可以刪除資料表如需詳細資訊，請參閱 ThoughtSpot 文件中的[從 Amazon Redshift 連線刪除具有相依物件的資料表](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-delete-table-dependencies.html)。 | DBA | 
| 刪除 Amazon Redshift 連線。 | （選用） 由於連線可用於多個資料來源或視覺化效果，您必須先刪除使用該連線的所有來源和任務，才能刪除 Amazon Redshift 連線。如需詳細資訊，請參閱 ThoughtSpot 文件中的[刪除 Amazon Redshift 連線](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-delete-connection.html)。 | DBA | 
|  檢查 Amazon Redshift 的連線參考。 | 請務必使用 ThoughtSpot 文件中的[連線參考](https://cloud-docs.thoughtspot.com/admin/ts-cloud/ts-cloud-embrace-redshift-connection-reference.html)，提供 Amazon Redshift 連線所需的資訊。 | DBA | 

## 其他資訊
<a name="migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift-additional"></a>
+ [使用 ThoughtSpot 和 Amazon Redshift 進行任何規模的 AI 驅動分析](https://aws.amazon.com/blogs/apn/ai-driven-analytics-at-any-scale-with-thoughtspot-and-amazon-redshift/)
+ [Amazon Redshift 定價](https://aws.amazon.com/redshift/pricing/)
+ [AWS SCT 入門](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_GettingStarted.html) 
+ [Amazon Redshift 入門](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html)
+ [使用資料擷取代理程式](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/agents.html)
+ [Chick-fil-A 使用 ThoughtSpot 和 AWS 改善洞見的速度](https://www.thoughtspot.com/sites/default/files/pdf/ThoughtSpot-Chick-fil-A-AWS-Case-Study.pdf) 

# 使用 Oracle GoldenGate 從 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate"></a>

*Dhairya Jindani、Sindhusha Paturu 和 Rajeshkumar Sabankar，Amazon Web Services*

## 總結
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate-summary"></a>

此模式說明如何使用 Oracle Cloud Infrastructure (OCI) GoldenGate 將 Oracle 資料庫遷移至 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)。

透過使用 Oracle GoldenGate，您可以在來源資料庫與一或多個目的地資料庫之間複寫資料，並將停機時間降至最低。

**注意**  
來源 Oracle 資料庫可以是內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。使用內部部署複寫工具時，您可以使用類似的程序。

## 先決條件和限制
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Oracle GoldenGate 授權
+ 連接至 PostgreSQL 資料庫的 Java Database Connectivity (JDBC) 驅動程式
+ 在目標 Amazon RDS for PostgreSQL 資料庫上使用 [AWS 結構描述Schema Conversion Tool](https://aws.amazon.com/dms/schema-conversion-tool/)和資料表

**限制**
+ Oracle GoldenGate 只能複寫現有的資料表資料 （初始載入） 和持續變更 （變更資料擷取）

**產品版本**
+ Oracle Database Enterprise Edition 10g 或更新版本 
+ OracleGoldenGate12.2.0.1.1 for Oracle 或更新版本
+ 適用於 PostgreSQLor 較新版本的 OracleGoldenGate12.2.0.1.1

## Architecture
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate-architecture"></a>

下圖顯示使用 Oracle GoldenGate 將 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL 的範例工作流程：

![\[從內部部署 Oracle 資料庫到 Amazon RDS for PostgreSQL 的遷移工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/384f0eaf-8582-474a-a7f4-ec1048a4feb3/images/de541887-0d5f-4a9a-b136-ce2599355cb8.png)


該圖顯示以下工作流程：

1. Oracle GoldenGate [擷取程序](https://docs.oracle.com/goldengate/c1230/gg-winux/GGCON/processes-and-terminology.htm#GUID-6419F3A9-71EC-4D14-9C41-3BAA1E3CA19C)會針對來源資料庫執行，以擷取資料。

1. Oracle GoldenGate [Replicat 程序](https://docs.oracle.com/goldengate/c1230/gg-winux/GGCON/processes-and-terminology.htm#GUID-5EF0326C-9058-4C40-8925-98A223388C95)會將擷取的資料交付至目標 Amazon RDS for PostgreSQL 資料庫。

## 工具
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate-tools"></a>
+ [Oracle GoldenGate](https://www.oracle.com/integration/goldengate/#:~:text=OCI%20GoldenGate%20is%20a%20real,in%20the%20Oracle%20Cloud%20Infrastructure.) 可協助您在 Oracle Cloud Infrastructure 中設計、執行、協調和監控資料複寫和串流資料處理解決方案。
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。

## 史詩
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate-epics"></a>

### 下載並安裝 Oracle GoldenGate
<a name="download-and-install-oracle-goldengate"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 Oracle GoldenGate。 | 下載下列版本的 Oracle GoldenGate：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.html)若要下載軟體，請參閱 [Oracle 網站上的 Oracle GoldenGate Downloads](https://www.oracle.com/middleware/technologies/goldengate-downloads.html)。 | DBA | 
| 在來源 Oracle 資料庫伺服器上安裝 Oracle GoldenGate for Oracle。 | 如需說明，請參閱 [Oracle GoldenGate 文件](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/toc.htm)。 | DBA | 
| 在 Amazon EC2 執行個體上安裝 Oracle GoldenGate for PostgreSQL 資料庫。 | 如需說明，請參閱 [Oracle GoldenGate 文件](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/toc.htm)。 | DBA | 

### 在來源和目標資料庫上設定 Oracle GoldenGate
<a name="configure-oracle-goldengate-on-the-source-and-target-databases"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源資料庫上設定 Oracle GoldenGate for Oracle 資料庫。 | 如需說明，請參閱 [Oracle GoldenGate 文件](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/toc.htm)。請務必設定下列項目：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.html) | DBA | 
| 在目標資料庫上設定 Oracle GoldenGate for PostgreSQL。 | 如需說明，請參閱 [Oracle 網站上的使用 Oracle GoldenGate for PostgreSQL 的第 VI 部分](https://docs.oracle.com/en/middleware/goldengate/core/19.1/gghdb/using-oracle-goldengate-postgresql.html)。請務必設定下列項目：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.html) | DBA | 

### 設定資料擷取
<a name="configure-the-data-capture"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源資料庫中設定擷取程序。 | 在來源 Oracle 資料庫中，建立擷取檔案以擷取資料。如需說明，請參閱 Oracle 文件中的[新增 EXTRACT](https://docs.oracle.com/goldengate/1212/gg-winux/GWURF/ggsci_commands006.htm#GWURF122)。擷取檔案包含建立擷取參數檔案和追蹤檔案目錄。 | DBA | 
| 設定資料幫浦，將追蹤檔案從來源傳輸到目標資料庫。 | 遵循 Oracle 網站上的*資料庫公用程式* [PARFILE](https://docs.oracle.com/database/121/SUTIL/GUID-7A045C82-5993-44EB-AFAD-B7D39C34BCCD.htm#SUTIL859) 中的指示，建立 EXTRACT 參數檔案和線索檔案目錄。如需詳細資訊，請參閱 Oracle 網站上的 *Fusion Middleware Understanding Oracle GoldenGate* 中的[什麼是線索？](https://docs.oracle.com/goldengate/c1230/gg-winux/GGCON/processes-and-terminology.htm#GUID-88674F53-1E07-4C00-9868-598F82D7113C)。 | DBA | 
| 在 Amazon EC2 執行個體上設定複寫。 | 建立複寫參數檔案和追蹤檔案目錄。如需建立複寫參數檔案的詳細資訊，請參閱 Oracle 資料庫文件中的第 [3.5 節驗證參數檔案。](https://docs.oracle.com/en/middleware/goldengate/core/21.3/admin/using-oracle-goldengate-parameter-files.html#GUID-1E32A9AD-25DB-4243-93CD-E643E7116215)如需建立追蹤檔案目錄的詳細資訊，請參閱 Oracle Cloud 文件中的[建立追蹤](https://docs.oracle.com/en/cloud/paas/goldengate-cloud/gwuad/creating-trail.html)。請務必在目標的 GLOBALS 檔案中新增檢查點資料表項目。如需詳細資訊，請參閱 Oracle 網站上的 *Fusion Middleware Understanding Oracle GoldenGate* 中的[什麼是複本？](https://docs.oracle.com/goldengate/c1230/gg-winux/GGCON/processes-and-terminology.htm#GGCON-GUID-5EF0326C-9058-4C40-8925-98A223388C95)。 | DBA | 

### 設定資料複寫
<a name="configure-the-data-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源資料庫中，建立參數檔案以擷取初始載入的資料。 | 遵循 Oracle Cloud 文件中[在 GGSCI 中建立參數檔案](https://docs.oracle.com/en/cloud/paas/goldengate-cloud/gwuad/using-oracle-goldengate-parameter-files.html#GUID-5C49C522-8B28-4E4B-908D-66A33717CE6C)的指示。確定 Manager 正在目標上執行。 | DBA | 
| 在目標資料庫中，建立參數檔案以複寫初始載入的資料。 | 遵循 Oracle Cloud 文件中[在 GGSCI 中建立參數檔案](https://docs.oracle.com/en/cloud/paas/goldengate-cloud/gwuad/using-oracle-goldengate-parameter-files.html#GUID-5C49C522-8B28-4E4B-908D-66A33717CE6C)的指示。請務必新增並啟動複寫程序。 | DBA | 

### 切換到 Amazon RDS for PostgreSQL 資料庫
<a name="cut-over-to-the-amazon-rds-for-postgresql-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止複寫程序，並確保來源和目標資料庫處於同步狀態。 | 比較來源和目標資料庫之間的資料列計數，以確保資料複寫成功。 | DBA | 
| 設定資料定義語言 (DDL) 支援。 | 執行 DDL 指令碼，以在 PostgreSQL 上建立觸發條件、序列、同義詞和參考金鑰。您可以使用任何標準 SQL 用戶端應用程式來連線至資料庫叢集中的資料庫。例如，您可以使用 [pgAdmin](https://www.pgadmin.org/) 連線到資料庫執行個體。 | DBA | 

## 相關資源
<a name="migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate-resources"></a>
+ [Amazon RDS for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) (*Amazon RDS 使用者指南*)
+ [Amazon EC2 文件](https://docs.aws.amazon.com/ec2/)
+ [Oracle GoldenGate 支援的處理方法和資料庫](https://docs.oracle.com/goldengate/1212/gg-winux/GWUAD/wu_about_gg.htm#GWUAD112) (Oracle 文件）

# 使用 AWS DMS 將 Oracle 分割的資料表遷移至 PostgreSQL
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms"></a>

*Saurav Mishra 和 Eduardo Valentim，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-summary"></a>

此模式說明如何使用不支援原生分割的 AWS Database Migration Service (AWS DMS)，加速將分割的資料表從 Oracle 載入 PostgreSQL。目標 PostgreSQL 資料庫可以安裝在 Amazon Elastic Compute Cloud (Amazon EC2) 上，也可以是 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora PostgreSQL 相容版本資料庫執行個體。 

上傳分割的資料表包含下列步驟：

1. 建立類似於 Oracle 分割區資料表的父資料表，但不包含任何分割區。

1. 建立將繼承自您在步驟 1 中建立之父資料表的子資料表。

1. 建立程序函數和觸發程序來處理父資料表中的插入。

不過，由於每次插入都會觸發觸發，因此使用 AWS DMS 的初始負載可能會非常慢。

為了加速從 Oracle 到 PostgreSQL 9.0 的初始載入，此模式會為每個分割區建立個別的 AWS DMS 任務，並載入對應的子資料表。然後，您可以在切換期間建立觸發。 

PostgreSQL 第 10 版支援原生分割。不過，在某些情況下，您可能會決定使用繼承的分割。如需詳細資訊，請參閱[其他資訊](#migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-additional)一節。

## 先決條件和限制
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 具有分割資料表的來源 Oracle 資料庫
+ AWS 上的 PostgreSQL 資料庫

**產品版本**
+ PostgreSQL 9.0

## Architecture
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ Oracle 中的分割資料表

**目標技術堆疊**
+ PostgreSQL 中的分割資料表 （在 Amazon EC2、Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 上）

**目標架構**

![\[Oracle 中的分割資料表資料會移至每個分割區的 AWS DMS 任務，然後移至 PostgreSQL。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7fa2898e-3308-436a-aec8-ab6f680d7bac/images/1b9742ea-a13d-434c-83a7-56686cf76ea0.png)


## 工具
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。

## 史詩
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-epics"></a>

### 設定 AWS DMS
<a name="set-up-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 PostgreSQL 中建立資料表。 | 在 PostgreSQL 中建立父資料表和對應的子資料表，其中包含分割區所需的檢查條件。 | DBA | 
| 為每個分割區建立 AWS DMS 任務。 | 在 AWS DMS 任務中包含分割區的篩選條件。將分割區對應至對應的 PostgreSQL 子資料表。 | DBA | 
| 使用完全載入和變更資料擷取 (CDC) 執行 AWS DMS 任務。 | 請確定 `StopTaskCachedChangesApplied` 參數設定為 ，`true`且 `StopTaskCachedChangesNotApplied` 參數設定為 `false`。 | DBA | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止複寫任務。 | 在您停止任務之前，請確認來源和目的地是同步的。 | DBA | 
| 在父資料表上建立觸發。 | 由於父資料表會收到所有插入和更新命令，請建立觸發程序，根據分割條件將這些命令路由至個別的子資料表。 | DBA | 

## 相關資源
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-resources"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [資料表分割 (PostgreSQL 文件）](https://www.postgresql.org/docs/10/ddl-partitioning.html)

## 其他資訊
<a name="migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms-additional"></a>

雖然 PostgreSQL 第 10 版支援原生分割區，但您可能會決定將繼承的分割區用於下列使用案例：
+ 分割會強制執行規則，表示所有分割區都必須具有與父系相同的資料欄集，但資料表繼承支援具有額外資料欄的子系。
+ 資料表繼承支援多個繼承。
+ 宣告式分割僅支援清單和範圍分割。使用資料表繼承，您可以根據需要分割資料。不過，如果限制排除無法有效剔除分割區，則查詢效能會受到影響。
+ 與使用資料表繼承相比，某些操作在使用宣告式分割時需要更強大的鎖定。例如，在分割資料表中新增或移除分割區時，需要在父資料表上`ACCESS EXCLUSIVE`鎖定，而`SHARE UPDATE EXCLUSIVE`鎖定足以進行一般繼承。

使用個別任務分割區時，如果有任何 AWS DMS 驗證問題，您也可以重新載入分割區。為了獲得更好的效能和複寫控制，請在不同的複寫執行個體上執行任務。

# 從 Amazon RDS for Oracle 遷移至 Amazon RDS for MySQL
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql"></a>

*Jitender Kumar、Srini Ramaswamy 和 Neha Sharma，Amazon Web Services*

## 總結
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql-summary"></a>

此模式提供將 Amazon Relational Database Service (Amazon RDS) for Oracle 資料庫執行個體遷移至 Amazon Web Services (AWS) 上 Amazon RDS for MySQL 資料庫執行個體的指引。模式使用 AWS Database Migration Service (AWS DMS) 和 AWS Schema Conversion Tool (AWS SCT)。 

模式提供處理預存程序遷移的最佳實務。它還涵蓋 和程式碼變更，以支援應用程式層。

## 先決條件和限制
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Amazon RDS for Oracle 來源資料庫。
+ Amazon RDS for MySQL 目標資料庫。來源和目標資料庫應位於相同的虛擬私有雲端 (VPC) 中。如果您使用的是多個 VPCs，或者您必須擁有必要的存取許可。
+ 允許來源和目標資料庫、AWS SCT、應用程式伺服器和 AWS DMS 之間連線的安全群組。
+ 具有在來源資料庫上執行 AWS SCT 所需權限的使用者帳戶。
+ 啟用補充記錄，以在來源資料庫上執行 AWS DMS。

**限制**
+ 來源和目標 Amazon RDS 資料庫大小限制為 64 TB。如需 Amazon RDS 大小資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html)。
+ Oracle 對資料庫物件不區分大小寫，但 MySQL 不區分大小寫。AWS SCT 可以在建立物件時處理此問題。不過，需要一些手動工作才能支援全案例不敏感。
+ 此遷移不會使用 MySQL 擴充功能來啟用 Oracle 原生函數。AWS SCT 會處理大多數轉換，但需要一些工作才能手動變更程式碼。
+ 應用程式中需要 Java Database Connectivity (JDBC) 驅動程式變更。

**產品版本**
+ Amazon RDS for Oracle 12.2.0.1 及更新版本。如需目前支援的 RDS for Oracle 版本，請參閱 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Concepts.database-versions.html)。
+ Amazon RDS for MySQL 8.0.15 及更新版本。如需目前支援的 RDS for MySQL 版本，請參閱 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Concepts.VersionMgmt.html)。
+ AWS DMS 3.3.0 版及更新版本。如需 AWS DMS 支援的[來源端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.Sources.html)和[目標端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.Targets.html)的詳細資訊，請參閱 AWS 文件。
+ AWS SCT 1.0.628 版及更新版本。 請參閱 [AWS 文件中的 AWS SCT 來源和目標端點支援矩陣](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。

## Architecture
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql-architecture"></a>

**來源技術堆疊**
+ Amazon RDS for Oracle。如需詳細資訊，請參閱[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。 

**目標技術堆疊**
+ Amazon RDS for MySQL。如需詳細資訊，請參閱[使用 MySQL 相容資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)。

**遷移架構**

在下圖中，AWS SCT 會從 Amazon RDS for Oracle 來源資料庫複製和轉換結構描述物件，並將物件傳送至 Amazon RDS for MySQL 目標資料庫。AWS DMS 會從來源資料庫複寫資料，並將其傳送至 Amazon RDS for MySQL 執行個體。

![\[部署在私有子網路中的 AWS SCT、AWS DMS 和 Amazon RDS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e1efa7c2-47c1-4677-80bc-6b19250fc0d6/images/b54a8442-9ab9-4074-b8f6-a08f87fa2f52.jpeg)


## 工具
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql-tools"></a>
+ [AWS Data Migration Service](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間進行遷移。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。此模式使用 [Amazon RDS for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 和 [Amazon RDS for MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html)。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。

## 史詩
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql-epics"></a>

### 準備遷移
<a name="prepare-for-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
|  識別目標伺服器執行個體的硬體需求。 |  | DBA、SysAdmin | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA、SysAdmin | 
| 選擇適當的執行個體類型 （容量、儲存功能、網路功能）。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA、SysAdmin  | 
| 選擇應用程式遷移策略。 | 考慮您是否希望將完全停機時間或部分停機時間用於切換活動。 | DBA、SysAdmin、應用程式擁有者 | 

### 設定基礎設施
<a name="configure-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC 和子網路。 |  | SysAdmin | 
| 建立安全群組和網路存取控制清單 ACLs)。 |  | SysAdmin | 
| 設定和啟動 Amazon RDS for Oracle 執行個體。 |  | DBA、SysAdmin | 
| 設定和啟動 Amazon RDS for MySQL 執行個體。 |  | DBA、SysAdmin | 
| 準備測試案例以驗證程式碼轉換。 | 這將有助於對轉換後的程式碼進行單位測試。 | DBA、開發人員 | 
| 設定 AWS DMS 執行個體。 |  |  | 
| 在 AWS DMS 中設定來源和目標端點。 |  |  | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS SCT 產生目標資料庫指令碼。 | 檢查 AWS SCT 轉換之程式碼的準確性。需要一些手動工作。 | DBA、開發人員 | 
| 在 AWS SCT 中，選擇「不區分大小寫」設定。 | 在 AWS SCT 中，選擇專案設定、目標案例敏感度、不區分大小寫。 | DBA、開發人員 | 
| 在 AWS SCT 中，選擇不使用 Oracle 原生函數。 | 在專案設定中，檢查函數 TO\$1CHAR/TO\$1NUMBER/TO\$1DATE。 | DBA、開發人員 | 
| 變更 "sql%notfound" 程式碼。 | 您可能需要手動轉換程式碼。 |  | 
| 查詢預存程序中的資料表和物件 （使用小寫查詢）。 |  | DBA、開發人員 | 
| 完成所有變更後建立主要指令碼，然後在目標資料庫上部署主要指令碼。 |  | DBA、開發人員 | 
| 使用範例資料對預存程序和應用程式呼叫進行單元測試。 |  |  | 
| 清除在單位測試期間建立的資料。 |  | DBA、開發人員 | 
| 捨棄目標資料庫上的外部金鑰限制。 | 載入初始資料需要此步驟。如果您不想捨棄外部金鑰限制，您必須為主要和次要資料表特定的資料建立遷移任務。 | DBA、開發人員 | 
| 在目標資料庫上捨棄主索引鍵和唯一索引鍵。 | 此步驟可為初始載入提供更好的效能。 | DBA、開發人員 | 
| 在來源資料庫上啟用補充記錄。 |  | DBA | 
| 在 AWS DMS 中建立初始載入的遷移任務，然後執行它。 | 選擇 選項以遷移現有資料。 | DBA | 
| 將主索引鍵和外部索引鍵新增至目標資料庫。 | 初始載入後需要新增限制條件。 | DBA、開發人員 | 
| 建立遷移任務以進行持續複寫。 | 持續複寫可讓目標資料庫與來源資料庫保持同步。 | DBA | 

### 遷移應用程式
<a name="migrate-applications"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 Oracle 原生函數取代為 MySQL 原生函數。 |  | 應用程式擁有者 | 
| 請確定 SQL 查詢中的資料庫物件只使用小寫名稱。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 切換到目標資料庫
<a name="cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉應用程式伺服器。 |  | 應用程式擁有者 | 
| 驗證來源和目標資料庫是否同步。 |  | DBA、應用程式擁有者 | 
| 停止 Amazon RDS for Oracle 資料庫執行個體。 |  | DBA | 
| 停止遷移任務。 | 這會在您完成上一個步驟後自動停止。 | DBA | 
| 將 JDBC 連線從 Oracle 變更為 MySQL。 |  | 應用程式擁有者、DBA | 
| 啟動應用程式。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱並驗證專案文件。 |  | DBA、SysAdmin | 
| 收集遷移時間、手動與工具任務的百分比、節省成本等指標。 |  | DBA、SysAdmin | 
| 停止和刪除 AWS DMS 執行個體。 |  | DBA | 
| 移除來源和目標端點。 |  | DBA | 
| 移除遷移任務。 |  | DBA | 
| 拍攝 Amazon RDS for Oracle 資料庫執行個體的快照。 |  | DBA | 
| 刪除 Amazon RDS for Oracle 資料庫執行個體。 |  | DBA | 
| 關閉並刪除您使用的任何其他臨時 AWS 資源。 |  | DBA、SysAdmin | 
| 關閉專案並提供任何意見回饋。 |  | DBA | 

## 相關資源
<a name="migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql-resources"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/Welcome.html)
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)

# 使用 AWS DMS 和 AWS SCT 從 Amazon EC2 上的 IBM Db2 遷移至 Aurora PostgreSQL 相容 Amazon EC2
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct"></a>

*Sirsendu Halder 和 Abhimanyu Chhabra，Amazon Web Services*

## 總結
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct-summary"></a>

此模式提供將 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 IBM Db2 資料庫遷移至 Amazon Aurora PostgreSQL 相容版本資料庫執行個體的指引。此模式使用 AWS Database Migration Service (AWS DMS) 和 AWS Schema Conversion Tool (AWS SCT) 進行資料遷移和結構描述轉換。

此模式針對具有大量交易的多 TB IBM Db2 資料庫，以幾乎沒有停機時間的線上遷移策略為目標。建議您將主索引鍵 PKs) 和外部索引鍵 (FKs) 中的資料欄與資料類型轉換為 PostgreSQL `NUMERIC``INT`或 `BIGINT`，以獲得更好的效能。 

## 先決條件和限制
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶 
+ EC2 執行個體上的來源 IBM Db2 資料庫 EC2 

**產品版本**
+ DB2/LINUXX8664 11.1.4.4 版及更新版本

## Architecture
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊******
+ EC2 執行個體上的 Db2 資料庫 EC2  

**目標技術堆疊**
+ Aurora PostgreSQL 相容版本 10.18 或更新版本的資料庫執行個體

**資料庫遷移架構******

![\[使用 AWS DMS 從 Amazon EC2 上的 IMB Db2 遷移至 Aurora PostgreSQL 相容。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5e737fab-3e04-4887-9fb0-d1c88503b57d/images/789fabcc-8052-40d5-a746-986d799576e9.png)


## 工具
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料庫遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降至最低。您可以使用 AWS DMS 在最廣泛使用的商業和開放原始碼資料庫之間遷移資料。AWS DMS 支援在不同資料庫平台之間進行異質遷移，例如 IBM Db2 到 Aurora PostgreSQL 相容版本 10.18 或更新版本。如需詳細資訊，請參閱 AWS DMS 文件中的[資料遷移來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.html)和[資料遷移目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.html)。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 透過自動將來源資料庫結構描述和大部分資料庫程式碼物件，包括檢視、預存程序和函數，轉換為與目標資料庫相容的格式，來支援異質資料庫遷移。任何未自動轉換的物件都會清楚標示，以便手動轉換以完成遷移。AWS SCT 也可以掃描內嵌 SQL 陳述式的應用程式原始碼，並進行轉換。 

## 史詩
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct-epics"></a>

### 設定環境
<a name="set-up-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Aurora PostgreSQL 相容資料庫執行個體。 | 若要建立資料庫執行個體，請遵循 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html)中的指示。針對引擎類型，選擇 **Amazon Aurora**。針對版本，選擇 **Amazon Aurora PostgreSQL 相容版本**。Aurora PostgreSQL 相容版本 10.18 或更新版本的資料庫執行個體應與來源 IBM Db2 資料庫位於相同的虛擬私有雲端 (VPC) 中。 | Amazon RDS | 

### 轉換資料庫結構描述
<a name="convert-your-database-schema"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝並驗證 AWS SCT。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.html) | AWS 管理員、DBA、遷移工程師 | 
| 啟動 AWS SCT 並建立專案。 | 若要啟動 AWS SCT 工具並建立新專案以執行資料庫遷移評估報告，請遵循 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.Launching)中的指示。 | 遷移工程師 | 
| 新增資料庫伺服器並建立映射規則。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.html) | 遷移工程師 | 
| 建立資料庫遷移評估報告。 | 依照 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.AssessmentReport)中的步驟建立資料庫遷移評估報告。 | 遷移工程師 | 
| 檢視評估報告。 | 使用資料庫遷移評估報告的**摘要**索引標籤來檢視報告並分析資料。此分析將協助您判斷遷移的複雜性。如需詳細資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_AssessmentReport.View.html)。 | 遷移工程師 | 
| 轉換結構描述。 | 若要轉換來源資料庫結構描述：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.html)如需詳細資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.Converting)。 | 遷移工程師 | 
| 將轉換後的資料庫結構描述套用至目標資料庫執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.html)如需詳細資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.ApplyingConversion)。 | 遷移工程師 | 

### 遷移您的資料
<a name="migrate-your-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 VPC 和資料庫參數群組。 | 設定 VPC 和資料庫參數群組，並設定遷移所需的傳入規則和參數。如需說明，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Prerequisites.html)。針對 VPC 安全群組，選取 Db2 的 EC2 執行個體和 Aurora PostgreSQL 相容資料庫執行個體。此複寫執行個體必須與來源和目標資料庫執行個體位於相同的 VPC 中。 | 遷移工程師 | 
| 準備來源和目標資料庫執行個體。 | 準備來源和目標資料庫執行個體以進行遷移。在生產環境中，來源資料庫將已存在。對於來源資料庫，伺服器名稱必須是執行 Db2 之 EC2 執行個體的公有網域名稱系統 (DNS)。對於使用者名稱，您可以使用 `db2inst1`，後面接著連接埠，這會是 IBM Db2 的 5000。 | 遷移工程師 | 
| 建立 Amazon EC2 用戶端和端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.html) | 遷移工程師 | 
| 建立複寫執行個體。 | 使用 AWS DMS 主控台建立複寫執行個體，並指定來源和目標端點。複寫執行個體會在端點之間執行資料遷移。如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Replication.html)。 | 遷移工程師 | 
| 建立 AWS DMS 任務以遷移資料。 | 依照 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Replication.html#CHAP_GettingStarted.Replication.Tasks)中的步驟建立任務，將來源 IBM Db2 資料表載入目標 PostgreSQL 資料庫執行個體。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.html) | 遷移工程師 | 

## 相關資源
<a name="migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct-resources"></a>

**參考**
+ [Amazon Aurora 文件](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html)
+ [PostgreSQL 外部資料包裝函式 (FDW) 文件](https://www.postgresql.org/docs/10/postgres-fdw.html) 
+ [PostgreSQL IMPORT FOREIGN SCHEMA 文件](https://www.postgresql.org/docs/10/sql-importforeignschema.html) 
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/index.html)  
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 

**教學課程和影片**
+ [AWS DMS 入門 ](https://aws.amazon.com/dms/getting-started/)（逐步解說）
+ [Amazon EC2 簡介 - Elastic Cloud Server & Hosting with AWS](https://www.youtube.com/watch?v=TsRBftzZsQo) （影片）

# 使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms"></a>

*Kumar Babu P G，Amazon Web Services*

## 總結
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms-summary"></a>

此模式說明如何將內部部署 Oracle 8i 或 9i 資料庫遷移至 Amazon Relational Database Service (Amazon RDS) for PostgreSQL 或 Amazon Aurora PostgreSQL。AWS Database Migration Service (AWS DMS) 不支援 Oracle 8i 或 9i 作為來源，因此 Quest SharePlex 會將內部部署 8i 或 9i 資料庫的資料複寫到與 AWS DMS 相容的中繼 Oracle 資料庫 (Oracle 10g 或 11g)。

從中繼 Oracle 執行個體，使用 AWS Schema Conversion Tool (AWS SCT) 和 AWS DMS，將結構描述和資料遷移至 AWS 上的 PostgreSQL 資料庫。此方法有助於將資料從來源 Oracle 資料庫持續串流到具有最小複寫延遲的目標 PostgreSQL 資料庫執行個體。在此實作中，停機時間僅限於建立或驗證目標 PostgreSQL 資料庫上所有外部金鑰、觸發條件和序列所需的時間長度。

遷移使用已安裝 Oracle 10g 或 11g 的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體來託管來源 Oracle 資料庫的變更。AWS DMS 使用此中繼 Oracle 執行個體做為來源，將資料串流至 Amazon RDS for PostgreSQL 或 Aurora PostgreSQL。資料複寫可以從現場部署 Oracle 資料庫暫停並繼續到中繼 Oracle 執行個體。它也可以暫停並繼續從中繼 Oracle 執行個體到目標 PostgreSQL 資料庫，以便您可以使用 AWS DMS 資料驗證或自訂資料驗證工具來驗證資料。

## 先決條件和限制
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的來源 Oracle 8i 或 9i 資料庫 
+ 在內部部署資料中心和 AWS 之間設定的 AWS Direct Connect 
+ 在本機電腦或安裝 AWS SCT 的 EC2 執行個體上安裝的 AWS SCT 連接器的 Java Database Connectivity (JDBC) 驅動程式
+ 熟悉[使用 Oracle 資料庫做為 AWS DMS 來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 PostgreSQL 資料庫做為 AWS DMS 目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)
+ 熟悉 Quest SharePlex 資料複寫

 

**限制**
+ 資料庫大小限制為 64 TB
+ 內部部署 Oracle 資料庫必須是 Enterprise Edition

 

**產品版本**
+ 來源資料庫的 Oracle 8i 或 9i
+ 適用於中繼資料庫的 Oracle 10g 或 11g 
+ PostgreSQL 9.6 或更新版本

## Architecture
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms-architecture"></a>

**來源技術堆疊**
+ Oracle 8i 或 9i 資料庫 
+ Quest SharePlex 

 

**目標技術堆疊**
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 

** **

**來源和目標架構**

![\[Architecture diagram showing migration from on-premises Oracle database to AWS cloud using various services.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/b6c30668-fc2e-4293-a59a-e01fd151f4bb/images/25082670-0bf3-4b20-8c80-99c6633b046f.png)


## 工具
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms-tools"></a>
+ **AWS DMS** – [AWS Database Migration Service](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html) (AWS DMS) 可協助您快速安全地遷移資料庫。來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降到最低。AWS DMS 可以在最廣泛使用的商業和開放原始碼資料庫之間遷移您的資料。 
+ **AWS SCT** – [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) (AWS SCT) 會自動將來源資料庫結構描述和大部分資料庫程式碼物件，包括檢視、預存程序和函數，轉換為與目標資料庫相容的格式，讓異質資料庫遷移成為可預測。無法自動轉換的物件會清楚標示，以便手動轉換以完成遷移。AWS SCT 也可以掃描應用程式原始碼以取得內嵌 SQL 陳述式，並將其轉換為資料庫結構描述轉換專案的一部分。在此過程中，AWS SCT 會透過將舊版 Oracle 和 SQL Server 函數轉換為其 AWS 對等函數來執行雲端原生程式碼最佳化，協助您在遷移資料庫的同時現代化應用程式。當結構描述轉換完成時，AWS SCT 可以使用內建的資料遷移代理程式，協助將資料從各種資料倉儲遷移到 Amazon Redshift。
+ **Quest SharePlex** – [Quest SharePlex](https://www.quest.com/register/120420/?gclid=Cj0KCQiA6IHwBRCJARIsALNjViVSt9fHqAsf9XbWkoCwKKyQqollR_5kSxNhBagh9s3spQT4IQCaVy0aAmCnEALw_wcB) 是一種 Oracle-to-Oracle 資料複寫工具，可在最短的停機時間下移動資料，而不會遺失資料。

## 史詩
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms-epics"></a>

### 建立 EC2 執行個體並安裝 Oracle
<a name="create-the-ec2-instance-and-install-oracle"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Amazon EC2 的網路。 | 建立虛擬私有雲端 (VPC)、子網路、網際網路閘道、路由表和安全群組。 | AWS SysAdmin | 
| 建立新的 EC2 執行個體。 | 選取 EC2 執行個體的 Amazon Machine Image (AMI)。選擇執行個體大小並設定執行個體詳細資訊：執行個體數量 (1)、上一個步驟的 VPC 和子網路、自動指派公有 IP 和其他選項。新增儲存體、設定安全群組，以及啟動執行個體。出現提示時，請建立並儲存下一個步驟的金鑰對。 | AWS SysAdmin | 
| 在 EC2 執行個體上安裝 Oracle。 | 取得授權和必要的 Oracle 二進位檔，並在 EC2 執行個體上安裝 Oracle 10g 或 11g。 | DBA | 

### 在 EC2 執行個體上設定 SharePlex 並設定資料複寫
<a name="set-up-shareplex-on-an-ec2-instance-and-configure-data-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 SharePlex。 | 建立 Amazon EC2 執行個體並安裝與 Oracle 8i 或 9i 相容的 SharePlex 二進位檔。 | AWS SysAdmin、DBA | 
| 設定資料複寫。 | 遵循 SharePlex 最佳實務，設定從內部部署 Oracle 8i/9i 資料庫到 Oracle 10g/11g 執行個體的資料複寫。 | DBA | 

### 將 Oracle 資料庫結構描述轉換為 PostgreSQL
<a name="convert-the-oracle-database-schema-to-postgresql"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS SCT。 | 建立新的報告，然後連接至 Oracle 做為來源，而 PostgreSQL 做為目標。在專案設定中，開啟 SQL 指令碼索引標籤，並將目標 SQL 指令碼變更為多個檔案。 | DBA | 
| 轉換 Oracle 資料庫結構描述。 | 在動作索引標籤中，選擇產生報告、轉換結構描述，然後儲存為 SQL。 | DBA | 
| 修改 AWS SCT 產生的 SQL 指令碼。 |  | DBA | 

### 建立和設定 Amazon RDS 資料庫執行個體
<a name="create-and-configure-the-amazon-rds-db-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS 資料庫執行個體。 | 在 Amazon RDS 主控台中，建立新的 PostgreSQL 資料庫執行個體。 | AWS SysAdmin、DBA | 
| 設定資料庫執行個體。 | 指定資料庫引擎版本、資料庫執行個體類別、異地同步備份部署、儲存類型和配置的儲存。輸入資料庫執行個體識別符、主要使用者名稱和主要密碼。 | AWS SysAdmin、DBA | 
| 設定網路和安全性。 | 指定 VPC、子網路群組、公有可存取性、可用區域偏好設定和安全群組。 | AWS SysAdmin、DBA | 
| 設定資料庫選項。 | 指定資料庫名稱、連接埠、參數群組、加密和主金鑰。 | AWS SysAdmin、DBA | 
| 設定備份。 | 指定備份保留期、備份時段、開始時間、持續時間，以及是否要將標籤複製到快照。 | AWS SysAdmin、DBA | 
| 設定監控選項。 | 啟用或停用增強型監控和效能洞察。 | AWS SysAdmin、DBA | 
| 設定維護選項。 | 指定自動次要版本升級、維護時段，以及開始日期、時間和持續時間。 | AWS SysAdmin、DBA | 
| 從 AWS SCT 執行預遷移指令碼。 | 在 Amazon RDS 執行個體上執行這些指令碼：create\$1database.sql、create\$1sequence.sql、create\$1table.sql、create\$1view.sql 和 create\$1function.sql。 | AWS SysAdmin、DBA | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-by-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS DMS 中建立複寫執行個體。 | 完成名稱、執行個體類別、VPC （與 EC2 執行個體相同）、異地同步備份和公有可存取性的欄位。在進階組態區段中，指定配置的儲存、子網路群組、可用區域、VPC 安全群組和 AWS Key Management Service (AWS KMS) 根金鑰。 | AWS SysAdmin、DBA | 
| 建立來源資料庫端點。 | 指定端點名稱、類型、來源引擎 (Oracle)、伺服器名稱 (Amazon EC2 私有 DNS 名稱）、連接埠、SSL 模式、使用者名稱、密碼、SID、VPC （指定具有複寫執行個體的 VPC) 和複寫執行個體。若要測試連線，請選擇執行測試，然後建立端點。您也可以設定下列進階設定：maxFileSize 和 numberDataTypeScale。 | AWS SysAdmin、DBA | 
| 建立 AWS DMS 複寫任務。 | 指定任務名稱、複寫執行個體、來源和目標端點，以及複寫執行個體。針對遷移類型，選擇「遷移現有資料並複寫持續變更」。清除「建立時啟動任務」核取方塊。 | AWS SysAdmin、DBA | 
| 設定 AWS DMS 複寫任務設定。 | 針對目標資料表準備模式，選擇「不執行任何動作」。在完全載入完成後停止任務，以建立主索引鍵。指定有限或完整 LOB 模式，並啟用控制資料表。或者，您可以設定 CommitRate 進階設定。 | DBA | 
| 設定資料表映射。 | 在資料表映射區段中，為遷移中包含的所有結構描述中的所有資料表建立包含規則，然後建立排除規則。新增三個轉換規則，將結構描述、資料表和資料欄名稱轉換為小寫，並新增此特定遷移所需的任何其他規則。 | DBA | 
| 啟動 任務。 | 啟動複寫任務。確定完全載入正在執行中。在主要 Oracle 資料庫上執行 ALTER SYSTEM SWITCH LOGFILE，以啟動任務。 | DBA | 
| 從 AWS SCT 執行中遷移指令碼。 | 在 Amazon RDS for PostgreSQL 中，執行這些指令碼：create\$1index.sql 和 create\$1constraint.sql。 | DBA | 
| 重新啟動任務以繼續變更資料擷取 (CDC)。 | 在 Amazon RDS for PostgreSQL 資料庫執行個體中，執行 VACUUM，然後重新啟動 AWS DMS 任務以套用快取的 CDC 變更。 | DBA | 

### 切換到 PostgreSQL 資料庫
<a name="cut-over-to-the-postgresql-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查 AWS DMS 日誌和中繼資料表。 | 驗證任何錯誤並視需要修正。 | DBA | 
| 停止所有 Oracle 相依性。 | 關閉 Oracle 資料庫上的接聽程式，並執行 ALTER SYSTEM SWITCH LOGFILE。在未顯示活動時停止 AWS DMS 任務。 | DBA | 
| 從 AWS SCT 執行遷移後指令碼。 | 在 Amazon RDS for PostgreSQL 中，執行這些指令碼：create\$1foreign\$1key\$1constraint.sql 和 create\$1triggers.sql。 | DBA | 
| 完成任何其他 Amazon RDS for PostgreSQL 步驟。 | 視需要遞增序列以符合 Oracle，執行 VACUUM 和 ANALYZE，並拍攝快照以符合合規。 | DBA | 
| 開啟 Amazon RDS for PostgreSQL 的連線。 | 從 Amazon RDS for PostgreSQL 移除 AWS DMS 安全群組、新增生產安全群組，並將您的應用程式指向新的資料庫。 | DBA | 
| 清除 AWS DMS 資源。 | 移除端點、複寫任務、複寫執行個體和 EC2 執行個體。 | SysAdmin、DBA | 

## 相關資源
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms-resources"></a>
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html)
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [Amazon RDS for PostgreSQL 定價](https://aws.amazon.com/rds/postgresql/pricing/)
+ [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ [使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html) 
+ [Quest SharePlex 文件](https://support.quest.com/shareplex/9.0.2/technical-documents)

# 使用具體化視觀表和 AWS DMS，從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms"></a>

*Kumar Babu P G 和 Pragnesh Patel，Amazon Web Services*

## 總結
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-summary"></a>

此模式說明如何將內部部署舊版 Oracle 8i 或 9i 資料庫遷移至 Amazon Relational Database Service (Amazon RDS) for PostgreSQL 或 Amazon Aurora PostgreSQL 相容版本。 

AWS Database Migration Service (AWS DMS) 不支援 Oracle 8i 或 9i 作為來源，因此此模式使用與 AWS DMS 相容的中繼 Oracle 資料庫執行個體，例如 Oracle 10g 或 11g。它也會使用具體化視觀表功能，將資料從來源 Oracle 8i/9i 執行個體遷移至中繼 Oracle 10g/11g 執行個體。

AWS Schema Conversion Tool (AWS SCT) 會轉換資料庫結構描述，而 AWS DMS 會將資料遷移至目標 PostgreSQL 資料庫。 

此模式可協助想要從舊版 Oracle 資料庫遷移的使用者，將資料庫停機時間降至最低。在此實作中，停機時間會受限於在目標資料庫上建立或驗證所有外部金鑰、觸發條件和序列所需的時間長度。 

模式使用已安裝 Oracle 10g/11g 資料庫的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體，以協助 AWS DMS 串流資料。您可以暫停從現場部署 Oracle 資料庫到中繼 Oracle 執行個體的串流複寫，讓 AWS DMS 能夠跟上資料驗證的進度，或使用其他資料驗證工具。當 AWS DMS 已完成遷移目前的變更時，PostgreSQL 資料庫執行個體和中繼 Oracle 資料庫將具有相同的資料。

## 先決條件和限制
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的來源 Oracle 8i 或 9i 資料庫 
+ 在內部部署資料中心和 AWS 之間設定的 AWS Direct Connect
+ 在本機電腦或安裝 AWS SCT 的 EC2 執行個體上安裝的 AWS SCT 連接器的 Java Database Connectivity (JDBC) 驅動程式
+ 熟悉[使用 Oracle 資料庫做為 AWS DMS 來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 PostgreSQL 資料庫做為 AWS DMS 目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)

**限制**
+ 資料庫大小限制為 64 TB

**產品版本**
+ 來源資料庫的 Oracle 8i 或 9i
+ 適用於中繼資料庫的 Oracle 10g 或 11g
+ PostgreSQL 10.17 或更新版本

## Architecture
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-architecture"></a>

**來源技術堆疊**
+ Oracle 8i 或 9i 資料庫 

**目標技術堆疊**
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容

**目標架構**

![\[從舊版 Oracle 資料庫遷移至 Amazon RDS 或 Aurora 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8add9b21-1b62-46a2-bb8e-0350f36a924a/images/f34f9b0f-f1da-4c27-a385-71b12d16c375.png)


## 工具
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-tools"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html) 有助於快速安全地遷移資料庫。來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降至最低。AWS DMS 可以在最廣泛使用的商業和開放原始碼資料庫之間遷移您的資料。
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大多數資料庫程式碼物件，包括檢視、預存程序和函數，轉換為與目標資料庫相容的格式。無法自動轉換的物件會清楚標示，以便手動轉換以完成遷移。AWS SCT 也可以掃描應用程式原始碼以取得內嵌 SQL 陳述式，並將其轉換為資料庫結構描述轉換專案的一部分。在此過程中，AWS SCT 會透過將舊版 Oracle 和 SQL Server 函數轉換為其 AWS 對等函數來執行雲端原生程式碼最佳化，協助您在遷移資料庫的同時現代化應用程式。當結構描述轉換完成時，AWS SCT 可以使用內建的資料遷移代理程式，協助將資料從各種資料倉儲遷移到 Amazon Redshift。 

## 最佳實務
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-best-practices"></a>

如需重新整理具體化視觀表的最佳實務，請參閱下列 Oracle 文件：
+ [重新整理具體化視觀表](https://docs.oracle.com/database/121/DWHSG/refresh.htm#DWHSG-GUID-64068234-BDB0-4C12-AE70-75571046A586)
+ [具體化視觀表的快速重新整理](https://docs.oracle.com/database/121/DWHSG/refresh.htm#DWHSG8361)

## 史詩
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-epics"></a>

### 在 EC2 執行個體上安裝 Oracle 並建立具體化視觀表
<a name="install-oracle-on-an-ec2-instance-and-create-materialized-views"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 EC2 執行個體的網路。 | 建立虛擬私有雲端 (VPC)、子網路、網際網路閘道、路由表和安全群組。 | AWS SysAdmin | 
| 建立 EC2 執行個體。 | 選取 EC2 執行個體的 Amazon Machine Image (AMI)。選擇執行個體大小並設定執行個體詳細資訊：執行個體數量 (1)、上一個步驟的 VPC 和子網路、自動指派公有 IP 和其他選項。新增儲存體、設定安全群組，以及啟動執行個體。出現提示時，請建立並儲存下一個步驟的金鑰對。 | AWS SysAdmin | 
| 在 EC2 執行個體上安裝 Oracle。 | 取得授權和必要的 Oracle 二進位檔，並在 EC2 執行個體上安裝 Oracle 10g 或 11g。 | DBA | 
| 設定 Oracle 聯網。 | 在 中修改或新增項目`listener.ora`，以連線至內部部署來源 Oracle 8i/9i 資料庫，然後建立資料庫連結。 | DBA | 
| 建立具體化視觀表。 | 識別要在來源 Oracle 8i/9i 資料庫中複寫的資料庫物件，然後使用資料庫連結為所有物件建立具體化檢視。 | DBA | 
| 部署指令碼，以所需的間隔重新整理具體化視觀表。 | 開發和部署指令碼，以在 Amazon EC2 Oracle 10g/11g 執行個體上以所需的間隔重新整理具體化視觀表。使用增量重新整理選項來重新整理具體化視觀表。 | DBA | 

### 將 Oracle 資料庫結構描述轉換為 PostgreSQL
<a name="convert-the-oracle-database-schema-to-postgresql"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS SCT。 | 建立新的報告，然後連接至 Oracle 做為來源，而 PostgreSQL 做為目標。在專案設定中，開啟 **SQL 指令碼**索引標籤。將目標 SQL 指令碼變更為**多個檔案**。(AWS SCT 不支援 Oracle 8i/9i 資料庫，因此您必須在中繼 Oracle 10g/11g 執行個體上還原僅限結構描述的傾印，並將其用作 AWS SCT 的來源。) | DBA | 
| 轉換 Oracle 資料庫結構描述。 | 在**動作**索引標籤上，選擇**產生報告**、**轉換結構描述**，然後**儲存為 SQL**。 | DBA | 
| 修改 SQL 指令碼。 | 根據最佳實務進行修改。例如，切換到適當的資料類型，並為 Oracle 特定函數開發 PostgreSQL 對等項目。 | DBA、DevDBA | 

### 建立和設定 Amazon RDS 資料庫執行個體以託管轉換後的資料庫
<a name="create-and-configure-the-amazon-rds-db-instance-to-host-the-converted-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS 資料庫執行個體。 | 在 Amazon RDS 主控台中，建立新的 PostgreSQL 資料庫執行個體。 | AWS SysAdmin、DBA | 
| 設定資料庫執行個體。 | 指定資料庫引擎版本、資料庫執行個體類別、異地同步備份部署、儲存類型和配置的儲存。輸入資料庫執行個體識別符、主要使用者名稱和主要密碼。 | AWS SysAdmin、DBA | 
| 設定網路和安全性。 | 指定 VPC、子網路群組、公有可存取性、可用區域偏好設定和安全群組。 | DBA、SysAdmin | 
| 設定資料庫選項。 | 指定資料庫名稱、連接埠、參數群組、加密和主金鑰。 | DBA、AWS SysAdmin | 
| 設定備份。 | 指定備份保留期、備份時段、開始時間、持續時間，以及是否要將標籤複製到快照。 | AWS SysAdmin、DBA | 
| 設定監控選項。 | 啟用或停用增強型監控和效能洞察。 | AWS SysAdmin、DBA | 
| 設定維護選項。 | 指定自動次要版本升級、維護時段，以及開始日期、時間和持續時間。 | AWS SysAdmin、DBA | 
| 從 AWS SCT 執行預遷移指令碼。 | 在目標 Amazon RDS for PostgreSQL 執行個體上，使用 AWS SCT 中的 SQL 指令碼和其他修改來建立資料庫結構描述。這些可能包括執行多個指令碼，包括使用者建立、資料庫建立、結構描述建立、資料表、檢視、函數和其他程式碼物件。 | AWS SysAdmin、DBA | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-by-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS DMS 中建立複寫執行個體。 | 完成名稱、執行個體類別、VPC （與 EC2 執行個體相同）、異地同步備份和公有可存取性的欄位。在進階組態區段中，指定配置的儲存、子網路群組、可用區域、VPC 安全群組和 AWS Key Management Service (AWS KMS) 金鑰。 | AWS SysAdmin、DBA | 
| 建立來源資料庫端點。 | 指定端點名稱、類型、來源引擎 (Oracle)、伺服器名稱 (EC2 執行個體的私有 DNS 名稱）、連接埠、SSL 模式、使用者名稱、密碼、SID、VPC （指定具有複寫執行個體的 VPC) 和複寫執行個體。若要測試連線，請選擇**執行測試**，然後建立端點。您也可以設定下列進階設定：**maxFileSize** 和 **numberDataTypeScale**。 | AWS SysAdmin、DBA | 
| 將 AWS DMS 連線至 Amazon RDS for PostgreSQL。 | 如果您的 PostgreSQL 資料庫位於另一個 VPCs，請建立跨 VPC 連線的遷移安全群組。 | AWS SysAdmin、DBA | 
| 建立目標資料庫端點。 | 指定端點名稱、類型、來源引擎 (PostgreSQL)、伺服器名稱 (Amazon RDS 端點）、連接埠、SSL 模式、使用者名稱、密碼、資料庫名稱、VPC （指定具有複寫執行個體的 VPC) 和複寫執行個體。若要測試連線，請選擇**執行測試**，然後建立端點。您也可以設定下列進階設定：**maxFileSize** 和 **numberDataTypeScale**。 | AWS SysAdmin、DBA | 
| 建立 AWS DMS 複寫任務。 | 指定任務名稱、複寫執行個體、來源和目標端點，以及複寫執行個體。針對遷移類型，選擇**遷移現有資料並複寫持續變更**。清除**建立時啟動任務**核取方塊。 | AWS SysAdmin、DBA | 
| 設定 AWS DMS 複寫任務設定。 | 針對目標資料表準備模式，選擇**不執行任何**動作。完全載入完成後停止任務 （以建立主索引鍵）。指定有限或完整 LOB 模式，並啟用控制資料表。或者，您可以設定 **CommitRate** 進階設定。 | DBA | 
| 設定資料表映射。 | 在**資料表映射**區段中，為遷移中包含的所有結構描述中的所有資料表建立包含規則，然後建立排除規則。新增三個轉換規則，將結構描述、資料表和資料欄名稱轉換為小寫，並新增此特定遷移所需的任何其他規則。 | DBA | 
| 啟動 任務。 | 啟動複寫任務。確定完全載入正在執行中。在主要 Oracle 資料庫`ALTER SYSTEM SWITCH LOGFILE`上執行 以啟動任務。 | DBA | 
| 從 AWS SCT 執行中遷移指令碼。 | 在 Amazon RDS for PostgreSQL 中，執行下列指令碼： `create_index.sql`和 `create_constraint.sql`（如果最初未建立完整的結構描述）。 | DBA | 
| 繼續任務以繼續變更資料擷取 (CDC)。 | 在 Amazon RDS for PostgreSQL 資料庫執行個體`VACUUM`上執行，然後重新啟動 AWS DMS 任務以套用快取的 CDC 變更。 | DBA | 

### 切換到 PostgreSQL 資料庫
<a name="cut-over-to-the-postgresql-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查 AWS DMS 日誌和驗證資料表。 | 檢查並修正任何複寫或驗證錯誤。 | DBA | 
| 停止使用現場部署 Oracle 資料庫及其相依性。 | 停止所有 Oracle 相依性、關閉 Oracle 資料庫上的接聽程式，然後執行 `ALTER SYSTEM SWITCH LOGFILE`。在未顯示活動時停止 AWS DMS 任務。 | DBA | 
| 從 AWS SCT 執行遷移後指令碼。 | 在 Amazon RDS for PostgreSQL 中，執行這些指令碼：`create_foreign_key_constraint.sql and create_triggers.sql`。請確定序列是最新的。 | DBA | 
| 完成其他 Amazon RDS for PostgreSQL 步驟。 | 視需要遞增序列以符合 Oracle、執行 `VACUUM`和 `ANALYZE`，並拍攝快照以符合規範。 | DBA | 
| 開啟 Amazon RDS for PostgreSQL 的連線。 | 從 Amazon RDS for PostgreSQL 移除 AWS DMS 安全群組、新增生產安全群組，並將您的應用程式指向新的資料庫。 | DBA | 
| 清除 AWS DMS 物件。 | 移除端點、複寫任務、複寫執行個體和 EC2 執行個體。 | SysAdmin、DBA | 

## 相關資源
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms-resources"></a>
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html)
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [Amazon RDS for PostgreSQL 定價](https://aws.amazon.com/rds/postgresql/pricing/)
+ [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ [使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)

# 使用 AWS DMS 和 AWS SCT 從 Oracle on Amazon EC2 遷移至 Amazon RDS for MySQL
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct"></a>

*Anil Kunapareddy，Amazon Web Services*

*Harshad Gohil，無*

## 摘要
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-summary"></a>

在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上管理 Oracle 資料庫需要 資源，而且成本高昂。將這些資料庫移至適用於 MySQL 資料庫執行個體的 Amazon Relational Database Service (Amazon RDS)，可透過最佳化整體 IT 預算來簡化您的任務。Amazon RDS for MySQL 也提供異地同步備份、可擴展性和自動備份等功能。 

此模式會逐步引導您在 Amazon EC2 上將來源 Oracle 資料庫遷移至目標 Amazon RDS for MySQL 資料庫執行個體。它使用 AWS Database Migration Service (AWS DMS) 遷移資料，並使用 AWS Schema Conversion Tool (AWS SCT) 將來源資料庫結構描述和物件轉換為與 Amazon RDS for MySQL 相容的格式。

## 先決條件和限制
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 在 ARCHIVELOG 模式下執行執行個體和接聽程式服務的來源資料庫
+ 目標 Amazon RDS for MySQL 資料庫，具有足夠的資料遷移儲存空間

**限制**
+ AWS DMS 不會在目標資料庫上建立結構描述；您必須這麼做。目標的結構描述名稱必須已存在。來源結構描述中的資料表會匯入至使用者/結構描述，AWS DMS 會使用此結構描述來連線至目標執行個體。如果您必須遷移多個結構描述，即必須建立多項複寫任務。

**產品版本**
+ 版本 10.2 及更新版本、11g 及最高 12.2 和 18c 的所有 Oracle 資料庫版本。如需支援版本的最新清單，請參閱[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)和[使用 MySQL 相容資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。如需 AWS SCT 支援的 Oracle 資料庫版本的相關資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。
+ AWS DMS 支援 MySQL 5.5、5.6 和 5.7 版。

## Architecture
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊**
+ EC2 執行個體上的 Oracle 資料庫  

**目標技術堆疊**
+ Amazon RDS for MySQL 資料庫執行個體

**資料遷移架構**

![\[使用 AWS DMS 從 Amazon EC2 上的 Oracle 遷移到 Amazon RDS for MySQL\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8a8e346e-7944-4999-bc11-208efead3792/images/c00f908c-f348-41dd-a31c-3931b990777a.png)


**來源和目標架構  **

![\[使用 AWS DMS 和 AWS SCT 從 Amazon EC2 上的 Oracle 遷移到 Amazon RDS for MySQL\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8a8e346e-7944-4999-bc11-208efead3792/images/e7ba7ac0-3094-4142-b355-fb192e242432.png)


## 工具
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-tools"></a>
+ **AWS DMS** - [AWS Database Migration Service](https://docs.aws.amazon.com/dms/) (AWS DMS) 是一種 Web 服務，可用來將資料從內部部署、Amazon RDS 資料庫執行個體或 EC2 執行個體上的資料庫遷移到 AWS 服務上的資料庫，例如 Amazon RDS for MySQL 或 EC2 執行個體。您也可以將資料庫從 AWS 服務遷移至內部部署資料庫。您可以在異質或同質資料庫引擎之間遷移資料。
+ **AWS SCT** - [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) (AWS SCT) 會自動將來源資料庫結構描述和大部分資料庫程式碼物件，包括檢視、預存程序和函數，轉換為與目標資料庫相容的格式，使異質資料庫遷移可預測。使用 AWS SCT 轉換資料庫結構描述和程式碼物件之後，您可以使用 AWS DMS 將資料從來源資料庫遷移至目標資料庫，以完成遷移專案。

## 史詩
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別來源和目標資料庫版本和引擎。 |  | DBA/開發人員 | 
| 識別 DMS 複寫執行個體。 |  | DBA/開發人員 | 
| 識別儲存需求，例如儲存類型和容量。 |  | DBA/開發人員 | 
| 識別網路需求，例如延遲和頻寬。 |  |  DBA/開發人員 | 
| 識別來源和目標伺服器執行個體的硬體需求 （根據 Oracle 相容性清單和容量需求）。 |  | DBA/開發人員 | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA/開發人員 | 
| 安裝 AWS SCT 和 Oracle 驅動程式。 |  | DBA/開發人員 | 
| 決定備份策略。 |  | DBA/開發人員 | 
| 判斷可用性需求。 |  | DBA/開發人員 | 
| 識別應用程式遷移和切換策略。 |  | DBA/開發人員 | 
| 根據容量、儲存體和網路功能，選取適當的資料庫執行個體類型。 |  | DBA/開發人員 | 

### 設定環境
<a name="configure-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) 來源、目標和複寫執行個體應該位於相同的 VPC 中。最好在相同的可用區域中擁有這些項目。 |  | 開發人員 | 
| 建立資料庫存取所需的安全群組。 |  |  開發人員 | 
| 產生和設定金鑰對。 |  | 開發人員 | 
| 設定子網路、可用區域和 CIDR 區塊。 |  | 開發人員 | 

### 設定來源：EC2 執行個體上的 Oracle 資料庫
<a name="configure-the-source-oracle-database-on-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用必要的使用者和角色在 Amazon EC2 上安裝 Oracle Database。 |  | DBA | 
|  執行下一欄中的三個步驟，從 EC2 執行個體外部存取 Oracle。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.html) | DBA | 
| 重新啟動 Amazon EC2 時，公有 DNS 會變更。請務必更新 'tnsnames' 和 'listener' 中的 Amazon EC2 公有 DNS，或使用彈性 IP 地址。 |  | DBA/開發人員 | 
| 設定 EC2 執行個體安全群組，讓複寫執行個體和必要的用戶端可以存取來源資料庫。 |  | DBA/開發人員 | 

### 設定目標：Amazon RDS for MySQL
<a name="configure-the-target-amazon-rds-for-mysql"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定和啟動 Amazon RDS for MySQL 資料庫執行個體。 |  | 開發人員 | 
| 在 Amazon RDS for MySQL 資料庫執行個體中建立必要的資料表空間。 |  | DBA | 
| 設定安全群組，讓複寫執行個體和必要的用戶端可以存取目標資料庫。 |  | 開發人員 | 

### 設定 AWS SCT 並在目標資料庫中建立結構描述
<a name="configure-aws-sct-and-create-a-schema-in-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS SCT 和 Oracle 驅動程式。 |  | 開發人員 | 
| 輸入適當的參數並連接到來源和目標。 |  | 開發人員 | 
| 產生結構描述轉換報告。 |  | 開發人員 | 
| 視需要更正程式碼和結構描述，特別是資料表空間和引號，並在目標資料庫上執行。 |  |  開發人員 | 
| 在遷移資料之前，驗證來源與目標上的結構描述。 |  | 開發人員 | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 對於完全載入和變更資料擷取 (CDC) 或僅 CDC，您必須設定額外的連線屬性。 |  | 開發人員 | 
| AWS DMS 來源 Oracle 資料庫定義中指定的使用者必須獲得所有必要的權限。如需完整清單，請參閱 https：//https://docs.aws.amazon.com/dms/latest/userguide/CHAP\$1Source.Oracle.html\$1CHAP\$1Source.Oracle.Self-Managed。 |  | DBA/開發人員 | 
| 在來源資料庫中啟用補充記錄。 |  | DBA/開發人員 | 
| 對於完全載入和變更資料擷取 (CDC) 或僅 CDC，請在來源資料庫中啟用 ARCHIVELOG 模式。 |  | DBA | 
| 建立來源和目標端點，並測試連線。 |  | 開發人員 | 
| 成功連接端點時，請建立複寫任務。 |  | 開發人員 | 
| 在任務中選取僅限 CDC （或） 完全載入加上 CDC，以分別擷取僅限連續複寫 （或） 完全載入加上持續變更的變更。 |  | 開發人員 | 
| 執行複寫任務並監控 Amazon CloudWatch logs。 |  |  開發人員 | 
| 驗證來源和目標資料庫中的資料。 |  | 開發人員 | 

### 遷移您的應用程式並切換
<a name="migrate-your-application-and-cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 請遵循應用程式遷移策略的步驟。 |  | DBA、開發人員、應用程式擁有者 | 
| 請遵循應用程式切換/切換策略的步驟。 |  | DBA、開發人員、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源資料庫與目標資料庫中的結構描述和資料。 |  | DBA/開發人員 | 
| 收集遷移時間的指標、手動與工具的百分比、節省成本等。 |  |  DBA/Developer/AppOwner | 
| 檢閱專案文件和成品。 |  | DBA/Developer/AppOwner | 
| 關閉臨時 AWS 資源。 |  | DBA/開發人員 | 
| 關閉專案並提供意見回饋。 |  | DBA/Developer/AppOwner | 

## 相關資源
<a name="migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-resources"></a>
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 
+ [AWS DMS 網站](https://aws.amazon.com/dms/)
+ [AWS DMS 部落格文章](https://aws.amazon.com/blogs/database/tag/dms/) 
+ [將 Oracle Database 遷移到 AWS 的策略](https://d1.awsstatic.com/whitepapers/strategies-for-migrating-oracle-database-to-aws.pdf) 
+ [Amazon RDS for Oracle FAQs](https://aws.amazon.com/rds/oracle/faqs/) 
+ [Oracle 常見問答集](https://aws.amazon.com/oracle/faq/) 
+ [Amazon EC2](https://aws.amazon.com/ec2/) 
+ [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)
+ [在雲端運算環境中授權 Oracle 軟體](http://www.oracle.com/us/corporate/pricing/cloud-licensing-070579.pdf)

# 使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for MariaDB
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct"></a>

*Veeranjaneyulu Grandhi 和 vinod kumar，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct-summary"></a>

此模式會逐步引導您將 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 Oracle 資料庫遷移至適用於 MariaDB 資料庫執行個體的 Amazon Relational Database Service (Amazon RDS)。模式使用 AWS Data Migration Service (AWS DMS) 進行資料遷移，並使用 AWS Schema Conversion Tool (AWS SCT) 進行結構描述轉換。

在 EC2 執行個體上管理 Oracle 資料庫需要更多資源，而且比在 Amazon RDS 上使用資料庫更昂貴。Amazon RDS 可讓您輕鬆地在雲端中設定、操作和擴展關聯式資料庫。Amazon RDS 提供經濟實惠且可調整大小的容量，同時自動化耗時的管理任務，例如硬體佈建、資料庫設定、修補和備份。

## 先決條件和限制
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 啟動並執行執行個體和接聽程式服務的來源 Oracle 資料庫。此資料庫應處於 ARCHIVELOG 模式。
+ 熟悉[使用 Oracle 資料庫做為 AWS DMS 來源。](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 Oracle 做為 AWS SCT 來源。](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)

**限制**
+ 資料庫大小限制：64 TB 

**產品版本**
+ 版本 10.2 及更新版本、11g 及最高 12.2 和 18c 的所有 Oracle 資料庫版本。如需支援版本的最新清單，請參閱 [AWS 文件中的使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)和 AWS [SCT 版本資料表](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。
+ Amazon RDS 支援 MariaDB Server Community Server 10.3、10.4、10.5 和 10.6 版。如需支援版本的最新清單，請參閱[Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MariaDB.html)。

## Architecture
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊**
+ EC2 執行個體上的 Oracle 資料庫

**目標技術堆疊**
+ Amazon RDS for MariaDB

**資料遷移架構**

![\[使用 AWS DMS 進行遷移。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0b4269c6-8ea3-4672-ad14-1ffac1dc14f3/images/ed191145-e5c2-4d61-8827-31f081450c03.png)


**目標架構**

![\[使用 AWS SCT 進行遷移。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0b4269c6-8ea3-4672-ad14-1ffac1dc14f3/images/0171f548-37dd-4110-851c-7e74dfff3732.png)


## 工具
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct-tools"></a>
+ [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) (AWS SCT) 會自動將來源資料庫結構描述和大部分資料庫程式碼物件，包括檢視、預存程序和函數，轉換為與目標資料庫相容的格式，讓異質資料庫遷移可預測。使用 AWS SCT 轉換資料庫結構描述和程式碼物件之後，您可以使用 AWS DMS 將資料從來源資料庫遷移到目標資料庫，以完成遷移專案。如需詳細資訊，請參閱 [AWS SCT 文件中的使用 Oracle 做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)。
+ [AWS Database Migration Service](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) (AWS DMS) 可協助您快速安全地將資料庫遷移至 AWS。來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降至最低。AWS DMS 可以在最廣泛使用的商業和開放原始碼資料庫之間遷移您的資料。AWS DMS 支援同質遷移，例如 Oracle 到 Oracle，以及不同資料庫平台之間的異質遷移，例如 Oracle 或 Microsoft SQL Server 到 Amazon Aurora。若要進一步了解遷移 Oracle 資料庫，請參閱 [AWS DMS 文件中的使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。

## 史詩
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct-epics"></a>

### 規劃遷移
<a name="plan-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別版本和資料庫引擎。 | 識別來源和目標資料庫版本和引擎。 | DBA、開發人員 | 
| 識別複寫執行個體。 | 識別 AWS DMS 複寫執行個體。 | DBA、開發人員 | 
| 識別儲存需求。 | 識別儲存類型和容量。 | DBA、開發人員 | 
| 識別網路需求。 | 識別網路延遲和頻寬。 | DBA、開發人員 | 
| 識別硬體需求。 | 識別來源和目標伺服器執行個體的硬體需求 （根據 Oracle 相容性清單和容量需求）。 | DBA、開發人員 | 
| 識別安全需求。 | 識別來源和目標資料庫的網路存取安全需求。 | DBA、開發人員 | 
| 安裝驅動程式。 | 安裝最新的 AWS SCT 和 Oracle 驅動程式。 | DBA、開發人員 | 
| 決定備份策略。 |  | DBA、開發人員 | 
| 判斷可用性需求。 |  | DBA、開發人員 | 
| 選擇應用程式遷移/切換策略。 |  | DBA、開發人員 | 
| 選取 執行個體類型。 | 根據容量、儲存體和網路功能選取適當的執行個體類型。 | DBA、開發人員 | 

### 設定環境
<a name="configure-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC)  | 來源、目標和複寫執行個體應位於相同的 VPC 和相同的可用區域 （建議）。 | 開發人員 | 
| 建立安全群組。 | 建立資料庫存取所需的安全群組。 | 開發人員 | 
| 產生金鑰對。 | 產生和設定金鑰對。 | 開發人員 | 
| 設定其他資源。 | 設定子網路、可用區域和 CIDR 區塊。 | 開發人員 | 

### 設定來源
<a name="configure-the-source"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 EC2 執行個體。 | 如需說明，請參閱 [Amazon EC2 文件](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)。 | 開發人員 | 
| 安裝 Oracle 資料庫。 | 在 EC2 執行個體上安裝 Oracle 資料庫，其中包含必要的使用者和角色。 | DBA | 
| 請依照任務描述中的步驟，從 EC2 執行個體外部存取 Oracle。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct.html) | DBA | 
| 更新 Amazon EC2 公有 DNS。 | EC2 執行個體重新啟動後，公有 DNS 會變更。請務必更新 `tnsnames`和 中的 Amazon EC2 公有 DNS`listener`，或使用彈性 IP 地址。 | DBA、開發人員 | 
| 設定 EC2 執行個體安全群組。 | 設定 EC2 執行個體安全群組，讓複寫執行個體和必要的用戶端可以存取來源資料庫。 | DBA、開發人員 | 

### 設定目標 Amazon RDS for MariaDB 環境
<a name="configure-the-target-amazon-rds-for-mariadb-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 RDS 資料庫執行個體。 | 設定和啟動 Amazon RDS for MariaDB 資料庫執行個體。 | 開發人員 | 
| 建立資料表空間。 | 在 Amazon RDS MariaDB 資料庫中建立任何必要的資料表空間。 | DBA | 
| 設定安全群組。 | 設定安全群組，讓複寫執行個體和必要的用戶端可以存取目標資料庫。 | 開發人員 | 

### 設定 AWS SCT
<a name="configure-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝驅動程式。 | 安裝最新的 AWS SCT 和 Oracle 驅動程式。 | 開發人員 | 
| 連接。 | 輸入適當的參數，然後連接到來源和目標。 | 開發人員 | 
| 產生結構描述轉換報告。 | 產生 AWS SCT 結構描述轉換報告。 | 開發人員 | 
| 視需要更正程式碼和結構描述。 | 對程式碼和結構描述進行任何必要的更正 （特別是資料表空間和引號）。 | DBA、開發人員 | 
| 驗證結構描述。 | 在載入資料之前，驗證來源與目標上的結構描述。 | 開發人員 | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定連線屬性。 | 對於完全載入和變更資料擷取 (CDC)，或僅針對 CDC，請設定額外的連線屬性。如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MariaDB.html)。 | 開發人員 | 
| 啟用補充記錄。 | 在來源資料庫上啟用補充記錄。 | DBA、開發人員 | 
| 啟用封存日誌模式。 | 對於完全載入和 CDC （或僅適用於 CDC)，請在來源資料庫上啟用封存日誌模式。 | DBA | 
| 建立和測試端點。 | 建立來源和目標端點並測試連線。如需詳細資訊，請參閱 [Amazon DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)。 | 開發人員 | 
| 建立複寫任務。 | 成功連接端點時，請建立複寫任務。如需詳細資訊，請參閱 [Amazon DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Task.CDC.html)。 | 開發人員 | 
| 選擇複寫類型。 | 在任務中選擇**僅限 CDC** 或**完全載入加上 CDC**，以擷取僅限連續複寫的變更，或分別針對完全載入和持續變更進行的變更。 | 開發人員 | 
| 啟動並監控任務。 | 啟動複寫任務並監控 Amazon CloudWatch logs。如需詳細資訊，請參閱 [Amazon DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html)。 | 開發人員 | 
| 驗證資料。 | 驗證來源和目標資料庫中的資料。 | 開發人員 | 

### 遷移應用程式並切換到目標資料庫
<a name="migrate-applications-and-cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循所選的應用程式遷移策略。 |  | DBA、應用程式擁有者、開發人員 | 
| 遵循所選的應用程式切換/切換策略。 |  | DBA、應用程式擁有者、開發人員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證結構描述和資料。 | 確保在專案關閉之前，在來源與目標中成功驗證結構描述和資料。 | DBA、開發人員 | 
| 收集指標。 | 收集遷移時間、手動與工具任務的百分比、節省成本和類似條件的指標。 | DBA、應用程式擁有者、開發人員 | 
| 檢閱文件。 | 檢閱專案文件和成品。 | DBA、應用程式擁有者、開發人員 | 
| 關閉資源。 | 關閉臨時 AWS 資源。 | DBA、開發人員 | 
| 關閉專案。 | 關閉遷移專案並提供任何意見回饋。 | DBA、應用程式擁有者、開發人員 | 

## 相關資源
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct-resources"></a>
+ [MariaDB Amazon RDS 概觀](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MariaDB.html)
+ [Amazon RDS for MariaDB 產品詳細資訊](https://aws.amazon.com/rds/mariadb/features)
+ [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ [將 Oracle 資料庫遷移至 AWS 的策略](https://docs.aws.amazon.com/whitepapers/latest/strategies-migrating-oracle-db-to-aws/strategies-migrating-oracle-db-to-aws.html)
+ [在雲端運算環境中授權 Oracle 軟體](http://www.oracle.com/us/corporate/pricing/cloud-licensing-070579.pdf)
+ [Amazon RDS for Oracle FAQs](https://aws.amazon.com/rds/oracle/faqs/)
+ [AWS DMS 概觀](https://aws.amazon.com/dms/)
+ [AWS DMS 部落格文章](https://aws.amazon.com/blogs/database/tag/dms/)
+ [Amazon EC2 概觀](https://aws.amazon.com/ec2/)
+ [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)

# 使用 AWS DMS 和 AWS SCT 將內部部署 Oracle 資料庫遷移至 Amazon RDS for MySQL
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct"></a>

*Sergey Dmitriev 和 Naresh Damera，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-summary"></a>

此模式會逐步引導您將現場部署 Oracle 資料庫遷移至 MySQL 資料庫執行個體的 Amazon Relational Database Service (Amazon RDS)。它使用 AWS Database Migration Service (AWS DMS) 遷移資料，並使用 AWS Schema Conversion Tool (AWS SCT) 將來源資料庫結構描述和物件轉換為與 Amazon RDS for MySQL 相容的格式。

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-prerequisites-and-limitations"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的來源 Oracle 資料庫 

**限制**
+ 資料庫大小限制：64 TB

**產品版本**
+ 版本 11g （版本 11.2.0.3.v1 和更新版本） 和最高 12.2 和 18c 的所有 Oracle 資料庫版本。如需支援版本的最新清單，請參閱[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。如需 AWS SCT 支援的 Oracle 資料庫版本的相關資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。 
+ AWS DMS 目前支援 MySQL 5.5、5.6 和 5.7 版。如需支援版本的最新清單，請參閱 [AWS 文件中的使用 MySQL 相容資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)。

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫

**目標技術堆疊**
+ Amazon RDS for MySQL 資料庫執行個體

**資料遷移架構**

![\[AWS 雲端 architecture showing data migration from on-premises to RDS via VPC, Internet Gateway, and AWS DMS.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0385e5ad-a1ca-4c29-945b-592321d95f9d/images/c872e033-b13a-4436-b503-0632b5d437ae.png)


 

## 工具
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-tools"></a>
+ **AWS DMS** - [AWS Database Migration Services](https://docs.aws.amazon.com/dms/latest/userguide/) (AWS DMS) 可協助您遷移關聯式資料庫、資料倉儲、NoSQL 資料庫和其他類型的資料存放區。您可以使用 AWS DMS 將資料遷移至 AWS 雲端，可在現場部署執行個體 (透過 AWS 雲端設定) 或在雲端和現場部署設定之間進行。
+ **AWS SCT** - [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) (AWS SCT) 用於將您的資料庫結構描述從一個資料庫引擎轉換為另一個資料庫引擎。工具轉換的自訂程式碼包含檢視、預存程序和函數。工具無法自動轉換的任何程式碼都會清楚標示，讓您可以自行轉換。

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
|  識別目標伺服器執行個體的硬體需求。 |  | DBA、SysAdmin | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA、SysAdmin | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA、SysAdmin  | 
| 識別應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立虛擬私有雲端 (VPC) 和子網路。 |  | SysAdmin | 
| 建立安全群組和網路存取控制清單 ACLs)。 |  | SysAdmin | 
| 設定和啟動 Amazon RDS 資料庫執行個體。 |  | DBA、SysAdmin | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS SCT 遷移資料庫結構描述。 |  | DBA | 
| 使用 AWS DMS 遷移資料。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS SCT 來分析和轉換應用程式程式碼內的 SQL 程式碼。 | 如需詳細資訊，請參閱 https：//https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP\$1Converting.App.html。 | 應用程式擁有者 | 
| 遵循應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA、SysAdmin | 
| 檢閱並驗證專案文件。 |  | DBA、SysAdmin | 
| 收集遷移時間的指標、手動與工具的 %、節省成本等。 |  | DBA、SysAdmin | 
| 關閉專案並提供意見回饋。 |  |  | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct-related-resources"></a>

**參考**
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/)
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)

**教學課程和影片**
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [AWS DMS （影片）](https://www.youtube.com/watch?v=zb4GcjEdl8U) 
+ [Amazon RDS （影片）](https://www.youtube.com/watch?v=igRfulrrYCo) 

# 使用 Oracle 旁觀者和 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms"></a>

*Cady Motyka，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms-summary"></a>

此模式說明如何將現場部署 Oracle 資料庫遷移至下列任一 PostgreSQL 相容 AWS 資料庫服務，並將停機時間降至最低：
+ PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)
+ Amazon Aurora PostgreSQL-Compatible Edition

解決方案使用 AWS Database Migration Service (AWS DMS) 來遷移資料、AWS Schema Conversion Tool (AWS SCT) 來轉換資料庫結構描述，以及 Oracle bystander 資料庫來協助管理遷移。在此實作中，停機時間僅限於建立或驗證資料庫上所有外部金鑰所需的時間。 

解決方案也使用 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體搭配 Oracle 旁觀者資料庫，以協助透過 AWS DMS 控制資料串流。您可以暫停從現場部署 Oracle 資料庫到 Oracle 旁觀者的串流複寫，以啟用 AWS DMS 來跟上資料驗證的進度，或使用其他資料驗證工具。當 AWS DMS 完成遷移目前的變更時，Amazon RDS for PostgreSQL 資料庫執行個體或 Aurora PostgreSQL 相容資料庫執行個體和旁觀者資料庫將具有相同的資料。 

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 已設定 Active Data Guard 待命資料庫的現場部署資料中心中的來源 Oracle 資料庫
+ 在內部部署資料中心和 AWS Secrets Manager 之間設定 AWS Direct Connect，以存放資料庫秘密
+ AWS SCT 連接器的 Java Database Connectivity (JDBC) 驅動程式，安裝在本機電腦或安裝 AWS SCT 的 EC2 執行個體上
+ 熟悉[使用 Oracle 資料庫做為 AWS DMS 來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)

**限制**
+ 資料庫大小限制：64 TB

**產品版本**
+ AWS DMS 支援 10.2 版和更新版本 （適用於 10.x 版）、11g 和最高 12.2、18c 和 19c 版的所有 Oracle 資料庫版本。如需支援版本的最新清單，請參閱[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。如需 AWS SCT 支援的 Oracle 資料庫版本的相關資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。
+ AWS DMS 支援 PostgreSQL 9.4 版和更新版本 （適用於 9.x 版）、10.x、11.x、12.x 和 13.x 版。如需最新資訊，請參閱 [AWS 文件中的使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)。

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫
+ 保留 Oracle 資料庫旁觀者的 AnEC2 執行個體

**目標技術堆疊**
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 執行個體、PostgreSQL 9.3 及更新版本

**目標架構**

下圖顯示使用 AWS DMS 和 Oracle 旁觀者，將 Oracle 資料庫遷移至 PostgreSQL 相容 AWS 資料庫的範例工作流程：

![\[將內部部署 Oracle 資料庫遷移至 AWS 上的 PostgreSQL。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6f5d5500-8b09-4bd1-8ef9-e670d58d07f8/images/1de98abd-c143-481a-b55f-e8d00eb96a38.png)


## 工具
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms-epics"></a>

### 將 Oracle 資料庫結構描述轉換為 PostgreSQL
<a name="convert-the-oracle-database-schema-to-postgresql"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS SCT。 | 建立新的報告，並連接至 Oracle 做為來源，而 PostgreSQL 做為目標。在**專案設定**中，前往 **SQL 指令碼索引標籤**。將**目標 SQL 指令碼**變更為**多個檔案**。這些檔案將在稍後使用，並命名如下：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.html) | DBA | 
| 轉換 Oracle 資料庫結構描述。 | 在**動作**索引標籤中，選擇**產生報告**。然後，選擇**轉換結構描述**，然後選擇**另存為 SQL**。 | DBA | 
| 修改指令碼。 | 例如，如果來源結構描述中的數字已在 PostgreSQL 中轉換為數值格式，但您想要改用 **BIGINT **以獲得更好的效能，您可能想要修改指令碼。 | DBA | 

### 建立和設定 Amazon RDS 資料庫執行個體
<a name="create-and-configure-the-amazon-rds-db-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS 資料庫執行個體。 | 在正確的 AWS 區域中，建立新的 PostgreSQL 資料庫執行個體。如需詳細資訊，請參閱 Amazon RDS 文件中的[建立 PostgreSQL 資料庫執行個體和連線至 PostgreSQL 資料庫執行個體上的](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.PostgreSQL.html)資料庫。 | AWS SysAdmin、DBA | 
| 設定資料庫執行個體規格。 | 指定資料庫引擎版本、資料庫執行個體類別、異地同步備份部署、儲存類型和配置的儲存。輸入資料庫執行個體識別符、主要使用者名稱和主要密碼。 | AWS SysAdmin、DBA | 
| 設定網路和安全性。 | 指定虛擬私有雲端 (VPC)、子網路群組、公有可存取性、可用區域偏好設定和安全群組。 | DBA、SysAdmin | 
| 設定資料庫選項。 | 指定資料庫名稱、連接埠、參數群組、加密和 KMS 金鑰。 | AWS SysAdmin、DBA | 
| 設定備份。 | 指定備份保留期、備份時段、開始時間、持續時間，以及是否要將標籤複製到快照。 | AWS SysAdmin、DBA | 
| 設定監控選項。 | 啟用或停用增強型監控和效能洞察。 | AWS SysAdmin、DBA | 
| 設定維護選項。 | 指定自動次要版本升級、維護時段，以及開始日期、時間和持續時間。 | AWS SysAdmin、DBA | 
| 從 AWS SCT 執行預遷移指令碼。 | 在 Amazon RDS 執行個體上，執行 AWS SCT 產生的下列指令碼：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.html) | AWS SysAdmin、DBA | 

### 在 Amazon EC2 中設定 Oracle 旁觀者
<a name="configure-the-oracle-bystander-in-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Amazon EC2 的網路。 | 建立新的 VPC、子網路、網際網路閘道、路由表和安全群組。 | AWS SysAdmin | 
| 建立 EC2 執行個體。 | 在適當的 AWS 區域中，建立新的 EC2 執行個體。選取 Amazon Machine Image (AMI)，選擇執行個體大小，並設定執行個體詳細資訊：執行個體數量 (1)、您在先前任務中建立的 VPC 和子網路、自動指派公有 IP 和其他選項。新增儲存、設定安全群組和啟動。出現提示時，請建立並儲存下一個步驟的金鑰對。 | AWS SysAdmin | 
| 將 Oracle 來源資料庫連接至 EC2 執行個體。 | 將 IPv4 公有 IP 地址和 DNS 複製到文字檔案，並使用 SSH 連線，如下所示：**ssh -i "your\$1file.pem" ec2-user@<your-IP-address-or-public-DNS>**。 | AWS SysAdmin | 
| 在 Amazon EC2 中為旁觀者設定初始主機。 | 設定 SSH 金鑰、Bash 設定檔、ORATAB 和符號連結。建立 Oracle 目錄。 | AWS SysAdmin、Linux Admin | 
| 在 Amazon EC2 中設定旁觀者的資料庫副本 | 使用 RMAN 建立資料庫複本、啟用補充記錄，以及建立待命控制檔案。複製完成後，將資料庫置於復原模式。 | AWS SysAdmin、DBA | 
| 設定 Oracle Data Guard。 | 修改您的 **listener.ora** 檔案並啟動接聽程式。設定新的封存目的地。將旁觀者置於復原模式、取代暫存檔案以避免未來損毀、視需要安裝 crontab 以防止封存目錄空間不足，以及編輯來源和待命的 **manage-trclog-files-oracle.cfg** 檔案。 | AWS SysAdmin、DBA | 
| 準備 Oracle 資料庫以同步運送。 | 新增待命日誌檔案並變更復原模式。變更來源主要和來源待命上傳送至 **SYNC AFFIRM** 的日誌。在主要 上切換日誌，透過 Amazon EC2 旁觀者警示日誌確認您正在使用待命日誌檔案，並確認重做串流正在 SYNC 中流動。 | AWS SysAdmin、DBA | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-with-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS DMS 中建立複寫執行個體。 | 完成名稱、執行個體類別、VPC （與 Amazon EC2 執行個體相同）、異地同步備份和公有可存取性的欄位。在**進階**下，指定配置的儲存、子網路群組、可用區域、VPC 安全群組和 AWS Key Management Service (AWS KMS) 金鑰。 | AWS SysAdmin、DBA | 
| 建立來源資料庫端點。 | 指定端點名稱、類型、來源引擎 (Oracle)、伺服器名稱 (Amazon EC2 私有 DNS 名稱）、連接埠、SSL 模式、使用者名稱、密碼、SID、VPC （指定具有複寫執行個體的 VPC) 和複寫執行個體。若要測試連線，請選擇**執行測試**，然後建立端點。您也可以設定下列進階設定：**maxFileSize** 和 **numberDataTypeScale**。 | AWS SysAdmin、DBA | 
| 將 AWS DMS 連線至 Amazon RDS for PostgreSQL。 | 建立跨 VPCs 連線的遷移安全群組。 | AWS SysAdmin、DBA | 
| 建立目標資料庫端點。 | 指定端點名稱、類型、來源引擎 (PostgreSQL)、伺服器名稱 (Amazon RDS 端點）、連接埠、SSL 模式、使用者名稱、密碼、資料庫名稱、VPC （指定具有複寫執行個體的 VPC) 和複寫執行個體。若要測試連線，請選擇**執行測試**，然後建立端點。您也可以設定下列進階設定：**maxFileSize **和 **numberDataTypeScale**。 | AWS SysAdmin、DBA | 
| 建立 AWS DMS 複寫任務。 | 指定任務名稱、複寫執行個體、來源和目標端點，以及複寫執行個體。針對遷移類型，選擇**遷移現有資料並複寫持續變更**。清除**建立時啟動任務**核取方塊。 | AWS SysAdmin、DBA | 
| 設定 AWS DMS 複寫任務設定。 | 針對目標資料表準備模式，選擇**不執行任何動作**。完全載入完成後停止任務 （建立主索引鍵）。指定有限或完整 LOB 模式，並啟用控制資料表。或者，您可以設定 **CommitRate** 進階設定。 | DBA | 
| 設定資料表映射。 | 在**資料表映射**區段中，為遷移中包含的所有結構描述中的所有資料表建立**包含**規則，然後建立**排除**規則。新增三個轉換規則，將結構描述、資料表和資料欄名稱轉換為小寫，並新增此特定遷移所需的任何其他規則。 | DBA | 
| 啟動 任務。 | 啟動複寫任務。確定完全載入正在執行中。在主要 Oracle 資料庫上執行 **ALTER SYSTEM SWITCH LOGFILE**，以啟動任務。 | DBA | 
| 從 AWS SCT 執行中遷移指令碼。 | 在 Amazon RDS for PostgreSQL 中，執行 AWS SCT 產生的下列指令碼：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.html) | DBA | 
| 重新啟動任務以繼續變更資料擷取 (CDC)。 | 在 Amazon RDS for PostgreSQL 資料庫執行個體上執行 **VACUUM**，然後重新啟動 AWS DMS 任務以套用快取的 CDC 變更。 | DBA | 

### 切換到 PostgreSQL 資料庫
<a name="cut-over-to-the-postgresql-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱 AWS DMS 日誌和驗證資料表是否有任何錯誤。 | 檢查並修正任何複寫或驗證錯誤。 | DBA | 
| 停止所有 Oracle 相依性。 | 停止所有 Oracle 相依性、關閉 Oracle 資料庫上的接聽程式，並執行 **ALTER SYSTEM SWITCH LOGFILE**。在未顯示活動時停止 AWS DMS 任務。 | DBA | 
| 從 AWS SCT 執行遷移後指令碼。 | 在 Amazon RDS for PostgreSQL 中，執行 AWS SCT 產生的下列指令碼：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.html) | DBA | 
| 完成其他 Amazon RDS for PostgreSQL 步驟。 | 視需要遞增序列以符合 Oracle，執行 **VACUUM** 和 **ANALYZE**，並拍攝快照以符合合規。 | DBA | 
| 開啟 Amazon RDS for PostgreSQL 的連線。 | 從 Amazon RDS for PostgreSQL 移除 AWS DMS 安全群組、新增生產安全群組，並將您的應用程式指向新的資料庫。 | DBA | 
| 清除 AWS DMS 物件。 | 移除端點、複寫任務、複寫執行個體和 EC2 執行個體。 | SysAdmin、DBA | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms-resources"></a>
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/)
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [Amazon RDS for PostgreSQL 定價](https://aws.amazon.com/rds/postgresql/pricing/) 

# 使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Amazon Redshift
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct"></a>

*Piyush Goyal 和 Brian motzer，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct-summary"></a>

此模式提供使用 AWS Database Migration Service (AWS DMS) 和 AWS Schema Conversion Tool (AWS SCT)，將 Oracle 資料庫遷移至 Amazon Web Services (AWS) 雲端中 Amazon Redshift 雲端資料倉儲的指引。模式涵蓋現場部署或安裝在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的來源 Oracle 資料庫。它還涵蓋 Oracle 資料庫的 Amazon Relational Database Service (Amazon RDS)。

## 先決條件和限制
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct-prereqs"></a>

**先決條件**
+ 在內部部署資料中心或 AWS 雲端中執行的 Oracle 資料庫
+ 作用中的 AWS 帳戶
+ 熟悉[使用 Oracle 資料庫做為 AWS DMS 來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 Amazon Redshift 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Redshift.html)
+ 了解 Amazon RDS、Amazon Redshift、適用的資料庫技術和 SQL
+ 適用於 AWS SCT 連接器的 Java Database Connectivity (JDBC) 驅動程式，其中已安裝 AWS SCT

**產品版本**
+ 對於自我管理的 Oracle 資料庫，AWS DMS 支援 10.2 版和更新版本 （適用於 10.*x* 版）、11g 和最高 12.2、18c 和 19c 版的所有 Oracle 資料庫版本。對於 AWS 管理的 Amazon RDS for Oracle 資料庫，AWS DMS 支援 11g 版 (11.2.0.4 版和更新版本） 和最多 12.2、18c 和 19c 版的所有 Oracle 資料庫版本。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。

## Architecture
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊**

下列其中一項：
+ 內部部署 Oracle 資料庫
+ EC2 執行個體上的 Oracle 資料庫
+ Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**
+ Amazon Redshift

**目標架構**

*從 AWS 雲端中執行的 Oracle 資料庫到 Amazon Redshift：*

![\[將 AWS 雲端中的 Oracle 資料庫遷移至 Amazon Redshift 資料倉儲。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/22807be0-c7e0-49c6-8923-7d23bf83a50d/images/7140e819-81d6-45c4-805b-8e10828076a7.png)


*從現場部署資料中心中執行的 Oracle 資料庫到 Amazon Redshift：*

![\[將內部部署 Oracle 資料庫遷移至 Amazon Redshift 資料倉儲。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/22807be0-c7e0-49c6-8923-7d23bf83a50d/images/d6654b48-0e1b-4b01-a261-5a640be01fd7.png)


## 工具
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct-tools"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) - AWS Data Migration Service (AWS DMS) 可協助您快速安全地將資料庫遷移至 AWS。來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降至最低。AWS DMS 可以在最廣泛使用的商業和開放原始碼資料庫之間遷移您的資料。 
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) - AWS Schema Conversion Tool (AWS SCT) 可用來將現有的資料庫結構描述從一個資料庫引擎轉換為另一個資料庫引擎。它支援各種資料庫引擎做為來源，包括 Oracle、SQL Server 和 PostgresSQL。

## 史詩
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料庫版本。 | 驗證來源和目標資料庫版本，並確認 AWS DMS 支援這些版本。如需有關支援的 Oracle 資料庫版本的資訊，請參閱[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。如需使用 Amazon Redshift 做為目標的資訊，請參閱[使用 Amazon Redshift 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Redshift.html)。 | DBA | 
| 建立 VPC 和安全群組。 | 在您的 AWS 帳戶中，如果虛擬私有雲端 (VPC) 不存在，請建立它。為來源和目標資料庫的傳出流量建立安全群組。如需詳細資訊，請參閱 [Amazon Virtual Private Cloud (Amazon VPC) 文件](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)。 | 系統管理員 | 
| 安裝 AWS SCT。 | 下載並安裝最新版本的 AWS SCT 及其對應的驅動程式。如需詳細資訊，請參閱[安裝、驗證和更新 AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html)。 | DBA | 
| 為 AWS DMS 任務建立使用者。 | 在來源資料庫中建立 AWS DMS 使用者，並授予其讀取權限。AWS SCT 和 AWS DMS 都會使用此使用者。 | DBA | 
| 測試資料庫連線。 | 測試 Oracle 資料庫執行個體的連線。 | DBA | 
| 在 AWS SCT 中建立新專案。 | 開啟 AWS SCT 工具並建立新的專案。 | DBA | 
| 分析要遷移的 Oracle 結構描述。 | 使用 AWS SCT 分析要遷移的結構描述，並產生資料庫遷移評估報告。如需詳細資訊，請參閱 AWS SCT 文件中的[建立資料庫遷移評估報告](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_AssessmentReport.Create.html)。 | DBA | 
| 檢閱評估報告。 | 檢閱報告是否有遷移可行性。有些資料庫物件可能需要手動轉換。如需報告的詳細資訊，請參閱 AWS SCT 文件中的[檢視評估報告](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_AssessmentReport.View.html)。 | DBA | 

### 準備目標資料庫
<a name="prepare-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon Redshift 叢集。 | 在您先前建立的 VPC 內建立 Amazon Redshift 叢集。如需詳細資訊，請參閱 [Amazon Redshift 文件中的 Amazon Redshift 叢集](https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html)。 | DBA | 
| 建立資料庫使用者。 | 從 Oracle 來源資料庫擷取使用者、角色和授權的清單。在目標 Amazon Redshift 資料庫中建立使用者，並套用上一個步驟中的角色。 | DBA | 
| 評估資料庫參數。 | 檢閱 Oracle 來源資料庫中的資料庫選項、參數、網路檔案和資料庫連結，並評估其對目標的適用性。            | DBA | 
| 將任何相關設定套用至目標。 | 如需此步驟的詳細資訊，請參閱 Amazon Redshift 文件中的[組態參考](https://docs.aws.amazon.com/redshift/latest/dg/cm_chap_ConfigurationRef.html)。 | DBA | 

### 在目標資料庫中建立物件
<a name="create-objects-in-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在目標資料庫中建立 AWS DMS 使用者。 | 在目標資料庫中建立 AWS DMS 使用者，並授予讀取和寫入權限。驗證來自 AWS SCT 的連線。 | DBA | 
| 轉換結構描述、檢閱 SQL 報告，並儲存任何錯誤或警告。 | 如需詳細資訊，請參閱 [AWS SCT 文件中的使用 AWS SCT 轉換資料庫結構描述](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Converting.html)。 | DBA | 
| 將結構描述變更套用至目標資料庫，或將其儲存為 .sql 檔案。 | 如需說明，請參閱 [AWS SCT 文件中的在 AWS SCT 中儲存和套用轉換後的結構描述](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Converting.DW.html#CHAP_Converting.DW.SaveAndApply)。 | DBA | 
| 驗證目標資料庫中的物件。 | 驗證在目標資料庫中上一個步驟中建立的物件。重寫或重新設計任何未成功轉換的物件。 | DBA | 
| 停用外部索引鍵和觸發條件。 | 停用任何外部索引鍵和觸發條件。這些可能會在執行 AWS DMS 的完全載入程序期間造成資料載入問題。 | DBA | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 複寫執行個體。 | 登入 AWS 管理主控台，然後開啟 AWS DMS 主控台。在導覽窗格中，選擇**複寫執行個體**、**建立複寫執行個體**。如需詳細說明，請參閱 *AWS DMS 文件中的 AWS DMS 入門*中的[步驟 1](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html#CHAP_GettingStarted.ReplicationInstance)。 | DBA | 
| 建立來源和目標端點。 | 建立來源和目標端點，測試從複寫執行個體到來源和目標端點的連線。如需詳細說明，請參閱 *AWS DMS 文件中的 AWS DMS 入門*中的[步驟 2](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html#CHAP_GettingStarted.Endpoints)。 | DBA | 
| 建立複寫任務。 | 建立複寫任務，然後選取適當的遷移方法。如需詳細說明，請參閱 *AWS DMS 文件中的 AWS DMS 入門*中的[步驟 3](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html#CHAP_GettingStarted.Tasks)。 | DBA | 
| 啟動資料複寫。 | 啟動複寫任務並監控日誌是否有任何錯誤。 | DBA | 

### 遷移您的應用程式
<a name="migrate-your-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立應用程式伺服器。 | 在 AWS 上建立新的應用程式伺服器。 | 應用程式擁有者 | 
| 遷移應用程式程式碼。 | 將應用程式碼遷移至新的伺服器。 | 應用程式擁有者 | 
| 設定應用程式伺服器。 | 設定目標資料庫和驅動程式的應用程式伺服器。 | 應用程式擁有者 | 
| 最佳化應用程式程式碼。 | 最佳化目標引擎的應用程式碼。 | 應用程式擁有者 | 

### 切換到目標資料庫
<a name="cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證使用者。 | 在目標 Amazon Redshift 資料庫中，驗證使用者並授予他們角色和權限。 | DBA | 
| 驗證應用程式是否已鎖定。 | 請確定應用程式已鎖定，以防止進一步變更。 | 應用程式擁有者 | 
| 驗證資料。 | 驗證目標 Amazon Redshift 資料庫中的資料。 | DBA | 
| 啟用外部索引鍵和觸發條件。 | 在目標 Amazon Redshift 資料庫中啟用外部金鑰和觸發條件。 | DBA | 
| 連線至新的資料庫。 | 設定應用程式以連線至新的 Amazon Redshift 資料庫。 | 應用程式擁有者 | 
| 執行最終檢查。 | 在上線之前執行最終的全面系統檢查。 | DBA，應用程式擁有者 | 
| 上線。 | 使用目標 Amazon Redshift 資料庫上線。 | DBA | 

### 關閉遷移專案
<a name="close-the-migration-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 | 關閉臨時 AWS 資源，例如 AWS DMS 複寫執行個體和用於 AWS SCT 的 EC2 執行個體。  | DBA，系統管理員 | 
| 檢閱文件。 | 檢閱並驗證遷移專案文件。    | DBA，系統管理員 | 
| 收集指標。 | 收集遷移專案的相關資訊，例如遷移時間、手動與工具任務的百分比，以及節省總成本。  | DBA，系統管理員 | 
| 關閉專案。 | 關閉專案並提供意見回饋。 | DBA，系統管理員 | 

## 相關資源
<a name="migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct-resources"></a>

**參考**
+ [AWS DMS 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [AWS SCT 使用者指南](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 
+ [Amazon Redshift 入門指南](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html)

**教學課程和影片**
+ [深入探討 AWS SCT 和 AWS DMS](https://www.youtube.com/watch?v=kJs9U4ys5FE) （來自 AWS re：Invent 2019 的簡報）
+ [AWS Database Migration Service 入門](https://aws.amazon.com/dms/getting-started/)

# 使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Aurora PostgreSQL
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct"></a>

*Senthil Ramasamy，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-summary"></a>

此模式說明如何使用 AWS Data Migration Service (AWS DMS) 和 AWS Schema Conversion Tool (AWS SCT)，將 Oracle 資料庫遷移至 Amazon Aurora PostgreSQL 相容版本。 

此模式涵蓋現場部署的來源 Oracle 資料庫、安裝在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 Oracle 資料庫，以及 Oracle 資料庫的 Amazon Relational Database Service (Amazon RDS)。模式會將這些資料庫轉換為 Aurora PostgreSQL 相容。

## 先決條件和限制
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心或 AWS 雲端中的 Oracle 資料庫。
+ SQL 用戶端安裝在本機電腦或 EC2 執行個體上。
+ AWS SCT 連接器的 Java Database Connectivity (JDBC) 驅動程式，安裝在本機電腦或安裝 AWS SCT 的 EC2 執行個體上。

**限制**
+ 資料庫大小限制：128 TB 
+ 如果來源資料庫支援商用off-the-shelf(COTS) 應用程式或特定於廠商，您可能無法將其轉換為另一個資料庫引擎。使用此模式之前，請確認應用程式支援 Aurora PostgreSQL 相容。 

**產品版本**
+ 對於自我管理的 Oracle 資料庫，AWS DMS 支援 10.2 版和更新版本 （適用於 10.x 版）、11g 版，以及高達 12.2、18c 和 19c 版的所有 Oracle 資料庫版本。如需支援 Oracle 資料庫版本的最新清單 （包括自我管理和 Amazon RDS for Oracle)[，請參閱使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)和[使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)。
+ 我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。如需 AWS SCT 支援的 Oracle 資料庫版本的相關資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。 
+ Aurora 支援 Amazon Aurora PostgreSQL 版本和引擎版本中列出的 PostgreSQL 版本。 [ PostgreSQL ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html)

## Architecture
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊**

下列其中一項：
+ 內部部署 Oracle 資料庫
+ EC2 執行個體上的 Oracle 資料庫  
+ Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**
+ Aurora PostgreSQL 相容 

**目標架構**

![\[將 Oracle 資料庫遷移至 Aurora PostgreSQL 相容的目標架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6de157c4-dcc9-4186-ae32-17efbbbee709/images/68beb634-926e-4908-97b1-edcd23e06a2b.png)


**資料遷移架構**
+ 從 AWS 雲端中執行的 Oracle 資料庫   
![\[AWS 上 Oracle 資料庫的資料遷移架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6de157c4-dcc9-4186-ae32-17efbbbee709/images/7fc32019-3db1-485b-93e5-6d5539be048c.png)

   
+ 從內部部署資料中心執行的 Oracle 資料庫  
![\[內部部署資料中心中 Oracle 資料庫的資料遷移架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6de157c4-dcc9-4186-ae32-17efbbbee709/images/c70d8774-aef7-4414-9766-ce8f25757c4b.png)

## 工具
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。

## 史詩
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備來源資料庫。 | 若要準備來源資料庫，請參閱 [AWS SCT 文件中的使用 Oracle 資料庫做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)。 | DBA | 
| 為 AWS SCT 建立 EC2 執行個體。 | 視需要建立和設定 AWS SCT 的 EC2 執行個體。 | DBA | 
| 下載 AWS SCT。 | 下載最新版本的 AWS SCT 和相關聯的驅動程式。如需詳細資訊，請參閱 [AWS SCT 文件中的安裝、驗證和更新](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html) AWS SCT。 | DBA | 
| 新增使用者和許可。 | 在來源資料庫中新增和驗證先決條件使用者和許可。 | DBA | 
| 建立 AWS SCT 專案。 | 為工作負載建立 AWS SCT 專案，並連線至來源資料庫。如需說明，請參閱 [AWS SCT 文件中的建立 AWS SCT 專案](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.Project)和[新增資料庫伺服器](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.AddServers)。 | DBA | 
| 評估可行性。 | 產生評估報告，摘要無法自動轉換之結構描述的動作項目，並提供手動轉換工作的預估值。如需詳細資訊，請參閱 AWS SCT 文件中的[建立和檢閱資料庫遷移評估報告](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.AssessmentReport)。 | DBA | 

### 準備目標資料庫
<a name="prepare-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立目標 Amazon RDS 資料庫執行個體。 | 使用 Amazon Aurora 做為資料庫引擎，建立目標 Amazon RDS 資料庫執行個體。如需說明，請參閱[《Amazon RDS 文件》中的建立 Amazon RDS 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html)。 | DBA | 
| 擷取使用者、角色和許可。 | 從來源資料庫擷取使用者、角色和許可的清單。 | DBA | 
| 映射使用者。 | 將現有的資料庫使用者映射至新的資料庫使用者。 | 應用程式擁有者 | 
| 建立使用者。 | 在目標資料庫中建立使用者。 | DBA、應用程式擁有者 | 
| 套用角色。 | 將上一個步驟的角色套用至目標資料庫。 | DBA | 
| 檢查選項、參數、網路檔案和資料庫連結。 | 檢閱來源資料庫是否有選項、參數、網路檔案和資料庫連結，然後評估其對目標資料庫的適用性。 | DBA | 
| 套用設定。 | 將任何相關設定套用至目標資料庫。 | DBA | 

### 傳輸物件
<a name="transfer-objects"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS SCT 連線。 | 設定目標資料庫的 AWS SCT 連線。 | DBA | 
| 使用 AWS SCT 轉換結構描述。 | AWS SCT 會自動將來源資料庫結構描述和大多數自訂程式碼轉換為與目標資料庫相容的格式。工具無法自動轉換的任何程式碼都會清楚標示，讓您可以手動轉換。 | DBA | 
| 檢閱報告。 | 檢閱產生的 SQL 報告，並儲存任何錯誤和警告。 | DBA | 
| 套用自動化結構描述變更。 | 將自動化結構描述變更套用至目標資料庫，或將其儲存為 .sql 檔案。 | DBA | 
| 驗證物件。 | 驗證 AWS SCT 是否已在目標上建立物件。 | DBA | 
| 處理未轉換的項目。 | 手動重寫、拒絕或重新設計任何無法自動轉換的項目。 | DBA、應用程式擁有者 | 
| 套用角色和使用者許可。 | 套用產生的角色和使用者許可，並檢閱任何例外狀況。 | DBA | 

### 遷移資料
<a name="migrate-the-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定 方法。 | 決定遷移資料的方法。 | DBA | 
| 建立複寫執行個體。 | 從 AWS DMS 主控台建立複寫執行個體。如需詳細資訊，請參閱 [AWS DMS 文件中的使用 AWS DMS 複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.html)。 | DBA | 
| 建立來源和目標端點。 | 若要建立端點，請遵循 [AWS DMS 文件中的建立來源和目標端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)中的指示。 | DBA | 
| 建立複寫任務。 | 若要建立任務，請參閱 [AWS DMS 文件中的使用 AWS DMS 任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.html)。 | DBA | 
| 啟動複寫任務並監控日誌。 | 如需此步驟的詳細資訊，請參閱 [AWS DMS 文件中的監控 AWS DMS 任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html)。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 分析和轉換應用程式程式碼中的 SQL 項目。 | 使用 AWS SCT 來分析和轉換應用程式程式碼中的 SQL 項目。當您將資料庫結構描述從一個引擎轉換到另一個引擎，您也需更新應用程式中的 SQL 程式碼，以便與新的資料庫引擎互動，取代舊引擎。您可以檢視、分析、編輯和儲存轉換後的 SQL 程式碼。 | 應用程式擁有者 | 
| 建立應用程式伺服器。 | 在 AWS 上建立新的應用程式伺服器。 | 應用程式擁有者 | 
| 遷移應用程式程式碼。 | 將應用程式碼遷移至新的伺服器。 | 應用程式擁有者 | 
| 設定應用程式伺服器。 | 設定目標資料庫和驅動程式的應用程式伺服器。 | 應用程式擁有者 | 
| 修正程式碼。 | 修正應用程式中來源資料庫引擎特有的任何程式碼。 | 應用程式擁有者 | 
| 最佳化程式碼。 | 最佳化目標資料庫引擎的應用程式程式碼。 | 應用程式擁有者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 切換到目標資料庫。 | 執行切換到新資料庫。 | DBA | 
| 鎖定應用程式。 | 鎖定應用程式，避免任何進一步的變更。 | 應用程式擁有者 | 
| 驗證變更。 | 驗證所有變更是否已傳播到目標資料庫。 | DBA | 
| 重新導向至目標資料庫。 | 將新的應用程式伺服器指向目標資料庫。 | 應用程式擁有者 | 
| 檢查所有項目。 | 執行最終、全面的系統檢查。 | 應用程式擁有者 | 
| 上線。 | 完成最終切換任務。 | 應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時資源。 | 關閉臨時 AWS 資源，例如 AWS DMS 複寫執行個體和用於 AWS SCT 的 EC2 執行個體。 | DBA、應用程式擁有者 | 
| 更新意見回饋。 | 更新內部團隊的 AWS DMS 程序意見回饋。 | DBA、應用程式擁有者 | 
| 修訂程序和範本。 | 修訂 AWS DMS 程序並視需要改善範本。 | DBA、應用程式擁有者 | 
| 驗證文件。 | 檢閱並驗證專案文件。 | DBA、應用程式擁有者 | 
| 收集指標。 | 收集指標以評估遷移時間、手動與工具成本節省的百分比等。 | DBA、應用程式擁有者 | 
| 關閉專案。 | 關閉遷移專案，並向利益相關者提供意見回饋。 | DBA、應用程式擁有者 | 

## 相關資源
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-resources"></a>

**參考**
+ [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ [使用 PostgreSQL 資料庫做為 AWS Database Migration Service 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)
+ [Oracle Database 11g/12c 至具有 PostgreSQL 相容性 (9.6.x) 遷移手冊的 Amazon Aurora](https://d1.awsstatic.com/whitepapers/Migration/oracle-database-amazon-aurora-postgresql-migration-playbook.pdf) 
+ [具有 PostgreSQL 相容性 (12.4) 遷移手冊的 Oracle Database 19c 到 Amazon Aurora](https://d1.awsstatic.com/whitepapers/Migration/oracle-database-amazon-aurora-postgresql-migration-playbook-12.4.pdf)
+ [將 Amazon RDS for Oracle 資料庫遷移至 Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/dms/latest/sbs/chap-oracle-postgresql.html)
+ [AWS Data Migration Service](https://aws.amazon.com/dms/)
+ [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 
+ [從 Oracle 遷移至 Amazon Aurora](https://aws.amazon.com/getting-started/projects/migrate-oracle-to-amazon-aurora/)
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)

**教學課程和影片**
+ [資料庫遷移Step-by-Step演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [AWS Data Migration Service](https://www.youtube.com/watch?v=zb4GcjEdl8U) （影片）
+ [將 Oracle 資料庫遷移至 PostgreSQL](https://www.youtube.com/watch?v=ibtNkChGFkw) （影片）

## 其他資訊
<a name="migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct-additional"></a>

.

# 將資料從現場部署 Oracle 資料庫遷移至 Aurora PostgreSQL
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql"></a>

*Michelle Deng 和 Shunan Xiang，Amazon Web Services*

## 總結
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql-summary"></a>

此模式提供從現場部署 Oracle 資料庫到 Amazon Aurora PostgreSQL 相容版本的資料遷移指導。它針對包含具有高資料處理語言 (DML) 活動的大型資料表的多 TB Oracle 資料庫，以停機時間最短的線上資料遷移策略為目標。Oracle Active Data Guard 待命資料庫用作從主要資料庫卸載資料遷移的來源。可在完全載入期間暫停從 Oracle 主要資料庫到待命的複寫，以避免 ORA-01555 錯誤。 

具有資料類型 NUMBER 的主索引鍵 PKs) 或外部索引鍵 (FKs) 中的資料表資料欄通常用於在 Oracle 中存放整數。我們建議您在 PostgreSQL 中將這些轉換為 INT 或 BIGINT，以獲得更好的效能。您可以使用 AWS Schema Conversion Tool (AWS SCT) 來變更 PK 和 FK 資料欄的預設資料類型映射。（如需詳細資訊，請參閱 AWS 部落格文章[將 NUMBER 資料類型從 Oracle 轉換為 PostgreSQL](https://aws.amazon.com/blogs/database/convert-the-number-data-type-from-oracle-to-postgresql-part-2/)。) 此模式中的資料遷移使用 AWS Database Migration Service (AWS DMS) 進行完全載入和變更資料擷取 (CDC)。

您也可以使用此模式將內部部署 Oracle 資料庫遷移至 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)，或在 Amazon Elastic Compute Cloud (Amazon EC2) 上託管的 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容。

## 先決條件和限制
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 已設定 Active Data Guard 待命的現場部署資料中心中的 Oracle 來源資料庫 
+ 在內部部署資料中心和 AWS 雲端之間設定的 AWS Direct Connect
+ 熟悉[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 PostgreSQL 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)

**限制**
+ Amazon Aurora 資料庫叢集最多可建立 128 TiB 的儲存體。Amazon RDS for PostgreSQL 資料庫執行個體最多可建立 64 TiB 的儲存體。如需最新的儲存資訊，請參閱 AWS 文件中的[Amazon Aurora 儲存和可靠性](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.Overview.StorageReliability.html)以及[Amazon RDS 資料庫執行個體儲存](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html)。

**產品版本**
+ AWS DMS 支援 10.2 版和更新版本 （適用於 10.x 版）、11g 和最高 12.2、18c 和 19c 版的所有 Oracle 資料庫版本。如需支援版本的最新清單，請參閱 [AWS 文件中的使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。

## Architecture
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql-architecture"></a>

**來源技術堆疊**
+ 已設定 Oracle Active Data Guard 待命的現場部署 Oracle 資料庫 

**目標技術堆疊**
+ Aurora PostgreSQL 相容 

**資料遷移架構**

![\[將 Oracle 資料庫遷移至 Aurora PostgreSQL 相容\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/49f9b03e-6d33-4ac0-94ad-d3e6d02e6d63/images/0038a36b-fb7d-4f2d-8376-8d38290b0736.png)


## 工具
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql-tools"></a>
+ **AWS DMS** - [AWS Database Migration Service](https://docs.aws.amazon.com/dms/index.html) (AWS DMS) 支援數個來源和目標資料庫。如需支援的 [Oracle 來源和目標資料庫版本和版本的清單，請參閱 AWS DMS 文件中的使用 Oracle 資料庫做為](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html) AWS DMS 的來源。如果 AWS DMS 不支援來源資料庫，您必須選取另一種方法來遷移階段 6 中的資料 (*在範例*區段中）。**重要注意事項：**由於這是異質遷移，因此您必須先檢查資料庫是否支援商用off-the-shelf(COTS) 應用程式。如果應用程式是 COTS，請先諮詢廠商，確認支援 Aurora PostgreSQL 相容，然後再繼續。如需詳細資訊，請參閱 [AWS 文件中的 AWS DMS Step-by-Step遷移演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)。
+ **AWS SCT** - [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/Welcome.htm) (AWS SCT) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以促進異質資料庫遷移。工具轉換的自訂程式碼包含檢視、預存程序和函數。工具無法自動轉換的任何程式碼都會清楚標示，讓您可以自行轉換。 

## 史詩
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本。 |  | DBA | 
| 安裝 AWS SCT 和驅動程式。 |  | DBA | 
| 新增並驗證 AWS SCT 先決條件使用者和 grant-source 資料庫。 |  | DBA | 
| 為工作負載建立 AWS SCT 專案，並連線至來源資料庫。 |  | DBA | 
| 產生評估報告並評估可行性。 |  | DBA、應用程式擁有者 | 

### 準備目標資料庫
<a name="prepare-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Aurora PostgreSQL 相容目標資料庫。 |  | DBA | 
| 從來源資料庫擷取使用者、角色和授予清單。 |  | DBA | 
| 將現有的資料庫使用者映射至新的資料庫使用者。 |  | 應用程式擁有者 | 
| 在目標資料庫中建立使用者。 |  | DBA | 
| 將上一個步驟的角色套用至目標 Aurora PostgreSQL 相容資料庫。 |  | DBA | 
| 從來源資料庫檢閱資料庫選項、參數、網路檔案和資料庫連結，並評估其對目標資料庫的適用性。 |  | DBA、應用程式擁有者 | 
| 將任何相關設定套用至目標資料庫。 |  | DBA | 

### 準備進行資料庫物件程式碼轉換
<a name="prepare-for-database-object-code-conversion"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定目標資料庫的 AWS SCT 連線。 |  | DBA | 
| 在 AWS SCT 中轉換結構描述，並將轉換後的程式碼儲存為 .sql 檔案。 |  | DBA、應用程式擁有者 | 
| 手動轉換任何無法自動轉換的資料庫物件。 |  | DBA、應用程式擁有者 | 
| 最佳化資料庫程式碼轉換。 |  | DBA、應用程式擁有者 | 
| 根據物件類型，將 .sql 檔案分成多個 .sql 檔案。 |  | DBA、應用程式擁有者 | 
| 驗證目標資料庫中的 SQL 指令碼。 |  | DBA、應用程式擁有者 | 

### 準備資料遷移
<a name="prepare-for-data-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 複寫執行個體。 |  | DBA | 
| 建立來源和目標端點。 | 如果 PKs和 FKs的資料類型從 Oracle 中的 NUMBER 轉換為 PostgreSQL 中的 BIGINT，請考慮在建立來源端點`numberDataTypeScale=-2`時指定連線屬性。 | DBA | 

### 遷移資料 – 完全載入
<a name="migrate-data-ndash-full-load"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在目標資料庫中建立結構描述和資料表。 |  | DBA | 
|  透過分組資料表或根據資料表大小分割大型資料表來建立 AWS DMS 完全載入任務。 |  | DBA | 
| 短暫停止來源 Oracle 資料庫上的應用程式。 |  | 應用程式擁有者 | 
| 確認 Oracle 待命資料庫與主要資料庫同步，並停止從主要資料庫到待命資料庫的複寫。 |  | DBA、應用程式擁有者 | 
| 在來源 Oracle 資料庫上啟動應用程式。 |  | 應用程式擁有者 | 
| 從 Oracle 待命資料庫平行啟動 AWS DMS 完全載入任務至 Aurora PostgreSQL 相容資料庫。 |  | DBA | 
| 在完全載入完成後建立 PKs 和次要索引。 |  | DBA | 
| 驗證資料。 |  | DBA | 

### 遷移資料 – CDC
<a name="migrate-data-ndash-cdc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Oracle 待命與主要資料庫同步時，以及在先前任務中重新啟動應用程式之前，透過指定自訂 CDC 開始時間或系統變更號碼 (SCN) 來建立 AWS DMS 持續複寫任務。 |  | DBA | 
| 平行啟動 AWS DMS 任務，將 Oracle 待命資料庫的持續變更複寫至 Aurora PostgreSQL 相容資料庫。 |  | DBA | 
| 重新建立從 Oracle 主要資料庫到待命資料庫的複寫。 |  | DBA | 
| 監控日誌，並在目標 Aurora PostgreSQL 相容資料庫與來源 Oracle 資料庫幾乎同步時停止 Oracle 資料庫上的應用程式。 |  | DBA、應用程式擁有者 | 
| 當目標與來源 Oracle 資料庫完全同步時，停止 AWS DMS 任務。 |  | DBA | 
| 建立 FKs並驗證目標資料庫中的資料。 |  | DBA | 
| 在目標資料庫中建立函數、檢視、觸發程序、序列和其他物件類型。 |  | DBA | 
| 在目標資料庫中套用角色授予。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS SCT 來分析和轉換應用程式程式碼內的 SQL 陳述式。 |  | 應用程式擁有者 | 
| 在 AWS 上建立新的應用程式伺服器。 |  | 應用程式擁有者 | 
| 將應用程式碼遷移至新的伺服器。 |  | 應用程式擁有者 | 
| 設定目標資料庫和驅動程式的應用程式伺服器。 |  | 應用程式擁有者 | 
| 修正應用程式中來源資料庫引擎特有的任何程式碼。 |  | 應用程式擁有者 | 
| 最佳化目標資料庫的應用程式碼。 |  | 應用程式擁有者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將新的應用程式伺服器指向目標資料庫。 |  | DBA、應用程式擁有者 | 
| 執行健全度檢查。 |  | DBA、應用程式擁有者 | 
| 上線。 |  | DBA、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA，系統管理員 | 
| 檢閱並驗證專案文件。 |  | DBA、應用程式擁有者 | 
| 收集遷移時間、手動與工具使用的百分比、節省成本和類似資料的指標。 |  | DBA、應用程式擁有者 | 
| 關閉專案並提供意見回饋。 |  | DBA、應用程式擁有者 | 

## 相關資源
<a name="migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql-resources"></a>

**參考**
+ [與 Aurora PostgreSQL 相容之 Oracle 資料庫：遷移手冊](https://d1.awsstatic.com/whitepapers/Migration/oracle-database-amazon-aurora-postgresql-migration-playbook.pdf) 
+ [將 Amazon RDS for Oracle Database遷移至 Amazon Aurora MySQL](https://docs.aws.amazon.com/dms/latest/sbs/chap-rdsoracle2aurora.html)
+ [AWS DMS 網站](https://aws.amazon.com/dms/)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [AWS SCT 網站](https://aws.amazon.com/dms/schema-conversion-tool/)
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [從 Oracle 遷移至 Amazon Aurora](https://aws.amazon.com/getting-started/projects/migrate-oracle-to-amazon-aurora/)

**教學課程**
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/) 
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [AWS Database Migration Service Step-by-Step演練](https://docs.aws.amazon.com/dms/latest/sbs/dms-sbs-welcome.html)

# 使用 AWS DMS 從 SAP ASE 遷移至 Amazon RDS for SQL Server
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms"></a>

*Amit Kumar，Amazon Web Services*

## 總結
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms-summary"></a>

此模式提供將 SAP Adaptive Server Enterprise (ASE) 資料庫遷移至執行 Microsoft SQL Server 之 Amazon Relational Database Service (Amazon RDS) 資料庫執行個體的指引。來源資料庫可以位於內部部署資料中心或 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。模式使用 AWS Database Migration Service (AWS DMS) 遷移資料，以及 （選用） 電腦輔助軟體工程 (CASE) 工具來轉換資料庫結構描述。

## 先決條件和限制
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心或 EC2 執行個體上的 SAP ASE 資料庫
+ 啟動並執行的目標 Amazon RDS for SQL Server 資料庫

**限制**
+ 資料庫大小限制：64 TB

**產品版本**
+ 僅限 SAP ASE 15.7 或 16.x 版。如需最新資訊，請參閱[使用 SAP 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SAP.html)。
+ 對於 Amazon RDS 目標資料庫，AWS DMS 支援 [Amazon RDS 上的 Microsoft SQL Server 版本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.VersionSupport)，適用於 Enterprise、Standard、Web 和 Express 版本。如需支援版本的最新資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.SQLServer.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。 

## Architecture
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms-architecture"></a>

**來源技術堆疊 **
+ 內部部署或 Amazon EC2 執行個體上的 SAP ASE 資料庫

**目標技術堆疊 **
+ Amazon RDS for SQL Server 資料庫執行個體

**來源和目標架構**

*從 Amazon EC2 上的 SAP ASE 資料庫到 Amazon RDS for SQL Server 資料庫執行個體：*

![\[Amazon EC2 上 SAP ASE 到 Amazon RDS for SQL Server 的目標架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5ca697a2-9ca3-4231-b457-c1dc59ada5f1/images/957bdcf0-ab58-4b6d-a71a-d0ecbc31822c.png)


*從內部部署 SAP ASE 資料庫到 Amazon RDS for SQL Server 資料庫執行個體：*

![\[內部部署 SAP ASE 到 Amazon RDS for SQL Server 的目標架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5ca697a2-9ca3-4231-b457-c1dc59ada5f1/images/65aab2f5-0e63-4c34-97e2-cd4ac23751a4.png)


## 工具
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms-tools"></a>
+ [AWS Database Migration Service](https://docs.aws.amazon.com/dms/) (AWS DMS) 是一種 Web 服務，可用來將資料從內部部署、Amazon RDS 資料庫執行個體或 EC2 執行個體上的資料庫中遷移到 AWS 服務上的資料庫，例如 Amazon RDS for SQL Server 或 EC2 執行個體。您也可以將資料庫從 AWS 服務遷移至內部部署資料庫。您可以在異質或同質資料庫引擎之間遷移資料。
+ 對於結構描述轉換，您可以選擇使用 [erwin Data Modeler](https://erwin.com/products/erwin-data-modeler/) 或 [SAP PowerDesigner](https://www.sap.com/products/technology-platform/powerdesigner-data-modeling-tools.html)。

## 史詩
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本。 |  | DBA | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA、SysAdmin | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA、SysAdmin | 
| 識別應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立虛擬私有雲端 (VPC) 和子網路。 |  | SysAdmin | 
| 建立安全群組和網路存取控制清單 ACLs)。 |  | SysAdmin | 
| 設定和啟動 Amazon RDS 資料庫執行個體。 |  | SysAdmin | 

### 遷移資料 - 選項 1
<a name="migrate-data---option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 手動遷移資料庫結構描述，或使用 CASE 工具，例如 erwin Data Modeler 或 SAP PowerDesigner。 |  | DBA | 

### 遷移資料 - 選項 2
<a name="migrate-data---option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS DMS 遷移資料。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA、SysAdmin | 
| 檢閱並驗證專案文件。 |  | DBA、SysAdmin、應用程式擁有者 | 
| 收集指標，例如遷移時間、手動與自動任務的百分比，以及節省成本。 |  | DBA、SysAdmin、應用程式擁有者 | 
| 關閉專案並提供意見回饋。 |  | DBA、SysAdmin、應用程式擁有者 | 

## 相關資源
<a name="migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms-resources"></a>

**參考**
+ [AWS DMS 網站](https://aws.amazon.com/dms/)
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)
+ [使用 SAP ASE 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SAP.html)
+ [RDS Custom for SQL Server 的限制](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-reqs-limits-MS.html)

**教學課程和影片**
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [AWS DMS （影片）](https://www.youtube.com/watch?v=zb4GcjEdl8U) 
+ [Amazon RDS （影片）](https://www.youtube.com/watch?v=igRfulrrYCo) 

# 使用 AWS DMS 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms"></a>

*Marcelo Fernandes，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms-summary"></a>

此模式提供使用 AWS Data Migration Service (AWS DMS) 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift 的指引。

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的來源 Microsoft SQL Server 資料庫
+ 使用 Amazon Redshift 資料庫做為 AWS DMS 目標的已完成先決條件，如 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Redshift.html#CHAP_Target.Redshift.Prerequisites)所述

**產品版本**
+ SQL Server 2005-2019、Enterprise、Standard、Workgroup、Developer 和 Web 版本。如需支援版本的最新清單，請參閱 [AWS 文件中的使用 Microsoft SQL Server 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html)。

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ 內部部署 Microsoft SQL Server 資料庫 

**目標技術堆疊**
+ Amazon Redshift

**資料遷移架構**

 

![\[使用 AWS DMS 將內部部署 SQL Server 資料庫遷移至 Amazon Redshift 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/65b2be1b-740e-4d4d-99a8-f77c4ea6553d/images/3a094bf2-be31-4d83-8dd2-9dc078321055.png)


## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms-tools"></a>
+ [AWS DMS ](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)是一種資料遷移服務，支援多種類型的來源和目標資料庫。如需有關支援與 AWS DMS 搭配使用的 Microsoft SQL Server 資料庫版本和版本的資訊，請參閱 [AWS DMS 文件中的使用 Microsoft SQL Server 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html)。如果 AWS DMS 不支援您的來源資料庫，您必須選取用於資料遷移的替代方法。

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
| 識別目標伺服器執行個體的硬體需求。 |  | DBA，系統管理員 | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA，系統管理員 | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA，系統管理員 | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA，系統管理員 | 
| 識別應用程式遷移策略。 |  | DBA、應用程式擁有者、系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) | 如需詳細資訊，請參閱 AWS 文件中的[在 VPC 中使用資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html)。 | 系統管理員 | 
| 建立安全群組。 |  | 系統管理員 | 
| 設定和啟動 Amazon Redshift 叢集。 | 如需詳細資訊，請參閱[《Amazon Redshift 文件》中的建立範例 Amazon Redshift 叢集](https://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-launch-sample-cluster.html)。 | DBA，系統管理員 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS DMS 從 Microsoft SQL Server 資料庫遷移資料。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 |  | DBA、應用程式擁有者、系統管理員 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時資源。 |  | DBA，系統管理員 | 
| 檢閱並驗證專案文件。 |  | DBA、應用程式擁有者、系統管理員 | 
| 收集指標，例如遷移時間、手動與自動任務的百分比，以及節省成本。 |  | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案並提供意見回饋。 |  | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms-resources"></a>

**參考**
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/index.html)
+ [Amazon Redshift 文件](https://docs.aws.amazon.com/redshift/)
+ [Amazon Redshift 定價](https://aws.amazon.com/redshift/pricing/)

**教學課程和影片**
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [開始使用 Amazon RedShift](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html)
+ [使用 Amazon Redshift 資料庫做為 AWS Database Migration Service 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Redshift.html)
+ [AWS DMS （影片）](https://www.youtube.com/watch?v=zb4GcjEdl8U) 

# 使用 AWS SCT 資料擷取代理程式將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents"></a>

*Neha Thakur，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-summary"></a>

此模式概述使用 AWS Schema Conversion Tool (AWS SCT) 資料擷取代理程式，將內部部署 Microsoft SQL Server 來源資料庫遷移至 Amazon Redshift 目標資料庫的步驟。代理程式是與 AWS SCT 整合的外部程式，但在別處執行資料轉換，並代表您與其他 AWS 服務互動。  

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-prereqs"></a>

**先決條件**
+ 用於內部部署資料中心內資料倉儲工作負載的 Microsoft SQL Server 來源資料庫
+ 作用中的 AWS 帳戶

**產品版本**
+ Microsoft SQL Server 2008 版或更新版本。如需支援版本的最新清單，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。 

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-architecture"></a>

**技術堆疊****來源**
+ 內部部署 Microsoft SQL Server 資料庫

**技術堆疊****目標**
+ Amazon Redshift

**資料遷移架構**

![\[使用 AWS SCT 資料擷取代理程式將 SQL Server 資料庫遷移至 Amazon Redshift。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6975f67a-0705-47b4-a1b8-90aaa2597a04/images/dbff958b-7601-442e-9e23-4d07edd0ccfd.png)


## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-tools"></a>
+ [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) (AWS SCT) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以處理異質資料庫遷移。當來源和目標資料庫非常不同時，您可以使用 AWS SCT 代理程式來執行額外的資料轉換。如需詳細資訊，請參閱 AWS 文件中的將[資料從現場部署資料倉儲遷移至 Amazon Redshift](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/agents.dw.html)。

## 最佳實務
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-best-practices"></a>
+ [AWS SCT 的最佳實務](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_BestPractices.html)
+ [Amazon Redshift 的最佳實務 ](https://docs.aws.amazon.com/redshift/latest/dg/best-practices.html)

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-epics"></a>

### 準備遷移
<a name="prepare-for-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
| 識別目標伺服器執行個體的硬體需求。 |  | DBA、SysAdmin | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA、SysAdmin | 
| 選擇適當的執行個體類型 （容量、儲存功能、網路功能）。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA、SysAdmin | 
| 選擇應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 設定基礎設施
<a name="configure-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立虛擬私有雲端 (VPC) 和子網路。 |  | SysAdmin | 
| 建立安全群組。 |  | SysAdmin | 
| 設定和啟動 Amazon Redshift 叢集。 |  | SysAdmin | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS SCT 資料擷取代理程式遷移資料。 |  | DBA | 

### 遷移應用程式
<a name="migrate-applications"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循所選的應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 切換到目標資料庫
<a name="cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA、SysAdmin | 
| 檢閱並驗證專案文件。 |  | DBA、SysAdmin、應用程式擁有者 | 
| 收集指標，例如遷移時間、手動與自動任務的百分比，以及節省成本。 |  | DBA、SysAdmin、應用程式擁有者 | 
| 關閉專案並提供任何意見回饋。 |  | DBA、SysAdmin、應用程式擁有者 | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents-resources"></a>

**參考**
+ [AWS SCT 使用者指南](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [使用資料擷取代理程式](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/agents.html)
+ [Amazon Redshift 定價](https://aws.amazon.com/redshift/pricing/)

**教學課程和影片**
+ [AWS Schema Conversion Tool入門](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_GettingStarted.html)
+ [開始使用 Amazon RedShift](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html)

# 將舊版應用程式從 Oracle Pro\$1C 遷移至 ECPG
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg"></a>

*Sai Parthasaradhi 和 Mahesh Balumuri，Amazon Web Services*

## 摘要
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg-summary"></a>

大多數具有內嵌 SQL 程式碼的舊版應用程式會使用 Oracle Pro\$1C 前置編譯器來存取資料庫。當您將這些 Oracle 資料庫遷移至 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora PostgreSQL 相容版本時，您必須將應用程式程式碼轉換為與 PostgreSQL 中預編譯器相容的格式，稱為 ECPG。此模式說明如何將 Oracle Pro\$1C 程式碼轉換為 PostgreSQL ECPG 中的同等程式碼。 

如需 Pro\$1C 的詳細資訊，請參閱 [Oracle 文件](https://docs.oracle.com/cd/E11882_01/appdev.112/e10825/pc_01int.htm#i2415)。如需 ECPG 的簡介，請參閱[其他資訊](#migrate-legacy-applications-from-oracle-pro-c-to-ecpg-additional)一節。

## 先決條件和限制
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫
+ 在內部部署執行的 Oracle 資料庫

## 工具
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg-tools"></a>
+ 下一節中列出的 PostgreSQL 套件。
+ [AWS CLI ](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)– AWS Command Line Interface (AWS CLI) 是一種開放原始碼工具，可透過命令列 shell 中的命令與 AWS 服務互動。透過最少的組態，您可以從命令提示中執行 AWS CLI 命令，該命令會實作與瀏覽器型 AWS 管理主控台所提供功能相同的功能。

## 史詩
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg-epics"></a>

### 在 CentOS 或 RHEL 上設定建置環境
<a name="set-the-build-environment-on-centos-or-rhel"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 PostgreSQL 套件。 | 使用以下命令安裝所需的 PostgreSQL 套件。<pre>yum update -y<br />yum install -y yum-utils<br />rpm -ivh https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm<br />dnf -qy module disable postgresql</pre> | 應用程式開發人員、DevOps 工程師 | 
| 安裝標頭檔案和程式庫。 | 使用以下命令安裝包含標頭檔案和程式庫的 `postgresql12-devel`套件。在開發和執行階段環境中安裝 套件，以避免執行階段環境中發生錯誤。<pre>dnf -y install postgresql12-devel<br />yum install ncompress zip ghostscript jq unzip wget git -y</pre>僅針對開發環境，也請執行下列命令。<pre>yum install zlib-devel make -y<br />ln -s /usr/pgsql-12/bin/ecpg /usr/bin/</pre> | 應用程式開發人員、DevOps 工程師 | 
| 設定環境路徑變數。 | 設定 PostgreSQL 用戶端程式庫的環境路徑。<pre>export PATH=$PATH:/usr/pgsql-12/bin</pre> | 應用程式開發人員、DevOps 工程師 | 
| 視需要安裝其他軟體。 | 如有必要，請在 Oracle 中安裝 **pgLoader** 作為 **SQL\$1Loader** 的替代。<pre>wget -O /etc/yum.repos.d/pgloader-ccl.repo https://dl.packager.io/srv/opf/pgloader-ccl/master/installer/el/7.repo<br />yum install pgloader-ccl -y<br />ln -s /opt/pgloader-ccl/bin/pgloader /usr/bin/</pre>如果您從 Pro\$1C 模組呼叫任何 Java 應用程式，請安裝 Java。<pre>yum install java -y</pre>安裝 **ant** 以編譯 Java 程式碼。<pre>yum install ant -y</pre> | 應用程式開發人員、DevOps 工程師 | 
| 安裝 AWS CLI。 | 安裝 AWS CLI 來執行命令，以從您的應用程式與 AWS Secrets Manager 和 Amazon Simple Storage Service (Amazon S3) 等 AWS 服務互動。Amazon S3<pre>cd /tmp/<br />curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"<br />unzip awscliv2.zip<br />./aws/install -i /usr/local/aws-cli -b /usr/local/bin --update</pre> | 應用程式開發人員、DevOps 工程師 | 
| 識別要轉換的程式。 | 識別您要從 Pro\$1C 轉換為 ECPG 的應用程式。 | 應用程式開發人員、應用程式擁有者 | 

### 將 Pro\$1C 程式碼轉換為 ECPG
<a name="convert-pro-c-code-to-ecpg"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 移除不需要的標頭。 | 移除 PostgreSQL 中不需要的`include `標頭，例如 `oci.h`、 `oratypes`和 `sqlda`。 | 應用程式擁有者、應用程式開發人員 | 
| 更新變數宣告。 | 為用作主機變數的所有變數宣告新增`EXEC SQL`陳述式。從您的應用程式中移除宣告，`EXEC SQL VAR`例如以下內容。<pre>EXEC SQL VAR query IS STRING(2048);</pre> | 應用程式開發人員、應用程式擁有者 | 
| 更新 ROWNUM 功能。 | PostgreSQL 中無法使用 `ROWNUM`函數。將此取代為 SQL 查詢中的`ROW_NUMBER`視窗函數。Pro\$1C 程式碼：<pre>SELECT SUBSTR(RTRIM(FILE_NAME,'.txt'),12) INTO :gcpclFileseq  <br />FROM   (SELECT FILE_NAME <br />FROM  DEMO_FILES_TABLE <br />WHERE FILE_NAME    LIKE '%POC%' <br />ORDER BY FILE_NAME DESC) FL2 <br />WHERE ROWNUM <=1 ORDER BY ROWNUM;</pre>ECPG 程式碼：<pre>SELECT SUBSTR(RTRIM(FILE_NAME,'.txt'),12) INTO :gcpclFileseq  <br />FROM   (SELECT FILE_NAME , ROW_NUMBER() OVER (ORDER BY FILE_NAME DESC) AS ROWNUM<br />FROM  demo_schema.DEMO_FILES_TABLE <br />WHERE FILE_NAME    LIKE '%POC%'<br />ORDER BY FILE_NAME DESC) FL2 <br />WHERE ROWNUM <=1 ORDER BY ROWNUM; </pre> | 應用程式開發人員、應用程式擁有者 | 
| 更新函數參數以使用別名變數。 | 在 PostgreSQL 中，函數參數無法用作主機變數。使用別名變數覆寫它們。Pro\$1C 程式碼：<pre>int processData(int referenceId){<br />  EXEC SQL char col_val[100];<br />  EXEC SQL select column_name INTO :col_val from table_name where col=:referenceId;<br />}</pre>ECPG 程式碼：<pre>int processData(int referenceIdParam){<br />  EXEC SQL int referenceId = referenceIdParam;<br />  EXEC SQL char col_val[100];<br />  EXEC SQL select column_name INTO :col_val from table_name where col=:referenceId;<br />}</pre> | 應用程式開發人員、應用程式擁有者 | 
| 更新結構類型。 | `typedef` 如果`struct`類型變數用作主機變數，請使用 定義 `EXEC SQL BEGIN`和 `END`區塊中的`struct`類型。如果`struct`類型是在標頭 (`.h`) 檔案中定義，請包含`EXEC SQL`包含陳述式的檔案。Pro\$1C 程式碼：標頭檔案 (`demo.h`)<pre>struct s_partition_ranges<br />{<br /> char   sc_table_group[31];<br /> char   sc_table_name[31];<br /> char   sc_range_value[10];<br />}; <br />struct s_partition_ranges_ind<br />{<br />  short    ss_table_group;<br />  short    ss_table_name;<br />  short    ss_range_value;<br />}; </pre>ECPG 程式碼：標頭檔案 (`demo.h`)<pre>EXEC SQL BEGIN DECLARE SECTION;<br />typedef struct <br />{<br />  char   sc_table_group[31];<br />  char   sc_table_name[31];<br />  char   sc_range_value[10];<br />} s_partition_ranges; <br />typedef struct <br />{<br />  short    ss_table_group;<br />  short    ss_table_name;<br />  short    ss_range_value;<br />} s_partition_ranges_ind; <br />EXEC SQL END DECLARE SECTION;</pre>Pro\$1C 檔案 (`demo.pc`)<pre>#include "demo.h"<br />struct s_partition_ranges gc_partition_data[MAX_PART_TABLE] ;<br />struct s_partition_ranges_ind gc_partition_data_ind[MAX_PART_TABLE] ;</pre>ECPG 檔案 (`demo.pc`)<pre>exec sql include "demo.h"<br />EXEC SQL BEGIN DECLARE SECTION;<br />s_partition_ranges gc_partition_data[MAX_PART_TABLE] ;<br />s_partition_ranges_ind gc_partition_data_ind[MAX_PART_TABLE] ;<br />EXEC SQL END DECLARE SECTION;</pre> | 應用程式開發人員、應用程式擁有者 | 
| 修改邏輯以從游標擷取。 | 若要使用陣列變數從游標擷取多個資料列，請將程式碼變更為使用 `FETCH FORWARD`。Pro\$1C 程式碼：<pre>EXEC SQL char  aPoeFiles[MAX_FILES][FILENAME_LENGTH];<br />EXEC SQL FETCH filename_cursor into :aPoeFiles;</pre>ECPG 程式碼：<pre>EXEC SQL char  aPoeFiles[MAX_FILES][FILENAME_LENGTH];<br />EXEC SQL int fetchSize = MAX_FILES;<br />EXEC SQL FETCH FORWARD :fetchSize filename_cursor into :aPoeFiles;</pre> | 應用程式開發人員、應用程式擁有者 | 
| 修改沒有傳回值的套件呼叫。 | 沒有傳回值的 Oracle 套件函數應該使用 指標變數呼叫。如果您的應用程式包含多個具有相同名稱的函數，或不明類型的函數產生執行時間錯誤，請輸入將值傳送到資料類型。Pro\$1C 程式碼：<pre>void ProcessData (char *data , int id)<br />{        <br />        EXEC SQL EXECUTE<br />               BEGIN<br />                  pkg_demo.process_data (:data, :id);                                                                                    <br />               END;<br />       END-EXEC;<br />}</pre>ECPG 程式碼：<pre>void ProcessData (char *dataParam, int idParam )<br />{<br />        EXEC SQL char *data = dataParam;<br />        EXEC SQL int id = idParam;<br />        EXEC SQL short rowInd;<br />        EXEC SQL short rowInd = 0;<br />        EXEC SQL SELECT pkg_demo.process_data (<br />                       inp_data => :data::text,<br />                       inp_id => :id<br />               ) INTO :rowInd;<br />}</pre> | 應用程式開發人員、應用程式擁有者 | 
| 重寫 SQL\$1CURSOR 變數。 | 重寫`SQL_CURSOR`變數及其實作。Pro\$1C 程式碼：<pre>/* SQL Cursor */<br />SQL_CURSOR      demo_cursor;<br />EXEC SQL ALLOCATE :demo_cursor;<br />EXEC SQL EXECUTE<br />  BEGIN<br />      pkg_demo.get_cursor(     <br />        demo_cur=>:demo_cursor<br />      );<br />  END;<br />END-EXEC;</pre>ECPG 程式碼：<pre>EXEC SQL DECLARE demo_cursor CURSOR FOR SELECT<br />         * from<br />    pkg_demo.open_filename_rc(<br />            demo_cur=>refcursor<br />          ) ;<br />EXEC SQL char open_filename_rcInd[100]; <br /># As the below function returns cursor_name as <br /># return we need to use char[] type as indicator. <br />EXEC SQL SELECT pkg_demo.get_cursor (<br />        demo_cur=>'demo_cursor'<br />    ) INTO :open_filename_rcInd;</pre> | 應用程式開發人員、應用程式擁有者 | 
| 套用常見的遷移模式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-legacy-applications-from-oracle-pro-c-to-ecpg.html) | 應用程式開發人員、應用程式擁有者 | 
| 視需要啟用偵錯。 | 若要在偵錯模式下執行 ECPG 程式，請在主要函數區塊中新增下列命令。<pre>ECPGdebug(1, stderr); </pre> | 應用程式開發人員、應用程式擁有者 | 

### 編譯 ECPG 程式
<a name="compile-ecpg-programs"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 ECPG 的可執行檔。 | 如果您有名為 的內嵌 SQL C 來源檔案`prog1.pgc`，您可以使用下列命令序列來建立可執行程式。<pre>ecpg prog1.pgc<br />cc -I/usr/local/pgsql/include -c prog1.c<br />cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg</pre> | 應用程式開發人員、應用程式擁有者 | 
| 建立要編譯的 make 檔案。 | 建立 make 檔案以編譯 ECPG 程式，如下列範例檔案所示。<pre>CFLAGS ::= $(CFLAGS) -I/usr/pgsql-12/include -g -Wall<br />LDFLAGS ::= $(LDFLAGS) -L/usr/pgsql-12/lib -Wl,-rpath,/usr/pgsql-12/lib<br />LDLIBS ::= $(LDLIBS) -lecpg<br />PROGRAMS = test <br />.PHONY: all clean<br />%.c: %.pgc<br />      ecpg $<<br />all: $(PROGRAMS)<br />clean:<br />    rm -f $(PROGRAMS) $(PROGRAMS:%=%.c) $(PROGRAMS:%=%.o)</pre> | 應用程式開發人員、應用程式擁有者 | 

### 測試應用程式。
<a name="test-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試代碼。 | 測試轉換後的應用程式程式碼，以確保其正常運作。 | 應用程式開發人員、應用程式擁有者、測試工程師 | 

## 相關資源
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg-resources"></a>
+ [ECPG - C 中的內嵌 SQL](https://www.postgresql.org/docs/current/static/ecpg.html) (PostgreSQL 文件）
+ [錯誤處理](https://www.postgresql.org/docs/12/ecpg-errors.html) (PostgreSQL 文件）
+ [為什麼要使用 Oracle Pro\$1C/C\$1\$1 前置編譯器 ](https://docs.oracle.com/cd/E11882_01/appdev.112/e10825/pc_01int.htm#i2415)(Oracle 文件）

## 其他資訊
<a name="migrate-legacy-applications-from-oracle-pro-c-to-ecpg-additional"></a>

PostgreSQL 具有內嵌 SQL 前置編譯器 ECPG，相當於 Oracle Pro\$1C 前置編譯器。ECPG 會將內嵌 SQL 陳述式的 C 程式轉換為標準 C 程式碼，方法是將 SQL 呼叫取代為特殊函數呼叫。然後，可以使用任何 C 編譯器工具鏈處理輸出檔案。

**輸入和輸出檔案**

ECPG 會將您在命令列指定的每個輸入檔案轉換為對應的 C 輸出檔案。如果輸入檔案名稱沒有副檔名，則會假設 .pgc。檔案的副檔名由 取代`.c`，以建構輸出檔案名稱。不過，您可以使用 `-o`選項覆寫預設輸出檔案名稱。

如果您使用破折號 (`-`) 做為輸入檔案名稱， ECPG 會從標準輸入 讀取程式，並寫入標準輸出，除非您使用 `-o`選項覆寫該程式。

**標頭檔案**

當 PostgreSQL 編譯器編譯預先處理的 C 程式碼檔案時，它會在 PostgreSQL `include`目錄中尋找 ECPG 標頭檔案。因此，您可能必須使用 `-I`選項，將編譯器指向正確的目錄 （例如，`-I/usr/local/pgsql/include`)。

**Libraries (程式庫)**

使用 C 程式碼搭配內嵌 SQL `libecpg`的程式必須連結到程式庫。例如，您可以使用連結器選項` -L/usr/local/pgsql/lib -lecpg`。

轉換後的 ECPG 應用程式會透過內嵌 SQL 程式庫 (`ecpglib`) 呼叫`libpq`程式庫中的函數，並使用標準前端/後端通訊協定與 PostgreSQL 伺服器通訊。

# 將虛擬產生的資料欄從 Oracle 遷移至 PostgreSQL
<a name="migrate-virtual-generated-columns-from-oracle-to-postgresql"></a>

*Veeranjaneyulu Grandhi、Rajesh Madiwale 和 Ramesh Pathuri，Amazon Web Services*

## 總結
<a name="migrate-virtual-generated-columns-from-oracle-to-postgresql-summary"></a>

在 11 版和更早版本中，PostgreSQL 不提供直接等同於 Oracle 虛擬資料欄的功能。在從 Oracle 資料庫遷移至 PostgreSQL 第 11 版或更早版本時，處理虛擬產生的資料欄很困難，原因有兩個： 
+ 遷移期間看不到虛擬資料欄。
+ PostgreSQL 不支援版本 12 之前的`generate`表達式。

不過，有模擬類似功能的解決方法。當您使用 AWS Database Migration Service (AWS DMS) 將資料從 Oracle Database 遷移至 PostgreSQL 第 11 版及更早版本時，您可以使用觸發函數在虛擬產生的資料欄中填入值。此模式提供 Oracle 資料庫和 PostgreSQL 程式碼的範例，您可以用於此目的。在 AWS 上，您可以將 Amazon Relational Database Service (Amazon RDS) 用於 PostgreSQL，或將 Amazon Aurora PostgreSQL 相容版本用於 PostgreSQL 資料庫。

從 PostgreSQL 第 12 版開始，支援產生的資料欄。產生的資料欄可以即時從其他資料欄值計算，也可以計算和儲存。[PostgreSQL 產生的資料欄](https://www.postgresql.org/docs/12/ddl-generated-columns.html)類似於 Oracle 虛擬資料欄。

## 先決條件和限制
<a name="migrate-virtual-generated-columns-from-oracle-to-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 來源 Oracle 資料庫 
+ Target PostgreSQL 資料庫 (Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容）
+ [PL/pgSQL](https://www.postgresql.org/docs/current/plpgsql.html) 編碼專業知識

**限制**
+ 僅適用於第 12 版之前的 PostgreSQL 版本。 
+ 適用於 Oracle 資料庫 11g 版或更新版本。
+ 資料遷移工具不支援虛擬資料欄。
+ 僅適用於相同資料表中定義的資料欄。
+ 如果虛擬產生的資料欄是指確定性的使用者定義函數，則不能用作分割索引鍵資料欄。
+ 表達式的輸出必須是純量值。它無法傳回 Oracle 提供的資料類型、使用者定義的類型`LOB`、 或 `LONG RAW`。
+ 針對虛擬資料欄定義的索引等同於 PostgreSQL 中的函數型索引。
+ 必須收集資料表統計資料。

## 工具
<a name="migrate-virtual-generated-columns-from-oracle-to-postgresql-tools"></a>
+ [pgAdmin 4](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。此工具提供圖形界面，可簡化資料庫物件的建立、維護和使用。
+ [Oracle SQL Developer](https://www.oracle.com/database/sqldeveloper/) 是免費的整合開發環境，可在傳統和雲端部署中使用 Oracle 資料庫中的 SQL。 

## 史詩
<a name="migrate-virtual-generated-columns-from-oracle-to-postgresql-epics"></a>

### 建立來源和目標資料庫資料表
<a name="create-source-and-target-database-tables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立來源 Oracle 資料庫資料表。 | 在 Oracle Database 中，使用下列陳述式建立具有虛擬產生資料欄的資料表。<pre>CREATE TABLE test.generated_column<br />( CODE NUMBER,<br />STATUS VARCHAR2(12) DEFAULT 'PreOpen',<br />FLAG CHAR(1) GENERATED ALWAYS AS (CASE UPPER(STATUS) WHEN 'OPEN' THEN 'N' ELSE 'Y' END) VIRTUAL VISIBLE<br />);</pre>在此來源資料表中，資料`STATUS`欄中的資料會透過 AWS DMS 遷移至目標資料庫。不過，資料`FLAG`欄會使用 `generate by`功能填入，因此 AWS DMS 在遷移期間看不到此資料欄。若要實作 的功能`generated by`，您必須使用目標資料庫中的觸發條件和函數來填入資料`FLAG`欄中的值，如下圖所示。 | DBA，應用程式開發人員 | 
| 在 AWS 上建立目標 PostgreSQL 資料表。 | 使用下列陳述式在 AWS 上建立 PostgreSQL 資料表。<pre>CREATE TABLE test.generated_column<br />(<br />    code integer not null,<br />    status character varying(12) not null ,<br />    flag character(1)<br />);</pre>在此資料表中，資料`status`欄是標準資料欄。`flag` 資料欄將根據資料欄中的資料產生資料`status`欄。 | DBA，應用程式開發人員 | 

### 建立觸發函數來處理 PostgreSQL 中的虛擬資料欄
<a name="create-a-trigger-function-to-handle-the-virtual-column-in-postgresql"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 PostgreSQL 觸發。 | 在 PostgreSQL 中，建立觸發條件。<pre>CREATE TRIGGER tgr_gen_column<br />AFTER INSERT OR UPDATE OF status ON test.generated_column<br />FOR EACH ROW <br />EXECUTE FUNCTION test.tgf_gen_column();</pre> | DBA，應用程式開發人員 | 
| 建立 PostgreSQL 觸發函數。 | 在 PostgreSQL 中，為觸發建立 函數。此函數會填入由應用程式或 AWS DMS 插入或更新的虛擬資料欄，並驗證資料。<pre>CREATE OR REPLACE FUNCTION test.tgf_gen_column() RETURNS trigger AS $VIRTUAL_COL$<br />BEGIN<br />IF (TG_OP = 'INSERT') THEN<br />IF (NEW.flag IS NOT NULL) THEN<br />RAISE EXCEPTION 'ERROR: cannot insert into column "flag"' USING DETAIL = 'Column "flag" is a generated column.';<br />END IF;<br />END IF;<br />IF (TG_OP = 'UPDATE') THEN<br />IF (NEW.flag::VARCHAR != OLD.flag::varchar) THEN<br />RAISE EXCEPTION 'ERROR: cannot update column "flag"' USING DETAIL = 'Column "flag" is a generated column.';<br />END IF;<br />END IF;<br />IF TG_OP IN ('INSERT','UPDATE') THEN<br />IF (old.flag is NULL) OR (coalesce(old.status,'') != coalesce(new.status,'')) THEN<br />UPDATE test.generated_column<br />SET flag = (CASE UPPER(status) WHEN 'OPEN' THEN 'N' ELSE 'Y' END)<br />WHERE code = new.code;<br />END IF;<br />END IF;<br />RETURN NEW;<br />END<br />$VIRTUAL_COL$ LANGUAGE plpgsql;</pre> | DBA，應用程式開發人員 | 

### 使用 AWS DMS 測試資料遷移
<a name="test-data-migration-by-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立複寫執行個體。 | 若要建立複寫執行個體，請遵循 AWS DMS 文件中[的指示](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.Creating.html)。複寫執行個體應與來源和目標資料庫位於相同的虛擬私有雲端 (VPC) 中。 | DBA，應用程式開發人員 | 
| 建立來源和目標端點。 | 若要建立端點，請遵循 AWS DMS 文件中[的指示](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)。 | DBA，應用程式開發人員 | 
| 測試端點連線。 | 您可以透過指定 VPC 和複寫執行個體，然後選擇**執行**測試來測試端點連線。 | DBA，應用程式開發人員 | 
| 建立並啟動完整載入任務。 | 如需說明，請參閱 AWS DMS 文件中的[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)和[完全載入任務設定](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.CustomizingTasks.TaskSettings.FullLoad.html)。 | DBA，應用程式開發人員 | 
| 驗證虛擬資料欄的資料。 | 比較來源和目標資料庫中虛擬資料欄中的資料。您可以手動驗證資料或撰寫此步驟的指令碼。 | DBA，應用程式開發人員 | 

## 相關資源
<a name="migrate-virtual-generated-columns-from-oracle-to-postgresql-resources"></a>
+ [AWS Database Migration Service 入門](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html) (AWS DMS 文件）
+ [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html) (AWS DMS 文件）
+ [使用 PostgreSQL 資料庫做為 AWS DMS 的目標 ](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)(AWS DMS 文件）
+ [PostgreSQL 中產生的資料欄](https://www.postgresql.org/docs/12/ddl-generated-columns.html) (PostgreSQL 文件）
+ [觸發函數](https://www.postgresql.org/docs/12/plpgsql-trigger.html) (PostgreSQL 文件）
+ Oracle 資料庫中的[虛擬資料欄](https://docs.oracle.com/database/121/SQLRF/statements_7002.htm#SQLRF01402) (Oracle 文件）

# 在 Aurora PostgreSQL 相容上設定 Oracle UTL\$1FILE 功能
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible"></a>

*Rakesh Raghav 和 anuradha chintha，Amazon Web Services*

## 總結
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-summary"></a>

在從 Oracle 遷移到 Amazon Web Services (AWS) 雲端上 Amazon Aurora PostgreSQL 相容版本的過程中，您可能會遇到多個挑戰。例如，遷移依賴 Oracle `UTL_FILE`公用程式的程式碼一律是一項挑戰。在 Oracle PL/SQL 中，`UTL_FILE`套件會搭配基礎作業系統用於檔案操作，例如讀取和寫入。`UTL_FILE` 公用程式適用於伺服器和用戶端機器系統。 

Amazon Aurora PostgreSQL 相容是受管資料庫產品。因此，無法存取資料庫伺服器上的檔案。此模式會逐步引導您整合 Amazon Simple Storage Service (Amazon S3) 和 Amazon Aurora PostgreSQL 相容，以實現`UTL_FILE`功能子集。使用此整合，我們可以建立和使用檔案，而無需使用第三方擷取、轉換和載入 (ETL) 工具或服務。

或者，您可以設定 Amazon CloudWatch 監控和 Amazon SNS 通知。

我們建議在生產環境中實作此解決方案之前，先徹底測試此解決方案。

## 先決條件和限制
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ AWS Database Migration Service (AWS DMS) 專業知識
+ PL/pgSQL 編碼的專業知識
+ Amazon Aurora PostgreSQL 相容叢集
+ S3 儲存貯體

**限制**

此模式不提供可取代 Oracle `UTL_FILE`公用程式的功能。不過，您可以進一步增強步驟和範本程式碼，以實現資料庫現代化目標。

**產品版本**
+ Amazon Aurora PostgreSQL 相容版本 11.9

## Architecture
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-architecture"></a>

**目標技術堆疊**
+ Amazon Aurora PostgreSQL 相容
+ Amazon CloudWatch
+ Amazon Simple Notification Service (Amazon SNS)
+ Amazon S3

**目標架構**

下圖顯示解決方案的高階表示法。

![\[資料檔案會上傳至 S3 儲存貯體，使用 aws_s3 副檔名處理，並傳送至 Aurora 執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/3aeecd46-1f87-41f9-a9cd-f8181f92e83f/images/4a6c5f5c-58fb-4355-b243-d09a15c1cec6.png)


1. 檔案會從應用程式上傳到 S3 儲存貯體。

1. `aws_s3` 延伸模組會使用 PL/pgSQL 存取資料，並將資料上傳至 Aurora PostgreSQL 相容。

## 工具
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-tools"></a>
+ [Amazon Aurora PostgreSQL 相容](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html) – Amazon Aurora PostgreSQL 相容版本是全受管、PostgreSQL 相容和 ACID 相容關聯式資料庫引擎。它結合了高階商業資料庫的速度和可靠性，以及開放原始碼資料庫的成本效益。
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) – AWS Command Line Interface (AWS CLI) 是管理 AWS 服務的統一工具。只需下載和設定一個工具，您就可以從命令列控制多個 AWS 服務，並透過指令碼將其自動化。
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) – Amazon CloudWatch 會監控 Amazon S3 資源和使用方式。
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是網際網路的儲存體。在此模式中，Amazon S3 提供儲存層來接收和存放檔案，以供取用和往返 Aurora PostgreSQL 相容叢集傳輸。
+ [aws\$1s3](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html#aws_s3.table_import_from_s3) – `aws_s3`延伸模組整合 Amazon S3 和 Aurora PostgreSQL 相容。
+ [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) – Amazon Simple Notification Service (Amazon SNS) 會協調和管理發佈者和用戶端之間的訊息傳遞或傳送。在此模式中，Amazon SNS 用於傳送通知。
+ [pgAdmin](https://www.pgadmin.org/docs/) – pgAdmin 是 Postgres 的開放原始碼管理工具。pgAdmin 4 提供圖形界面，用於建立、維護和使用資料庫物件。

**Code**

為了實現所需的功能， 模式會使用類似於 的命名來建立多個函數`UTL_FILE`。*其他資訊*區段包含這些函數的程式碼基底。

在程式碼中，將 取代`testaurorabucket`為測試 S3 儲存貯體的名稱。`us-east-1` 將 取代為測試 S3 儲存貯體所在的 AWS 區域。

## 史詩
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-epics"></a>

### 整合 Amazon S3 和 Aurora PostgreSQL 相容
<a name="integrate-amazon-s3-and-aurora-postgresql-compatible"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 IAM 政策。 | 建立 AWS Identity and Access Management (IAM) 政策，以授予 S3 儲存貯體和其中物件的存取權。如需程式碼，請參閱*其他資訊*一節。 | AWS 管理員，DBA | 
| 將 Amazon S3 存取角色新增至 Aurora PostgreSQL。 | 建立兩個 IAM 角色：一個角色用於讀取，一個角色用於寫入存取 Amazon S3。將兩個角色連接到 Aurora PostgreSQL 相容叢集： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible.html)如需詳細資訊，請參閱 Aurora PostgreSQL 相容文件，了解如何[將資料匯入](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PostgreSQL.S3Import.html)和[匯出](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/postgresql-s3-export.html)至 Amazon S3。 | AWS 管理員，DBA | 

### 在 Aurora PostgreSQL 相容中設定擴充功能
<a name="set-up-the-extensions-in-aurora-postgresql-compatible"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 aws\$1commons 延伸模組。 | `aws_commons` 延伸模組是`aws_s3`延伸模組的相依性。 | DBA、開發人員 | 
| 建立 aws\$1s3 延伸模組。 | `aws_s3` 延伸模組會與 Amazon S3 互動。 | DBA、開發人員 | 

### 驗證 Amazon S3 和 Aurora PostgreSQL 相容整合
<a name="validate-amazon-s3-and-aurora-postgresql-compatible-integration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試將檔案從 Amazon S3 匯入 Aurora PostgreSQL。 | 若要測試將檔案匯入 Aurora PostgreSQL 相容，請建立範例 CSV 檔案並將其上傳至 S3 儲存貯體。根據 CSV 檔案建立資料表定義，並使用 `aws_s3.table_import_from_s3`函數將檔案載入資料表。 | DBA、開發人員 | 
| 測試將檔案從 Aurora PostgreSQL 匯出至 Amazon S3。 | 若要測試從 Aurora PostgreSQL 相容匯出檔案，請建立測試資料表、填入資料，然後使用 `aws_s3.query_export_to_s3`函數匯出資料。 | DBA、開發人員 | 

### 若要模擬 UTL\$1FILE 公用程式，請建立包裝函式
<a name="to-mimic-the-utl_file-utility-create-wrapper-functions"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 utl\$1file\$1utility 結構描述。 | 結構描述會將包裝函式放在一起。若要建立結構描述，請執行下列命令。<pre>CREATE SCHEMA utl_file_utility;</pre> | DBA、開發人員 | 
| 建立 file\$1type 類型。 | 若要建立 `file_type`類型，請使用下列程式碼。<pre>CREATE TYPE utl_file_utility.file_type AS (<br />    p_path character varying(30),<br />    p_file_name character varying<br />);<br /><br /><br /></pre> | DBA/開發人員 | 
| 建立初始化函數。 | `init` 函數會初始化常見的變數，例如 `bucket`或 `region`。如需程式碼，請參閱*其他資訊*一節。 | DBA/開發人員 | 
| 建立包裝函式。 | 建立包裝函式 `fopen`、 `put_line`和 `fclose`。如需程式碼，請參閱*其他資訊*一節。 | DBA、開發人員 | 

### 測試包裝函式
<a name="test-the-wrapper-functions"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在寫入模式下測試包裝函式。 | 若要在寫入模式下測試包裝函式，請使用*其他資訊*區段中提供的程式碼。 | DBA、開發人員 | 
| 在附加模式下測試包裝函式。 | 若要在附加模式下測試包裝函式，請使用*其他資訊*區段中提供的程式碼。 | DBA、開發人員 | 

## 相關資源
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-resources"></a>
+ [Amazon S3 整合](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PostgreSQL.S3Import.html)
+ [Amazon S3](https://aws.amazon.com/s3/)
+ [Aurora](https://aws.amazon.com/rds/aurora/?nc2=h_ql_prod_db_aa&aurora-whats-new.sort-by=item.additionalFields.postDateTime&aurora-whats-new.sort-order=desc)
+ [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/)
+ [Amazon SNS](https://aws.amazon.com/sns/?nc2=h_ql_prod_ap_sns&whats-new-cards.sort-by=item.additionalFields.postDateTime&whats-new-cards.sort-order=desc)

## 其他資訊
<a name="set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible-additional"></a>

**設定 IAM 政策**

建立下列政策。


| 
| 
| 政策名稱 | JSON | 
| --- |--- |
| S3IntRead | <pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Sid": "S3integrationtest",<br />            "Effect": "Allow",<br />            "Action": [<br />                "s3:GetObject",<br />                "s3:ListBucket"<br />            ],<br />            "Resource": [<br />         "arn:aws:s3:::testaurorabucket/*",<br />         "arn:aws:s3:::testaurorabucket"<br />            ]<br />        }<br />    ]<br />}</pre> | 
| S3IntWrite | <pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Sid": "S3integrationtest",<br />            "Effect": "Allow",<br />            "Action": [<br />                "s3:PutObject",                <br />                "s3:ListBucket"<br />            ],<br />            "Resource": [                "arn:aws:s3:::testaurorabucket/*",                "arn:aws:s3:::testaurorabucket"<br />            ]<br />        }<br />    ]<br />}</pre> | 

**建立初始化函數**

若要初始化常見變數，例如 `bucket`或 `region`，請使用下列程式碼建立 `init`函數。

```
CREATE OR REPLACE FUNCTION utl_file_utility.init(
    )
    RETURNS void
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
AS $BODY$
BEGIN
      perform set_config
      ( format( '%s.%s','UTL_FILE_UTILITY', 'region' )
      , 'us-east-1'::text
      , false );

      perform set_config
      ( format( '%s.%s','UTL_FILE_UTILITY', 's3bucket' )
      , 'testaurorabucket'::text
      , false );
END;
$BODY$;
```

**建立包裝函式**

建立 `fopen`、 `put_line`和 `fclose` 包裝函式。

*fopen*

```
CREATE OR REPLACE FUNCTION utl_file_utility.fopen(
    p_file_name character varying,
    p_path character varying,
    p_mode character DEFAULT 'W'::bpchar,
    OUT p_file_type utl_file_utility.file_type)
    RETURNS utl_file_utility.file_type
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
AS $BODY$
declare
    v_sql character varying;
    v_cnt_stat integer;
    v_cnt integer;
    v_tabname character varying;
    v_filewithpath character varying;
    v_region character varying;
    v_bucket character varying;

BEGIN
    /*initialize common variable */
    PERFORM utl_file_utility.init();
    v_region := current_setting( format( '%s.%s', 'UTL_FILE_UTILITY', 'region' ) );
    v_bucket :=  current_setting( format( '%s.%s', 'UTL_FILE_UTILITY', 's3bucket' ) );
    
    /* set tabname*/
    v_tabname := substring(p_file_name,1,case when strpos(p_file_name,'.') = 0 then length(p_file_name) else strpos(p_file_name,'.') - 1 end );
    v_filewithpath := case when NULLif(p_path,'') is null then p_file_name else concat_ws('/',p_path,p_file_name) end ;
    raise notice 'v_bucket %, v_filewithpath % , v_region %', v_bucket,v_filewithpath, v_region;
    
    /* APPEND MODE HANDLING; RETURN EXISTING FILE DETAILS IF PRESENT ELSE CREATE AN EMPTY FILE */
    IF p_mode = 'A' THEN
        v_sql := concat_ws('','create temp table if not exists ', v_tabname,' (col1 text)');
        execute v_sql;

        begin
        PERFORM aws_s3.table_import_from_s3 
            ( v_tabname, 
            '',  
            'DELIMITER AS ''#''', 
            aws_commons.create_s3_uri 
            (     v_bucket, 
                v_filewithpath ,
                v_region)
            );
        exception
            when others then
             raise notice 'File load issue ,%',sqlerrm;
             raise;
        end;
        execute concat_ws('','select count(*) from ',v_tabname) into v_cnt;

        IF v_cnt > 0 
        then
            p_file_type.p_path := p_path;
            p_file_type.p_file_name := p_file_name;
        else         
            PERFORM aws_s3.query_export_to_s3('select ''''', 
                            aws_commons.create_s3_uri(v_bucket, v_filewithpath, v_region)            
                              );

            p_file_type.p_path := p_path;
            p_file_type.p_file_name := p_file_name;        
        end if;
        v_sql := concat_ws('','drop table ', v_tabname);        
        execute v_sql;            
    ELSEIF p_mode = 'W' THEN
            PERFORM aws_s3.query_export_to_s3('select ''''', 
                            aws_commons.create_s3_uri(v_bucket, v_filewithpath, v_region)            
                              );
            p_file_type.p_path := p_path;
            p_file_type.p_file_name := p_file_name;
    END IF;    
    
EXCEPTION
        when others then
            p_file_type.p_path := p_path;
            p_file_type.p_file_name := p_file_name;
            raise notice 'fopenerror,%',sqlerrm;
            raise;
END;
$BODY$;
```

*put\$1line*

```
CREATE OR REPLACE FUNCTION utl_file_utility.put_line(
    p_file_name character varying,
    p_path character varying,
    p_line text,
    p_flag character DEFAULT 'W'::bpchar)
    RETURNS boolean
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
AS $BODY$
/**************************************************************************
* Write line, p_line in windows format to file, p_fp - with carriage return
* added before new line.
**************************************************************************/
declare
    v_sql varchar;
    v_ins_sql varchar;
    v_cnt INTEGER;
    v_filewithpath character varying;
    v_tabname  character varying;
    v_bucket character varying;
    v_region character varying;    

BEGIN
 PERFORM utl_file_utility.init();

/* check if temp table already exist */

 v_tabname := substring(p_file_name,1,case when strpos(p_file_name,'.') = 0 then length(p_file_name) else strpos(p_file_name,'.') - 1 end );

 v_sql := concat_ws('','select count(1) FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace where n.nspname like ''pg_temp_%''' 
                         ,' AND pg_catalog.pg_table_is_visible(c.oid) AND Upper(relname) = Upper( '''
                         ,  v_tabname ,''' ) ');
  
 execute v_sql into v_cnt;
  
  IF v_cnt = 0 THEN
         v_sql := concat_ws('','create temp table ',v_tabname,' (col text)');
        execute v_sql;
        /* CHECK IF APPEND MODE */
        IF upper(p_flag) = 'A' THEN
            PERFORM utl_file_utility.init();                        
            v_region := current_setting( format( '%s.%s', 'UTL_FILE_UTILITY', 'region' ) );
            v_bucket :=  current_setting( format( '%s.%s', 'UTL_FILE_UTILITY', 's3bucket' ) );
            
            /* set tabname*/            
            v_filewithpath := case when NULLif(p_path,'') is null then p_file_name else concat_ws('/',p_path,p_file_name) end ;            
            
            begin
               PERFORM aws_s3.table_import_from_s3 
                     ( v_tabname, 
                          '',  
                       'DELIMITER AS ''#''', 
                        aws_commons.create_s3_uri 
                           ( v_bucket, 
                               v_filewithpath, 
                               v_region    )
                    );
            exception
                when others then
                    raise notice  'Error Message : %',sqlerrm;
                    raise;
            end;    
        END IF;    
    END IF;
    /* INSERT INTO TEMP TABLE */              
    v_ins_sql := concat_ws('','insert into ',v_tabname,' values(''',p_line,''')');
    execute v_ins_sql;
    RETURN TRUE;
    exception
            when others then
                raise notice  'Error Message : %',sqlerrm;
                raise;
END;
$BODY$;
```

*關閉*

```
CREATE OR REPLACE FUNCTION utl_file_utility.fclose(
    p_file_name character varying,
    p_path character varying)
    RETURNS boolean
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
AS $BODY$
DECLARE
    v_filewithpath character varying;
    v_bucket character varying;
    v_region character varying;
    v_tabname character varying;
    v_sql character varying;
BEGIN
      PERFORM utl_file_utility.init();
  
    v_region := current_setting( format( '%s.%s', 'UTL_FILE_UTILITY', 'region' ) );
    v_bucket :=  current_setting( format( '%s.%s', 'UTL_FILE_UTILITY', 's3bucket' ) );

    v_tabname := substring(p_file_name,1,case when strpos(p_file_name,'.') = 0 then length(p_file_name) else strpos(p_file_name,'.') - 1 end );
    v_filewithpath := case when NULLif(p_path,'') is null then p_file_name else concat_ws('/',p_path,p_file_name) end ;

    raise notice 'v_bucket %, v_filewithpath % , v_region %', v_bucket,v_filewithpath, v_region ;
    
    /* exporting to s3 */
    perform aws_s3.query_export_to_s3
        (concat_ws('','select * from ',v_tabname,'  order by ctid asc'), 
            aws_commons.create_s3_uri(v_bucket, v_filewithpath, v_region)
        );
    v_sql := concat_ws('','drop table ', v_tabname);
    execute v_sql;    
    RETURN TRUE;
EXCEPTION 
       when others then
     raise notice 'error fclose %',sqlerrm;
     RAISE;
END;
$BODY$;
```

**測試您的設定和包裝函式**

使用以下匿名程式碼區塊來測試您的設定。

*測試寫入模式*

下列程式碼會在 S3 儲存貯`s3inttest`體中寫入名為 的檔案。

```
do $$
declare
l_file_name varchar := 's3inttest' ;
l_path varchar := 'integration_test' ;
l_mode char(1) := 'W';
l_fs utl_file_utility.file_type ;
l_status boolean;

begin
select * from
utl_file_utility.fopen( l_file_name, l_path , l_mode ) into l_fs ;
raise notice 'fopen : l_fs : %', l_fs;

select * from
utl_file_utility.put_line( l_file_name, l_path ,'this is test file:in s3bucket: for test purpose', l_mode ) into l_status ;
raise notice 'put_line : l_status %', l_status;

select * from utl_file_utility.fclose( l_file_name , l_path ) into l_status ;
raise notice 'fclose : l_status %', l_status;

end;
$$
```

*測試附加模式*

下列程式碼會將行附加至先前測試中建立的 `s3inttest` 檔案。

```
do $$
declare
l_file_name varchar := 's3inttest' ;
l_path varchar := 'integration_test' ;
l_mode char(1) := 'A';
l_fs utl_file_utility.file_type ;
l_status boolean;

begin
select * from
utl_file_utility.fopen( l_file_name, l_path , l_mode ) into l_fs ;
raise notice 'fopen : l_fs : %', l_fs;


select * from
utl_file_utility.put_line( l_file_name, l_path ,'this is test file:in s3bucket: for test purpose : append 1', l_mode ) into l_status ;
raise notice 'put_line : l_status %', l_status;

select * from
utl_file_utility.put_line( l_file_name, l_path ,'this is test file:in s3bucket : for test purpose : append 2', l_mode ) into l_status ;
raise notice 'put_line : l_status %', l_status;

select * from utl_file_utility.fclose( l_file_name , l_path ) into l_status ;
raise notice 'fclose : l_status %', l_status;

end;
$$
```

**Amazon SNS 通知**

或者，您可以在 S3 儲存貯體上設定 Amazon CloudWatch 監控和 Amazon SNS 通知。如需詳細資訊，請參閱[監控 Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/monitoring-overview.html) 和[設定 Amazon SNS 通知](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html)。

# 從 Oracle 遷移到 Amazon Aurora PostgreSQL 後驗證資料庫物件
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql"></a>

*Venkatramana Chintha 和 Eduardo Valentim，Amazon Web Services*

## 總結
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql-summary"></a>

此模式描述將 step-by-step方法。 PostgreSQL

此模式概述資料庫物件驗證的使用案例和步驟；如需更多詳細資訊，請參閱 [AWS 資料庫部落格上的使用 AWS SCT 和 AWS DMS 在遷移後驗證資料庫物件](https://aws.amazon.com/blogs/database/validating-database-objects-after-migration-using-aws-sct-and-aws-dms/)。 [https://aws.amazon.com/blogs/](https://aws.amazon.com/blogs/)

## 先決條件和限制
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 已遷移至 Aurora PostgreSQL 相容資料庫的現場部署 Oracle 資料庫。 
+ 已套用 Aurora PostgreSQL 相容資料庫 [AmazonRDSDataFullAccess](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/query-editor.html) 政策的登入憑證。 
+ 此模式使用 [Aurora Serverless 資料庫叢集的查詢編輯器](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/query-editor.html)，可在 Amazon Relational Database Service (Amazon RDS) 主控台中使用。不過，您可以將此模式與任何其他查詢編輯器搭配使用。 

**限制**
+ Oracle SYNONYM 物件無法在 PostgreSQL 中使用，但可以透過**檢視**或 SET search\$1path 查詢進行部分驗證。
+ Amazon RDS 查詢編輯器僅適用於[特定 AWS 區域和特定 MySQL 和 PostgreSQL 版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/query-editor.html)。

## Architecture
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql-architecture"></a>

 

![\[Database migration workflow showing on-premises Oracle to AWSAurora PostgreSQL via client program and validation scripts.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7c028960-6dea-46ad-894d-e42cefd50c03/images/be5f8ae3-f5af-4c5e-9440-09ab410beaa1.png)


 

## 工具
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql-tools"></a>

**工具**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html) – Aurora PostgreSQL 相容是全受管、PostgreSQL 相容且 ACID 相容的關聯式資料庫引擎，結合了高階商業資料庫的速度和可靠性，以及開放原始碼資料庫的簡單性和成本效益。
+ [Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) – Amazon Relational Database Service (Amazon RDS) 可讓您更輕鬆地在 AWS 雲端中設定、操作和擴展關聯式資料庫。其能為產業標準的關聯式資料庫提供具成本效益、可調整大小的容量，並管理常見的資料庫管理任務。
+ [Aurora Severless 的查詢編輯器](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/query-editor.html) – 查詢編輯器可協助您在 Amazon RDS 主控台中執行 SQL 查詢。您可以在 Aurora Serverless 資料庫叢集上執行任何有效的 SQL 陳述式，包括資料處理和資料定義陳述式。

若要驗證物件，請使用「附件」區段中「物件驗證指令碼」檔案中的完整指令碼。使用下表做為參考。


| 
| 
| Oracle 物件 | 要使用的指令碼 | 
| --- |--- |
| 套件 | 查詢 1 | 
| 表格 | 查詢 3 | 
| 檢視 | 查詢 5 | 
| 序列 | 查詢 7 | 
| 觸發 |  查詢 9 | 
| 主索引鍵 | 查詢 11 | 
| 索引 | 查詢 13 | 
| 檢查限制 | 查詢 15 | 
| 外部索引鍵  | 查詢 17  | 


| 
| 
| PostgreSQL 物件 | 要使用的指令碼 | 
| --- |--- |
| 套件 | 查詢 2 | 
| 表格 | 查詢 4 | 
| 檢視 | 查詢 6 | 
| 序列 | 查詢 8 | 
| 觸發 | 查詢 10 | 
| 主索引鍵 | 查詢 12 | 
| 索引 | 查詢 14 | 
| 檢查限制 | 查詢 16 | 
| 外部索引鍵 | 查詢 18 | 

## 史詩
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql-epics"></a>

### 驗證來源 Oracle 資料庫中的物件
<a name="validate-objects-in-the-source-oracle-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源 Oracle 資料庫中執行「套件」驗證查詢。 | 從「附件」區段下載並開啟「物件驗證指令碼」檔案。透過用戶端程式連線至來源 Oracle 資料庫。從「物件驗證指令碼」檔案執行「查詢 1」驗證指令碼。重要：在查詢中輸入您的 Oracle 使用者名稱，而不是「your\$1schema」。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「資料表」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 3」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「檢視」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 5」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「序列」計數驗證。 | 從「物件驗證指令碼」檔案執行「查詢 7」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「觸發器」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 9」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「主索引鍵」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 11」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「索引」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 13」驗證指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「檢查限制條件」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 15」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「外部金鑰」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 17」驗證指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 

### 驗證目標 Aurora PostgreSQL 相容資料庫中的物件
<a name="validate-objects-in-the-target-aurora-postgresql-compatible-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用查詢編輯器連線至目標 Aurora PostgreSQL 相容資料庫。 | 登入 AWS 管理主控台並開啟 Amazon RDS 主控台。在右上角，選擇您建立 Aurora PostgreSQL 相容資料庫的 AWS 區域。在導覽窗格中，選擇「資料庫」，然後選擇目標 Aurora PostgreSQL 相容資料庫。在「動作」中，選擇「查詢」。重要：如果您之前尚未連線到資料庫，則「連線至資料庫」頁面會開啟。然後，您需要輸入資料庫資訊，例如使用者名稱和密碼。 | 開發人員，DBA | 
| 執行「套件」驗證查詢。 | 從「附件」區段中的「物件驗證指令碼」檔案執行「查詢 2」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「資料表」驗證查詢。 | 返回 Aurora PostgreSQL 相容資料庫的查詢編輯器，並從「物件驗證指令碼」檔案執行「查詢 4」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「檢視」驗證查詢。 | 返回 Aurora PostgreSQL 相容資料庫的查詢編輯器，並從「物件驗證指令碼」檔案執行「查詢 6」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「序列」計數驗證。 | 返回 Aurora PostgreSQL 相容資料庫的查詢編輯器，並從「物件驗證指令碼」檔案執行「查詢 8」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「觸發器」驗證查詢。 | 返回 Aurora PostgreSQL 相容資料庫的查詢編輯器，並從「物件驗證指令碼」檔案執行「查詢 10」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「主索引鍵」驗證查詢。 | 返回 Aurora PostgreSQL 相容資料庫的查詢編輯器，並從「物件驗證指令碼」檔案執行「查詢 12」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「索引」驗證查詢。 | 返回 Aurora PostgreSQL 相容資料庫的查詢編輯器，並從「物件驗證指令碼」檔案執行「查詢 14」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「檢查限制條件」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 16」指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 
| 執行「外部金鑰」驗證查詢。 | 從「物件驗證指令碼」檔案執行「查詢 18」驗證指令碼。請務必記錄查詢結果。 | 開發人員，DBA | 

### 比較來源和目標資料庫驗證記錄
<a name="compare-source-and-target-database-validation-records"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 比較並驗證兩個查詢結果。 | 比較 Oracle 和 Aurora PostgreSQL 相容資料庫的查詢結果，以驗證所有物件。如果它們都相符，則所有物件都已成功驗證。 | 開發人員，DBA | 

## 相關資源
<a name="validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql-resources"></a>
+ [使用 AWS SCT 和 AWS DMS 驗證遷移後的資料庫物件](https://aws.amazon.com/blogs/database/validating-database-objects-after-migration-using-aws-sct-and-aws-dms/)
+ [Amazon Aurora 功能：PostgreSQL 相容版本](https://aws.amazon.com/rds/aurora/postgresql-features/)

## 附件
<a name="attachments-7c028960-6dea-46ad-894d-e42cefd50c03"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/7c028960-6dea-46ad-894d-e42cefd50c03/attachments/attachment.zip)

# 重新託管
<a name="migration-rehost-pattern-list"></a>

**Topics**
+ [加速探索 Microsoft 工作負載並將其遷移至 AWS](accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.md)
+ [在重新託管遷移至 期間建立防火牆請求的核准程序 AWS](create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws.md)
+ [將 EC2 Windows 執行個體擷取並遷移至 AWS Managed Services 帳戶](ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.md)
+ [將 Couchbase Server 資料庫遷移至 Amazon EC2](migrate-couchbase-server-ec2.md)
+ [使用日誌運送將 LUW 的 Db2 遷移至 Amazon EC2，以減少中斷時間](migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time.md)
+ [將 LUW 的 Db2 遷移至具有高可用性災難復原的 Amazon EC2](migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery.md)
+ [使用 appcmd.exe 將 IIS 託管應用程式遷移至 Amazon EC2](migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.md)
+ [使用 Application Migration Service 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.md)
+ [在 上將 F5 BIG-IP 工作負載遷移至 F5 BIG-IP VE AWS 雲端](migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud.md)
+ [使用二進位方法將內部部署 Go Web 應用程式遷移至 AWS Elastic Beanstalk](migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.md)
+ [AWS 使用 將內部部署 SFTP 伺服器遷移至 AWS Transfer for SFTP](migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp.md)
+ [使用 AWS Application Migration Service 將內部部署 VM 遷移至 Amazon EC2](migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service.md)
+ [使用 將小型資料集從內部部署遷移至 Amazon S3 AWS SFTP](migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon EC2 上的 Oracle](migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon EC2](migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.md)
+ [使用 AWS MGN 將 RHEL BYOL 系統遷移至包含 AWS 授權的執行個體](migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2.md)
+ [在 AWS 雲端中重新託管內部部署工作負載：遷移檢查清單](rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist.md)
+ [使用 Amazon FSx 設定 SQL Server Always On FCI 的異地同步備份基礎設施](set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.md)
+ [使用 BMC Discovery 查詢來擷取遷移資料以進行遷移規劃](use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning.md)

# 加速探索 Microsoft 工作負載並將其遷移至 AWS
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws"></a>

*Ali Alzand，Amazon Web Services*

## 總結
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-summary"></a>

此模式說明如何使用 [Migration Validator Toolkit PowerShell 模組](https://github.com/aws-samples/migration-validator-toolkit-for-microsoft-workloads)來探索 Microsoft 工作負載並將其遷移至 AWS。此模組的運作方式是針對與任何 Microsoft 工作負載相關聯的一般任務，執行多次檢查和驗證。例如，模組會檢查是否有可能連接多個磁碟的執行個體，或使用多個 IP 地址的執行個體。如需模組可執行之檢查的完整清單，請參閱模組 GitHub 頁面上的[檢查](https://github.com/aws-samples/migration-validator-toolkit-for-microsoft-workloads#checks)一節。

您的組織可透過 Migration Validator Toolkit PowerShell 模組，減少用來探索 Microsoft 工作負載上有哪些應用程式和服務正在運作的時間和心力。此模組也可助您識別工作負載的組態，以便瞭解 AWS 是否支援您的組態。此模組也會提供後續步驟和緩解動作的建議，以避免在遷移之前、期間或之後出現任何組態錯誤。

## 先決條件和限制
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-prereqs"></a>

**先決條件**
+ 本機管理員帳戶
+ PowerShell 4.0

**限制**
+ 僅適用於 Microsoft Windows Server 2012 R2 或更新版本

## 工具
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-tools"></a>

**工具**
+ PowerShell 4.0

**程式碼儲存庫**

此模式的 Migration Validator Toolkit PowerShell 模組可在 GitHub[migration-validator-toolkit-for-microsoft-workloads](https://github.com/aws-samples/migration-validator-toolkit-for-microsoft-workloads) 中取得。

## 史詩
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-epics"></a>

### 在單一目標上執行 Migration Validator Toolkit PowerShell 模組
<a name="run-the-migration-validator-toolkit-powershell-module-on-a-single-target"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載、擷取、匯入和叫用模組。 | 選擇下列其中一種方法來下載和部署模組：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html)**執行 PowerShell 指令碼**在 PowerShell 中，執行下列範例程式碼：<pre>#MigrationValidatorToolkit<br />$uri = 'https://github.com/aws-samples/migration-validator-toolkit-for-microsoft-workloads/archive/refs/heads/main.zip'<br />$destination = (Get-Location).Path<br />if ((Test-Path -Path "$destination\MigrationValidatorToolkit.zip" -PathType Leaf) -or (Test-Path -Path "$destination\MigrationValidatorToolkit")) {<br />    write-host "File $destination\MigrationValidatorToolkit.zip or folder $destination\MigrationValidatorToolkit found, exiting"<br />}else {<br />    Write-host "Enable TLS 1.2 for this PowerShell session only."<br />    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12<br />    $webClient = New-Object System.Net.WebClient<br />    Write-host "Downloading MigrationValidatorToolkit.zip"<br />    $webClient.DownloadFile($uri, "$destination\MigrationValidatorToolkit.zip")<br />    Write-host "MigrationValidatorToolkit.zip download successfully"<br />    Add-Type -Assembly "system.io.compression.filesystem"<br />    [System.IO.Compression.ZipFile]::ExtractToDirectory("$destination\MigrationValidatorToolkit.zip","$destination\MigrationValidatorToolkit")<br />    Write-host "Extracting MigrationValidatorToolkit.zip complete successfully"<br />    Import-Module "$destination\MigrationValidatorToolkit\migration-validator-toolkit-for-microsoft-workloads-main\MigrationValidatorToolkit.psm1"; Invoke-MigrationValidatorToolkit<br />}</pre>此程式碼會從 .zip 檔案下載模組。然後，程式碼會擷取、匯入和叫用模組。**下載並解壓縮 .zip 檔案**[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html)**複製 GitHub 儲存庫**[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html) | 系統管理員 | 
| 手動叫用模組。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html)[Format-Table](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-7.3)format：<pre>Import-Module .\MigrationValidatorToolkit.psm1;Invoke-MigrationValidatorToolkit</pre>[Format-List](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-list?view=powershell-7.3)format：<pre>Import-Module .\MigrationValidatorToolkit.psm1;Invoke-MigrationValidatorToolkit -List</pre>[Out-GridView](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-gridview?view=powershell-7.3)format：<pre>Import-Module .\MigrationValidatorToolkit.psm1;Invoke-MigrationValidatorToolkit -GridView</pre>[ConvertTo-Csvformat](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-csv?view=powershell-7.3)：<pre>Import-Module .\MigrationValidatorToolkit.psm1;Invoke-MigrationValidatorToolkit -csv</pre> | 系統管理員 | 

### 在多個目標上執行 Migration Validator Toolkit PowerShell 模組
<a name="run-the-migration-validator-toolkit-powershell-module-on-multiple-targets"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 .zip 檔案或複製 GitHub 儲存庫。 | 請選擇下列其中一個選項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html)<pre>git clone https://github.com/aws-samples/migration-validator-toolkit-for-microsoft-workloads.git</pre> | 系統管理員 | 
| 更新 server.csv 清單。 | 如果您下載了 .zip 檔案，請遵循下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html) | 系統管理員 | 
| 叫用 模組。 | 您可以使用網域內任何使用具有目標電腦管理員存取權的網域使用者的電腦。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html)<pre>Import-Module .\MigrationValidatorToolkit.psm1;Invoke-DomainComputers</pre>輸出 .csv 檔案會以字首名稱儲存在 中`MigrationValidatorToolkit\Outputs\folder``DomainComputers_MigrationAutomations_YYYY-MM-DDTHH-MM-SS`。 | 系統管理員 | 

## 疑難排解
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| `MigrationValidatorToolkit` 會將有關執行、命令和錯誤的資訊寫入執行中主機上的日誌檔案。 | 您可以在下列位置手動檢視日誌檔案：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.html) | 

## 相關資源
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-resources"></a>
+ [將 Microsoft 工作負載遷移至 AWS 的選項、工具和最佳實務](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-microsoft-workloads-aws/introduction.html) (AWS 規範性指導）
+ [Microsoft 遷移模式](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migration-migration-patterns-by-workload-microsoft-pattern-list.html) (AWS 方案指引）
+ [AWS 免費雲端遷移服務](https://aws.amazon.com/free/migration/) (AWS 文件）
+ [預先定義的啟動後動作 ](https://docs.aws.amazon.com/mgn/latest/ug/predefined-post-launch-actions.html)（應用程式行銷文件）

## 其他資訊
<a name="accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws-additional"></a>

**常見問答集**

*我可以在哪裡執行 Migration Validator Toolkit PowerShell 模組？*

您可以在 Microsoft Windows Server 2012 R2 或更新版本上執行模組。

*何時執行此模組？*

我們建議您在遷移旅程的評估[階段](https://aws.amazon.com/cloud-migration/how-to-migrate/)執行模組。

*模組是否會修改我現有的伺服器？*

否。此模組中的所有動作皆為唯讀。

*執行模組需要多長時間？*

執行模組通常需要 1-5 分鐘，但取決於您伺服器的資源配置。

*模組需要執行哪些許可？*

您必須從本機管理員帳戶執行模組。

*我可以在實體伺服器上執行模組嗎？*

是，只要作業系統是 Microsoft Windows Server 2012 R2 或更新版本即可。

*如何為多部伺服器大規模執行模組？*

若要大規模在多個加入網域的電腦上執行模組，請遵循本指南多個*目標的執行遷移驗證工具組 PowerShell 模組*中的步驟。對於未加入網域的電腦，請使用遠端調用或在本機執行模組，方法是遵循本指南*單一目標上執行遷移驗證工具組 PowerShell 模組*中的步驟。

# 在重新託管遷移至 期間建立防火牆請求的核准程序 AWS
<a name="create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws"></a>

*Srikanth Rangavajhala，Amazon Web Services*

## 摘要
<a name="create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws-summary"></a>

如果您想要在 上使用 [AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)或 [Cloud Migration Factory AWS](https://aws.amazon.com/solutions/implementations/cloud-migration-factory-on-aws/) 來重新託管遷移至 AWS 雲端，其中一個先決條件是您必須保持 TCP 連接埠 443 和 1500 開啟。一般而言，開啟這些防火牆連接埠需要您的資訊安全 (InfoSec) 團隊核准。

此模式概述在重新託管遷移至 期間，從 InfoSec 團隊取得防火牆請求核准的程序 AWS 雲端。您可以使用此程序來避免 InfoSec 團隊拒絕您的防火牆請求，這會變得昂貴且耗時。防火牆請求程序在 AWS 遷移顧問和主管之間有兩個審核和核准步驟，這些人員會與您的 InfoSec 和應用程式團隊合作以開啟防火牆連接埠。

此模式假設您正在規劃與 AWS 顧問或組織中的遷移專家進行重新託管遷移。如果您的組織沒有防火牆核准程序或防火牆請求空白核准表單，您可以使用此模式。如需詳細資訊，請參閱此模式*的限制*一節。如需 Application Migration Service 網路需求的詳細資訊，請參閱 Application Migration Service 文件中的[網路需求](https://docs.aws.amazon.com/mgn/latest/ug/Network-Requirements.html)。

## 先決條件和限制
<a name="create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws-prereqs"></a>

**先決條件**
+ 與您組織的 AWS 顧問或遷移專家進行規劃的重新託管遷移
+ 遷移堆疊所需的連接埠和 IP 資訊
+ 現有和未來的狀態架構圖
+ 有關內部部署和目的地基礎設施、連接埠和zone-to-zone流量流程的防火牆資訊
+ 防火牆請求檢閱檢查清單 （已連接）
+ 防火牆請求文件，根據您組織的需求進行設定
+ 防火牆檢閱者和核准者的聯絡人清單，包括下列角色：
  + **防火牆請求提交者** – AWS 遷移專家或顧問。防火牆請求提交者也可以是您組織的遷移專家。
  + **防火牆請求檢閱者** – 一般而言，這是來自 的單一聯絡點 (SPOC) AWS。
  + **防火牆請求核准者** – InfoSec 團隊成員。

**限制**
+ 此模式說明一般防火牆請求核准程序。個別組織的需求可能有所不同。
+ 請務必追蹤防火牆請求文件的變更。

下表顯示此模式的使用案例。


| 
| 
| 您的組織是否具有現有的防火牆核准程序？ | 您的組織是否有現有的防火牆請求表單？  | 建議動作 | 
| --- |--- |--- |
| 是 | 是 | 與 AWS 顧問或遷移專家合作，以實作組織的程序。 | 
| 否 | 是 | 使用此模式的防火牆核准程序。使用您組織的 AWS 顧問或遷移專家來提交防火牆請求括號核准表單。 | 
| 否 | 否 | 使用此模式的防火牆核准程序。使用您組織的 AWS 顧問或遷移專家來提交防火牆請求括號核准表單。 | 

## Architecture
<a name="create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws-architecture"></a>

下圖顯示防火牆請求核准程序的步驟。

![\[在重新託管遷移至 AWS 雲端期間，由 InfoSec 團隊進行防火牆請求核准的程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cf9b58ad-ab6f-43d3-92da-968529c8d042/images/c672f7ce-6e9f-4dbc-bf2c-4272a6c4432b.png)


## 工具
<a name="create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws-tools"></a>

您可以使用 [Palo Alto Networks](https://www.paloaltonetworks.com/) 或 [SolarWinds](https://www.solarwinds.com/) 等掃描器工具來分析和驗證防火牆和 IP 地址。

## 史詩
<a name="create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws-epics"></a>

### 分析防火牆請求
<a name="analyze-the-firewall-request"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 分析連接埠和 IP 地址。 | 防火牆請求提交者完成初始分析，以了解所需的防火牆連接埠和 IP 地址。完成後，他們會請求您的 InfoSec 團隊開啟所需的連接埠並映射 IP 地址。 | AWS 雲端工程師、遷移專家 | 

### 驗證防火牆請求
<a name="validate-the-firewall-request"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證防火牆資訊。 |  AWS 雲端 工程師會與您的 InfoSec 團隊安排會議。在此會議期間，工程師會檢查並驗證防火牆請求資訊。一般而言，防火牆請求提交者與防火牆請求者是同一個人。如果觀察到或建議任何項目，此驗證階段可能會根據核准者提供的意見回饋而變得反覆。 | AWS 雲端工程師、遷移專家 | 
| 更新防火牆請求文件。 | 在 InfoSec 團隊分享其意見回饋後，防火牆請求文件會編輯、儲存和重新上傳。本文件會在每次反覆運算後更新。我們建議您將此文件存放在版本控制的儲存資料夾中。這表示會追蹤並正確套用所有變更。 | AWS 雲端工程師、遷移專家 | 

### 提交防火牆請求
<a name="submit-the-firewall-request"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 提交防火牆請求。 | 在防火牆請求核准者核准防火牆空白核准請求之後， AWS 雲端 工程師會提交防火牆請求。請求會指定必須開放的連接埠，以及映射和更新 所需的 IP 地址 AWS 帳戶。您可以在提交防火牆請求後提出建議或提供意見回饋。我們建議您自動化此意見回饋程序，並透過定義的工作流程機制傳送任何編輯。  | AWS 雲端工程師、遷移專家 | 

## 附件
<a name="attachments-cf9b58ad-ab6f-43d3-92da-968529c8d042"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/cf9b58ad-ab6f-43d3-92da-968529c8d042/attachments/attachment.zip)

# 將 EC2 Windows 執行個體擷取並遷移至 AWS Managed Services 帳戶
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account"></a>

*Anil Kunapareddy 和 Venkatramana Chintha，Amazon Web Services*

## 總結
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account-summary"></a>

此模式說明將 Amazon Elastic Compute Cloud (Amazon EC2) Windows 執行個體遷移和擷取至 Amazon Web Services (AWS) Managed Services (AMS) 帳戶的step-by-step程序。AMS 可協助您更有效率且安全地管理執行個體。AMS 提供營運彈性、增強安全性和合規性，並協助您最佳化容量並降低成本。

此模式從您已遷移至 AMS 帳戶中臨時子網路的 EC2 Windows 執行個體開始。您可以使用各種遷移服務和工具來執行此任務，例如 AWS Application Migration Service。

若要變更 AMS 受管環境，您可以針對特定操作或動作建立並提交變更請求 (RFC)。使用 AMS 工作負載擷取 (WIGS) RFC，您可以將執行個體擷取至 AMS 帳戶並建立自訂 Amazon Machine Image (AMI)。然後，您可以透過提交另一個 RFC 來建立 EC2 堆疊來建立 AMS 受管 EC2 執行個體。如需詳細資訊，請參閱 [AMS 文件中的 AMS 工作負載擷取](https://docs.aws.amazon.com/managedservices/latest/appguide/ams-workload-ingest.html)。

## 先決條件和限制
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account-prereqs"></a>

**先決條件**
+ 作用中的 AMS 受管 AWS 帳戶
+ 現有的登陸區域
+ 在 AMS 受管 VPC 中進行變更的許可
+ 您 AMS 帳戶中預備子網路中的 Amazon EC2 Windows 執行個體
+ 完成使用 AMS WIGS 遷移工作負載[的一般先決條件](https://docs.aws.amazon.com/managedservices/latest/appguide/ex-migrate-instance-prereqs.html) 
+ 完成使用 AMS WIGS 遷移工作負載的 [Windows 先決條件](https://docs.aws.amazon.com/managedservices/latest/appguide/ex-migrate-prereqs-win.html) 

**限制**
+ 此模式適用於操作 Windows Server 的 EC2 執行個體。此模式不適用於執行其他作業系統的執行個體，例如 Linux。

## Architecture
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account-architecture"></a>

**來源技術堆疊**

AMS 帳戶中預備子網路中的 Amazon EC2 Windows 執行個體

**目標技術堆疊**

AWS Managed Services (AMS) 管理的 Amazon EC2 Windows 執行個體

**目標架構**

![\[將 Amazon EC2 Windows 執行個體遷移並擷取至 AWS Managed Services 帳戶的程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/393c21cb-b6c6-4446-b597-b62e29fdb7f8/images/0b2fa855-7460-49f8-9e7f-3485e6ce1745.png)


## 工具
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以使用 Amazon EC2 視需要啟動任意數量或任意數量的虛擬伺服器，也可以向外擴展或向內擴展。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Managed Services (AMS)](https://docs.aws.amazon.com/managedservices/?id=docs_gateway) 提供 AWS 基礎設施的持續管理，包括 AWS 工作負載的監控、事件管理、安全指導、修補程式支援和備份，協助您更有效率且安全地操作。

**其他服務**
+ [PowerShell](https://learn.microsoft.com/en-us/powershell/) 是在 Windows、Linux 和 macOS 上執行的 Microsoft 自動化和組態管理程式。

## 史詩
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account-epics"></a>

### 在執行個體上設定設定
<a name="configure-settings-on-the-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 變更 DNS 用戶端設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 
| 變更 Windows Update 設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 
| 啟用防火牆。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 

### 準備 AMS WIGS 的執行個體
<a name="prepare-the-instance-for-ams-wigs"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除並準備執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 
| 修復 sppnp.dll 檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 
| 執行預先 WIG 驗證指令碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 
| 建立故障安全 AMI。 | 在預先 WIG 驗證通過之後，建立擷取前 AMI，如下所示：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html)如需詳細資訊，請參閱 [AMS 文件中的 AMI \$1 Create](https://docs.aws.amazon.com/managedservices/latest/ctref/deployment-advanced-ami-create.html)。 | 遷移工程師 | 

### 擷取和驗證執行個體
<a name="ingest-and-validate-the-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 提交 RFC 以建立工作負載擷取堆疊。 | 提交變更請求 (RFC) 以啟動 AMS WIGS。如需說明，請參閱 AMS 文件中的[工作負載擷取堆疊：建立](https://docs.aws.amazon.com/managedservices/latest/appguide/ex-workload-ingest-col.html)。這會啟動工作負載擷取，並安裝 AMS 所需的所有軟體，包括備份工具、Amazon EC2 管理軟體和防毒軟體。 | 遷移工程師 | 
| 驗證成功遷移。 | 工作負載擷取完成後，您可以看到 AMS 受管執行個體和 AMS 擷取的 AMI。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 

### 在目標 AMS 帳戶中啟動執行個體
<a name="launch-the-instance-in-the-target-ams-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 提交 RFC 以建立 EC2 堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.html) | 遷移工程師 | 

## 相關資源
<a name="ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account-resources"></a>

**AWS 方案指引**
+ [在 Windows 上自動化 AWS Managed Services 的工作負載前擷取活動](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automate-pre-workload-ingestion-activities-for-aws-managed-services-on-windows.html)
+ [使用 Python 在 AMS 中自動建立 RFC](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automatically-create-an-rfc-in-ams-using-python.html?did=pg_card&trk=pg_card)

**AMS 文件**
+ [AMS 工作負載擷取](https://docs.aws.amazon.com/managedservices/latest/appguide/ams-workload-ingest.html)
+ [遷移如何變更您的資源](https://docs.aws.amazon.com/managedservices/latest/appguide/ex-migrate-changes.html)
+ [遷移工作負載：標準程序](https://docs.aws.amazon.com/managedservices/latest/appguide/mp-migrate-stack-process.html)

**行銷資源**
+ [AWS Managed Services](https://aws.amazon.com/managed-services/)
+ [AWS Managed Services FAQs](https://aws.amazon.com/managed-services/faqs/)
+ [AWS Managed Services 資源](https://aws.amazon.com/managed-services/resources/)
+ [AWS Managed Services功能](https://aws.amazon.com/managed-services/features/)

# 將 Couchbase Server 資料庫遷移至 Amazon EC2
<a name="migrate-couchbase-server-ec2"></a>

*Subhani Shaik，Amazon Web Services*

## 總結
<a name="migrate-couchbase-server-ec2-summary"></a>

此模式說明如何將 Couchbase Server 從內部部署環境遷移至 Amazon Elastic Compute Cloud (Amazon EC2) AWS。

Couchbase Server 是分散式 NoSQL (JSON 文件） 資料庫，可提供關聯式資料庫功能。將 Couchbase Server 資料庫遷移到 AWS 可以提供更高的可擴展性、改善的效能、成本效益、增強的安全性、簡化的管理和全域覆蓋，這可以使需要高可用性和低延遲資料存取的應用程式受益。您也可以透過 AWS 受管服務存取進階功能。

上的 Couchbase Server AWS 提供下列主要功能： 
+ 記憶體優先架構
+ 高可用性、災難復原和負載平衡
+ 多主機、多區域部署，提供最佳效能

如需主要優點的詳細資訊，請參閱[其他資訊](#migrate-couchbase-server-ec2-additional)一節和 [Couchbase 網站](https://www.couchbase.com/partners/amazon/)。

## 先決條件和限制
<a name="migrate-couchbase-server-ec2-prereqs"></a>

**先決條件**
+  AWS 帳戶 使用虛擬私有雲端 (VPC)、兩個可用區域、私有子網路和安全群組的作用中 。如需說明，請參閱《Amazon Virtual Private Cloud (Amazon [VPC) 文件》中的建立](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html) VPC。
+ 在來源和目標環境之間啟用連線。如需 Couchbase Server 使用的 TCX 連接埠相關資訊，請參閱 [Couchbase 文件](https://docs.couchbase.com/server/current/install/install-ports.html)。

## Architecture
<a name="migrate-couchbase-server-ec2-architecture"></a>

下圖顯示將 Couchbase Server 遷移至 的高階架構 AWS。

![\[在 AWS 上重新託管 Couchbase Server 的遷移架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4cedced2-3528-4f12-b19e-7d389e820cc1/images/ac22133a-895f-4999-b1e1-57f69e83a326.png)


從內部部署 Couchbase 叢集，資料會使用 透過客戶閘道移動[AWS Direct Connect](https://aws.amazon.com/directconnect/)。資料會通過路由器和 Direct Connect 路由，並透過 [AWS Virtual Private Network (Site-to-Site VPN)](https://aws.amazon.com/vpn/) 閘道到達 VPC。VPC 包含執行 Couchbase Server 的 EC2 執行個體。 AWS 基礎設施也包含用於存取控制的 [AWS Identity and Access Management (IAM)](https://aws.amazon.com/iam/)、用於資料加密的 [AWS Key Management Service (AWS KMS)](https://aws.amazon.com/kms/)、用於區塊儲存的 [Amazon Elastic Block Store (Amazon EBS)](https://aws.amazon.com/ebs/)，以及用於資料儲存的 [Amazon Simple Storage Service (Amazon S3)](https://aws.amazon.com/s3/)。

## 工具
<a name="migrate-couchbase-server-ec2-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 會透過標準乙太網路光纖纜線將您的內部網路連結至某個 Direct Connect 位置。透過此連線，您可以在網路路徑中略過網際網路服務提供者 AWS 服務 時，直接建立虛擬介面至公有。

## 最佳實務
<a name="migrate-couchbase-server-ec2-best-practices"></a>
+ 在不同的操作平台上[安裝和設定 Couchbase](https://docs.couchbase.com/server/current/install/install-intro.html) 
+ 在 上部署 Couchbase Server 的[最佳實務](https://docs.couchbase.com/server/current/cloud/couchbase-cloud-deployment.html#aws-best-practices) AWS
+ [建立 Couchbase 叢集](https://docs.couchbase.com/server/current/manage/manage-nodes/create-cluster.html)
+ Couchbase 應用程式[的效能最佳實務](https://docs.couchbase.com/dotnet-sdk/current/project-docs/performance.html) 
+ Couchbase Server [的安全最佳實務](https://docs.couchbase.com/server/current/learn/security/security-overview.html) 
+ Couchbase Server 資料庫的[儲存最佳實務](https://www.couchbase.com/forums/t/what-is-the-best-document-storage-strategy-in-couchbase/1573) 

## 史詩
<a name="migrate-couchbase-server-ec2-epics"></a>

### 部署適用於 Couchbase Server 的 Amazon EC2 執行個體
<a name="deploy-an-ec2-instance-for-couchbase-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 開啟 Amazon EC2 主控台。 | 登入 [AWS 管理主控台](https://console.aws.amazon.com/) 並開啟 [Amazon EC2 主控台](https://console.aws.amazon.com/ec2/)。 | DevOps 工程師、Couchbase 管理員 | 
| 部署 Amazon EC2 執行個體。 | 啟動符合內部部署 Couchbase Server 組態的 EC2 執行個體。如需如何部署 EC2 執行個體的詳細資訊，請參閱 [Amazon EC2 文件中的啟動 Amazon EC2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)。 Amazon EC2  | DevOps 工程師、Couchbase 管理員 | 

### 在 Amazon EC2 上安裝和設定 Couchbase Server
<a name="install-and-configure-couchbase-server-on-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 Couchbase 叢集。 | 在 Amazon EC2 上安裝 [Couchbase Server 之前，請檢閱 Couchbase Server 部署準則](https://docs.couchbase.com/server/current/install/install-production-deployment.html)。若要安裝 Couchbase Server，請參閱 [Couchbase Server 文件](https://docs.couchbase.com/server/current/install/install-intro.html) | Couchbase 管理員 | 
| 設定叢集。 | 若要設定叢集，請參閱 Couchbase 文件中的[叢集組態選項](https://docs.couchbase.com/cloud/clusters/databases.html#cluster-configuration-options)。 | Couchbase 管理員 | 

### 新增節點並重新平衡 Couchbase 叢集
<a name="add-a-new-node-and-rebalance-the-couchbase-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 新增 EC2 執行個體的節點。 | 將已安裝 Couchbase 的新部署 EC2 執行個體新增至現有的現場部署叢集。如需說明，請參閱 Couchbase Server 文件中的[新增節點並重新平衡](https://docs.couchbase.com/server/current/manage/manage-nodes/add-node-and-rebalance.html)。 | Couchbase 管理員 | 
| 重新平衡叢集。 | 重新平衡程序可讓新增的節點與 EC2 執行個體成為 Couchbase 叢集的作用中成員。如需說明，請參閱 Couchbase Server 文件中的[新增節點並重新平衡](https://docs.couchbase.com/server/current/manage/manage-nodes/add-node-and-rebalance.html)  | Couchbase 管理員 | 

### 重新設定連線
<a name="reconfigure-connections"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 移除內部部署節點並重新平衡。 | 您現在可以從叢集中移除內部部署節點。移除節點後，請遵循重新平衡程序，在叢集中的可用節點之間重新分配資料、索引、事件處理和查詢處理。如需說明，請參閱 Couchbase Server 文件中的[移除節點並重新平衡](https://docs.couchbase.com/server/current/manage/manage-nodes/remove-node-and-rebalance.html)。 | Couchbase 管理員 | 
| 更新連線參數。 | 更新應用程式的連線參數以使用新的 Amazon EC2 IP 地址，讓您的應用程式可以連線到新的節點。 | Couchbase 應用程式開發人員 | 

## 相關資源
<a name="migrate-couchbase-server-ec2-resources"></a>
+ [Couchbase 伺服器服務](https://docs.couchbase.com/server/current/learn/services-and-indexes/services/services.html)
+ [使用 部署 Couchbase 伺服器 AWS Marketplace](https://docs.couchbase.com/server/current/cloud/couchbase-aws-marketplace.html)
+ [連線至 Couchbase Server](https://docs.couchbase.com/server/current/guides/connect.html)
+ [管理儲存貯體](https://docs.couchbase.com/server/current/manage/manage-buckets/bucket-management-overview.html)
+ [跨資料中心複寫 (XDCR)](https://docs.couchbase.com/server/current/learn/clusters-and-availability/xdcr-overview.html)
+ [Couchbase Inc. 授權合約](https://www.couchbase.com/LA20190115/)

## 其他資訊
<a name="migrate-couchbase-server-ec2-additional"></a>

**主要優點**

遷移 Couchbase 資料庫 AWS 以提供下列優點：

**延展性**。​ 您可以根據需求向上或向下擴展 Couchbase 叢集，而無需管理實體硬體，因此您可以輕鬆容納波動的資料磁碟區和應用程式用量。 AWS 提供：
+ 垂直和水平擴展選項
+ [全域部署](https://aws.amazon.com/about-aws/global-infrastructure/)功能
+ 跨 的負載平衡 AWS 區域
+ [資料庫擴展解決方案](https://aws.amazon.com/blogs/database/scaling-your-amazon-rds-instance-vertically-and-horizontally/)
+ [內容交付](https://aws.amazon.com/solutions/content-delivery/)最佳化

**效能最佳化**。 AWS 提供高效能網路基礎設施和[最佳化執行個體類型](https://aws.amazon.com/ec2/instance-types/)，以確保 Couchbase 資料庫的快速資料存取和低延遲。
+ [高效能運算 (HPC)](https://aws.amazon.com/hpc/) 選項
+ 透過 [Amazon CloudFront](https://aws.amazon.com/cloudfront/) 提供全域內容
+ 多個[儲存選項](https://aws.amazon.com/products/storage/)
+ 進階[資料庫服務](https://aws.amazon.com/products/databases/)，包括 Amazon Relational Database Service (Amazon RDS) 和 Amazon DynamoDB
+ 使用 的低延遲連線 [Direct Connect](https://aws.amazon.com/directconnect/)

**成本最佳化。**選取適當的執行個體類型和組態，以根據您的工作負載平衡效能和成本。只需為您使用的資源付費。這可以透過消除管理內部部署硬體和利用規模 AWS 雲端 經濟的需求來降低您的營運成本。
+ [預留執行個體](https://aws.amazon.com/ec2/pricing/reserved-instances/)可協助您提前規劃，並在使用 Couchbase 時大幅降低成本 AWS。
+ [自動擴展](https://aws.amazon.com/autoscaling/)可防止過度佈建，並協助您最佳化使用率和成本效率。

**增強安全性**。受益於 上的強大安全功能 AWS，例如資料加密、存取控制和安全群組，以協助保護您存放在 Couchbase 中的敏感資料。其他優點：
+ [AWS 共同責任模型](https://aws.amazon.com/compliance/shared-responsibility-model/)可清楚區分**雲端安全性 （責任）AWS 和雲端安全性 ** （客戶責任）。
+ [AWS 合規](https://aws.amazon.com/compliance/)支援主要安全標準。
+ AWS 提供進階[加密](https://docs.aws.amazon.com/prescriptive-guidance/latest/encryption-best-practices/welcome.html)選項。
+ [AWS Identity and Access Management (IAM)](https://aws.amazon.com/iam/) 可協助您管理 資源的安全存取。

**簡化的 management**. AWS provides 受管服務適用於 Couchbase，因此您可以專注於應用程式開發，而不是管理基礎基礎設施。

**全球觸角**。您可以將 Couchbase 叢集部署到多個 AWS 區域 ，為全球使用者實現低延遲。您可以將資料庫完全部署在雲端或混合環境中。您可以使用內建的企業級安全性，以及從邊緣到雲端的資料快速、高效的雙向同步來保護資料。同時，您可以使用一致的程式設計模型來簡化開發，以建置 Web 和行動應用程式。

**業務持續性**：
+ **資料備份和復原**。如果發生問題，您可以使用 [AWS Backup](https://aws.amazon.com/backup/)來確保資料彈性和輕鬆復原。如需災難復原選項，請參閱 [AWS Well-Architected Framework 文件](https://docs.aws.amazon.com/whitepapers/latest/disaster-recovery-workloads-on-aws/disaster-recovery-options-in-the-cloud.html)。
+ **Couchbase 多區域部署**：若要在多區域 AWS 環境中部署 Couchbase 資料庫，您可以在 中訂閱 Couchbase Server[AWS Marketplace](https://aws.amazon.com/marketplace/pp/prodview-zy5g2wqmqdyzw)，使用 [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)範本在每個區域中建立個別的 Couchbase 叢集，然後設定跨區域複寫以同步跨區域的資料。此組態可確保跨多個區域的高可用性和地理備援。如需詳細資訊，請參閱 [Couchbase 文件中的使用 部署 Couchbase 伺服器 AWS Marketplace](https://docs.couchbase.com/server/current/cloud/couchbase-aws-marketplace.html)。

**基礎設施敏捷性**：
+ 快速[資源佈建](https://aws.amazon.com/products/management-and-governance/use-cases/provisioning-and-orchestration/)和取消佈建
+ [全球基礎設施](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/)觸角
+ 根據需求[自動擴展 ](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html)
+ 用於一致部署的[基礎設施即程式碼 (IaC)](https://aws.amazon.com/what-is/iac/) 
+ 針對不同工作負載進行最佳化的多個[執行個體類型 ](https://aws.amazon.com/ec2/instance-types/)

**創新啟用**：
+ 存取最新技術，包括 [AI/ML](https://aws.amazon.com/ai/generative-ai/)、[IoT](https://aws.amazon.com/iot/) [和分析](https://aws.amazon.com/big-data/datalakes-and-analytics/)
+ [受管服務](https://aws.amazon.com/blogs/architecture/reduce-operational-load-using-aws-managed-services-for-your-data-solutions/)，可降低營運開銷
+ [現代應用程式](https://aws.amazon.com/modern-apps/)開發實務
+ [無伺服器](https://aws.amazon.com/serverless/)運算選項

**卓越營運**：
+ [集中式監控和記錄](https://docs.aws.amazon.com/prescriptive-guidance/latest/designing-control-tower-landing-zone/logging-monitoring.html)
+ [自動化資源管理](https://aws.amazon.com/systems-manager/)
+ [預測性維護](https://aws.amazon.com/what-is/predictive-maintenance/)功能
+ [增強對資源用量的可見](https://aws.amazon.com/about-aws/whats-new/2024/12/amazon-cloudwatch-provides-centralized-visibility-telemetry-configurations/)性
+ [簡化的部署程序](https://aws.amazon.com/blogs/mt/streamline-change-processes-and-improve-governance-with-aws-well-architected/)

**現代化機會**：
+ [Microservices](https://aws.amazon.com/microservices/) 架構
+ [DevOps](https://aws.amazon.com/devops/) 實務實作
+ [雲端原生](https://aws.amazon.com/what-is/cloud-native/)應用程式開發
+ [傳統應用程式現代化](https://docs.aws.amazon.com/prescriptive-guidance/latest/strategy-modernizing-applications/welcome.html)

**競爭優勢**：
+ [更快的上市時間](https://aws.amazon.com/blogs/smb/accelerate-time-to-market-and-business-growth-with-an-automated-software-as-a-service-platform/)
+ 改善[客戶體驗](https://aws.amazon.com/blogs/publicsector/improving-customer-experience-for-the-public-sector-using-aws-services/)
+ [資料驅動](https://aws.amazon.com/data/data-driven-decision-making/)型決策
+ 增強[的商業智慧](https://aws.amazon.com/what-is/business-intelligence/)

# 使用日誌運送將 LUW 的 Db2 遷移至 Amazon EC2，以減少中斷時間
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time"></a>

*Feng Cai、Ambarish Satarkar 和 Saurabh Sharma，Amazon Web Services*

## 總結
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-summary"></a>

當客戶將 IBM Db2 for LUW (Linux、UNIX 和 Windows) 工作負載遷移至 Amazon Web Services (AWS) 時，使用 Amazon Elastic Compute Cloud (Amazon EC2) 搭配自帶授權 (BYOL) 模型是最快的方式。不過，將大量資料從內部部署 Db2 遷移到 AWS 可能是一項挑戰，特別是當中斷時段很短時。許多客戶嘗試將中斷時段設定為少於 30 分鐘，這對於資料庫本身來說幾乎沒有時間。

此模式涵蓋如何使用交易日誌運送，以短暫中斷時段完成 Db2 遷移。此方法適用於小端 Linux 平台上的 Db2。

## 先決條件和限制
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 在 ECDb2EC2 執行個體，符合內部部署檔案系統配置
+ EC2 執行個體可存取的 Amazon Simple Storage Service (Amazon S3) 儲存貯體
+ AWS Identity and Access Management (IAM) 政策和角色，用於對 Amazon S3 進行程式設計呼叫
+ Amazon EC2 和內部部署伺服器上的同步時區和系統時鐘
+ 透過 AWS [ Site-to-Site VPN 或 AWS](https://aws.amazon.com/vpn/) [Direct Connect 連線至 AWS](https://aws.amazon.com/directconnect/) 的內部部署網路

**限制**
+ Db2 內部部署執行個體和 Amazon EC2 必須位於相同的[平台系列](https://www.ibm.com/docs/en/db2/11.1?topic=dbrs-backup-restore-operations-between-different-operating-systems-hardware-platforms)。
+ 必須記錄 Db2 內部部署工作負載。若要封鎖任何未記錄的交易，請在資料庫組態`blocknonlogged=yes`中設定 。

**產品版本**
+ Db2 for LUW 11.5.9 版及更新版本

## Architecture
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-architecture"></a>

**來源技術堆疊**
+ Linux** **x86\$164 上的 Db2 

**目標技術堆疊**
+ Amazon EBS
+ Amazon EC2
+ AWS Identity and Access Management (IAM)
+ Amazon S3
+ AWS Site-to-Site或 Direct Connect

**目標架構**

下圖顯示一個在內部部署執行的 Db2 執行個體，具有與 Amazon EC2 上的 Db2 的虛擬私有網路 (VPN) 連線。虛線代表資料中心和 AWS 雲端之間的 VPN 通道。

![\[使用交易日誌運送在短暫中斷時段內完成 Db2 遷移的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7dec6e4a-a92e-4204-9e42-f89d7dcafbfa/images/a7e1c1d6-2ec1-4271-952d-a58260ad7c81.png)


## 工具
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-tools"></a>

**AWS 服務**
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 透過標準乙太網路光纖纜線，將您的內部網路連結至 Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的虛擬介面，同時略過網路路徑中的網際網路服務供應商。
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 提供區塊層級儲存磁碟區，可與 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體搭配使用。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Site-to-Site VPN](https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html) 可協助您在 AWS 上啟動的執行個體與您自己的遠端網路之間傳遞流量。

**其他工具**
+ [db2cli](https://www.ibm.com/docs/en/db2/11.5?topic=commands-db2cli-db2-interactive-cli) 是 Db2 互動式 CLI 命令。

## 最佳實務
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-best-practices"></a>
+ 在目標資料庫上，使用 [Amazon S3 的閘道端點](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html)來存取 Amazon S3 中的資料庫備份映像和日誌檔案。
+ 在來源資料庫上，使用適用於 [Amazon S3 的 AWS PrivateLink ](https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html) 將資料庫備份映像和日誌檔案傳送至 Amazon S3。

## 史詩
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-epics"></a>

### 設定環境變數
<a name="set-environment-variables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定環境變數。 | 此模式使用以下名稱：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time.html)您可以變更它們以符合您的環境。 | DBA | 

### 設定內部部署 Db2 伺服器
<a name="configure-the-on-premises-db2-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS CLI。 | 若要下載並安裝最新版本的 AWS CLI，請執行下列命令：<pre>$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"<br />unzip awscliv2.zip<br />sudo ./aws/install</pre> | Linux 管理員 | 
| 設定 Db2 封存日誌的本機目的地。 | 若要讓 Amazon EC2 上的目標資料庫與內部部署來源資料庫保持同步，需要從來源擷取最新的交易日誌。在此設定中， `/db2logs`會在來源`LOGARCHMETH2`上由 設定為預備區域。此目錄中的封存日誌會同步至 Amazon S3，並由 Amazon EC2 上的 Db2 存取。模式使用 ，`LOGARCHMETH2`因為 `LOGARCHMETH1` 可能已設定為使用 AWS CLI 命令無法存取的第三方廠商工具。若要擷取日誌，請執行下列命令：<pre>db2 connect to sample<br />db2 update db cfg for SAMPLE using LOGARCHMETH2 disk:/db2logs</pre> | DBA | 
| 執行線上資料庫備份。 | 執行線上資料庫備份，並將其儲存至本機備份檔案系統：<pre>db2 backup db sample online to /backup </pre> | DBA | 

### 設定 S3 儲存貯體和 IAM 政策
<a name="set-up-the-s3-bucket-and-iam-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 為現場部署伺服器建立 S3 儲存貯體，以在 AWS 上將備份 Db2 映像和日誌檔案傳送至 。Amazon EC2 也會存取儲存貯體：<pre>aws s3api create-bucket --bucket logshipmig-db2 --region us-east-1 </pre> | AWS 系統管理員 | 
|  建立 IAM 政策。 | `db2bucket.json` 檔案包含存取 Amazon S3 儲存貯體的 IAM 政策：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Action": [<br />                "kms:GenerateDataKey",<br />                "kms:Decrypt",<br />                "s3:PutObject",<br />                "s3:GetObject",<br />                "s3:AbortMultipartUpload",<br />                "s3:ListBucket",<br />                "s3:DeleteObject",<br />                "s3:GetObjectVersion",<br />                "s3:ListMultipartUploadParts"<br />            ],<br />            "Resource": [<br />                "arn:aws:s3:::logshipmig-db2/*",<br />                "arn:aws:s3:::logshipmig-db2"<br />            ]<br />        }<br />    ]<br />}</pre>若要建立政策，請使用下列 AWS CLI 命令：<pre>aws iam create-policy \<br />      --policy-name db2s3policy \<br />      --policy-document file://db2bucket.json </pre> JSON 輸出會顯示政策的 Amazon Resource Name (ARN)，其中 `aws_account_id`代表您的帳戶 ID：<pre>"Arn": "arn:aws:iam::aws_account_id:policy/db2s3policy"</pre> | AWS 管理員、AWS 系統管理員 | 
| 將 IAM 政策連接至 EC2 執行個體所使用的 IAM 角色。 | 在大多數 AWS 環境中，執行中的 EC2 執行個體具有由系統管理員設定的 IAM 角色。如果未設定 IAM 角色，請建立角色，然後選擇 EC2 主控台上的**修改 IAM 角色**，將角色與託管 Db2 資料庫的 EC2 執行個體建立關聯。使用政策 ARN 將 IAM 政策連接至 IAM 角色：<pre>aws iam attach-role-policy \<br />    --policy-arn "arn:aws:iam::aws_account_id:policy/db2s3policy"  \<br />    --role-name db2s3role  </pre>連接政策後，與 IAM 角色相關聯的任何 EC2 執行個體都可以存取 S3 儲存貯體。 | AWS 管理員、AWS 系統管理員 | 

### 將來源資料庫備份映像和日誌檔案傳送至 Amazon S3
<a name="send-the-source-database-backup-image-and-log-files-to-amazon-s3"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在內部部署 Db2 伺服器上設定 AWS CLI。 | 使用 設定 AWS CLI，`Access Key ID`並在先前步驟中`Secret Access Key`產生：<pre>$ aws configure <br />AWS Access Key ID [None]: *************<br />AWS Secret Access Key [None]: ***************************<br />Default region name [None]: us-east-1<br />Default output format [None]: json</pre>  | AWS 管理員、AWS 系統管理員 | 
| 將備份映像傳送至 Amazon S3。 | 稍早，線上資料庫備份已儲存至`/backup`本機目錄。若要將備份映像傳送至 S3 儲存貯體，請執行下列命令：<pre>aws s3 sync /backup s3://logshipmig-db2/SAMPLE_backup</pre> | AWS 管理員、遷移工程師 | 
| 將 Db2 封存日誌傳送至 Amazon S3。 | 將內部部署 Db2 封存日誌與 Amazon EC2 上目標 Db2 執行個體可存取的 S3 儲存貯體同步：<pre>aws s3 sync /db2logs s3://logshipmig-db2/SAMPLE_LOG</pre>使用 cron 或其他排程工具定期執行此命令。頻率取決於來源資料庫封存交易日誌檔案的頻率。 | AWS 管理員、遷移工程師 | 

### 將 Amazon EC2 上的 Db2 連線至 Amazon S3 並啟動資料庫同步 Amazon EC2
<a name="connect-db2-on-amazon-ec2-to-amazon-s3-and-start-the-database-sync"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 PKCS12 金鑰存放區。 | Db2 使用公有金鑰密碼編譯標準 (PKCS) 加密金鑰存放區來保護 AWS 存取金鑰的安全。建立金鑰存放區並設定來源 Db2 執行個體以使用它：<pre>gsk8capicmd_64 -keydb -create -db "/home/db2inst1/.keystore/db2s3.p12" -pw "<password>" -type pkcs12 -stash <br /> <br />db2 "update dbm cfg using keystore_location /home/db2inst1/.keystore/db2s3.p12 keystore_type pkcs12"</pre> | DBA | 
| 建立 Db2 儲存體存取別名。 | 若要建立[儲存存取別名](https://www.ibm.com/docs/en/db2/11.5?topic=commands-catalog-storage-access)，請使用下列指令碼語法：`db2 "catalog storage access alias <alias_name> vendor S3 server <S3 endpoint> container '<bucket_name>'"`例如，您的指令碼可能如下所示：`db2 "catalog storage access alias DB2AWSS3 vendor S3 server s3.us-east-1.amazonaws.com container 'logshipmig-db2'" ` | DBA | 
| 設定預備區域。 | 根據預設，Db2 會使用 `DB2_OBJECT_STORAGE_LOCAL_STAGING_PATH`做為臨時區域，在 Amazon S3 之間上傳和下載檔案。預設路徑位於執行個體主目錄`sqllib/tmp/RemoteStorage.xxxx`下，並`xxxx`參照 Db2 分割區編號。請注意，預備區域必須有足夠的容量來存放備份映像和日誌檔案。您可以使用登錄檔，將暫存區域指向不同的目錄。我們也建議使用 `DB2_ENABLE_COS_SDK=ON`、 `DB2_OBJECT_STORAGE_SETTINGS=EnableStreamingRestore`和程式`awssdk`庫的連結，略過資料庫備份和還原的 Amazon S3 預備區域：<pre>#By root:<br />cp -rp /home/db2inst1/sqllib/lib64/awssdk/RHEL/7.6/* /home/db2inst1/sqllib/lib64/<br /><br />#By db2 instance owner:<br />db2set DB2_OBJECT_STORAGE_LOCAL_STAGING_PATH=/db2stage<br />db2set DB2_ENABLE_COS_SDK=ON<br />Db2set DB2_OBJECT_STORAGE_SETTINGS=EnableStreamingRestore<br />db2stop<br />db2start</pre> | DBA | 
| 從備份映像還原資料庫。 | 從 S3 儲存貯體中的備份映像還原 Amazon EC2 上的目標資料庫：<pre>db2 restore db sample from DB2REMOTE://DB2AWSS3/logshipmig-db2/SAMPLE_backup replace existing</pre> | DBA | 
| 向前滾動資料庫。 | 還原完成後，目標資料庫將進入向前滾動擱置狀態。設定 `LOGARCHMETH1`和 ，`LOGARCHMETH2`以便 Db2 知道在何處取得交易日誌檔案：<pre>db2 update db cfg for SAMPLE using LOGARCHMETH1 'DB2REMOTE://DB2AWSS3//SAMPLE_LOGS/'<br />db2 update db cfg for SAMPLE using LOGARCHMETH2 OFF</pre>開始資料庫向前滾動：<pre>db2 ROLLFORWARD DATABASE sample to END OF LOGS</pre>此命令會處理已傳輸至 S3 儲存貯體的所有日誌檔案。根據現場部署 Db2 伺服器上`s3 sync`命令的頻率定期執行。例如，如果 每小時`s3 sync`執行一次，且同步所有日誌檔案需要 10 分鐘，請將 命令設定為每小時 10 分鐘後執行一次。 | DBA | 

### 在切換時段將 Db2 帶入 Amazon EC2
<a name="bring-db2-on-amazon-ec2-online-during-the-cutover-window"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 讓目標資料庫上線。 | 在切換時段期間，執行下列其中一項操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time.html)將最後一個交易日誌同步至 Amazon S3 後，請執行 `ROLLFORWARD`命令最後一次：<pre>db2 rollforward DB sample to END OF LOGS<br />db2 rollforward DB sample complete<br /><br />                                 Rollforward Status<br />....<br /> Rollforward status                     = not pending<br />....<br />DB20000I  The ROLLFORWARD command completed successfully.<br /><br />db2 activate db sample<br />DB20000I  The ACTIVATE DATABASE command completed successfully.</pre>將目標資料庫上線，並將應用程式連線指向 Amazon EC2 上的 Db2。 Amazon EC2 | DBA | 

## 疑難排解
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 如果多個資料庫在不同的主機 (DEV、QA、PROD) 上具有相同的執行個體名稱和資料庫名稱，則備份和日誌可能會移至相同的子目錄。 | 針對 DEV、QA 和 PROD 使用不同的 S3 儲存貯體，並將主機名稱新增為子目錄字首，以避免混淆。 | 
| 如果同一個位置有多個備份映像，當您還原時，會收到下列錯誤：`SQL2522N More than one backup file matches the time stamp value provided for the backed up database image.` | 在 `restore`命令中，新增備份的時間戳記：`db2 restore db sample from DB2REMOTE://DB2AWSS3/logshipmig-db2/SAMPLE_backup taken at 20230628164042 replace existing` | 

## 相關資源
<a name="migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time-resources"></a>
+ [不同作業系統和硬體平台之間的 Db2 備份和還原操作](https://www.ibm.com/docs/en/db2/11.5?topic=dbrs-backup-restore-operations-between-different-operating-systems-hardware-platforms)
+ [設定 Db2 STORAGE ACCESS ALIAS 和 DB2REMOTE](https://www.ibm.com/docs/en/db2/11.5?topic=commands-catalog-storage-access)
+ [Db2 ROLLFORWARD 命令](https://www.ibm.com/docs/en/db2/11.5?topic=commands-rollforward-database)
+ [Db2 次要日誌封存方法](https://www.ibm.com/docs/en/db2/11.5?topic=parameters-logarchmeth2-secondary-log-archive-method)

# 將 LUW 的 Db2 遷移至具有高可用性災難復原的 Amazon EC2
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery"></a>

*Feng Cai、Aruna Gangireddy 和 Venkatesan Govindan，Amazon Web Services*

## 摘要
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-summary"></a>

當客戶將 IBM Db2 LUW (Linux、UNIX 和 Windows) 工作負載遷移至 Amazon Web Services (AWS) 時，使用 Amazon Elastic Compute Cloud (Amazon EC2) 搭配自帶授權 (BYOL) 模型是最快的方式。不過，將大量資料從內部部署 Db2 遷移到 AWS 可能是一項挑戰，特別是當中斷時段很短時。許多客戶嘗試將中斷時段設定為少於 30 分鐘，這對於資料庫本身來說幾乎沒有時間。

此模式涵蓋如何使用 Db2 高可用性災難復原 (HADR)，以短暫的中斷時段完成 Db2 遷移。此方法適用於在小端 Linux 平台上且未使用資料分割功能 (DPF) 的 Db2 資料庫。

## 先決條件和限制
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-prereqs"></a>

**先決條件 **
+ 作用中的 AWS 帳戶
+ 在符合內部部署檔案系統配置的 Amazon EC2 執行個體上執行的 Db2 執行個體 Amazon EC2 
+ EC2 執行個體可存取的 Amazon Simple Storage Service (Amazon S3) 儲存貯體
+ AWS Identity and Access Management (IAM) 政策和角色，用於對 Amazon S3 進行程式設計呼叫
+ Amazon EC2 和內部部署伺服器上的同步時區和系統時鐘
+ 透過 AWS [ Site-to-Site VPN 或 AWS](https://aws.amazon.com/vpn/) [Direct Connect 連線至 AWS](https://aws.amazon.com/directconnect/) 的內部部署網路
+ HADR 連接埠上的內部部署伺服器與 Amazon EC2 之間的通訊

**限制 **
+ Db2 內部部署執行個體和 Amazon EC2 必須位於相同的[平台系列](https://www.ibm.com/docs/en/db2/11.1?topic=dbrs-backup-restore-operations-between-different-operating-systems-hardware-platforms)。
+ 分割的資料庫環境中不支援 HADR。
+ HADR 不支援對資料庫日誌檔案使用原始 I/O （直接磁碟存取）。
+ HADR 不支援無限記錄。
+ `LOGINDEXBUILD` 必須設定為 `YES`，這會增加重建索引的日誌用量。
+ 必須記錄 Db2 內部部署工作負載。在資料庫組態`blocknonlogged=yes`中設定 ，以封鎖任何未記錄的交易。

**產品版本**
+ Db2 for LUW 11.5.9 版及更新版本

## Architecture
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-architecture"></a>

**來源技術堆疊**
+ Linux** **x86\$164 上的 Db2 

**目標技術堆疊**
+ Amazon EC2
+ AWS Identity and Access Management (IAM)
+ Amazon S3
+ AWS Site-to-Site VPN

**目標架構**

在下圖中，現場部署的 Db2 正在 上執行，`db2-server1`做為主要節點。它有兩個 HADR 待命目標。一個待命目標在內部部署，並且是選用的。另一個待命目標 `db2-ec2`位於 Amazon EC2。在將資料庫切換到 AWS 之後， 會`db2-ec2`成為主要資料庫。

![\[使用 Db2 HADR，以短中斷時段遷移內部部署 Db2 的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2db43e4b-f0ea-4a92-96da-4cafb7d3368b/images/5295420e-3cd8-4127-9a18-ade971c36339.png)


1. 日誌會從主要現場部署資料庫串流到待命現場部署資料庫。

1. 使用 Db2 HADR，日誌會透過 Site-to-Site VPN 從主要現場部署資料庫串流至 Amazon EC2 上的 Db2。 Amazon EC2

1. Db2 備份和封存日誌會從主要現場部署資料庫傳送至 AWS 上的 S3 儲存貯體。

## 工具
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-tools"></a>

**AWS 服務**
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 透過標準乙太網路光纖纜線，將您的內部網路連結至 Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的虛擬介面，同時略過網路路徑中的網際網路服務供應商。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Site-to-Site VPN](https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html) 可協助您在 AWS 上啟動的執行個體與您自己的遠端網路之間傳遞流量。

**其他工具**
+ [db2cli](https://www.ibm.com/docs/en/db2/11.5?topic=commands-db2cli-db2-interactive-cli) 是 Db2 互動式 CLI 命令。

## 最佳實務
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-best-practices"></a>
+ 在目標資料庫上，使用 [Amazon S3 的閘道端點](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html)來存取 Amazon S3 中的資料庫備份映像和日誌檔案。
+ 在來源資料庫上，使用適用於 [Amazon S3 的 AWS PrivateLink ](https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html) 將資料庫備份映像和日誌檔案傳送至 Amazon S3。

## 史詩
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-epics"></a>

### 設定環境變數
<a name="set-environment-variables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定環境變數。 | 此模式使用以下名稱和連接埠：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery.html)您可以變更它們以符合您的環境。 | DBA | 

### 設定內部部署 Db2 伺服器
<a name="configure-the-on-premises-db2-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS CLI。 | 若要下載並安裝最新版本的 AWS CLI，請執行下列命令：<pre>$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"<br />unzip awscliv2.zip<br />sudo ./aws/install</pre> | Linux 管理員 | 
| 設定 Db2 封存日誌的本機目的地。 | 大量更新批次任務和網路變慢等條件可能會導致 HADR 待命伺服器延遲。若要趕上進度，待命伺服器需要來自主要伺服器的交易日誌。請求日誌的位置順序如下：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery.html)在此設定中， `/db2logs`會在來源`LOGARCHMETH2`上由 設定為預備區域。此目錄中的封存日誌會同步至 Amazon S3，並由 Amazon EC2 上的 Db2 存取。模式使用 ，`LOGARCHMETH2`因為 `LOGARCHMETH1` 可能已設定為使用 AWS CLI 命令無法存取的第三方廠商工具：<pre>db2 connect to sample<br />db2 update db cfg for SAMPLE using LOGARCHMETH2 disk:/db2logs</pre> | DBA | 
| 執行線上資料庫備份。 | 執行線上資料庫備份，並將其儲存至本機備份檔案系統：<pre>db2 backup db sample online to /backup </pre> | DBA | 

### 設定 S3 儲存貯體和 IAM 政策
<a name="set-up-the-s3-bucket-and-iam-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 為現場部署伺服器建立 S3 儲存貯體，以在 AWS 上將備份 Db2 映像和日誌檔案傳送至 。儲存貯體將由 Amazon EC2 存取：<pre>aws s3api create-bucket --bucket hadrmig-db2 --region us-east-1 </pre> | AWS 管理員 | 
| 建立 IAM 政策。 | `db2bucket.json` 檔案包含用於存取 S3 儲存貯體的 IAM 政策：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Action": [<br />                "kms:GenerateDataKey",<br />                "kms:Decrypt",<br />                "s3:PutObject",<br />                "s3:GetObject",<br />                "s3:AbortMultipartUpload",<br />                "s3:ListBucket",<br />                "s3:DeleteObject",<br />                "s3:GetObjectVersion",<br />                "s3:ListMultipartUploadParts"<br />            ],<br />            "Resource": [<br />                "arn:aws:s3:::hadrmig-db2/*",<br />                "arn:aws:s3:::hadrmig-db2"<br />            ]<br />        }<br />    ]<br />}</pre>若要建立政策，請使用下列 AWS CLI 命令：<pre>aws iam create-policy \<br />      --policy-name db2s3hapolicy \<br />      --policy-document file://db2bucket.json </pre>JSON 輸出會顯示政策的 Amazon Resource Name (ARN)，其中 `aws_account_id`代表您的帳戶 ID：<pre>"Arn": "arn:aws:iam::aws_account_id:policy/db2s3hapolicy"</pre> | AWS 管理員、AWS 系統管理員 | 
| 將 IAM 政策連接至 IAM 角色。 | 通常，執行 Db2 的 EC2 執行個體會有系統管理員指派的 IAM 角色。 Db2 如果未指派 IAM 角色，您可以在 Amazon EC2 主控台上選擇**修改 IAM 角色**。將 IAM 政策連接至與 EC2 執行個體相關聯的 IAM 角色。連接政策後，EC2 執行個體可以存取 S3 儲存貯體：<pre>aws iam attach-role-policy --policy-arn "arn:aws:iam::aws_account_id:policy/db2s3hapolicy" --role-name db2s3harole   </pre> |  | 

### 將來源資料庫備份映像和日誌檔案傳送至 Amazon S3
<a name="send-the-source-database-backup-image-and-log-files-to-amazon-s3"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在內部部署 Db2 伺服器上設定 AWS CLI。 | 使用`Secret Access Key`您先前產生的 `Access Key ID`和 設定 AWS CLI：<pre>$ aws configure <br />AWS Access Key ID [None]: *************<br />AWS Secret Access Key [None]: ***************************<br />Default region name [None]: us-east-1<br />Default output format [None]: json</pre> | AWS 管理員、AWS 系統管理員 | 
| 將備份映像傳送至 Amazon S3。 | 稍早，線上資料庫備份已儲存至`/backup`本機目錄。若要將備份映像傳送至 S3 儲存貯體，請執行下列命令：<pre>aws s3 sync /backup s3://hadrmig-db2/SAMPLE_backup</pre> | AWS 管理員、AWS 系統管理員 | 
| 將 Db2 封存日誌傳送至 Amazon S3。 | 將內部部署 Db2 封存日誌與 Amazon EC2 上的目標 Db2 執行個體可存取的 Amazon S3 儲存貯體同步： Db2 Amazon EC2<pre>aws s3 sync /db2logs s3://hadrmig-db2/SAMPLE_LOGS</pre>使用 cron 或其他排程工具定期執行此命令。頻率取決於來源資料庫封存交易日誌檔案的頻率。 |  | 

### 將 Amazon EC2 上的 Db2 連線至 Amazon S3，並啟動初始資料庫同步 Amazon EC2
<a name="connect-db2-on-amazon-ec2-to-amazon-s3-and-start-the-initial-database-sync"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 PKCS12 金鑰存放區。 | Db2 使用公有金鑰密碼編譯標準 (PKCS) 加密金鑰存放區來保護 AWS 存取金鑰的安全。建立金鑰存放區，並設定來源 Db2 以使用它：<pre>gsk8capicmd_64 -keydb -create -db "/home/db2inst1/.keystore/db2s3.p12" -pw "<password>" -type pkcs12 -stash <br /> <br />db2 "update dbm cfg using keystore_location /home/db2inst1/.keystore/db2s3.p12 keystore_type pkcs12"</pre> | DBA | 
| 建立 Db2 儲存體存取別名。 | Db2 使用儲存存取別名，透過 `INGEST`、`BACKUP DATABASE`、 `LOAD`或 `RESTORE DATABASE`命令直接存取 Amazon S3。由於您已將 IAM 角色指派給 EC2 執行個體，`USER``PASSWORD`因此不需要：`db2 "catalog storage access alias <alias_name> vendor S3 server <S3 endpoint> container '<bucket_name>'"`例如，您的指令碼可能如下所示：`db2 "catalog storage access alias DB2AWSS3 vendor S3 server s3.us-east-1.amazonaws.com container 'hadrmig-db2'" ` | DBA | 
| 設定預備區域。 | 建議使用 `DB2_ENABLE_COS_SDK=ON`、 `DB2_OBJECT_STORAGE_SETTINGS=EnableStreamingRestore`和程式`awssdk`庫的連結，略過資料庫備份和還原的 Amazon S3 預備區域：<pre>#By root:<br />cp -rp /home/db2inst1/sqllib/lib64/awssdk/RHEL/7.6/* /home/db2inst1/sqllib/lib64/<br /><br />#By db2 instance owner:<br />db2set DB2_OBJECT_STORAGE_LOCAL_STAGING_PATH=/db2stage<br />db2set DB2_ENABLE_COS_SDK=ON<br />db2set DB2_OBJECT_STORAGE_LOCAL_STAGING_PATH=/db2stage<br />db2stop<br />db2start</pre> | DBA | 
| 從備份映像還原資料庫。 | 從 S3 儲存貯體中的備份映像還原 Amazon EC2 上的目標資料庫：<pre>db2 create db sample on /data1<br />db2 restore db sample from DB2REMOTE://DB2AWSS3/hadrmig-db2/SAMPLE_backup replace existing</pre> | DBA | 

### 在內部部署中設定沒有 HADR 的 HADR
<a name="set-up-hadr-with-no-hadr-on-premises"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將內部部署 Db2 伺服器設定為主要伺服器。 | 將 HADR on `db2-server1`（內部部署來源） 的資料庫組態設定更新為主要伺服器。`HADR_SYNCMODE` 設定為 `SUPERASYNC` 模式，其交易回應時間最短：`db2 update db cfg for sample using HADR_LOCAL_HOST db2-server1 HADR_LOCAL_SVC 50010 HADR_REMOTE_HOST db2-ec2 HADR_REMOTE_SVC 50012 HADR_REMOTE_INST db2inst1 HADR_SYNCMODE SUPERASYNC DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully`現場部署資料中心和 AWS 之間預計會發生一些網路延遲。（您可以根據網路可靠性設定不同的`HADR_SYNCMODE`值。 如需詳細資訊，請參閱[相關資源](#migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-resources)一節）。 | DBA | 
| 變更目標資料庫日誌封存目的地。 | 變更目標資料庫日誌封存目的地以符合 Amazon EC2 環境：<pre>db2 update db cfg for SAMPLE using LOGARCHMETH1 'DB2REMOTE://DB2AWSS3//SAMPLE_LOGS/' LOGARCHMETH2 OFF<br />DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully</pre> | DBA | 
| 在 Amazon EC2 伺服器上設定 Db2 的 HADR。 Amazon EC2  | 將 上的 HADR 資料庫組態更新`db2-ec2`為待命：`db2 update db cfg for sample using HADR_LOCAL_HOST db2-ec2 HADR_LOCAL_SVC 50012 HADR_REMOTE_HOST db2-server1 HADR_REMOTE_SVC 50010 HADR_REMOTE_INST db2inst1 HADR_SYNCMODE SUPERASYNC DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully` | DBA | 
| 驗證 HADR 設定。 | 驗證來源和目標 Db2 伺服器上的 HADR 參數。若要驗證 上的設定`db2-server1`，請執行下列命令：<pre>db2 get db cfg for sample|grep HADR<br /> HADR database role                                      = PRIMARY<br /> HADR local host name                  (HADR_LOCAL_HOST) = db2-server1<br /> HADR local service name                (HADR_LOCAL_SVC) = 50010<br /> HADR remote host name                (HADR_REMOTE_HOST) = db2-ec2<br /> HADR remote service name              (HADR_REMOTE_SVC) = 50012<br /> HADR instance name of remote server  (HADR_REMOTE_INST) = db2inst1<br /> HADR timeout value                       (HADR_TIMEOUT) = 120<br /> HADR target list                     (HADR_TARGET_LIST) = <br /> HADR log write synchronization mode     (HADR_SYNCMODE) = NEARSYNC<br /> HADR spool log data limit (4KB)      (HADR_SPOOL_LIMIT) = AUTOMATIC(52000)<br /> HADR log replay delay (seconds)     (HADR_REPLAY_DELAY) = 0<br /> HADR peer window duration (seconds)  (HADR_PEER_WINDOW) = 0<br /> HADR SSL certificate label             (HADR_SSL_LABEL) =<br /> HADR SSL Hostname Validation        (HADR_SSL_HOST_VAL) = OFF</pre> 若要驗證 上的設定`db2-ec2`，請執行下列命令：<pre>db2 get db cfg for sample|grep HADR<br /> HADR database role                                      = STANDBY<br /> HADR local host name                  (HADR_LOCAL_HOST) = db2-ec2<br /> HADR local service name                (HADR_LOCAL_SVC) = 50012<br /> HADR remote host name                (HADR_REMOTE_HOST) = db2-server1<br /> HADR remote service name              (HADR_REMOTE_SVC) = 50010<br /> HADR instance name of remote server  (HADR_REMOTE_INST) = db2inst1<br /> HADR timeout value                       (HADR_TIMEOUT) = 120<br /> HADR target list                     (HADR_TARGET_LIST) = <br /> HADR log write synchronization mode     (HADR_SYNCMODE) = SUPERASYNC<br /> HADR spool log data limit (4KB)      (HADR_SPOOL_LIMIT) = AUTOMATIC(52000)<br /> HADR log replay delay (seconds)     (HADR_REPLAY_DELAY) = 0<br /> HADR peer window duration (seconds)  (HADR_PEER_WINDOW) = 0<br /> HADR SSL certificate label             (HADR_SSL_LABEL) =<br /> HADR SSL Hostname Validation        (HADR_SSL_HOST_VAL) = OFF</pre>`HADR_LOCAL_HOST`、`HADR_REMOTE_HOST`、 `HADR_LOCAL_SVC`和 `HADR_REMOTE_SVC` 參數指出一個主要和一個待命 HADR 設定。 | DBA | 
| 啟動 Db2 HADR 執行個體。 | 首先在待命伺服器上啟動 Db2 HADR 執行個體`db2-ec2`：<pre>db2 start hadr on db sample as standby<br />DB20000I  The START HADR ON DATABASE command completed successfully.</pre>在主要 （來源） 伺服器 上啟動 Db2 HADR`db2-server1`：<pre>db2 start hadr on db sample as primary<br />DB20000I  The START HADR ON DATABASE command completed successfully.</pre>Db2 on 內部部署和 Amazon EC2 之間的 HADR 連線現已成功建立。Db2 主要伺服器`db2-ec2`會即時`db2-server1`開始將交易日誌記錄串流至 。 | DBA | 

### 當內部部署存在 HADR 時設定 HADR
<a name="set-up-hadr-when-hadr-exists-on-premises"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon EC2 上新增 Db2 作為輔助待命。 Amazon EC2  | 如果 HADR 在內部部署 Db2 執行個體上執行，您可以在 上執行下列命令`HADR_TARGET_LIST`，使用 新增 Amazon EC2 上的 Db2 做為輔助待命`db2-ec2`： Amazon EC2 `db2 update db cfg for sample using HADR_LOCAL_HOST db2-ec2 HADR_LOCAL_SVC 50012 HADR_REMOTE_HOST db2-server1 HADR_REMOTE_SVC 50010 HADR_REMOTE_INST db2inst1 HADR_SYNCMODE SUPERASYNC DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully. db2 update db cfg for sample using HADR_TARGET_LIST "db2-server1:50010\|db2-server2:50011" DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.` | DBA | 
| 將輔助待命資訊新增至內部部署伺服器。 | `HADR_TARGET_LIST` 在兩個內部部署伺服器上更新 （主要和待命）。在 `db2-server1`上執行下列程式碼：`db2 update db cfg for sample using HADR_TARGET_LIST "db2-server2:50011\|db2-ec2:50012" DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully. SQL1363W One or more of the parameters submitted for immediate modification were not changed dynamically. For these configuration parameters, the database must be shutdown and reactivated before the configuration parameter changes become effective.`在 `db2-server2`上執行下列程式碼：`db2 update db cfg for sample using HADR_TARGET_LIST "db2-server1:50010\|db2-ec2:50012" DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully. SQL1363W One or more of the parameters submitted for immediate modification were not changed dynamically. For these configuration parameters, the database must be shutdown and reactivated before the configuration parameter changes become effective.` | DBA | 
| 驗證 HADR 設定。 | 驗證來源和目標 Db2 伺服器上的 HADR 參數。在 `db2-server1`上執行下列程式碼：<pre>db2 get db cfg for sample|grep HADR<br /> HADR database role                                      = PRIMARY<br /> HADR local host name                  (HADR_LOCAL_HOST) = db2-server1<br /> HADR local service name                (HADR_LOCAL_SVC) = 50010<br /> HADR remote host name                (HADR_REMOTE_HOST) = db2-server2<br /> HADR remote service name              (HADR_REMOTE_SVC) = 50011<br /> HADR instance name of remote server  (HADR_REMOTE_INST) = db2inst1<br /> HADR timeout value                       (HADR_TIMEOUT) = 120<br /> HADR target list                     (HADR_TARGET_LIST) = db2-server2:50011|db2-ec2:50012<br /> HADR log write synchronization mode     (HADR_SYNCMODE) = NEARSYNC<br /> HADR spool log data limit (4KB)      (HADR_SPOOL_LIMIT) = AUTOMATIC(52000)<br /> HADR log replay delay (seconds)     (HADR_REPLAY_DELAY) = 0<br /> HADR peer window duration (seconds)  (HADR_PEER_WINDOW) = 0<br /> HADR SSL certificate label             (HADR_SSL_LABEL) =<br /> HADR SSL Hostname Validation        (HADR_SSL_HOST_VAL) = OFF</pre>在 `db2-server2`上執行下列程式碼：<pre>db2 get db cfg for sample|grep HADR<br /> HADR database role                                      = STANDBY<br /> HADR local host name                  (HADR_LOCAL_HOST) = db2-server2<br /> HADR local service name                (HADR_LOCAL_SVC) = 50011<br /> HADR remote host name                (HADR_REMOTE_HOST) = db2-server1<br /> HADR remote service name              (HADR_REMOTE_SVC) = 50010<br /> HADR instance name of remote server  (HADR_REMOTE_INST) = db2inst1<br /> HADR timeout value                       (HADR_TIMEOUT) = 120<br /> HADR target list                     (HADR_TARGET_LIST) = db2-server1:50010|db2-ec2:50012<br /> HADR log write synchronization mode     (HADR_SYNCMODE) = NEARSYNC<br /> HADR spool log data limit (4KB)      (HADR_SPOOL_LIMIT) = AUTOMATIC(52000)<br /> HADR log replay delay (seconds)     (HADR_REPLAY_DELAY) = 0<br /> HADR peer window duration (seconds)  (HADR_PEER_WINDOW) = 0<br /> HADR SSL certificate label             (HADR_SSL_LABEL) =<br /> HADR SSL Hostname Validation        (HADR_SSL_HOST_VAL) = OFF</pre>在 `db2-ec2`上執行下列程式碼：<pre>db2 get db cfg for sample|grep HADR<br /> HADR database role                                      = STANDBY<br /> HADR local host name                  (HADR_LOCAL_HOST) = db2-ec2<br /> HADR local service name                (HADR_LOCAL_SVC) = 50012<br /> HADR remote host name                (HADR_REMOTE_HOST) = db2-server1<br /> HADR remote service name              (HADR_REMOTE_SVC) = 50010<br /> HADR instance name of remote server  (HADR_REMOTE_INST) = db2inst1<br /> HADR timeout value                       (HADR_TIMEOUT) = 120<br /> HADR target list                     (HADR_TARGET_LIST) = db2-server1:50010|db2-server2:50011<br /> HADR log write synchronization mode     (HADR_SYNCMODE) = SUPERASYNC<br /> HADR spool log data limit (4KB)      (HADR_SPOOL_LIMIT) = AUTOMATIC(52000)<br /> HADR log replay delay (seconds)     (HADR_REPLAY_DELAY) = 0<br /> HADR peer window duration (seconds)  (HADR_PEER_WINDOW) = 0<br /> HADR SSL certificate label             (HADR_SSL_LABEL) =<br /> HADR SSL Hostname Validation        (HADR_SSL_HOST_VAL) = OFF</pre>`HADR_LOCAL_HOST`、`HADR_LOCAL_SVC`、`HADR_REMOTE_HOST`、 `HADR_REMOTE_SVC`和 `HADR_TARGET_LIST` 參數指出一個主要和兩個待命 HADR 設定。 |  | 
| 停止和啟動 Db2 HADR。 | `HADR_TARGET_LIST` 現在已在所有三個伺服器上設定 。每個 Db2 伺服器都知道另外兩個伺服器。停止並重新啟動 HADR （短暫中斷），以利用新的組態。在 `db2-server1`上執行下列命令：<pre>db2 stop hadr on db sample<br />db2 deactivate db sample<br />db2 activate db sample</pre>在 `db2-server2`上執行下列命令：<pre>db2 deactivate db sample<br />db2 start hadr on db sample as standby<br />SQL1766W  The command completed successfully</pre>在 `db2-ec2`上執行下列命令：<pre>db2 start hadr on db sample as standby<br />SQL1766W  The command completed successfully</pre>在 `db2-server1`上執行下列命令：<pre>db2 start hadr on db sample as primary<br />SQL1766W  The command completed successfully</pre>Db2 on 內部部署和 Amazon EC2 之間的 HADR 連線現已成功建立。Db2 主要伺服器`db2-server1`會開始即時串流交易日誌記錄到 `db2-server2`和 `db2-ec2` 。 | DBA | 

### 在切換時段將 Amazon EC2 上的 Db2 設為主要 Amazon EC2
<a name="make-db2-on-amazon-ec2-as-primary-during-the-cutover-window"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 確定待命伺服器上沒有 HADR 延遲。 | 從主要伺服器 檢查 HADR 狀態`db2-server1`。當 `HADR_STATE` 處於 `REMOTE_CATCHUP` 狀態時，請勿發出警示，當 `HADR_SYNCMODE`設為 時，這是正常的`SUPERASYNC`。`PRIMARY_LOG_TIME` 和 `STANDBY_REPLAY_LOG_TIME`顯示它們處於同步狀態：<pre>db2pd -hadr -db sample<br />                            HADR_ROLE = PRIMARY<br />                          REPLAY_TYPE = PHYSICAL<br />                        HADR_SYNCMODE = SUPERASYNC<br />                           STANDBY_ID = 2<br />                        LOG_STREAM_ID = 0<br />                           HADR_STATE = REMOTE_CATCHUP<br />.....<br />                     PRIMARY_LOG_TIME = 10/26/2022 02:11:32.000000 (1666750292)<br />                     STANDBY_LOG_TIME = 10/26/2022 02:11:32.000000 (1666750292)<br />              STANDBY_REPLAY_LOG_TIME = 10/26/2022 02:11:32.000000 (1666750292)</pre> | DBA | 
| 執行 HADR 接管。 | 若要完成遷移，請執行 HADR 接管命令來建立`db2-ec2`主要資料庫。使用 命令`db2pd`來驗證`HADR_ROLE`值：<pre>db2 TAKEOVER HADR ON DATABASE sample<br />DB20000I  The TAKEOVER HADR ON DATABASE command completed successfully.<br /><br />db2pd -hadr -db sample<br />Database Member 0 -- Database SAMPLE -- Active -- Up 0 days 00:03:25 -- Date 2022-10-26-02.46.45.048988<br /><br />                            HADR_ROLE = PRIMARY<br />                          REPLAY_TYPE = PHYSICAL</pre>若要完成遷移至 AWS，請將應用程式連線指向 Amazon EC2 上的 Db2。 Amazon EC2 |  | 

## 疑難排解
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 如果您因防火牆和安全原因而使用 NAT，主機可以有兩個 IP 地址 （一個內部和一個外部），這可能會導致 HADR IP 地址檢查失敗。`START HADR ON DATABASE` 命令將傳回下列訊息：`HADR_LOCAL_HOST:HADR_LOCAL_SVC (-xx-xx-xx-xx.:50011 (xx.xx.xx.xx:50011)) on remote database is different from HADR_REMOTE_HOST:HADR_REMOTE_SVC (xx-xx-xx-xx.:50011 (x.x.x.x:50011)) on local database.` | 若要[在 NAT 環境中支援 HADR，](https://www.ibm.com/docs/en/db2/11.5?topic=support-hadr-nat)您可以使用內部和外部地址`HADR_LOCAL_HOST`來設定 。例如，如果 Db2 伺服器具有內部名稱 `host1`和外部名稱 `host1E`，則 `HADR_LOCAL_HOST` 可以是 `HADR_LOCAL_HOST: "host1 \| host1E"`。 | 

## 相關資源
<a name="migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery-resources"></a>
+ [不同作業系統和硬體平台之間的 Db2 備份和還原操作](https://www.ibm.com/docs/en/db2/11.5?topic=dbrs-backup-restore-operations-between-different-operating-systems-hardware-platforms)
+ [設定 Db2 STORAGE ACCESS ALIAS 和 DB2REMOTE](https://www.ibm.com/docs/en/db2/11.5?topic=commands-catalog-storage-access)
+ [Db2 高可用性災難復原](https://www.ibm.com/docs/en/db2/11.5?topic=server-high-availability-disaster-recovery-hadr)
+ [hadr\$1syncmode - 用於對等狀態組態參數中日誌寫入的 HADR 同步模式](https://www.ibm.com/docs/en/db2/11.5?topic=dcp-hadr-syncmode-hadr-synchronization-mode-log-writes-in-peer-state)

# 使用 appcmd.exe 將 IIS 託管應用程式遷移至 Amazon EC2
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd"></a>

*Deepak Kumar，Amazon Web Services*

## 總結
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd-summary"></a>

當您將網際網路資訊服務 (IIS) 託管的應用程式遷移至 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體時，您需要解決幾個身分驗證挑戰。這些挑戰包括重新輸入應用程式集區身分的網域登入資料，以及可能為適當的網站功能重新產生機器金鑰。您可以使用 AWS Directory Service 與內部部署 Active Directory 建立信任關係，或在其中建立新的受管 Active Directory AWS。此模式說明在 Amazon EC2 執行個體上使用 IIS 備份和還原功能的乾淨遷移方法。此方法使用 appcmd.exe 在目標 EC2 執行個體上解除安裝和重新安裝 IIS，以便成功遷移 IIS 託管的網站、應用程式集區身分和機器金鑰。

## 先決條件和限制
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd-prereqs"></a>

**先決條件**
+  AWS 帳戶 目標伺服器的作用中 。
+ 具有託管網站的功能來源 IIS 伺服器。
+ 了解 IIS 工作原則，例如管理和組態。
+ 來源和目標伺服器上的系統管理員存取權。
+ 已完成將來源 IIS 伺服器遷移至目標 AWS 帳戶。您可以使用遷移工具 AWS Application Migration Service，例如 Amazon Machine Image (AMI) 快照型方法或其他遷移工具。

**限制**
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 依區域的服務](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

**產品版本**
+ IIS 8.5 或 IIS 10.0

## Architecture
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd-architecture"></a>

**來源技術堆疊**
+ 安裝 IIS 8.5 或 IIS 10.0 的 Windows Server

**目標技術堆疊**
+ 安裝 IIS 8.5 或 IIS 10.0 的 Windows Server
+ 應用程式遷移服務

**目標架構**

下圖顯示此模式的工作流程和架構元件。

![\[將 IIS 託管應用程式遷移至 Amazon EC2 的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2f9f7757-b2bc-4077-b51a-700de521424c/images/36aa9b7a-d0aa-4fa4-be47-9fee43b53c22.png)


解決方案包含下列步驟：

1. 在公司資料中心的來源 IIS 伺服器上[安裝](https://docs.aws.amazon.com/mgn/latest/ug/agent-installation.html)和設定 AWS 複寫代理程式。此代理程式會啟動複寫程序，並管理 的資料傳輸 AWS。

1.  AWS 複寫代理程式會建立與 Application Migration Service [的安全連線](https://docs.aws.amazon.com/mgn/latest/ug/Agent-Related-FAQ.html#How-Communication-Secured)，並開始複寫來源伺服器資料，包括 IIS 組態、網站和應用程式檔案。

1. Application Migration Service 會使用複寫的資料在應用程式子網路中啟動 EC2 執行個體。目標 EC2 執行個體會執行 IIS，並包含已遷移的應用程式及其相關聯的 Amazon Elastic Block Store (Amazon EBS) 磁碟區。在初始複寫之後，Application Migration Service 會繼續同步變更，直到您[準備好切換](https://docs.aws.amazon.com/mgn/latest/ug/migration-dashboard.html#ready-for-cutover1)到新環境為止。

## 工具
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd-tools"></a>

**AWS 服務**
+ [AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 可協助您將應用程式重新託管 (*提升和轉移*) 到 ， AWS 雲端 而無須變更且停機時間最短。
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/ebs/latest/userguide/what-is-ebs.html) 提供區塊層級儲存體磁碟區，可搭配使用 Amazon EC2 執行個體。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。

**其他工具**
+ 適用於 Windows Server 的[網際網路資訊服務 (IIS)](https://www.iis.net/overview) 是 Web 伺服器，具有可擴展且開放的架構，可在 Web 上託管任何內容。IIS 提供一組管理工具，包括管理和命令列工具 （例如 appcmd.exe)、受管程式碼和指令碼 APIs，以及 Windows PowerShell 支援。

## 史詩
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd-epics"></a>

### 在遷移前於來源備份 IIS
<a name="back-up-iis-at-source-prior-to-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IIS 託管網站、組態金鑰和`WAS`金鑰的備份。 | 若要為 IIS 託管網站、組態金鑰 (`iisConfigurationKey`) 和`WAS`金鑰 (`iisWasKey`) 建立備份，請在來源伺服器上使用 appcmd.exe。使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.html)若要匯出組態金鑰和`WAS`金鑰，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.html) | IIS 管理員 | 

### 在目標伺服器上解除安裝和重新安裝 IIS
<a name="uninstall-and-reinstall-iis-on-the-target-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在目標伺服器上解除安裝 IIS。 | 若要解除安裝目標伺服器上的 IIS，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.html) | IIS 管理員 | 
| 在目標伺服器上安裝 IIS。 | 若要在目標伺服器上安裝 IIS，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.html) | IIS 管理員 | 

### 從備份還原 IIS 網站和組態
<a name="restore-iis-websites-and-configuration-from-the-backups"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 還原 IIS 網站和組態。 | 若要還原您在目標伺服器上從來源伺服器建立的 IIS 備份，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.html) | IIS 管理員 | 

## 相關資源
<a name="migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd-resources"></a>

**AWS 文件**
+ [安裝複寫代理程式 AWS](https://docs.aws.amazon.com/mgn/latest/ug/agent-installation.html)(AWS Application Migration Service 文件）

**AWS 方案指引**
+ [使用 將內部部署 VM 遷移至 Amazon EC2 AWS Application Migration Service](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service.html)
+ [使用 AMIs 或 Amazon EBS 快照進行備份](https://docs.aws.amazon.com/prescriptive-guidance/latest/backup-recovery/ec2-backup.html#amis-snapshots)

**Microsoft 資源**
+ [應用程式集區身分](https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/iis/was-service-svchost-process-operation/understanding-identities#application-pool-identities)
+ [IIS 文件](https://learn.microsoft.com/en-us/iis/)
+ [IIS 8 appcmd.exe 文件](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/jj635852(v=ws.11))
+ [IIS 10 appcmd.exe 文件](https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/new-features-introduced-in-iis-10)
+ [強大的管理員工具](https://learn.microsoft.com/en-us/iis/overview/powerful-admin-tools)

# 使用 Application Migration Service 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn"></a>

*Senthil Ramasamy，Amazon Web Services*

## 總結
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-summary"></a>

此模式說明將 Microsoft SQL Server 資料庫從內部部署資料中心遷移至 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體的步驟。它使用 AWS Application Migration Service (AWS MGN) 來重新託管資料庫，方法是使用自動lift-and-shift。 AWS MGN 會執行來源資料庫伺服器的區塊層級複寫。

## 先決條件和限制
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-prereqs"></a>

**先決條件 **
+ 作用中 AWS 帳戶
+ 內部部署資料中心中的來源 Microsoft SQL Server 資料庫

**限制**
+ 您的網路頻寬可能會在內部部署資料中心與 之間受到限制 AWS。
+ AWS MGN 僅限於託管在具有專用儲存的獨立伺服器上的資料庫。它不支援遷移叢集資料庫系統和變更速率超過網路輸送量的資料庫系統。
+ 有些 AWS 服務 不適用於所有 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額頁面](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)，然後選擇服務的連結。

**產品版本**
+ Microsoft SQL Server 資料庫的所有版本
+ [支援 AWS MGN](https://docs.aws.amazon.com/mgn/latest/ug/Supported-Operating-Systems.html) 的 Windows 和 Linux 作業系統

## Architecture
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-architecture"></a>

**來源技術堆疊**

內部部署 Microsoft SQL Server 資料庫

**目標技術堆疊**

Amazon EC2 執行個體上的 Microsoft SQL Server 資料庫

**目標架構**

![\[將資料從內部部署企業資料中心複寫到 AWS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a459eaef-c256-4691-a7ec-2304f634228c/images/d8d6cee7-f42c-4686-bf92-6e6d39adfb17.png)


此架構使用 AWS MGN 將資料從內部部署企業資料中心複寫到 AWS。圖表顯示資料複寫程序、API 通訊，以及測試和切換階段。

1. 資料複寫：
   + AWS MGN 會將內部部署企業資料中心的資料複寫到 ， AWS 並啟動持續複寫的變更。
   + 預備子網路中的複寫伺服器會接收和處理資料。

1. API 通訊：
   + 複寫伺服器會透過 TCP 連接埠 443 連線至 AWS MGN、Amazon EC2 和 Amazon Simple Storage Service (Amazon S3) API 端點。Amazon S3
   + AWS MGN 會管理遷移。
   + Amazon EC2 會管理執行個體操作。

1. 測試和切換：
   + 使用複寫資料在操作子網路中測試執行個體啟動。
   + 測試成功後， AWS MGN 會為最終遷移建立切換執行個體。

## 工具
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-tools"></a>
+ [AWS Application Migration Service (AWS MGN)](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 可協助您將應用程式重新託管 (*提升和轉移*) 到 ， AWS 雲端 無需變更且停機時間最短。
+ [Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 透過標準乙太網路光纖纜線，將您的內部網路連結至 Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的虛擬介面，同時略過網路路徑中的網際網路服務供應商。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

## 最佳實務
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-best-practices"></a>
+ 在虛擬私有雲端 (VPC) 中為 AWS MGN、Amazon EC2 和 Amazon S3 設定 API 區域端點，以禁止從網際網路公開存取。
+ 設定 AWS MGN 啟動設定以啟動私有子網路中的目標資料庫伺服器。
+ 僅允許資料庫安全群組中的必要連接埠。
+ 遵循最低權限原則，並授予執行任務所需的最低許可。如需詳細資訊，請參閱 IAM 文件中的[授予最低權限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#grant-least-priv)和[安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)。

## 史詩
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-epics"></a>

### 設定 AWS MGN
<a name="set-up-aws-mgn"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS MGN。 | 在 AWS Application Migration Service 中搜尋 AWS 管理主控台，然後啟動設定程序。這會建立複寫範本，並將您重新導向至 MGN 主控台**來源伺服器**頁面。當您設定 MGN 服務時，請從產生的清單中選擇服務角色。 | DBA，遷移工程師 | 
| 新增來源伺服器。 | 新增現場部署來源資料庫伺服器的詳細資訊，然後新增伺服器。 | DBA，遷移工程師 | 
| 在來源伺服器上安裝 AWS MGN 代理程式。 | 下載 AWS MGN 代理程式安裝程式到您的本機系統，並將安裝程式轉移到您的來源資料庫伺服器。若要驗證安裝程式雜湊，請參閱驗證[AWS 下載的 Windows 2012 複寫代理程式安裝程式](https://docs.aws.amazon.com/mgn/latest/ug/windows-agent.html#installer-hash-table-2012)。 | DBA，遷移工程師 | 

### 在來源機器上安裝 AWS MGN 代理程式
<a name="install-aws-mgn-agent-on-source-machines"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 產生用戶端 IAM 登入資料。 | 安裝 AWS MGN 代理程式之前，請建立具有適當許可的新 IAM 使用者來產生 AWS 憑證。如需詳細資訊，請參閱適用於 [的 AWS 受管政策 AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/security-iam-awsmanpol.html)，以及[產生所需的 AWS 登入](https://docs.aws.amazon.com/mgn/latest/ug/credentials.html)資料。 | DBA，遷移工程師 | 
| 在來源伺服器上安裝 代理程式。 | 在託管 Microsoft SQL Server 資料庫的來源機器上安裝代理程式。如需詳細資訊，請參閱[在 Windows 伺服器上安裝 AWS 複寫代理](https://docs.aws.amazon.com/mgn/latest/ug/windows-agent.html)程式。提供下列 AWS 登入資料：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.html)您的唯一 AWS 登入資料可讓 AWS MGN 代理程式驗證和執行遷移任務。 | 應用程式擁有者、DBA、遷移工程師 | 
| 選擇要複寫的磁碟。 | 輸入您的 AWS 登入資料後，安裝程式會驗證您的伺服器是否符合代理程式安裝的最低需求 （例如，伺服器是否有足夠的磁碟空間安裝 AWS MGN 代理程式）。安裝程式會顯示磁碟區標籤和儲存詳細資訊。若要使用 AWS MGN 服務複寫資料庫，請選取來源伺服器上適用的磁碟。輸入每個磁碟的路徑，以逗號分隔。如果您想要複寫所有磁碟，請將路徑保留空白。確認選取的磁碟後，安裝會繼續進行。 | DBA，遷移工程師 | 
| 監控同步進度。 | AWS 複寫代理程式會先擷取所選磁碟的快照，然後複寫資料，以啟動同步程序。您可以從 AWS MGN 主控台的**來源伺服器**頁面監控同步進度。如需詳細資訊，請參閱[在遷移生命週期中監控伺服器](https://docs.aws.amazon.com/mgn/latest/ug/migration-dashboard.html)。 | DBA，遷移工程師 | 

### 使用 AWS MGN 複寫
<a name="replication-using-aws-mgn"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 管理複寫進度。 | 開始初始同步後，您的來源伺服器會出現在 AWS MGN 主控台中，您可以在其中管理和監控遷移。主控台會顯示完成複寫的預估時間，這取決於所選磁碟的總大小和可用的網路頻寬。 | DBA，遷移工程師 | 
| 驗證同步。 | 來源伺服器上的磁碟完全同步後，請確認所有選取的磁碟都列為完全同步，而且主控台中不會回報任何錯誤。 AWS MGN 主控台接著會自動將遷移生命週期狀態轉換為**就緒進行測試**，表示 中的複寫環境 AWS 已準備好進行效能和功能測試。 | 應用程式擁有者、DBA、遷移工程師 | 

### 測試和切換
<a name="test-and-cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定啟動設定。 | 在 AWS MGN 主控台中選擇來源伺服器，並更新目標測試執行個體的啟動設定。從來源**伺服器詳細資訊**頁面，導覽至**啟動設定**索引標籤以設定測試執行個體。選擇經濟實惠的執行個體類型和 Amazon Elastic Block Store (Amazon EBS) 磁碟區類型，然後設定安全群組和網路需求。如需詳細資訊，請參閱[啟動設定](https://docs.aws.amazon.com/mgn/latest/ug/launch-settings.html)。 | DBA，遷移工程師 | 
| 啟動目標測試執行個體。 | 導覽至同步來源機器的 AWS MGN 主控台，然後選擇**測試並切換**，然後啟動測試執行個體，以**啟動目標測試執行個體**。這會建立使用您設定的 設定部署測試執行個體的啟動任務。執行個體會在 中啟動， AWS 雲端 並複寫來源資料庫伺服器的環境。從啟動**歷史記錄**頁面監控啟動進度，您可以在其中追蹤執行個體建立並解決任何問題。 | DBA，遷移工程師 | 
| 驗證目標測試執行個體。 | 驗證 Amazon EC2 資料庫伺服器：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.html)執行驗證測試，以確保資料庫如預期般運作。 | DBA，遷移工程師 | 
| 重新命名伺服器。 | AWS MGN 遷移涉及現場部署來源伺服器的儲存層級複本。您的 SQL Server EC2 執行個體在其二進位檔中僅包含原始來源伺服器的詳細資訊，因此請更新二進位資訊以反映新伺服器的名稱。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.html) | DBA，遷移工程師 | 
| 啟動切換執行個體。 | 在 AWS MGN 主控台的**來源伺服器**頁面上，確認伺服器的遷移生命週期狀態**已準備好進行切換**。設定切換執行個體的啟動設定，確保設定反映您的現場部署環境。啟動切換之前，請關閉您的現場部署資料庫，以確保下列事項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.html)在 AWS MGN 主控台中啟動切換執行個體。當切換執行個體運作時，請登入執行個體並執行下列測試：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.html) | 應用程式擁有者、DBA、遷移工程師、遷移負責人 | 

## 疑難排解
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 初始同步會在身分驗證步驟失敗。 | 這是網路連線問題。複寫伺服器無法連線至 AWS MGN。 | 

## 相關資源
<a name="migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn-resources"></a>

**AWS 文件**
+ [入門 AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/getting-started.html)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2.html)
+ [什麼是 Amazon EC2 上的 Microsoft SQL Server？](https://docs.aws.amazon.com/sql-server-ec2/latest/userguide/sql-server-on-ec2-overview.html)

**影片**
+ [使用 執行提升和轉移遷移 AWS Application Migration Service](https://www.youtube.com/watch?v=tB0sAR3aCb4) （影片）

# 在 上將 F5 BIG-IP 工作負載遷移至 F5 BIG-IP VE AWS 雲端
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud"></a>

*Deepak Kumar，Amazon Web Services*

## 摘要
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud-summary"></a>

組織希望遷移至 AWS 雲端 ，以提高敏捷性和彈性。將 [F5 BIG-IP ](https://www.f5.com/products/big-ip-services)安全和流量管理解決方案遷移至 後 AWS 雲端，您可以專注於在整個企業架構中採用高價值操作模型的敏捷性和採用性。

此模式說明如何將 F5 BIG-IP 工作負載遷移至 上的 [F5 BIG-IP Virtual Edition (VE)](https://www.f5.com/products/big-ip-services/virtual-editions) 工作負載 AWS 雲端。工作負載的遷移方式是重新託管現有環境，並部署轉換的層面，例如服務探索和 API 整合。 [AWS CloudFormation 範本](https://github.com/F5Networks/f5-aws-cloudformation)可加速工作負載遷移至 AWS 雲端。

此模式適用於技術工程和架構團隊，這些團隊正在遷移 F5 安全和流量管理解決方案，並隨附 AWS 規範性指引網站上的指南[從 F5 BIG-IP 遷移至 F5 BIG-IP VE AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-f5-big-ip/welcome.html)。

## 先決條件和限制
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud-prereqs"></a>

**先決條件**
+ 現有的內部部署 F5 BIG-IP 工作負載。
+ BIG-IP VE 版本的現有 F5 授權。
+ 作用中 AWS 帳戶。
+ 透過 NAT 閘道或彈性 IP 地址設定輸出的現有虛擬私有雲端 (VPC)，並設定存取下列端點：Amazon Simple Storage Service (Amazon S3)、Amazon Elastic Compute Cloud (Amazon EC2)、 AWS Security Token Service (AWS STS) 和 Amazon CloudWatch。您也可以修改[模組化和可擴展的 VPC 架構](https://aws.amazon.com/quickstart/architecture/vpc/) Quick Start，做為部署的建置區塊。 
+ 一或兩個現有的可用區域，視您的需求而定。 
+ 每個可用區域中有三個現有的私有子網路。
+ AWS CloudFormation 範本，[可在 F5 GitHub 儲存庫中使用](https://github.com/F5Networks/f5-aws-cloudformation/blob/master/template-index.md)。 

在遷移期間，視您的需求而定，您也可以使用下列項目：
+ 管理彈性 IP 地址映射、次要 IP 映射和路由表變更的 [F5 雲端容錯移轉延伸](https://clouddocs.f5.com/products/extensions/f5-cloud-failover/latest/)。 
+ 如果您使用多個可用區域，則需要使用 F5 雲端容錯移轉延伸來處理彈性 IP 映射到虛擬伺服器。
+ 您應該考慮使用 [F5 Application Services 3 (AS3)](https://clouddocs.f5.com/products/extensions/f5-appsvcs-extension/latest/)、[F5 Application Services Templates (FAST)](https://clouddocs.f5.com/products/extensions/f5-appsvcs-templates/latest/) 或其他基礎設施做為程式碼 (IaC) 模型來管理組態。在 IaC 模型中準備組態並使用程式碼儲存庫，將有助於遷移和持續的管理工作。

**專業知識**
+ 此模式需要熟悉如何將一或多個 VPCs 連接到現有資料中心。如需詳細資訊，請參閱 [Network-to-Amazon Amazon VPC 連線選項](https://docs.aws.amazon.com/whitepapers/latest/aws-vpc-connectivity-options/network-to-amazon-vpc-connectivity-options.html)。 
+ F5 產品和模組也需要熟悉，包括[流量管理作業系統 (TMOS)](https://www.f5.com/services/resources/white-papers/tmos-redefining-the-solution)、[本機流量管理員 (LTM)](https://www.f5.com/products/big-ip-services/local-traffic-manager)、[全域流量管理員 (GTM)](https://techdocs.f5.com/kb/en-us/products/big-ip_gtm/manuals/product/gtm-concepts-11-5-0/1.html#unique_9842886)、[存取政策管理員 (APM)](https://www.f5.com/products/security/access-policy-manager)、[應用程式安全管理員 (ASM)](https://www.f5.com/pdf/products/big-ip-application-security-manager-overview.pdf)、[進階防火牆管理員 (AFM)](https://www.f5.com/products/security/advanced-firewall-manager) 和 [BIG-IQ](https://www.f5.com/products/automation-and-orchestration/big-iq)。

**產品版本**
+ 我們建議您使用 F5 BIG-IP [13.1 版](https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/releasenotes/product/relnote-bigip-ve-13-1-0.html)或更新版本，雖然模式支援 F5 BIG-IP [12.1 版或更新版本。](https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/releasenotes/product/relnote-bigip-12-1-4.html)

## Architecture
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud-architecture"></a>

**來源技術堆疊**
+ F5 BIG-IP 工作負載

**目標技術堆疊  **
+ Amazon CloudFront
+ CloudWatch
+ Amazon EC2
+ Amazon S3
+ Amazon VPC
+ AWS Global Accelerator
+ AWS STS
+ AWS Transit Gateway
+ F5 BIG-IP VE

**目標架構 **

![\[將 F5 BIG-IP 工作負載遷移至 F5 BIG-IP VE 工作負載的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/586fe806-fac1-48d3-9eb1-45a6c86430dc/images/16d7fc09-1ffe-4721-b503-d971db84cbae.png)


## 工具
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud-tools"></a>
+ [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速且一致地佈建資源，以及在整個 AWS 帳戶 和 生命週期中管理資源 AWS 區域。
+ [Amazon CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) 透過全球資料中心網路提供 Web 內容，進而降低延遲並改善效能，進而加快 Web 內容的發佈速度。  
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 可協助您 AWS 即時監控 AWS 資源的指標，以及您執行的應用程式。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 中提供可擴展的運算容量 AWS 雲端 。您可以根據需要啟動任意數量的虛擬伺服器，並快速擴展或縮減它們。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Security Token Service (AWS STS)](https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html) 可協助您為使用者請求暫時、有限權限的登入資料。
+ [AWS Transit Gateway](https://docs.aws.amazon.com/vpc/latest/tgw/what-is-transit-gateway.html) 是連接虛擬私有雲端 (VPC) 和內部部署網路的中央中樞。
+ [Amazon Virtual Private Cloud (Amazon VPC) ](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。

## 史詩
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud-epics"></a>

### 探索和評估
<a name="discovery-and-assessment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 評估 F5 BIG-IP 的效能。 | 收集並記錄虛擬伺服器上應用程式的效能指標，以及將遷移的系統指標。這將有助於正確調整目標 AWS 基礎設施的大小，以獲得更好的成本最佳化。 | F5 架構師、工程師和網路架構師、工程師 | 
| 評估 F5 BIG-IP 作業系統和組態。 | 評估要遷移哪些物件，以及是否需要維護網路結構，例如 VLANs。 | F5 架構師、工程師 | 
| 評估 F5 授權選項。 | 評估您需要的授權和耗用量模型。此評估應以您對 F5 BIG-IP 作業系統和組態的評估為基礎。 | F5 架構師、工程師 | 
| 評估公有應用程式。 | 決定哪些應用程式需要公有 IP 地址。將這些應用程式與所需的執行個體和叢集保持一致，以滿足效能和服務層級協議 (SLA) 要求。 | F5 架構師、雲端架構師、網路架構師、工程師、應用程式團隊 | 
| 評估內部應用程式。 | 評估內部使用者將使用哪些應用程式。請確定您知道這些內部使用者在組織中的位置，以及這些環境如何連線到 AWS 雲端。您也應該確保這些應用程式可以使用網域名稱系統 (DNS) 做為預設網域的一部分。 | F5 架構師、雲端架構師、網路架構師、工程師、應用程式團隊 | 
| 完成 AMI。 | 並非所有 F5 BIG-IP 版本都會建立為 Amazon Machine Image (AMIs)。如果您有特定的必要快速修正工程 (QFE) 版本，您可以使用 F5 BIG-IP Image Generator Tool。如需此工具的詳細資訊，請參閱「相關資源」一節。 | F5 架構師、雲端架構師、工程師 | 
| 完成執行個體類型和架構。 | 決定執行個體類型、VPC 架構和互連架構。 | F5 架構師、雲端架構師、網路架構師、工程師 | 

### 完成安全與合規相關活動
<a name="complete-security-and-compliance-related-activities"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 記錄現有的 F5 安全政策。 | 收集並記錄現有的 F5 安全政策。請務必在安全程式碼儲存庫中建立其複本。 | F5 架構師、工程師 | 
| 加密 AMI。 | （選用） 您的組織可能需要靜態資料加密。如需建立自訂自帶授權 (BYOL) 映像的詳細資訊，請參閱「相關資源」一節。 | F5 Architect， Engineer Cloud Architect， Engineer | 
| 強化裝置。 | 這將有助於防止潛在的漏洞。 | F5 架構師、工程師 | 

### 設定您的新 AWS 環境
<a name="configure-your-new-aws-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立邊緣和安全帳戶。 | 登入 AWS 管理主控台 並建立 AWS 帳戶 ，以提供和操作邊緣和安全服務。這些帳戶可能與為共用服務和應用程式操作 VPCs的帳戶不同。此步驟可作為登陸區域的一部分完成。 | 雲端架構師、工程師 | 
| 部署邊緣和安全性 VPCs。 | 設定交付邊緣和安全服務所需的 VPCs。 | 雲端架構師、工程師 | 
| 連線至來源資料中心。 | 連線至託管 F5 BIG-IP 工作負載的來源資料中心。 | 雲端架構師、網路架構師、工程師 | 
| 部署 VPC 連線。 | 將邊緣和安全服務 VPCs連接到應用程式 VPCs。 | Network Architect，工程師 | 
| 部署執行個體。 | 使用「相關資源」區段中的 CloudFormation 範本來部署執行個體。 | F5 架構師、工程師 | 
| 測試和設定執行個體容錯移轉。 | 請確定已設定 AWS 進階 HA iAPP 範本或 F5 雲端容錯移轉延伸模組並正常運作。 | F5 架構師、工程師 | 

### 設定聯網
<a name="configure-networking"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備 VPC 拓撲。 | 開啟 Amazon VPC 主控台，並確保您的 VPC 具有 F5 BIG-IP VE 部署所需的所有子網路和保護。 | 網路架構師、F5 架構師、雲端架構師、工程師 | 
| 準備您的 VPC 端點。 | 準備 Amazon EC2、Amazon S3 的 VPC 端點，如果 AWS STS F5 BIG-IP 工作負載無法存取 TMM 界面上的 NAT 閘道或彈性 IP 地址。 | 雲端架構師、工程師 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遷移組態。 | 在 上將 F5 BIG-IP 組態遷移至 F5 BIG-IP VE AWS 雲端。 | F5 架構師、工程師 | 
| 關聯次要 IPs。 | 虛擬伺服器 IP 地址與指派給執行個體的次要 IP 地址有關聯。指派次要 IP 地址，並確認已選取「允許重新對應/重新指派」。 | F5 架構師、工程師 | 

### 測試組態
<a name="test-configurations"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證虛擬伺服器組態。 | 測試虛擬伺服器。 | F5 架構師、應用程式團隊 | 

### 完成操作
<a name="finalize-operations"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立備份策略。 | 必須關閉系統才能建立完整快照。如需詳細資訊，請參閱「相關資源」一節中的「更新 F5 BIG-IP 虛擬機器」。 | F5 架構師、雲端架構師、工程師 | 
| 建立叢集容錯移轉 Runbook。 | 確定容錯移轉 Runbook 程序已完成。 | F5 架構師、工程師 | 
| 設定和驗證記錄。 | 設定 F5 遙測串流，將日誌傳送至所需的目的地。 | F5 架構師、工程師 | 

### 完成切換
<a name="complete-the-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 切換到新的部署。 |  | F5 架構師、雲端架構師、網路架構師、工程師、AppTeams | 

## 相關資源
<a name="migrate-an-f5-big-ip-workload-to-f5-big-ip-ve-on-the-aws-cloud-resources"></a>

**遷移指南**
+ [在 上從 F5 BIG-IP 遷移至 F5 BIG-IP VE AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-f5-big-ip/welcome.html)

**F5 資源**
+ [CloudFormation F5 GitHub 儲存庫中的 範本](https://github.com/F5Networks/f5-aws-cloudformation)
+ [中的 F5 AWS Marketplace](https://aws.amazon.com/marketplace/seller-profile?id=74d946f0-fa54-4d9f-99e8-ff3bd8eb2745)
+ [F5 BIG-IP VE 概觀](https://www.f5.com/products/big-ip-services/virtual-editions) 
+ [範例 Quickstart - BIG-IP Virtual Edition 搭配 WAF (LTM \$1 ASM)](https://github.com/F5Networks/f5-aws-cloudformation-v2/tree/main/examples/quickstart)
+ [F5 應用程式服務開啟 AWS：概觀 （影片）](https://www.youtube.com/watch?v=kutVjRHOAXo)
+ [F5 Application Services 3 延伸模組使用者指南 ](https://clouddocs.f5.com/products/extensions/f5-appsvcs-extension/latest/)
+ [F5 雲端文件](https://clouddocs.f5.com/training/community/public-cloud/html/intro.html)
+ [F5 iControl REST Wiki](https://clouddocs.f5.com/api/icontrol-rest/)
+ [F5 單一組態檔案概觀 (11.x - 15.x)](https://support.f5.com/csp/article/K13408)
+ [F5 白皮書](https://www.f5.com/services/resources/white-papers)
+ [F5 BIG-IP 影像產生器工具](https://clouddocs.f5.com/cloud/public/v1/ve-image-gen_index.html)
+ [更新 F5 BIG-IP VE 虛擬機器](https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/bigip-ve-setup-vmware-esxi-11-5-0/3.html)
+ [UCS 封存 "platform-migrate" 選項概觀](https://support.f5.com/csp/article/K82540512)

# 使用二進位方法將內部部署 Go Web 應用程式遷移至 AWS Elastic Beanstalk
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method"></a>

*Suhas Basavaraj 和 Shumaz Mukhtar Kazi，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-summary"></a>

此模式說明如何將內部部署 Go Web 應用程式遷移至 AWS Elastic Beanstalk。應用程式遷移後，Elastic Beanstalk 會建置來源套件的二進位檔，並將其部署至 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。

作為重新託管遷移策略，此模式的方法很快，不需要變更程式碼，這表示測試和遷移時間更少。 

## 先決條件和限制
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署 Go Web 應用程式。
+ 包含 Go 應用程式原始碼的 GitHub 儲存庫。如果您不使用 GitHub，還有其他方法可以[為 Elastic Beanstalk 建立應用程式原始碼套件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html)。

**產品版本**
+ Elastic Beanstalk 支援的最新 Go 版本。如需詳細資訊，請參閱 [Elastic Beanstalk 文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go)。

## Architecture
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-architecture"></a>

**來源技術堆疊**
+ 內部部署 Go Web 應用程式 

**目標技術堆疊**
+ AWS Elastic Beanstalk
+ Amazon CloudWatch

**目標架構*** *

![\[將 Go 應用程式遷移至 Elastic Beanstalk 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cd8d660d-5621-4ea7-8f97-7a1e321c57d3/images/1df543d9-7073-43d8-abd3-f1f7e57278eb.png)


## 工具
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-tools"></a>
+ [AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html) 可在 AWS 雲端中快速部署和管理應用程式，而使用者不必了解執行這些應用程式的基礎設施。Elastic Beanstalk 可降低管理複雜性而不會限制選擇或控制。
+ [GitHub](https://github.com/) 是一種開放原始碼分散式版本控制系統。

## 史詩
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-epics"></a>

### 建立 Go Web 應用程式原始碼套件 .zip 檔案
<a name="create-the-go-web-application-source-bundle-zip-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Go 應用程式的原始碼套件。 | 開啟包含 Go 應用程式原始碼的 GitHub 儲存庫，並準備原始碼套件。原始碼套件包含根目錄中的`application.go`原始碼檔案，該檔案託管 Go 應用程式的主要套件。如果您不使用 GitHub，請參閱此模式稍早*的先決條件*一節，了解建立應用程式原始碼套件的其他方式。 | 系統管理員、應用程式開發人員 | 
| 建立一個程式組態檔案。 | 在原始碼套件中建立`.ebextensions`資料夾，然後在此資料夾中建立 `options.config` 檔案。如需詳細資訊，請參閱 [Elastic Beanstalk 文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)。 | 系統管理員、應用程式開發人員 | 
|  建立原始碼套件 .zip 檔案。 | 執行下列命令。<pre>git archive -o ../godemoapp.zip HEAD</pre>這會建立原始碼套件 .zip 檔案。下載 .zip 檔案並將其儲存為本機檔案。.zip 檔案不能超過 512 MB，也不能包含父資料夾或頂層目錄。 | 系統管理員、應用程式開發人員 | 

### 將 Go Web 應用程式遷移至 Elastic Beanstalk
<a name="migrate-the-go-web-application-to-elastic-beanstalk"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇 Elastic Beanstalk 應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html)如需如何建立 Elastic Beanstalk 應用程式的指示，請參閱 [Elastic Beanstalk 文件](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.CreateApp.html)。 | 系統管理員、應用程式開發人員 | 
| 啟動 Elastic Beanstalk Web 伺服器環境。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html) | 系統管理員、應用程式開發人員 | 
| 將原始碼套件 .zip 檔案上傳至 Elastic Beanstalk。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method.html) | 系統管理員、應用程式開發人員 | 
| 測試部署的 Go Web 應用程式。 | 系統會將您重新導向至 Elastic Beanstalk 應用程式的概觀頁面。在概觀頂端**的環境 ID** 旁，選擇結尾為 的 URL `elasticbeanstalk.com` 以導覽至您的應用程式。您的應用程式必須在其組態檔案中使用此名稱做為環境變數，並在網頁上顯示它。 | 系統管理員、應用程式開發人員 | 

## 疑難排解
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 無法透過 Application Load Balancer 存取應用程式。 | 檢查包含 Elastic Beanstalk 應用程式的目標群組。如果運作狀態不佳，請登入您的 Elastic Beanstalk 執行個體並檢查`nginx.conf`檔案組態，以確認其路由至正確的運作狀態 URL。您可能需要變更目標群組運作狀態檢查 URL。 | 

## 相關資源
<a name="migrate-an-on-premises-go-web-application-to-aws-elastic-beanstalk-by-using-the-binary-method-resources"></a>
+ [Elastic Beanstalk 支援的 Go 平台版本](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go)
+ [搭配 Elastic Beanstalk 使用組態檔案](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)
+ [在 Elastic Beanstalk 中建立範例應用程式](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.CreateApp.html) 

# AWS 使用 將內部部署 SFTP 伺服器遷移至 AWS Transfer for SFTP
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp"></a>

*Akash Kumar，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp-summary"></a>

此模式說明如何 AWS 雲端 使用 AWS Transfer for SFTP 服務，將使用 Secure Shell (SSH) 檔案傳輸通訊協定 (SFTP) 的內部部署檔案傳輸解決方案遷移至 。使用者通常會透過其網域名稱或固定 IP 連線到 SFTP 伺服器。此模式涵蓋這兩種情況。

AWS Transfer for SFTP 是 的成員 AWS Transfer Family。這是一項安全傳輸服務，可讓您透過 SFTP 將檔案傳入和傳出 AWS 儲存服務。您可以 AWS Transfer for SFTP 搭配 Amazon Simple Storage Service (Amazon S3) 或 Amazon Elastic File System (Amazon EFS) 使用 。此模式使用 Amazon S3 進行儲存。

## 先決條件和限制
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 現有的 SFTP 網域名稱或固定的 SFTP IP。

**限制**
+ 您可以在一個請求中傳輸的最大物件目前為 5 GiB。對於大於 100 MiB 的檔案，請考慮使用 [Amazon S3 分段上傳](https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html)。

## Architecture
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp-architecture"></a>

**來源技術堆疊**
+ 內部部署平面檔案或資料庫傾印檔案。

**目標技術堆疊**
+ AWS Transfer for SFTP
+ Amazon S3
+ Amazon Virtual Private Cloud (Amazon VPC)
+ AWS Identity and Access Management (IAM) 角色和政策
+ 彈性 IP 位址
+ Security groups (安全群組)
+ Amazon CloudWatch Logs （選用）

**目標架構**

![\[使用 AWS Transfer for SFTP 將內部部署 SFTP 伺服器遷移至 AWS 雲端。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/ec0a905c-edef-48ba-9b5e-ea4a4040d320/images/f42aa711-bfe0-4ac6-9f66-5c18a1dd1c7a.png)


**自動化和擴展**

若要自動化此模式的目標架構，請使用連接的 CloudFormation 範本：
+ `amazon-vpc-subnets.yml` 會佈建具有兩個公有和兩個私有子網路的虛擬私有雲端 (VPC)。
+ `amazon-sftp-server.yml` 會佈建 SFTP 伺服器。
+ `amazon-sftp-customer.yml` 新增 使用者。

## 工具
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp-tools"></a>

**AWS 服務**
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 可協助您集中所有系統、應用程式的日誌， AWS 服務 以便您可以監控日誌並將其安全地存檔。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。此模式使用 Amazon S3 做為檔案傳輸的儲存系統。
+ [AWS Transfer for SFTP](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-family.html) 可協助您透過 SFTP 通訊協定將檔案傳入和傳出 AWS 儲存服務。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。

## 史詩
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp-epics"></a>

### 建立 VPC
<a name="create-a-vpc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立具有子網路的 VPC。 | 開啟 [Amazon VPC 主控台](https://console.aws.amazon.com/vpc/)。建立具有兩個公有子網路的虛擬私有雲端 (VPC)。（第二個子網路提供高可用性。)—或—您可以在 CloudFormation [主控台中部署連接的 CloudFormation ](https://console.aws.amazon.com/cloudformation) 範本 `amazon-vpc-subnets.yml`，以自動化此史詩中的任務。 | 開發人員、系統管理員 | 
| 新增網際網路閘道。 | 佈建網際網路閘道並將其連接到 VPC。 | 開發人員、系統管理員 | 
| 遷移現有的 IP。 | 將現有的 IP 連接到彈性 IP 地址。您可以從地址集區建立彈性 IP 地址並使用它。 | 開發人員、系統管理員 | 

### 佈建 SFTP 伺服器
<a name="provision-an-sftp-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 SFTP 伺服器。 | 開啟 [AWS Transfer Family 主控台](https://console.aws.amazon.com/transfer/)。請遵循 AWS Transfer Family 文件中[為伺服器建立面向網際網路的端點](https://docs.aws.amazon.com/transfer/latest/userguide/create-server-in-vpc.html#create-internet-facing-endpoint)中的指示，使用面向網際網路的端點建立 SFTP 伺服器。針對**端點類型**，選擇**託管的 VPC**。針對**存取**，選擇**網際網路面向**。針對 **VPC**，選擇您在上一個史詩中建立的 VPC。—或—您可以在 CloudFormation [主控台中部署連接的 CloudFormation ](https://console.aws.amazon.com/cloudformation) 範本 `amazon-sftp-server.yml`，以自動化此史詩中的任務。 | 開發人員、系統管理員 | 
| 遷移網域名稱。 | 將現有的網域名稱連接到自訂主機名稱。如果您使用新的網域名稱，請使用 **Amazon Route 53 DNS** 別名。針對現有的網域名稱，選擇**其他 DNS**。如需詳細資訊，請參閱 AWS Transfer Family 文件中的[使用自訂主機名稱](https://docs.aws.amazon.com/transfer/latest/userguide/requirements-dns.html)。 | 開發人員、系統管理員 | 
| 新增 CloudWatch 記錄角色。 | （選用） 如果您想要啟用 CloudWatch 記錄，請使用 CloudWatch Logs API 操作 `logs:CreateLogGroup`、 `logs:CreateLogStream`` logs:DescribeLogStreams`和 建立`Transfer`角色`logs:PutLogEvents`。如需詳細資訊，請參閱 AWS Transfer Family 文件中的[使用 CloudWatch 記錄活動](https://docs.aws.amazon.com/transfer/latest/userguide/monitoring.html#monitoring-enabling)。 | 開發人員、系統管理員 | 
| 儲存並提交。 | 選擇**儲存**。針對**動作**，選擇**開始**並等待 SFTP 伺服器建立為**線上**狀態。 | 開發人員、系統管理員 | 

### 將彈性 IP 地址映射至 SFTP 伺服器
<a name="map-elastic-ip-addresses-to-the-sftp-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止伺服器，以便您可以修改設定。 | 在 [AWS Transfer Family 主控台](https://console.aws.amazon.com/transfer/)上，選擇**伺服器**，然後選取您建立的 SFTP 伺服器。針對 **Actions** (動作)，選擇 **Stop** (停止)。當伺服器離線時，選擇**編輯**以修改其設定。 | 開發人員、系統管理員 | 
| 選擇可用區域和子網路。 | 在**可用區域**區段中，選擇 VPC 的可用區域和子網路。 | 開發人員、系統管理員 | 
| 新增彈性 IP 地址。 | 針對 **IPv4 地址**，為每個子網路選擇彈性 IP 地址，然後選擇**儲存**。 | 開發人員、系統管理員 | 

### 新增使用者
<a name="add-users"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IAM 角色，讓使用者存取 S3 儲存貯體。 | 建立 `Transfer`****和 新增的 IAM 角色` s3:ListBucket`` s3:GetBucketLocation`，`s3:PutObject`並使用 S3 儲存貯體名稱做為資源。如需詳細資訊，請參閱 AWS Transfer Family 文件中的[建立 IAM 角色和政策](https://docs.aws.amazon.com/transfer/latest/userguide/requirements-roles.html)。—或—您可以在 CloudFormation [主控台中部署連接的 CloudFormation ](https://console.aws.amazon.com/cloudformation) 範本 `amazon-sftp-customer.yml`，以自動化此史詩中的任務。 | 開發人員、系統管理員 | 
| 建立 S3 儲存貯體。 | 為應用程式建立 S3 儲存貯體。 | 開發人員、系統管理員 | 
| 建立選用資料夾。 | （選用） 如果您想要分別存放使用者的檔案，請在特定的 Amazon S3 資料夾中，視需要新增資料夾。 | 開發人員、系統管理員 | 
| 建立 SSH 公有金鑰。 | 若要建立 SSH 金鑰對，請參閱 AWS Transfer Family 文件中的[產生 SSH 金鑰](https://docs.aws.amazon.com/transfer/latest/userguide/key-management.html#sshkeygen)。 | 開發人員、系統管理員 | 
| 新增使用者。 | 在[AWS Transfer Family 主控台](https://console.aws.amazon.com/transfer/)上，選擇**伺服器**，選擇您建立的 SFTP 伺服器，然後選擇**新增使用者**。針對**主目錄**，選擇您建立的 S3 儲存貯體。針對 **SSH 公有金鑰**，指定 SSH 金鑰對的公有金鑰部分。新增 SFTP 伺服器的使用者，然後選擇**新增**。 | 開發人員、系統管理員 | 

### 測試 SFTP 伺服器
<a name="test-the-sftp-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新安全群組。 | 在 SFTP 伺服器**的安全群組**區段中，新增測試機器的 IP 以取得 SFTP 存取權。 | 開發人員 | 
| 使用 SFTP 用戶端公用程式來測試伺服器。 | 使用任何 SFTP 用戶端公用程式測試檔案傳輸。如需用戶端和說明的清單，請參閱 AWS Transfer Family 文件中的[使用用戶端傳輸檔案](https://docs.aws.amazon.com/transfer/latest/userguide/transfer-file.html)。 | 開發人員 | 

## 相關資源
<a name="migrate-an-on-premises-sftp-server-to-aws-using-aws-transfer-for-sftp-resources"></a>
+ [AWS Transfer Family 使用者指南](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-for-sftp.html)
+ [Amazon S3 使用者指南](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
+ Amazon EC2 文件中的[彈性 IP 地址](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html) 

## 附件
<a name="attachments-ec0a905c-edef-48ba-9b5e-ea4a4040d320"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/ec0a905c-edef-48ba-9b5e-ea4a4040d320/attachments/attachment.zip)

# 使用 AWS Application Migration Service 將內部部署 VM 遷移至 Amazon EC2
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service"></a>

*Thanh Nguyen，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-summary"></a>

進行應用程式遷移時，組織可以採取不同的方法來將應用程式伺服器從內部部署環境重新託管 （提升和轉移） 到 Amazon Web Services (AWS) 雲端。其中一種方法是佈建新的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體，然後從頭開始安裝和設定應用程式。另一種方法是使用第三方或 AWS 原生遷移服務同時遷移多個伺服器。

此模式概述使用 AWS Application Migration Service 將支援的虛擬機器 (VM) 遷移至 AWS 雲端上的 Amazon EC2 執行個體的步驟。您可以在此模式中使用 方法，手動逐一遷移一或多個虛擬機器，或根據概述的步驟建立適當的自動化指令碼來自動遷移。

## 先決條件和限制
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-prereqs"></a>

**先決條件**
+ 支援 Application Migration Service 的其中一個 AWS 區域中的作用中 AWS 帳戶
+ 使用 AWS Direct Connect 或虛擬私有網路 (VPN)，或透過網際網路，透過私有網路在來源伺服器與目標 EC2 伺服器之間建立網路連線

**限制**
+ 如需支援區域的最新清單，請參閱[支援的 AWS 區域](https://docs.aws.amazon.com/mgn/latest/ug/supported-regions.html)。
+ 如需支援的作業系統清單，請參閱[支援的作業系統](https://docs.aws.amazon.com/mgn/latest/ug/Supported-Operating-Systems.html)和 [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)*的一般*區段。

## Architecture
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-architecture"></a>

**來源技術堆疊**
+ 實體、虛擬或雲端託管伺服器，執行 Amazon EC2 支援的作業系統

**目標技術堆疊**
+ 執行與來源 VM 相同作業系統的 Amazon EC2 執行個體
+ Amazon Elastic Block Store (Amazon EBS)

**來源和目標架構**

下圖顯示解決方案的高階架構和主要元件。在內部部署資料中心中，有虛擬機器具有本機磁碟。在 AWS 上，有一個具有複寫伺服器的預備區域，以及具有 EC2 執行個體用於測試和切換的遷移資源區域。兩個子網路都包含 EBS 磁碟區。

![\[將支援的 VM 遷移至 AWS 雲端上 Amazon EC2 執行個體的主要元件。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/58c8bafd-9a6d-42d4-a5ce-08c4b9a286a3/images/f8396fad-7ee9-4f75-800f-e819f509e151.png)


1. 初始化 AWS Application Migration Service。

1. 設定預備區域伺服器組態和報告，包括預備區域資源。

1. 在來源伺服器上安裝代理程式，並使用連續的區塊層級資料複寫 （壓縮和加密）。

1. 自動化協同運作和系統轉換，以縮短切換時段。

**網路架構**

下圖顯示從聯網角度而言，解決方案的高階架構和主要元件，包括內部部署資料中心和 AWS 中主要元件之間通訊所需的通訊協定和連接埠。

![\[網路元件，包括用於資料中心和 AWS 之間通訊的通訊協定和連接埠。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/58c8bafd-9a6d-42d4-a5ce-08c4b9a286a3/images/2f594daa-ddba-4841-8785-6067e8d83c2f.png)


## 工具
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-tools"></a>
+ [AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 可協助您將應用程式重新託管 (*提升和轉移*) 至 AWS 雲端，無需變更且停機時間最短。

## 最佳實務
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-best-practices"></a>
+ 在目標 EC2 執行個體的切換完成之前，請勿讓來源伺服器離線或執行重新啟動。
+ 提供充分的機會，讓使用者在目標伺服器上執行使用者接受度測試 (UAT)，以識別和解決任何問題。理想情況下，此測試應在切換前至少兩週開始。
+ 經常監控 Application Migration Service 主控台上的伺服器複寫狀態，以及早識別問題。
+ 使用臨時 AWS Identity and Access Management (IAM) 登入資料進行代理程式安裝，而非永久的 IAM 使用者登入資料。

## 史詩
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-epics"></a>

### 產生 AWS 登入資料
<a name="generate-aws-credentials"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS 複寫代理程式 IAM 角色。 | 使用 AWS 帳戶的管理許可登入。在 AWS Identity and Access Management (IAM) [主控台](https://console.aws.amazon.com/iam/)上，建立 IAM 角色：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service.html) | AWS 管理員、遷移工程師 | 
| 產生臨時安全登入資料。 | 在已安裝 AWS Command Line Interface (AWS CLI) 的機器上，使用管理許可登入。或者 （在支援的 AWS 區域內），在 AWS 管理主控台上，使用 AWS 帳戶的管理許可登入，然後開啟 AWS CloudShell。使用下列命令產生臨時登入資料，`<account-id>`以 AWS 帳戶 ID 取代 。`aws sts assume-role --role-arn arn:aws:iam::<account-id>:role/MGN_Agent_Installation_Role --role-session-name mgn_installation_session_role`從 命令的輸出中，複製 `AccessKeyId`、 ** **`SecretAccessKey`和 的值** **`SessionToken`。** **將它們存放在安全的位置，以供日後使用。這些臨時登入資料將在一小時後過期。如果您在一小時後需要登入資料，請重複上述步驟。 | AWS 管理員、遷移工程師 | 

### 初始化 Application Migration Service 並建立複寫設定範本
<a name="initialize-application-migration-service-and-create-the-replication-settings-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 初始化服務。 | 在 主控台上，使用 AWS 帳戶的管理許可登入。選擇 **Application Migration Service**，然後選擇**開始使用**。 | AWS 管理員、遷移工程師 | 
| 建立和設定複寫設定範本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service.html)Application Migration Service 將自動建立促進資料複寫和啟動遷移伺服器所需的所有 IAM 角色。 | AWS 管理員、遷移工程師 | 

### 在來源機器上安裝 AWS 複寫代理程式
<a name="install-aws-replication-agents-on-source-machines"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備好必要的 AWS 登入資料。 | 當您在來源伺服器上執行安裝程式檔案時，您將需要輸入先前產生的臨時登入資料，包括 `AccessKeyId`、 `SecretAccessKey`和 `SessionToken`。 | 遷移工程師、AWS 管理員 | 
| 對於 Linux 伺服器，請安裝 代理程式。 | 複製安裝程式命令、登入您的來源伺服器，然後執行安裝程式。如需詳細說明，請參閱 [AWS 文件](https://docs.aws.amazon.com/mgn/latest/ug/linux-agent.html)。 | AWS 管理員、遷移工程師 | 
| 對於 Windows 伺服器，請安裝 代理程式。 | 將安裝程式檔案下載到每個伺服器，然後執行安裝程式命令。如需詳細說明，請參閱 [AWS 文件](https://docs.aws.amazon.com/mgn/latest/ug/windows-agent.html)。 | AWS 管理員、遷移工程師 | 
| 等待初始資料複寫完成。 | 安裝代理程式後，來源伺服器會顯示在 Application Migration Service 主控台的**來源伺服器**區段中。等待伺服器進行初始資料複寫。 | AWS 管理員、遷移工程師 | 

### 設定啟動設定
<a name="configure-launch-settings"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 指定伺服器詳細資訊。 | 在 Application Migration Service 主控台上，選擇**來源伺服器**區段，然後從清單中選擇伺服器名稱以存取伺服器詳細資訊。 | AWS 管理員、遷移工程師 | 
| 設定啟動設定。 | 選擇**啟動設定**索引標籤。您可以設定各種設定，包括一般啟動設定和 EC2 啟動範本設定。如需詳細說明，請參閱 [AWS 文件](https://docs.aws.amazon.com/mgn/latest/ug/launch-settings.html)。 | AWS 管理員、遷移工程師 | 

### 執行測試
<a name="perform-a-test"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試來源伺服器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service.html)將啟動伺服器。 | AWS 管理員、遷移工程師 | 
| 驗證測試是否成功完成。 | 測試伺服器完全啟動後，頁面上**的提醒**狀態會顯示每個伺服器**已啟動**。 | AWS 管理員、遷移工程師 | 
| 測試伺服器。 | 針對測試伺服器執行測試，以確保其如預期般運作。 | AWS 管理員、遷移工程師 | 

### 排程和執行切換
<a name="schedule-and-perform-a-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 排程切換時段。 | 與相關團隊安排適當的切換時間範圍。 | AWS 管理員、遷移工程師 | 
| 執行切換。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service.html)來源伺服器的**遷移生命週期**將變更為**進行中的切換**。 | AWS 管理員、遷移工程師 | 
| 驗證切換是否成功完成。 | 切換伺服器完全啟動後，**來源伺服器**頁面上的**提醒**狀態會顯示每個伺服器**已啟動**。 | AWS 管理員、遷移工程師 | 
| 測試伺服器。 | 針對切換伺服器執行測試，以確保其如預期般運作。 | AWS 管理員、遷移工程師 | 
| 完成切換。 | 選擇**測試和切換**，然後選擇**完成切換**以完成遷移程序。 | AWS 管理員、遷移工程師 | 

## 相關資源
<a name="migrate-an-on-premises-vm-to-amazon-ec2-by-using-aws-application-migration-service-resources"></a>
+ [AWS Application Migration Service](https://aws.amazon.com/application-migration-service/)
+ [AWS Application Migration Service 使用者指南](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)

# 使用 將小型資料集從內部部署遷移至 Amazon S3 AWS SFTP
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp"></a>

*Charles Gibson 和 Sergiy Shevchenko，Amazon Web Services*

## 總結
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp-summary"></a>

此模式說明如何使用 AWS Transfer for SFTP () 將小型資料集 (5 TB 或更少） 從內部部署資料中心遷移至 Amazon Simple Storage Service (Amazon S3)AWS SFTP。資料可以是資料庫傾印或一般檔案。

## 先決條件和限制
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 您的資料中心與 之間建立 AWS Direct Connect 的連結 AWS

**限制**
+ 資料檔案必須小於 5 TB。對於超過 5 TB 的檔案，您可以執行分段上傳至 Amazon S3 或選擇其他資料傳輸方法。 

## Architecture
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp-architecture"></a>

**來源技術堆疊**
+ 內部部署平面檔案或資料庫傾印

**目標技術堆疊**
+ Amazon S3

**來源和目標架構**

![\[Diagram showing data flow from on-premises servers to AWS 雲端 services via Direct Connect and VPN.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a9c016ff-3e68-4714-ac51-46cb4727397a/images/5c5bb9ea-d552-44e8-8d0d-df341f84f55d.png)


## 工具
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp-tools"></a>
+ [AWS SFTP](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-for-sftp.html) – 啟用使用安全檔案傳輸通訊協定 (SFTP) 將檔案直接傳入和傳出 Amazon S3。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) – 從現場部署資料中心建立專用網路連線 AWS。
+ [VPC 端點](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints.html) – 可讓您在沒有網際網路閘道、網路位址轉譯 (NAT) 裝置、VPN 連線或 Direct Connect 連線 AWS PrivateLink 的情況下，將 VPC 私下連線至支援的 AWS 服務 和採用 技術的 VPC 端點服務。VPC 中的執行個體不需要公有 IP 地址，即可與 服務中的資源通訊。

## 史詩
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 記錄目前的 SFTP 要求。 |  | 應用程式擁有者、SA | 
| 識別身分驗證需求。 | 要求可能包括金鑰型身分驗證、使用者名稱或密碼，或身分提供者 (IdP)。 | 應用程式擁有者、SA | 
| 識別應用程式整合需求。 |  | 應用程式擁有者 | 
| 識別需要 服務的使用者。 |  | 應用程式擁有者 | 
| 判斷 SFTP 伺服器端點的 DNS 名稱。 |  | 聯網 | 
| 決定備份策略。 |  | SA、DBA （如果傳輸資料）  | 
| 識別應用程式遷移或切換策略。 |  | 應用程式擁有者、SA、DBA | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 中建立一或多個虛擬私有雲端 (VPCs) 和子網路 AWS 帳戶。 |  | 應用程式擁有者、AMS | 
| 建立安全群組和網路存取控制清單 (ACL)。 |  | 安全性、聯網、AMS | 
| 建立 Amazon S3 儲存貯體。 |  | 應用程式擁有者、AMS | 
| 建立 AWS Identity and Access Management (IAM) 角色。 | 建立 IAM 政策，其中包含允許 AWS SFTP 存取 Amazon S3 儲存貯體的許可。此 IAM 政策決定您提供 SFTP 使用者的存取層級。建立另一個 IAM 政策以與 建立信任關係 AWS SFTP。 | 安全性、AMS | 
| 關聯已註冊的網域 （選用）。 | 如果您有自己的註冊網域，您可以將其與 SFTP 伺服器建立關聯。您可以將 SFTP 流量從網域或子網域路由到 SFTP 伺服器端點。 | 網路、AMS | 
| 建立 SFTP 伺服器。 | 指定 服務用來驗證使用者的身分提供者類型。 | 應用程式擁有者、AMS | 
| 開啟 SFTP 用戶端。 | 開啟 SFTP 用戶端，並將連線設定為使用 SFTP 端點主機。 AWS SFTP 支援任何標準 SFTP 用戶端。常用的 SFTP 用戶端包括 OpenSSH、WinSCP、Cyberduck 和 FileZilla。您可以從 AWS SFTP 主控台取得 SFTP 伺服器主機名稱。 | 應用程式擁有者、AMS | 

### 規劃和測試
<a name="plan-and-test"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 規劃應用程式遷移。 | 規劃所需的任何應用程式組態變更、設定遷移日期，以及判斷測試排程。 | 應用程式擁有者、AMS | 
| 測試基礎設施。 | 在非生產環境中進行測試。 | 應用程式擁有者、AMS | 

## 相關資源
<a name="migrate-small-sets-of-data-from-on-premises-to-amazon-s3-using-aws-sftp-resources"></a>

**參考**
+ [AWS Transfer for SFTP 使用者指南](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-for-sftp.html)
+ [AWS Direct Connect resources](https://aws.amazon.com/directconnect/resources/) 
+ [VPC 端點](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints.html)

**教學課程和影片**
+ [AWS Transfer for SFTP （影片）](https://www.youtube.com/watch?v=wcnGez5PP1E)
+ [AWS Transfer for SFTP 使用者指南](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-for-sftp.html)
+ [AWS SA 白板 - Direct Connect （影片）](https://www.youtube.com/watch?v=uP68iqyuqTg)

# 將內部部署 Oracle 資料庫遷移至 Amazon EC2 上的 Oracle
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2"></a>

*Baji Shaik 和 Pankaj Choudhary，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2-summary"></a>

此模式會逐步解說在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上將內部部署 Oracle 資料庫遷移至 Oracle 的步驟。它描述了遷移的兩個選項：使用 AWS Data Migration Service (AWS DMS) 或使用 RMAN、Data Pump 匯入/匯出、可傳輸資料表空間和 Oracle GoldenGate 等原生 Oracle 工具。

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的來源 Oracle 資料庫

**限制**
+ Amazon EC2 必須支援目標作業系統 (OS)。如需支援系統的完整清單，請參閱 [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)。

**產品版本**
+ 適用於 Enterprise、Standard、Standard One 和 Standard Two 等版本的 Oracle 10.2 版和更新版本 (適用於 10.x 版)、11g 版且最高可達 12.2 版，以及 18c 版。如需 AWS DMS 支援的最新版本清單，請參閱 AWS DMS 文件中的[資料遷移來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.html)中的「內部部署和 Amazon EC2 執行個體資料庫」。  

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫

**目標技術堆疊**
+ Amazon EC2 上的 Oracle 資料庫執行個體

**目標架構**

![\[在 Amaozn EC2 上設定 Oracle 資料庫的複寫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/66c98694-6580-4ffb-9f16-84de58cf8b07/images/386d5b14-8633-4ecc-98fb-59872de99d41.png)


**資料遷移架構**

*使用 AWS DMS：*

![\[使用 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon EC2。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/66c98694-6580-4ffb-9f16-84de58cf8b07/images/14954066-d22b-486a-a432-265296752878.png)


*使用原生 Oracle 工具：*

![\[使用 Oracle 工具將內部部署 Oracle 資料庫遷移至 Amazon EC2。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/66c98694-6580-4ffb-9f16-84de58cf8b07/images/82ba5fcb-8640-45fa-b432-2702dedc0774.png)


## 工具
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2-tools"></a>
+ **AWS DMS -**[AWS Database Migration Services](https://docs.aws.amazon.com/dms/index.html)(AWS DMS) 支援多種類型的來源和目標資料庫。如需有關支援的資料庫版本和版本的資訊，請參閱[使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。 
+ **原生 Oracle 工具 -**RMAN、Data Pump 匯入/匯出、可傳輸資料表空間、Oracle GoldenGate                                                         

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  驗證來源和目標資料庫的版本。 |  | DBA | 
|  識別目標作業系統的版本。 |  | DBA、SysAdmin | 
| 根據 Oracle 相容性清單和容量需求，識別目標伺服器執行個體的硬體需求。 |  | DBA、SysAdmin | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA、SysAdmin | 
| 識別網路需求 （延遲和頻寬）。 |  | DBA、SysAdmin | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路/主機存取安全需求。 |  | DBA、SysAdmin | 
| 識別 Oracle 軟體安裝所需的作業系統使用者清單。 |  | DBA、SysAdmin | 
| 下載 AWS Schema Conversion Tool (AWS SCT) 和驅動程式。 |  | DBA | 
| 為工作負載建立 AWS SCT 專案，並連線至來源資料庫。 |  | DBA | 
| 產生 SQL 檔案以建立物件 （資料表、索引、序列等）。 |  | DBA | 
| 決定備份策略。 |  | DBA、SysAdmin  | 
| 判斷可用性需求。 |  | DBA | 
| 識別應用程式遷移/切換策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在您的 AWS 帳戶中建立虛擬私有雲端 (VPC) 和子網路。 |  | SysAdmin | 
| 建立安全群組和網路存取控制清單 ACLs)。 |  | SysAdmin | 
| 設定和啟動 EC2 執行個體。 |  | SysAdmin | 

### 安裝 Oracle 軟體
<a name="install-the-oracle-software"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Oracle 軟體所需的作業系統使用者和群組。 |  | DBA、SysAdmin | 
| 下載必要的 Oracle 軟體版本。 |  |  | 
| 在 EC2 執行個體上安裝 Oracle 軟體。 |  | DBA、SysAdmin | 
| 使用 AWS SCT 產生的指令碼建立物件，例如資料表、主索引鍵、檢視和序列。 |  | DBA | 

### 遷移資料 - 選項 1
<a name="migrate-data---option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生 Oracle 工具或第三方工具來遷移資料庫物件和資料。 | Oracle 工具包括 Data Pump 匯入/匯出、RMAN、可傳輸資料表空間和 GoldenGate。 | DBA | 

### 遷移資料 - 選項 2
<a name="migrate-data---option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定遷移方法。 |  | DBA | 
| 在 AWS DMS 主控台中建立複寫執行個體。 |  | DBA | 
| 建立來源和目標端點。 |  | DBA | 
| 建立複寫任務。 |  | DBA | 
| 啟用變更資料擷取 (CDC) 以擷取連續複寫的變更。 |  | DBA | 
| 執行複寫任務並監控日誌。 |  | DBA | 
| 完成完全載入時，建立次要物件，例如索引和外部索引鍵。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式切換/切換策略。 |  | DBA、SysAdmin、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS Secrets Manager 資源。 |  | DBA、SysAdmin | 
| 檢閱並驗證專案文件。 |  | DBA、SysAdmin、應用程式擁有者 | 
| 收集遷移時間的指標、手動與工具的 %、節省成本等。 |  | DBA、SysAdmin、應用程式擁有者 | 
| 關閉專案並提供意見回饋。 |  |  | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2-resources"></a>

**參考**
+ [將 Oracle 資料庫遷移至 AWS 的策略](https://docs.aws.amazon.com/whitepapers/latest/strategies-migrating-oracle-db-to-aws/strategies-migrating-oracle-db-to-aws.html) 
+ [將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/)
+ [Amazon EC2 網站](https://aws.amazon.com/ec2/)
+ [AWS DMS 網站](https://aws.amazon.com/dms/)
+ [AWS DMS 部落格文章](https://aws.amazon.com/blogs/database/category/dms/)
+ [Amazon EC2 定價](https://aws.amazon.com/ec2/pricing/)
+ [在雲端運算環境中授權 Oracle 軟體](http://www.oracle.com/us/corporate/pricing/cloud-licensing-070579.pdf)

**教學課程和影片**
+ [Amazon EC2 入門](https://aws.amazon.com/ec2/getting-started/)
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [Amazon EC2 簡介 - Elastic Cloud Server & Hosting with AWS （影片）](https://www.youtube.com/watch?v=TsRBftzZsQo) 

# 使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon EC2
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump"></a>

*Navakanth Talluri，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-summary"></a>

遷移資料庫時，您必須考慮來源和目標資料庫引擎和版本、遷移工具和服務，以及可接受的停機時間期間等因素。如果您要將現場部署 Oracle 資料庫遷移至 Amazon Elastic Compute Cloud (Amazon EC2)，您可以使用 Oracle 工具，例如 Oracle Data Pump 和 Oracle Recovery Manager (RMAN)。如需策略的詳細資訊，請參閱[將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html)。

Oracle Data Pump 可協助您擷取資料庫的邏輯一致備份，並將其還原至目標 EC2 執行個體。此模式說明如何使用 Oracle Data Pump 和 `NETWORK_LINK` 參數，將現場部署 Oracle 資料庫遷移至 EC2 執行個體，並將停機時間降至最低。`NETWORK_LINK` 參數會透過資料庫連結開始匯入。目標 EC2 執行個體上的 Oracle Data Pump Import (impdp) 用戶端會連線至來源資料庫、從中擷取資料，以及將資料直接寫入目標執行個體上的資料庫。此解決方案中沒有使用的備份或*傾印*檔案。

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署 Oracle 資料庫：
  + 不是 Oracle Real Application Clusters (RAC) 資料庫
  + 不是 Oracle Automatic Storage Management (Oracle ASM) 資料庫
  + 處於讀寫模式。
+ 您已在內部部署資料中心和 AWS 之間建立 AWS Direct Connect 連結。如需詳細資訊，請參閱[建立連線](https://docs.aws.amazon.com/directconnect/latest/UserGuide/create-connection.html) (Direct Connect 文件）。

**產品版本**
+ Oracle 資料庫 10g 版本 1 (10.1) 和更新版本

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-architecture"></a>

**來源技術堆疊**
+ 內部部署資料中心中的獨立 （非 ASM 和非 ASM) Oracle 資料庫伺服器

**目標技術堆疊**
+ 在 Amazon EC2 上執行的 Oracle 資料庫

**目標架構**

AWS Well-Architected Framework 的[可靠性支柱](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/welcome.html)建議建立資料備份，以協助提供高可用性和彈性。如需詳細資訊，請參閱在 *AWS 上執行 Oracle 資料庫的最佳實務*中的[高可用性架構](https://docs.aws.amazon.com/whitepapers/latest/oracle-database-aws-best-practices/architecting-for-high-availability.html#amazon-ec2)。此模式會使用 Oracle Active Data Guard 在 EC2 執行個體上設定主要和待命資料庫。為了獲得高可用性，EC2 執行個體應該位於不同的可用區域。不過，可用區域可以位於相同的 AWS 區域或不同的 AWS 區域。

Active Data Guard 提供實體待命資料庫的唯讀存取權，並持續從主要資料庫套用重做變更。根據您的復原點目標 (RPO) 和復原時間目標 (RTO)，您可以選擇同步和非同步重做傳輸選項。

如果主要和待命 EC2 執行個體位於不同的 AWS 區域，下圖會顯示目標架構。

![\[連接至主要 EC2 執行個體上新資料庫的應用程式\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bdd49395-2f99-43e2-ad1d-a1d09d90fb58/images/37fcd4dc-5516-416b-a280-0c5f002880de.png)


**資料遷移架構**

完成目標架構的設定後，您可以使用 Oracle Data Pump 將內部部署資料和結構描述遷移至主要 EC2 執行個體。在切換期間，應用程式無法存取現場部署資料庫或目標資料庫。您可以關閉這些應用程式，直到它們可以連接到主要 EC2 執行個體上的新目標資料庫為止。

下圖顯示資料遷移期間的架構。在此範例架構中，主要和待命 EC2 執行個體位於不同的 AWS 區域。

![\[來源資料庫會連線至目標資料庫。應用程式與來源和目標DBs中斷連線\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bdd49395-2f99-43e2-ad1d-a1d09d90fb58/images/c58b669b-b11f-4d78-8911-c07b81b7c6a0.png)


## 工具
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-tools"></a>

**AWS 服務**
+ [AWS Direct Connect](https://aws.amazon.com/directconnect/) 透過標準乙太網路光纖纜線，將您的內部網路連結至 Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的虛擬介面，同時略過網路路徑中的網際網路服務供應商。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。

**其他工具和服務**
+ [Oracle Active Data Guard](https://docs.oracle.com/en/database/oracle/oracle-database/21/sbydb/introduction-to-oracle-data-guard-concepts.html#GUID-5E73667D-4A56-445E-911F-1E99092DD8D7) 可協助您建立、維護、管理和監控待命資料庫。
+ [Oracle Data Pump](https://www.oracle.com/technetwork/documentation/data-pump-overview-084963.html) 可協助您以高速將資料和中繼資料從一個資料庫移至另一個資料庫。

## 最佳實務
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-best-practices"></a>
+ [在 AWS 上執行 Oracle Database 的最佳實務](https://docs.aws.amazon.com/whitepapers/latest/oracle-database-aws-best-practices/architecting-for-security-and-performance.html)
+ [使用 NETWORK\$1LINK 匯入資料](https://docs.oracle.com/database/121/SUTIL/GUID-23E58D59-A477-4A87-BD0E-C82447581D0A.htm#SUTIL856)

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-epics"></a>

### 在 AWS 上設定 EC2 執行個體
<a name="set-up-the-ec2-instances-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別現場部署主機的來源硬體組態和核心參數。 | 驗證內部部署組態，包括儲存大小、每秒輸入/輸出操作 (IOPS) 和 CPU。這對以 CPU 核心為基礎的 Oracle 授權很重要。 | DBA、SysAdmin | 
| 在 AWS 上建立基礎設施。 | 建立虛擬私有雲端 (VPCs)、私有子網路、安全群組、網路存取控制清單 ACLs)、路由表和網際網路閘道。如需詳細資訊，請參閱下列內容：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.html) | DBA、AWS 系統管理員 | 
| 使用 Active Data Guard 設定 EC2 執行個體。 | 使用 Active Data Guard 組態來設定 AWS EC2 執行個體，如 [AWS Well-Architected Framework](https://docs.aws.amazon.com/wellarchitected/latest/framework/welcome.html) 中所述。EC2 執行個體上的 Oracle 資料庫版本可能與內部部署版本不同，因為此模式使用邏輯備份。注意下列事項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.html)如需詳細資訊，請參閱：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.html) | DBA、AWS 系統管理員 | 

### 將資料庫遷移至 Amazon EC2
<a name="migrate-the-database-to-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 EC2 執行個體建立內部部署資料庫的 dblink。 | 在 EC2 執行個體上的 Oracle 資料庫與內部部署 Oracle 資料庫之間建立資料庫連結 (dblink)。如需詳細資訊，請參閱[使用網路連結匯入移動資料](https://docs.oracle.com/database/121/SUTIL/GUID-3E1D4B46-E856-4ABE-ACC5-977A898BB0F1.htm#SUTIL806) (Oracle 文件）。 | DBA | 
| 驗證 EC2 執行個體與內部部署主機之間的連線。 | 使用 dblink 確認 EC2 執行個體與內部部署資料庫之間的連線正常運作。如需說明，請參閱 [CREATE DATABASE LINK](https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm) (Oracle 文件）。 | DBA | 
| 停止所有連接到現場部署資料庫的應用程式。 | 核准資料庫停機時間後，請關閉任何包含到現場部署資料庫的應用程式和相依任務。您可以直接從應用程式或使用 cron 從資料庫執行此操作。如需詳細資訊，請參閱[使用 Crontab 公用程式在 Oracle Linux 上排程任務](https://docs.oracle.com/en/learn/oracle-linux-crontab/index.html)。 | DBA，應用程式開發人員 | 
| 排程資料遷移任務。 | 在目標主機上，使用 命令`impdb`來排程 Data Pump 匯入。這會將目標資料庫連接到現場部署主機，並啟動資料遷移。如需詳細資訊，請參閱 [Data Pump Import](https://docs.oracle.com/database/121/SUTIL/GUID-D11E340E-14C6-43B8-AB09-6335F0C1F71B.htm#SUTIL300) 和 [NETWORK\$1LINK](https://docs.oracle.com/database/121/SUTIL/GUID-0871E56B-07EB-43B3-91DA-D1F457CF6182.htm#SUTIL919) (Oracle 文件）。 | DBA | 
| 驗證資料遷移。 | 資料驗證是重要的步驟。對於資料驗證，您可以使用自訂工具或 Oracle 工具，例如 dblink 和 SQL 查詢的組合。 | DBA | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將來源資料庫置於唯讀模式。 | 確認應用程式已關閉，且未對來源資料庫進行任何變更。以唯讀模式開啟來源資料庫。這可協助您避免任何開啟的交易。如需詳細資訊，請參閱 [SQL 陳述](https://docs.oracle.com/database/121/SQLRF/statements_1006.htm#i2135540)式`ALTER DATABASE`中的 (Oracle 文件）。 | DBA、DevOps 工程師、應用程式開發人員 | 
| 驗證物件計數和資料。 | 若要驗證資料和物件，請使用自訂工具或 Oracle 工具，例如 dblink 和 SQL 查詢的組合。 | DBA，應用程式開發人員 | 
| 將應用程式連接至主要 EC2 執行個體上的資料庫。 | 變更應用程式的連線屬性，以指向您在主要 EC2 執行個體上建立的新資料庫。 | DBA，應用程式開發人員 | 
| 驗證應用程式效能。 | 啟動應用程式。使用[自動化工作負載儲存庫](https://docs.oracle.com/database/121/RACAD/GUID-C3CD2DCE-38BD-46BA-BC32-7A28CAC9A7FD.htm#RACAD951) (Oracle 文件） 驗證應用程式的功能和效能。 | 應用程式開發人員、DevOps 工程師、DBA | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump-resources"></a>

**AWS 參考**
+ [將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html)
+ [Amazon EC2 for Oracle](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/ec2-oracle.html)
+ [將大量 Oracle 資料庫遷移至跨平台環境的 AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migrate-bulky-oracle-databases/welcome.html)
+ [VPCs和子網路](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html)
+ [教學課程：建立 VPC 以與資料庫執行個體搭配使用](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateVPC.html)

**Oracle 參考**
+ [Oracle Data Guard 組態](https://docs.oracle.com/en/database/oracle/oracle-database/21/sbydb/introduction-to-oracle-data-guard-concepts.html#GUID-AB9DF863-2C7E-4767-81F2-56AD0FA30B49)
+ [資料幫浦匯入](https://docs.oracle.com/database/121/SUTIL/GUID-D11E340E-14C6-43B8-AB09-6335F0C1F71B.htm#SUTIL300)

# 使用 AWS MGN 將 RHEL BYOL 系統遷移至包含 AWS 授權的執行個體
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn"></a>

*Mike Kuznetsov，Amazon Web Services*

## 摘要
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn-summary"></a>

當您使用 AWS Application Migration Service (AWS MGN) 將工作負載遷移至 AWS 時，您可能需要在遷移期間將 Red Hat Enterprise Linux (RHEL) 執行個體提升和轉移 （恢復），並將授權從預設自帶授權 (BYOL) 模型變更為 AWS License Included (LI) 模型。AWS MGN 支援使用 Amazon Machine Image (AMI) IDs可擴展方法。此模式說明如何在大規模重新託管遷移期間，在 RHEL 伺服器上完成授權變更。它還說明如何變更已在 Amazon Elastic Compute Cloud (Amazon EC2) 上執行的 RHEL 系統授權。

## 先決條件和限制
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn-prereqs"></a>

**先決條件**
+ 存取目標 AWS 帳戶
+ 在目標 AWS 帳戶和區域中初始化的 AWS MGN 以進行遷移 （如果您已經從現場部署系統遷移至 AWS，則不需要）
+ 具有有效 RHEL 授權的來源 RHEL 伺服器

## Architecture
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn-architecture"></a>

此模式涵蓋兩個案例：
+ 使用 AWS MGN 將系統從內部部署直接遷移到 AWS LI 執行個體。在此案例中，請遵循第一個 epic (*遷移至 LI 執行個體 - 選項 1*) 和第三個 epic 中的指示。
+ 針對已在 Amazon EC2 上執行的先前遷移 RHEL 系統，將授權模型從 BYOL 變更為 LI。在此案例中，請遵循第二個 epic (*遷移至 LI 執行個體* - *選項 2*) 和第三個 epic 中的指示。

**注意**  
第三個史詩涉及重新設定新的 RHEL 執行個體，以使用 AWS 提供的 Red Hat Update Infrastructure (RHUI) 伺服器。這兩個案例的此程序都相同。

## 工具
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn-tools"></a>

**AWS 服務**
+ [AWS Application Migration Service (AWS MGN)](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 可協助您將應用程式重新託管 （提升和轉移） 至 AWS 雲端，無需變更且停機時間最短。

## 史詩
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn-epics"></a>

### 遷移至 LI 執行個體 - 選項 1 （適用於內部部署 RHEL 系統）
<a name="migrate-to-li-instance---option-1-for-an-on-premises-rhel-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 尋找目標區域中 RHEL AWS LI 執行個體的 AMI ID。 | 請造訪 [AWS Marketplace](https://aws.amazon.com/marketplace) 或使用 [Amazon EC2 主控台](https://console.aws.amazon.com/ec2/)尋找符合 RHEL 來源系統版本的 RHEL AMI ID （例如 RHEL-7.7)，然後寫下 AMI ID。在 Amazon EC2 主控台上，您可以使用下列其中一個搜尋詞彙來篩選 AMIs：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html) | 雲端管理員 | 
| 設定 AWS MGN 啟動設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html)AWS MGN 現在將使用此版本的啟動範本來啟動測試或切換執行個體。如需詳細資訊，請參閱 [AWS MGN 文件](https://docs.aws.amazon.com/mgn/latest/ug/ec2-launch.html)。 | 雲端管理員 | 
| 驗證設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html) | 雲端管理員 | 
| 啟動新的 LI 執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html) | 雲端管理員 | 

### 遷移至 LI 執行個體 - 選項 2 （適用於 RHEL BYOL EC2 執行個體）
<a name="migrate-to-li-instance---option-2-for-a-rhel-byol-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 RHEL BYOL EC2 執行個體遷移至 AWS LI 執行個體。 | 您可以透過移動 RHEL 系統磁碟 (Amazon Elastic Block Store 磁碟區） 並將其連接至新的 LI 執行個體，將先前以 BYOL 形式遷移至 AWS 的 RHEL 系統切換至 AWS LI 執行個體。若要進行此切換，請依照下列步驟進行：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html) | 雲端管理員 | 

### 重新設定 RHEL 作業系統以使用 AWS 提供的 RHUI – 這兩個選項
<a name="reconfigure-rhel-os-to-use-aws-provided-rhui-ndash-both-options"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Red Hat 訂閱和授權取消註冊作業系統。 | 在遷移和成功切換後，必須從 Red Hat 訂閱中移除 RHEL 系統，以停止耗用 Red Hat 授權並避免重複計費。若要從 Red Hat 訂閱中移除 RHEL 作業系統，請遵循 [Red Hat 訂閱管理 (RHSM) 文件](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/installation_guide/chap-subscription-management-unregistering)中所述的程序。使用 CLI 命令： <pre>subscription-manager unregister</pre>您也可以停用訂閱管理員外掛程式，以停止檢查每次 **yum** 呼叫的訂閱狀態。若要這樣做，請編輯組態檔案並將 參數`/etc/yum/pluginconf.d/subscription-manager.conf`變更為 `enabled=1` `enabled=0`。 | Linux 或系統管理員 | 
| 使用 AWS 提供的 RHUI 取代舊的更新組態 (RHUI、Red Hat Satellite 網路、yum 儲存庫）。 | 您必須重新設定遷移的 RHEL 系統，才能使用 AWS 提供的 RHUI 伺服器。這可讓您存取 AWS 區域內的 RHUI 伺服器，而不需要外部更新基礎設施。變更包含下列程序：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html)以下是詳細的步驟和命令：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn.html) | Linux 或系統管理員 | 
| 驗證組態。 | 在目標遷移執行個體上，驗證新組態是否正確：<pre>sudo yum clean all <br />sudo yum repolist </pre> | Linux 或系統管理員 | 

## 相關資源
<a name="migrate-rhel-byol-systems-to-aws-license-included-instances-by-using-aws-mgn-resources"></a>
+ [AWS Application Migration Service (AWS MGN) 使用者指南](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)
+ [取得支援 IMDSv2 的 AWS RHUI 用戶端套件](https://access.redhat.com/solutions/5009491) (Red Hat 知識庫文章）
+ [Amazon EC2 啟動範本](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html) (Amazon EC2 文件）

# 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2"></a>

*Senthil Ramasamy，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-summary"></a>

此模式說明如何將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 Microsoft SQL Server。它涵蓋兩個遷移選項：使用 AWS Database Migration Service (AWS DMS) 或使用原生 Microsoft SQL Server 工具，例如備份和還原、複製資料庫精靈，或複製和連接資料庫。

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ Amazon EC2 支援的作業系統 （如需支援作業系統版本的完整清單，請參閱 [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/))
+ 內部部署資料中心中的 Microsoft SQL Server 來源資料庫

**產品版本**
+ 對於內部部署和 Amazon EC2 執行個體資料庫， AWS DMS 支援：
  + SQL Server 2005、2008、2008R2、2012、2014、2016、2017 和 2019 版 
  + 企業、標準、工作群組、開發人員和 Web 版本
+ 如需支援版本的最新清單，請參閱[使用 Microsoft SQL Server 資料庫做為目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.SQLServer.html)。  

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-architecture"></a>

**來源技術堆疊**
+ 內部部署 Microsoft SQL Server 資料庫

**目標技術堆疊**
+ EC2 執行個體上的 Microsoft SQL Server 資料庫

**目標架構**

![\[兩個可用區域中 EC2 執行個體上的主要和待命 Microsoft SQL Server 執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f0a155b3-4977-4e1f-8332-89eab29c1e25/images/53e2c27d-ceb4-4d88-a022-93dd0b343eaf.png)


**資料遷移架構**
+ 使用 AWS DMS

![\[使用 AWS DMS 將內部部署 SQL Server 資料遷移至 EC2 執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f0a155b3-4977-4e1f-8332-89eab29c1e25/images/1cbe32ea-e285-4cac-9153-4428bad9b229.png)

+ 使用原生 SQL Server 工具 

![\[使用原生 SQL Server 工具，將內部部署 SQL Server 資料遷移至 EC2 執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f0a155b3-4977-4e1f-8332-89eab29c1e25/images/ad2caf54-7399-4038-91a3-acba9fa7da29.png)


## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/) 可協助您將資料遷移至廣泛使用的商業和開放原始碼資料庫，包括 Oracle、SQL Server、MySQL 和 PostgreSQL。您可以使用 AWS DMS 將資料遷移到 AWS 雲端、內部部署執行個體之間 （透過 AWS 雲端 設定），或雲端和內部部署設定的組合之間。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 透過自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，支援異質資料庫遷移。
+ 原生 Microsoft SQL Server 工具包括備份和還原、複製資料庫精靈，以及複製和連接資料庫。

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本。 |  | DBA | 
| 識別目標作業系統版本。 |  | DBA，系統管理員 | 
| 根據 Microsoft SQL Server 相容性清單和容量需求，識別目標伺服器執行個體的硬體需求。 |  | DBA，系統管理員 | 
| 識別 類型和容量的儲存需求。 |  | DBA，系統管理員 | 
| 識別網路需求，包括延遲和頻寬。 |  | DBA，系統管理員 | 
| 根據容量、儲存功能和網路功能選擇 EC2 執行個體類型。 |  | DBA，系統管理員 | 
| 識別來源和目標資料庫的網路和主機存取安全需求。 |  | DBA，系統管理員 | 
| 識別 Microsoft SQL Server 軟體安裝所需的使用者清單。 |  | DBA，系統管理員 | 
| 決定備份策略。 |  | DBA | 
| 判斷可用性需求。 |  | DBA | 
| 識別應用程式遷移和切換策略。 |  | DBA，系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立虛擬私有雲端 (VPC) 和子網路。 |  | 系統管理員 | 
| 建立安全群組和網路存取控制清單 (ACL)。 |  | 系統管理員 | 
| 設定和啟動 EC2 執行個體。 |  | 系統管理員 | 

### 安裝軟體
<a name="install-the-software"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Microsoft SQL Server 軟體所需的使用者和群組。 |  | DBA，系統管理員 | 
| 下載 Microsoft SQL Server 軟體。 |  | DBA，系統管理員 | 
| 在 EC2 執行個體上安裝 Microsoft SQL Server 軟體並設定伺服器。 |  | DBA，系統管理員 | 

### 遷移資料 - 選項 1
<a name="migrate-the-data---option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生 Microsoft SQL Server 工具或第三方工具來遷移資料庫物件和資料。 | 工具包括備份和還原、複製資料庫精靈，以及複製和連接資料庫。如需詳細資訊，請參閱將 [Microsoft SQL Server 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-sql-server/)指南。 | DBA | 

### 遷移資料 - 選項 2
<a name="migrate-the-data---option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS DMS 遷移資料。 | 如需使用 的詳細資訊 AWS DMS，請參閱[相關資源](#migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-resources)區段中的連結。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 | 使用 AWS Schema Conversion Tool (AWS SCT) 來分析和修改內嵌在應用程式原始碼中的 SQL 程式碼。 | DBA、應用程式擁有者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式切換策略。 |  | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉所有臨時 AWS 資源。 | 暫時資源包括 的 AWS DMS 複寫執行個體和 EC2 執行個體 AWS SCT。 | DBA，系統管理員 | 
| 檢閱並驗證專案文件。 |  | DBA、應用程式擁有者、系統管理員 | 
| 收集遷移時間、手動與工具成本節省百分比等指標。 |  | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案並提供意見回饋。 |  | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2-resources"></a>

**參考**
+ [將 Microsoft SQL Server 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-sql-server/)
+ [Amazon EC2](https://aws.amazon.com/ec2/)
+ [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)
+ [Amazon EC2 定價](https://aws.amazon.com/ec2/pricing/)
+ [AWS Database Migration Service](https://aws.amazon.com/dms/)
+ [上的 Microsoft 產品 AWS](https://aws.amazon.com/windows/products/)
+ [上的 Microsoft 授權 AWS](https://aws.amazon.com/windows/resources/licensing/)
+ [上的 Microsoft SQL Server AWS](https://aws.amazon.com/windows/products/sql/)

**教學課程和影片**
+ [Amazon EC2 入門](https://aws.amazon.com/ec2/getting-started/)
+ [開始使用 ](https://aws.amazon.com/dms/getting-started/)AWS Database Migration Service
+ [將 Amazon EC2 執行個體加入您的 Simple AD Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/simple_ad_join_instance.html)
+ [將 Amazon EC2 執行個體加入您的 AWS Managed Microsoft AD Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_join_instance.html)
+ [AWS Database Migration Service](https://www.youtube.com/watch?v=zb4GcjEdl8U)（影片）
+ [Amazon EC2 簡介 – Elastic Cloud Server & Hosting with AWS](https://www.youtube.com/watch?v=TsRBftzZsQo) （影片）

# 在 AWS 雲端中重新託管內部部署工作負載：遷移檢查清單
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist"></a>

*Srikanth Rangavajhala，Amazon Web Services*

## 總結
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist-summary"></a>

在 Amazon Web Services (AWS) 雲端中重新託管內部部署工作負載涉及下列遷移階段：規劃、探索前、探索、建置、測試和切換。此模式概述階段及其相關任務。這些任務是以高層級描述，並支援大約 75% 的所有應用程式工作負載。您可以在敏捷的衝刺週期中，在兩到三週內實作這些任務。

您應該與您的遷移團隊和顧問一起檢閱和審核這些任務。檢閱後，您可以收集輸入、視需要消除或重新評估任務，以符合您的需求，並修改其他任務以支援您產品組合中至少 75% 的應用程式工作負載。然後，您可以使用 Atlassian Jira 或 Rally Software 等敏捷的專案管理工具來匯入任務、將任務指派給資源，以及追蹤遷移活動。 

模式假設您使用 [AWS Cloud Migration Factory](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/solution-overview.html) 來重新託管工作負載，但您可以使用您選擇的遷移工具。

Amazon Macie 可協助識別知識庫中的敏感資料，並將其儲存為 Amazon Simple Storage Service (Amazon S3) 儲存貯體中的資料來源、模型調用日誌和提示存放區。如需詳細資訊，請參閱 [Macie 文件](https://docs.aws.amazon.com/macie/latest/user/data-classification.html)。

## 先決條件和限制
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist-prereqs"></a>

**先決條件**
+ 用於追蹤遷移任務的專案管理工具 （例如，Atlassian Jira 或 Rally Software)
+ 在 AWS 上重新託管工作負載的遷移工具 （例如，[Cloud Migration Factory](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/solution-overview.html))

## Architecture
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist-architecture"></a>

**來源平台**
+ 內部部署來源堆疊 （包括技術、應用程式、資料庫和基礎設施）  

**目標平台**
+ AWS 雲端目標堆疊 （包括技術、應用程式、資料庫和基礎設施） 

**架構**

下圖說明使用 Cloud Migration Factory 和 AWS Application Migration Service 重新託管 （從內部部署來源環境探索並將伺服器遷移至 AWS)。

![\[使用 Cloud Migration Factory 和 Application Migration Service 在 AWS 上重新託管伺服器\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8e2d2d72-30cc-4e98-8abd-ac2ef95e599b/images/735ad65b-2646-4803-82c9-f7f93369b3a5.png)


## 工具
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist-tools"></a>
+ 您可以使用您選擇的遷移和專案管理工具。

## 史詩
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist-epics"></a>

### 規劃階段
<a name="planning-phase"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清理探索前待處理項目。 | 與部門主管和應用程式擁有者一起執行探索前待處理項目清理工作工作階段。  | 專案經理，敏捷 scrum 領導者 | 
|  執行衝刺規劃工作工作階段。 | 作為範圍界定練習，分發您要在衝刺和波浪之間遷移的應用程式。 | 專案經理，敏捷 scrum 領導者 | 

### 探索前階段
<a name="pre-discovery-phase"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 確認應用程式知識。 | 確認並記錄應用程式擁有者及其對應用程式的知識。判斷是否有另一個指標人員處理技術問題。 | 遷移專家 （採訪者） | 
| 確定應用程式合規要求。 | 向應用程式擁有者確認應用程式不需要符合支付卡產業資料安全標準 (PCI DSS)、沙賓法案 (SOX)、個人身分識別資訊 (PII) 或其他標準的要求。如果存在合規要求，團隊必須在要遷移的伺服器上完成合規檢查。 | 遷移專家 （採訪者） | 
| 確認生產版本需求。 | 與應用程式擁有者或技術聯絡人確認將遷移的應用程式發佈至生產環境 （例如發行日期和停機時間） 的需求。 | 遷移專家 （採訪者） | 
| 取得伺服器清單。 | 取得與目標應用程式相關聯的伺服器清單。 | 遷移專家 （採訪者） | 
| 取得顯示目前狀態的邏輯圖表。 | 從企業架構師或應用程式擁有者取得應用程式的目前狀態圖表。 | 遷移專家 （採訪者） | 
| 建立顯示目標狀態的邏輯圖表。 | 建立應用程式邏輯圖，顯示 AWS 上的目標架構。此圖表應說明伺服器、連線能力和映射因素。 | 企業架構師、企業擁有者 | 
| 取得伺服器資訊。 | 收集與應用程式相關聯的伺服器相關資訊，包括其組態詳細資訊。 | 遷移專家 （採訪者） | 
| 將伺服器資訊新增至探索範本。 | 將詳細的伺服器資訊新增至應用程式探索範本 （請參閱此模式附件`mobilize-application-questionnaire.xlsx`中的 )。此範本包含所有應用程式相關的安全性、基礎設施、作業系統和聯網詳細資訊。 | 遷移專家 （採訪者） | 
| 發佈應用程式探索範本。 | 與應用程式擁有者和遷移團隊共用應用程式探索範本，以供常見存取和使用。 | 遷移專家 （採訪者） | 

### 探索階段
<a name="discovery-phase"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 確認伺服器清單。 | 與應用程式擁有者或技術主管確認伺服器清單，以及每個伺服器的目的。 | 遷移專家 | 
| 識別並新增伺服器群組。 | 識別伺服器群組，例如 Web 伺服器或應用程式伺服器，並將此資訊新增至應用程式探索範本。選取每個伺服器應所屬的應用程式層 (Web、應用程式、資料庫）。 | 遷移專家 | 
| 填寫應用程式探索範本。 | 在遷移團隊、應用程式團隊和 AWS 的協助下，完成應用程式探索範本的詳細資訊。 | 遷移專家 | 
| 新增遺失的伺服器詳細資訊 （中介軟體和作業系統團隊）。 | 要求中介軟體和作業系統 (OS) 團隊檢閱應用程式探索範本，並新增任何遺失的伺服器詳細資訊，包括資料庫資訊。 | 遷移專家 | 
| 取得傳入/傳出流量規則 （網路團隊）。 | 要求網路團隊取得來源和目的地伺服器的傳入/傳出流量規則。網路團隊也應新增現有的防火牆規則、將這些規則匯出為安全群組格式，並將現有的負載平衡器新增至應用程式探索範本。 | 遷移專家 | 
| 識別必要的標記。 | 判斷應用程式的標記需求。 | 遷移專家 | 
| 建立防火牆請求詳細資訊。 | 擷取和篩選與應用程式通訊所需的防火牆規則。  | 遷移專家、解決方案架構師、網路領導  | 
| 更新 EC2 執行個體類型。 | 根據基礎設施和伺服器需求，更新要在目標環境中使用的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體類型。  | 遷移專家、解決方案架構師、網路領導 | 
| 識別目前的狀態圖表。 | 識別或建立顯示應用程式目前狀態的圖表。此圖表將用於資訊安全 (InfoSec) 請求。  | 解決方案架構師遷移專家 | 
| 完成未來狀態圖表。 | 完成顯示應用程式未來 （目標） 狀態的圖表。此圖表也會用於 InfoSec 請求。  | 解決方案架構師遷移專家 | 
| 建立防火牆或安全群組服務請求。 | 建立防火牆或安全群組服務請求 （用於開發/QA、生產前和生產）。如果您使用的是 Cloud Migration Factory，請包含尚未開啟的複寫特定連接埠。  | 遷移專家、解決方案架構師、網路領導 | 
| 檢閱防火牆或安全群組請求 (InfoSec 團隊）。 | 在此步驟中，InfoSec 團隊會檢閱並核准上一個步驟中建立的防火牆或安全群組請求。  | InfoSec 工程師，遷移專家 | 
| 實作防火牆安全群組請求 （網路團隊）。 | InfoSec 團隊核准防火牆請求後，網路團隊會實作必要的傳入/傳出防火牆規則。  | 遷移專家、解決方案架構師、網路領導 | 

### 建置階段 （重複用於開發/QA、生產前和生產環境）
<a name="build-phase-repeat-for-development-qa-pre-production-and-production-environments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 匯入應用程式和伺服器資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist.html)如果您不是使用 Cloud Migration Factory，請遵循設定遷移工具的指示。 | 遷移專家，雲端管理員 | 
| 檢查來源伺服器的先決條件。 | 與範圍內來源伺服器連線，以驗證先決條件，例如 TCP 連接埠 1500、TCP 連接埠 443、根磁碟區可用空間、.NET Framework 版本和其他參數。這些是複寫的必要項目。如需詳細資訊，請參閱 [Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#prerequisites-2)。 | 遷移專家，雲端管理員 | 
| 建立服務請求以安裝複寫代理程式。 | 建立服務請求，以在範圍內伺服器上安裝複寫代理程式，以進行開發/QA、生產前或生產。 | 遷移專家，雲端管理員 | 
| 安裝複寫代理程式。 | 在開發/QA、生產前或生產機器上的範圍內來源伺服器上安裝複寫代理程式。如需詳細資訊，請參閱 [Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#install-the-replication-agents)。 | 遷移專家，雲端管理員 | 
| 推送啟動後指令碼。 | Application Migration Service 支援啟動後指令碼，協助您自動化作業系統層級活動，例如在啟動目標執行個體後安裝或解除安裝軟體。此步驟會將啟動後指令碼推送至 Windows 或 Linux 機器，具體取決於為遷移而識別的伺服器。如需說明，請參閱 [Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#push-the-post-launch-scripts)。 | 遷移專家，雲端管理員 | 
| 驗證複寫狀態。 | 使用提供的指令碼，自動確認範圍內來源伺服器的複寫狀態。指令碼每五分鐘重複一次，直到指定波動中所有來源伺服器的狀態變更為**正常**為止。如需說明，請參閱 [Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#verify-the-replication-status)。 | 遷移專家，雲端管理員 | 
| 建立管理員使用者。 | 在從範圍內來源伺服器遷移到 AWS 之後，可能需要來源機器上的本機管理員或 sudo 使用者來疑難排解任何問題。當身分驗證伺服器 （例如 DC 或 LDAP 伺服器） 無法連線時，遷移團隊會使用此使用者登入目標伺服器。如需此步驟的說明，請參閱 [雲端遷移工廠實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/step4.html#add-a-user-to-the-admin-group)。 | 遷移專家，雲端管理員 | 
| 驗證啟動範本。 | 驗證伺服器中繼資料，以確保其成功運作且沒有無效資料。此步驟會驗證測試和切換中繼資料。如需說明，請參閱[Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#validate-launch-template-1)。 | 遷移專家，雲端管理員 | 

### 測試階段 （重複用於開發/QA、生產前和生產環境）
<a name="test-phase-repeat-for-development-qa-pre-production-and-production-environments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立服務請求。 | 為基礎設施團隊和其他團隊建立服務請求，以執行應用程式切換到開發/QA、生產前或生產執行個體。  | 遷移專家，雲端管理員 | 
| 設定負載平衡器 （選用）。 | 設定必要的負載平衡器，例如 [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html) 或具有 iRules 的 [F5 負載平衡器](https://www.f5.com/resources/white-papers/load-balancing-101-nuts-and-bolts)。 | 遷移專家，雲端管理員 | 
| 啟動執行個體進行測試。 | 在測試模式下，在 Application Migration Service 中啟動指定波的所有目標機器。如需詳細資訊，請參閱[Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#launch-instances-for-testing)。 | 遷移專家，雲端管理員 | 
| 驗證目標執行個體狀態。 | 檢查相同波次中所有範圍內來源伺服器的開機程序，以驗證目標執行個體的狀態。最多可能需要 30 分鐘才能啟動目標執行個體。您可以手動檢查狀態，方法是登入 Amazon EC2 主控台、搜尋來源伺服器名稱，以及檢閱**狀態檢查**欄。**通過的狀態 2/2 檢查**表示從基礎設施的角度來看，執行個體運作狀態良好。 | 遷移專家，雲端管理員 | 
| 修改 DNS 項目。 | 修改網域名稱系統 (DNS) 項目。(`host.conf`針對 Microsoft Windows 環境使用 `resolv.conf`或 。) 設定每個 EC2 執行個體以指向此主機的新 IP 地址。確定現場部署和 AWS 雲端伺服器之間沒有 DNS 衝突。此步驟和下列步驟是選用的，取決於託管伺服器的環境。 | 遷移專家，雲端管理員 | 
| 從 EC2 執行個體測試後端主機的連線能力。 | 使用遷移伺服器的網域登入資料來檢查登入。 | 遷移專家，雲端管理員 | 
| 更新 DNS A 記錄。 | 更新每個主機的 DNS A 記錄，以指向新的 Amazon EC2 私有 IP 地址。 | 遷移專家，雲端管理員 | 
| 更新 DNS CNAME 記錄。 | 更新虛擬 IPs（負載平衡器名稱） 的 DNS CNAME 記錄，以指向 Web 和應用程式伺服器的叢集。 | 遷移專家，雲端管理員 | 
| 在適用的環境中測試應用程式。 | 登入新的 EC2 執行個體，並在開發/QA、生產前和生產環境中測試應用程式。 | 遷移專家，雲端管理員 | 
| 標記為準備好進行切換。 | 測試完成時，請變更來源伺服器的狀態以表示其已準備好進行切換，讓使用者可以啟動切換執行個體。如需說明，請參閱 [雲端遷移工廠實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#mark-as-ready-for-cutover)。 | 遷移專家，雲端管理員 | 

### 切換階段
<a name="cutover-phase"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立生產部署計畫。 | 建立生產部署計畫 （包括備份計畫）。 | 遷移專家，雲端管理員 | 
| 將停機時間通知營運團隊。 | 通知 操作團隊伺服器的停機時間排程。有些團隊可能需要此通知的變更請求或服務請求 (CR/SR) 票證。 | 遷移專家，雲端管理員 | 
| 複寫生產機器。 | 使用 Application Migration Service 或其他遷移工具複寫生產機器。 | 遷移專家，雲端管理員 | 
| 關閉範圍內來源伺服器。 | 驗證來源伺服器的複寫狀態後，您可以關閉來源伺服器，以停止從用戶端應用程式到伺服器的交易。您可以在切換視窗中關閉來源伺服器。如需詳細資訊，請參閱 [雲端遷移工廠實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#shut-down-the-in-scope-source-servers)。 | 雲端管理員 | 
| 啟動切換的執行個體。 | 在 Application Migration Service 中以切換模式啟動指定波的所有目標機器。如需詳細資訊，請參閱 [雲端遷移工廠實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-factory-web-console.html#launch-instances-for-cutover)。 | 遷移專家，雲端管理員 | 
| 擷取目標執行個體 IPs。 | 擷取目標執行個體IPs。如果 DNS 更新是環境中的手動程序，您將需要取得所有目標執行個體的新 IP 地址。如需詳細資訊，請參閱 [雲端遷移工廠實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-command-prompt.html#retrieve-the-target-instance-ip)。 | 遷移專家，雲端管理員 | 
| 驗證目標伺服器連線。 | 更新 DNS 記錄後，請使用主機名稱連線到目標執行個體，以驗證連線。如需詳細資訊，請參閱 [雲端遷移工廠實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/list-of-automated-migration-activities-using-command-prompt.html#verify-the-target-server-connections)。 | 遷移專家，雲端管理員 | 

## 相關資源
<a name="rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist-resources"></a>
+ [如何遷移](https://aws.amazon.com/migrate-modernize-build/cloud-migration/how-to-migrate/)
+ [AWS Cloud Migration Factory 實作指南](https://docs.aws.amazon.com/solutions/latest/cloud-migration-factory-on-aws/solution-overview.html)
+ [使用 Cloud Migration Factory 自動化大規模伺服器遷移](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-factory-cloudendure/welcome.html)
+ [AWS Application Migration Service 使用者指南](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)
+ [Migration Acceleration Program (MAP)](https://aws.amazon.com/migration-acceleration-program/)

## 附件
<a name="attachments-8e2d2d72-30cc-4e98-8abd-ac2ef95e599b"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/8e2d2d72-30cc-4e98-8abd-ac2ef95e599b/attachments/attachment.zip)

# 使用 Amazon FSx 設定 SQL Server Always On FCI 的異地同步備份基礎設施
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx"></a>

*Manish Garg、T.V.R.L.Phani Kumar Dadi、Nishad Mankar 和 RAJNEESH TYAGI，Amazon Web Services*

## 總結
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-summary"></a>

如果您需要快速遷移大量 Microsoft SQL Server Always On 容錯移轉叢集執行個體 (FCIs)，此模式可協助您將佈建時間降至最低。透過使用自動化和 Amazon FSx for Windows File Server，可減少手動作業、人為錯誤，以及部署大量叢集所需的時間。

此模式會在 Amazon Web Services (AWS) 的多可用區域 （多可用區域） 部署中設定 SQL Server FCIs 的基礎設施。此基礎設施所需的 AWS 服務佈建是使用 [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 範本自動化的。[Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 執行個體上的 SQL Server 安裝和叢集節點建立是使用 PowerShell 命令執行。

此解決方案使用高度可用的多可用區域 [Amazon FSx for Windows](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html) 檔案系統做為存放 SQL Server 資料庫檔案的共用見證。託管 SQL Server 的 Amazon FSx 檔案系統和 EC2 Windows 執行個體會加入相同的 AWS Directory Service for Microsoft Active Directory (AWS Managed Microsoft AD) 網域。

## 先決條件和限制
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 具有足夠許可的 AWS 使用者，可使用 AWS CloudFormation 範本佈建資源
+ 適用於 Microsoft Active Directory 的 AWS Directory Service
+ AWS Secrets Manager 中要驗證金鑰/值對中 AWS Managed Microsoft AD 的登入資料：
  + `ADDomainName`：＜網域名稱>
  + `ADDomainJoinUserName`：<Domain Username>
  + `ADDomainJoinPassword`：＜網域使用者密碼>
  + `TargetOU`：<Target OU 值>
**注意**  
您將在 AWS Managed Microsoft AD 聯結活動的 AWS Systems Manager 自動化中使用相同的金鑰名稱。
+ SQL Server 安裝和 Windows 服務或網域帳戶建立的 SQL Server 媒體檔案，將在叢集建立期間使用
+ 虛擬私有雲端 (VPC)，在個別可用區域中有兩個公有子網路、可用區域中有兩個私有子網路、網際網路閘道、NAT 閘道、路由表關聯和跳接伺服器

**產品版本**
+ Windows Server 2012 R2 和 Microsoft SQL Server 2016

## Architecture
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-architecture"></a>

**來源技術堆疊**
+ 使用共用磁碟機搭配 FCIs 的內部部署 SQL Server

**目標技術堆疊**
+ AWS EC2 執行個體
+ Amazon FSx for Windows File Server
+ AWS Systems Manager Automation Runbook
+ 網路組態 (VPC、子網路、網際網路閘道、NAT 閘道、跳躍伺服器、安全群組）
+ AWS Secrets Manager
+ AWS 受管 Microsoft AD
+ Amazon EventBridge
+ AWS Identity and Access Management (IAM)

**目標架構**

下圖顯示單一 AWS 區域中的 AWS 帳戶，其中包含兩個可用區域的 VPC、兩個具有 NAT 閘道的公有子網路、第一個公有子網路中的跳轉伺服器、兩個私有子網路，每個子網路都有節點安全群組中 SQL Server 節點的 EC2 執行個體，以及連線至每個 SQL Server 節點的 Amazon FSx 檔案系統。也包含 AWS Directory Service、Amazon EventBridge、AWS Secrets Manager 和 AWS Systems Manager。

![\[具有公有和私有子網路中資源的異地同步備份架構，具有節點安全群組。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f09c0164-be2d-4665-a574-7ec29fd25082/images/543829a9-e130-4542-9c4e-7518c6cbe967.png)


**自動化和擴展**
+ 您可以使用 AWS Systems Manager 加入 AWS Managed Microsoft AD 並執行 SQL Server 安裝。

## 工具
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-tools"></a>

**AWS 服務**
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速一致地佈建資源，以及在整個 AWS 帳戶和區域的生命週期中管理這些資源。
+ [AWS Directory Service](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/what_is.html) 提供多種方式來搭配其他 AWS 服務使用 Microsoft Active Directory (AD)，例如 Amazon Elastic Compute Cloud (Amazon EC2)、Amazon Relational Database Service (Amazon RDS) for SQL Server 和 Amazon FSx for Windows File Server。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一種無伺服器事件匯流排服務，可協助您將應用程式與來自各種來源的即時資料連線。例如，AWS Lambda 函數、使用 API 目的地的 HTTP 調用端點，或其他 AWS 帳戶中的事件匯流排。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您以 API 呼叫 Secrets Manager，以程式設計方式擷取秘密，取代程式碼中的硬式編碼登入資料，包括密碼。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可協助您管理在 AWS 雲端中執行的應用程式和基礎設施。它可簡化應用程式和資源管理、縮短偵測和解決操作問題的時間，並協助您大規模安全地管理 AWS 資源。

**其他工具**
+ [PowerShell](https://learn.microsoft.com/en-us/powershell/) 是在 Windows、Linux 和 macOS 上執行的 Microsoft 自動化和組態管理程式。此模式使用 PowerShell 指令碼。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [aws-windows-failover-cluster-automation](https://github.com/aws-samples/aws-windows-failover-cluster-automation) 儲存庫中使用。

## 最佳實務
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-best-practices"></a>
+ 用於部署此解決方案的 IAM 角色應遵循最低權限原則。如需詳細資訊，請參閱 [IAM 文件](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)。
+ 遵循 [AWS CloudFormation 最佳實務](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html)。

## 史詩
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-epics"></a>

### 部署基礎設施
<a name="deploy-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 Systems Manager CloudFormation 堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps，DevOps 工程師 | 
| 部署基礎設施堆疊。 | 成功部署 Systems Manager 堆疊後，請建立`infra`堆疊，其中包含 EC2 執行個體節點、安全群組、Amazon FSx for Windows File Server 檔案系統和 IAM 角色。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps，DevOps 工程師 | 

### 設定 Windows SQL Server Always On FCI
<a name="set-up-the-windows-sql-server-always-on-fci"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 Windows 工具。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps、DevOps 工程師、DBA | 
| 在 Active Directory Domain Services 中預先準備叢集電腦物件。 | 若要預先準備 Active Directory Domain Services (AD DS) 中的叢集名稱物件 (CNO)，並預先準備叢集角色的虛擬電腦物件 (VCO)，請遵循 [Windows Server 文件](https://learn.microsoft.com/en-us/windows-server/failover-clustering/prestage-cluster-adds)中的指示。 | AWS DevOps、DBA、DevOps 工程師 | 
| 建立 WSFC。 | 若要建立 Windows Server 容錯移轉叢集 (WSFC) 叢集，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps、DBA、DevOps 工程師 | 
| 安裝 SQL Server 容錯移轉叢集。 | 設定 WSFC 叢集後，在主要執行個體 (node1) 上安裝 SQL Server 叢集。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html)<pre>D:\setup.exe /Q  `<br />/ACTION=InstallFailoverCluster `<br />/IACCEPTSQLSERVERLICENSETERMS `<br />/FEATURES="SQL,IS,BC,Conn"  `<br />/INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server"  `<br />/INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server"  `<br />/RSINSTALLMODE="FilesOnlyMode"  `<br />/INSTANCEID="MSSQLSERVER" `<br />/INSTANCENAME="MSSQLSERVER"  `<br />/FAILOVERCLUSTERGROUP="SQL Server (MSSQLSERVER)"  `<br />/FAILOVERCLUSTERIPADDRESSES="IPv4;<2nd Sec Private Ip node1>;Cluster Network 1;<subnet mask>"  `<br />/FAILOVERCLUSTERNETWORKNAME="<Fail over cluster Network Name>"  `<br />/INSTANCEDIR="C:\Program Files\Microsoft SQL Server"  `<br />/ENU="True"  `<br />/ERRORREPORTING=0  `<br />/SQMREPORTING=0  `<br />/SAPWD="<Domain User password>" `<br />/SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS"  `<br />/SQLSYSADMINACCOUNTS="<domain\username>" `<br />/SQLSVCACCOUNT="<domain\username>"  /SQLSVCPASSWORD="<Domain User password>" `<br />/AGTSVCACCOUNT="<domain\username>"  /AGTSVCPASSWORD="<Domain User password>" `<br />/ISSVCACCOUNT="<domain\username>" /ISSVCPASSWORD="<Domain User password>"  `<br />/FTSVCACCOUNT="NT Service\MSSQLFDLauncher"  `<br />/INSTALLSQLDATADIR="\\<FSX DNS name>\share\Program Files\Microsoft SQL Server"  `<br />/SQLUSERDBDIR="\\<FSX DNS name>\share\data"  `<br />/SQLUSERDBLOGDIR="\\<FSX DNS name>\share\log" `<br />/SQLTEMPDBDIR="T:\tempdb"  `<br />/SQLTEMPDBLOGDIR="T:\log"  `<br />/SQLBACKUPDIR="\\<FSX DNS name>\share\SQLBackup" `<br />/SkipRules=Cluster_VerifyForErrors `<br />/INDICATEPROGRESS</pre> | AWS DevOps、DBA、DevOps 工程師 | 
| 將次要節點新增至叢集。 | 若要將 SQL Server 新增至次要節點 （節點 2)，請執行下列PowerShell 命令。<pre>D:\setup.exe /Q  `<br />/ACTION=AddNode `<br />/IACCEPTSQLSERVERLICENSETERMS `<br />/INSTANCENAME="MSSQLSERVER"  `<br />/FAILOVERCLUSTERGROUP="SQL Server (MSSQLSERVER)" `<br />/FAILOVERCLUSTERIPADDRESSES="IPv4;<2nd Sec Private Ip node2>;Cluster Network 2;<subnet mask>" `<br />/FAILOVERCLUSTERNETWORKNAME="<Fail over cluster Network Name>" `<br />/CONFIRMIPDEPENDENCYCHANGE=1 `<br />/SQLSVCACCOUNT="<domain\username>"  /SQLSVCPASSWORD="<Domain User password>" `<br />/AGTSVCACCOUNT="domain\username>"  /AGTSVCPASSWORD="<Domain User password>" `<br />/FTSVCACCOUNT="NT Service\MSSQLFDLauncher" `<br />/SkipRules=Cluster_VerifyForErrors `<br />/INDICATEPROGRESS</pre> | AWS DevOps、DBA、DevOps 工程師 | 
| 測試 SQL Server FCI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | DBA，DevOps 工程師 | 

### 清除資源
<a name="clean-up-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除資源。 | 若要清除資源，請使用 AWS CloudFormation 堆疊刪除程序：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html)堆疊刪除完成後，堆疊將處於 `DELETE_COMPLETE` 狀態。根據預設，`DELETE_COMPLETE`處於 狀態的堆疊不會顯示在 CloudFormation 主控台中。若要顯示已刪除的堆疊，您必須變更堆疊檢視篩選條件，如在 [ AWS CloudFormation 主控台上檢視已刪除的堆疊](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-view-deleted-stacks.html)所述。如果刪除失敗，堆疊將處於 `DELETE_FAILED` 狀態。如需解決方案，請參閱 CloudFormation 文件中的[刪除堆疊失敗](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html#troubleshooting-errors-delete-stack-fails)。 | AWS DevOps、DBA、DevOps 工程師 | 

## 疑難排解
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| AWS CloudFormation 範本失敗 | 如果 CloudFormation 範本在部署期間失敗，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | 
| AWS Managed Microsoft AD 聯結失敗 | 若要疑難排解聯結問題，請依照下列步驟進行：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | 

## 相關資源
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-resources"></a>
+ [使用 Amazon FSx for Windows File Server 簡化 Microsoft SQL Server 高可用性部署](https://aws.amazon.com/blogs/storage/simplify-your-microsoft-sql-server-high-availability-deployments-using-amazon-fsx-for-windows-file-server/)
+ [將 FSx for Windows File Server 與 Microsoft SQL Server 搭配使用](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/sql-server.html)

# 使用 BMC Discovery 查詢來擷取遷移資料以進行遷移規劃
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning"></a>

*Ben Tailor-Hamblin、Emma Baldry、Simon Cunningham 和 Shabnam Khan，Amazon Web Services*

## 總結
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-summary"></a>

本指南提供查詢範例和步驟，協助您使用 BMC Discovery 從內部部署基礎設施和應用程式擷取資料。模式說明如何使用 BMC Discovery 查詢來掃描您的基礎設施，並擷取軟體、服務和相依性資訊。評估和調動大規模遷移至 Amazon Web Services (AWS) 雲端的階段需要擷取的資料。您可以使用此資料，針對遷移計畫中要一起遷移的應用程式做出關鍵決策。

## 先決條件和限制
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-prereqs"></a>

**先決條件**
+ BMC Helix Discovery 的 BMC Discovery （先前稱為 BMC ADDM) 授權或軟體即服務 (SaaS) 版本
+ 現場部署或 SaaS 版本的 BMC Discovery，[已安裝](https://docs.bmc.com/docs/discovery/221/installing-1050933835.html) 
**注意**  
對於內部部署版本的 BMC Discovery，您必須在用戶端網路上安裝應用程式，該用戶端網路可存取跨多個資料中心遷移範圍內的所有聯網和伺服器裝置。必須根據應用程式安裝指示提供用戶端網路的存取權。如果需要掃描 Windows Server 資訊，則必須在網路中設定 Windows Proxy Manager 裝置。
+ 如果您使用 BMC Helix Discovery，允許應用程式跨資料中心掃描裝置的[聯網存取](https://docs.bmc.com/docs/discovery/221/network-ports-used-for-discovery-communications-1050933821.html) 

**產品版本**
+ BMC Discovery 22.2 (12.5)
+ BMC Discovery 22.1 (12.4)
+ BMC Discovery 21.3 (12.3)
+ BMC Discovery 21.05 (12.2)
+ BMC Discovery 20.08 (12.1)
+ BMC Discovery 20.02 (12.0)
+ BMC Discovery 11.3
+ BMC Discovery 11.2
+ BMC Discovery 11.1
+ BMC Discovery 11.0
+ BMC Atrium Discovery 10.2
+ BMC Atrium Discovery 10.1
+ BMC Atrium Discovery 10.0

## Architecture
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-architecture"></a>

下圖顯示資產管理員如何使用 BMC Discovery 查詢來掃描 SaaS 和內部部署環境中的 BMC 模型應用程式。

![\[使用 BMC Discovery 擷取軟體、服務和相依性資訊的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5e549882-8deb-4459-8891-e39bbf80e320/images/0ebb3e68-5828-45aa-86f4-c741c7b6cd94.jpeg)


下圖顯示下列工作流程：資產管理員使用「BMC Discovery」或「BMC Helix Discovery」掃描在多個實體伺服器上託管的虛擬伺服器上執行的資料庫和軟體執行個體。此工具可以使用橫跨多個虛擬和實體伺服器的元件來建立應用程式模型。

**技術堆疊**
+ BMC 探索
+ BMC Helix 探索

## 工具
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-tools"></a>
+ [BMC Discovery](https://docs.bmc.com/xwiki/bin/view/IT-Operations-Management/Discovery/BMC-Discovery/) 是一種資料中心探索工具，可協助您自動探索資料中心。
+ [BMC Helix Discovery](https://www.bmc.com/it-solutions/bmc-helix-discovery.html) 是一種以 SaaS 為基礎的探索和相依性建模系統，可協助您動態建立資料資產及其相依性的模型。

## 最佳實務
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-best-practices"></a>

當您遷移至雲端時，最佳實務是映射應用程式、相依性和基礎設施資料。映射可協助您了解目前環境的複雜性，以及各種元件之間的相依性。

這些查詢提供的資產資訊很重要，原因有幾個：

1. **規劃** – 了解元件之間的相依性可協助您更有效地規劃遷移程序。例如，您可能需要先遷移某些元件，以確保其他元件可以成功遷移。

1. **風險評估** – 映射元件之間的相依性可協助您識別遷移過程中可能出現的任何潛在風險或問題。例如，您可能會發現某些元件依賴過時或不支援的技術，這些技術可能會導致雲端出現問題。

1. **雲端架構** – 映射您的應用程式和基礎設施資料也可以協助您設計符合您組織需求的合適雲端架構。例如，您可能需要設計多層架構，以支援高可用性或可擴展性需求。

整體而言，映射應用程式、相依性和基礎設施資料是雲端遷移程序中的關鍵步驟。映射練習可協助您更了解目前的環境、識別任何潛在問題或風險，以及設計適當的雲端架構。

## 史詩
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-epics"></a>

### 識別和評估探索工具
<a name="identify-and-evaluate-discovery-tooling"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別 ITSM 擁有者。 | 識別 IT Service Management (ITSM) 擁有者 （通常是透過聯絡營運支援團隊）。 | 遷移潛在客戶 | 
| 檢查 CMDB。 | 識別包含資產資訊的組態管理資料庫 (CMDBs) 數目，然後識別該資訊的來源。 | 遷移潛在客戶 | 
| 識別探索工具並檢查是否使用 BMC Discovery。 | 如果您的組織使用 BMC Discovery 將環境相關資料傳送至 CMDB 工具，請檢查其掃描的範圍和涵蓋範圍。例如，檢查 BMC Discovery 是否正在掃描所有資料中心，以及存取伺服器是否位於周邊區域。 | 遷移潛在客戶 | 
| 檢查應用程式建模的層級。 | 檢查應用程式是否在 BMC Discovery 中建模。如果沒有，建議使用 BMC Discovery 工具來建立哪些執行中的軟體執行個體提供應用程式和商業服務的模型。 | 遷移工程師，遷移負責人 | 

### 擷取基礎設施資料
<a name="extract-infrastructure-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 擷取實體和虛擬伺服器上的資料。 | 若要擷取由 BMC Discovery 掃描的實體和虛擬伺服器上的資料，請使用 [Query Builder](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html) 執行下列查詢：<pre>search Host show key as 'Serverid', virtual, name as 'HOSTNAME', os_type as 'osName', os_version as 'OS Version', num_logical_processors as 'Logical Processor Counts', cores_per_processor as 'Cores per Processor', logical_ram as 'Logical RAM', #Consumer:StorageUse:Provider:DiskDrive.size as 'Size'</pre>您可以使用擷取的資料來判斷適當的執行個體大小以進行遷移。 | 遷移工程師，遷移負責人 | 
| 擷取建模應用程式上的資料。 | 如果您的應用程式在 BMC Discovery 中建立模型，您可以擷取執行應用程式軟體之伺服器的資料。若要取得伺服器名稱，請使用[查詢建置器](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html)來執行下列查詢：<pre>search SoftwareInstance show key as 'ApplicationID', #RunningSoftware:HostedSoftware:Host:Host.key as 'ReferenceID', type, name</pre>應用程式透過執行中軟體執行個體的集合在 BMC Discovery 中建模。應用程式取決於執行應用程式軟體的所有伺服器。 | BMC Discovery 應用程式擁有者 | 
| 擷取資料庫上的資料。 | 若要取得所有掃描資料庫的清單，以及這些資料庫正在執行的伺服器，請使用 [Query Builder](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html) 執行下列查詢：<pre>search Database show key as 'Key', name, type as 'Source Engine Type', #Detail:Detail:ElementWithDetail:SoftwareInstance.name as 'Software Instance', #Detail:Detail:ElementWithDetail:SoftwareInstance.product_version as 'Product Version', #Detail:Detail:ElementWithDetail:SoftwareInstance.edition as 'Edition', #Detail:Detail:ElementWithDetail:SoftwareInstance.#RunningSoftware:HostedSoftware:Host:Host.key as 'ServerID'</pre> | 應用程式擁有者 | 
| 在伺服器通訊上擷取資料。 | 若要從歷史網路通訊日誌取得由 BMC Discovery 收集之伺服器間所有網路通訊的資訊，請使用[查詢建置器](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html)來執行下列查詢：<pre>search Host<br /> TRAVERSE InferredElement:Inference:Associate:DiscoveryAccess<br /> TRAVERSE DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:NetworkConnectionList<br /> TRAVERSE List:List:Member:DiscoveredNetworkConnection<br /> PROCESS WITH networkConnectionInfo</pre> | BMC Discovery 應用程式擁有者 | 
| 擷取應用程式探索的資料。 | 若要取得應用程式相依性的相關資訊，請使用[查詢建置器](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html)來執行下列查詢：<pre>search SoftwareInstance show key as 'SRC App ID', #Dependant:Dependency:DependedUpon:SoftwareInstance.key as 'DEST App ID'</pre> | BMC Discovery 應用程式擁有者 | 
| 擷取商業服務上的資料。 | 若要擷取主機提供之商業服務的資料，請使用[查詢建置器](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html)來執行下列查詢：<pre>search Host show name, #Host:HostedSoftware:AggregateSoftware:BusinessService.name as 'Name'</pre> | BMC Discovery 應用程式擁有者 | 

## 疑難排解
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 查詢無法執行或包含未填入的資料欄。 | 檢閱 BMC Discovery 中的資產記錄，並判斷您需要哪些欄位。然後，使用查詢[建置器取代查詢](https://docs.bmc.com/docs/discovery/221/query-builder-1051985747.html)中的這些欄位。 | 
| 不會填入相依資產的詳細資訊。 | 這可能是由於存取許可或網路連線。探索工具可能沒有存取特定資產的必要許可，特別是當它們位於不同的網路或不同環境中時。我們建議您與探索主題專家緊密合作，以確保識別所有相關資產。 | 

## 相關資源
<a name="use-bmc-discovery-queries-to-extract-migration-data-for-migration-planning-resources"></a>

**參考**
+ [BMC Discovery 授權權利](https://docs.bmc.com/docs/discovery/bmc-discovery-licensing-entitlement-531336348.html) (BMC 文件）
+ [BMC Discovery 功能和元件](https://docs.bmc.com/docs/discovery/221/bmc-discovery-features-and-components-1052418000.html) (BMC 文件）
+ [BMC Discovery 使用者指南](https://docs.bmc.com/xwiki/bin/view/IT-Operations-Management/Discovery/BMC-Discovery/) (BMC 文件）
+ [搜尋資料 （在 BMC Discovery 上）](https://docs.bmc.com/docs/discovery/120/searching-for-data-911457232.html) (BMC 文件）
+ 用於[遷移的產品組合探索和分析](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-portfolio-discovery/welcome.html) (AWS 規範性指導）

**教學課程和影片**
+ [BMC 探索：網路研討會 - 報告查詢最佳實務 （第 1 部分）](https://www.youtube.com/watch?v=iwXy6x40kO8) (YouTube)

# 重新定位
<a name="migration-relocate-pattern-list"></a>

**Topics**
+ [將 Amazon RDS for Oracle 資料庫遷移至另一個資料庫 AWS 帳戶 ， AWS 區域 並使用 AWS DMS 進行持續複寫](migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication.md)
+ [將 Amazon RDS 資料庫執行個體遷移至另一個 VPC 或帳戶](migrate-an-amazon-rds-db-instance-to-another-vpc-or-account.md)
+ [將 Amazon Redshift 叢集遷移至中國的 AWS 區域](migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china.md)
+ [使用 pg\$1transport 在兩個 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫](transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.md)

# 將 Amazon RDS for Oracle 資料庫遷移至另一個資料庫 AWS 帳戶 ， AWS 區域 並使用 AWS DMS 進行持續複寫
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication"></a>

*Durga Prasad Cheepuri 和 Eduardo Valentim，Amazon Web Services*

## 總結
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication-summary"></a>


| 
| 
| 警告：IAM 使用者具有長期登入資料，這會造成安全風險。為了協助降低此風險，建議您只為這些使用者提供執行任務所需的許可，並在不再需要這些使用者時將其移除。 | 
| --- |

此模式會逐步引導您將適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS) 來源資料庫遷移至不同 AWS 帳戶 和 的步驟 AWS 區域。模式使用資料庫快照進行一次性完整資料載入，並啟用 AWS Database Migration Service (AWS DMS) 進行持續複寫。

## 先決條件和限制
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶 ，其中包含來源 Amazon RDS for Oracle 資料庫，該資料庫已使用非default AWS Key Management Service (AWS KMS) 金鑰加密
+  AWS 帳戶 與來源資料庫 AWS 區域 不同的作用中 ，用於目標 Amazon RDS for Oracle 資料庫
+ 來源和目標 VPCs 之間的虛擬私有雲端 (VPC) 對等互連
+ 熟悉[使用 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ 熟悉[使用 Oracle 資料庫做為 的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Oracle.html) 

**產品版本**
+ Oracle 版本 11g （版本 11.2.0.3.v1 和更新版本） 和最高 12.2 和 18c。如需支援版本的最新清單，請參閱文件中[使用 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)，以及[使用 Oracle 資料庫做為 文件的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Oracle.html)。 AWS 如需 Amazon RDS 支援的 Oracle 版本，請參閱 [Amazon RDS 上的 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)。

## Architecture
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication-architecture"></a>

**來源和目標技術堆疊**
+ Amazon RDS for Oracle 資料庫執行個體

![\[連線至目標 AWS 帳戶的來源 AWS 帳戶，其中包含來源和目標區域\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5ecd5359-884e-455c-b5d0-ef08eda2ea1f/images/e17fa7fe-d924-4f35-9707-b93572fa1227.png)


**持續複寫架構**

![\[EC2 執行個體上的資料庫透過 VPC 對等連線至複寫執行個體和 Amazon RDS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5ecd5359-884e-455c-b5d0-ef08eda2ea1f/images/b60b3500-5d29-487a-bbab-0ae9f3f386aa.png)


## 工具
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication-tools"></a>

**用於一次性完整資料載入的工具**
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 會建立資料庫執行個體的儲存磁碟區快照，備份整個資料庫執行個體，而不只是個別資料庫。建立資料庫快照時，您必須找出要進行備份的資料庫執行個體，並為該資料庫快照命名，使得您稍後可透過它進行還原。建立快照所需的時間量因資料庫的大小而異。由於快照包括整個儲存體磁碟區，檔案大小，例如暫存檔案，也會影響建立快照所需的時間量。如需使用資料庫快照的詳細資訊，請參閱 [Amazon RDS 文件中的建立資料庫快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateSnapshot.html)。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 會建立 ** **Amazon RDS** **加密的** **金鑰。當您建立加密的資料庫執行個體時，您也可以提供加密[AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)金鑰的金鑰識別符。如果您未指定[AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)金鑰識別符，Amazon RDS 會將您的預設加密金鑰用於新的資料庫執行個體。 會為您的 [AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)建立預設加密金鑰 AWS 帳戶。每個 AWS 帳戶 都有不同的預設加密金鑰 AWS 區域。對於此模式，應使用非預設[AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)金鑰加密 Amazon RDS 資料庫執行個體。如需使用 Amazon RDS 加密[AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)金鑰的詳細資訊，請參閱 [Amazon RDS 文件中的加密 Amazon RDS 資源](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Encryption.html)。

**用於持續複寫的工具**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 用於複寫正在進行的變更，並保持來源和目標資料庫的同步。如需使用 AWS DMS 進行持續複寫的詳細資訊，請參閱 AWS DMS 文件中的[使用 AWS DMS 複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.html)。

## 史詩
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication-epics"></a>

### 設定您的來源 AWS 帳戶
<a name="configure-your-source-aws-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備來源 Oracle 資料庫執行個體。 | 讓 Amazon RDS for Oracle 資料庫執行個體以 ARCHIVELOG 模式執行，並設定保留期間。如需詳細資訊，請參閱[使用 AWS 受管 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Amazon-Managed)。 | DBA | 
| 設定來源 Oracle 資料庫執行個體的補充記錄。 | 設定 Amazon RDS for Oracle 資料庫執行個體的資料庫層級和資料表層級補充記錄。如需詳細資訊，請參閱[使用 AWS 受管 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Amazon-Managed)。 | DBA | 
| 更新來源帳戶中的 AWS KMS 金鑰政策。 | 更新來源中的 AWS KMS 金鑰政策 AWS 帳戶 ， AWS 帳戶 以允許目標使用加密的 Amazon RDS AWS KMS 金鑰。如需詳細資訊，請參閱 [AWS KMS 文件](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-modifying.html#key-policy-modifying-external-accounts)。 | SysAdmin | 
| 建立來源資料庫執行個體的手動 Amazon RDS 資料庫快照。 |  | AWS IAM 使用者 | 
| 與目標共用手動加密的 Amazon RDS 快照 AWS 帳戶。 | 如需詳細資訊，請參閱[共用資料庫快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ShareSnapshot.html)。 | AWS IAM 使用者 | 

### 設定您的目標 AWS 帳戶
<a name="configure-your-target-aws-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連接政策。 | 在目標中 AWS 帳戶，將 AWS Identity and Access Management (IAM) 政策連接至根 IAM 使用者，以允許 IAM 使用者使用共用 AWS KMS 金鑰複製加密的資料庫快照。 | SysAdmin | 
| 切換到來源 AWS 區域。 |  | AWS IAM 使用者 | 
| 複製共用快照。 | 在 Amazon RDS 主控台的**快照**窗格中，選擇**與我共用**，然後選取共用快照。使用來源資料庫所用 AWS KMS 金鑰的 Amazon Resource Name (ARN)，將快照複製到與來源資料庫 AWS 區域 相同的 。如需詳細資訊，請參閱[複製資料庫快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CopySnapshot.html)。 | AWS IAM 使用者 | 
| 切換到目標 AWS 區域，並建立新的 AWS KMS 金鑰。 |  | AWS IAM 使用者 | 
| 複製快照。 | 切換到來源 AWS 區域。在 Amazon RDS 主控台的**快照**窗格中，選擇**由我擁有**，然後選取複製的快照。 AWS 區域 使用新目標的 AWS KMS 金鑰，將快照複製到目標 AWS 區域。 | AWS IAM 使用者 | 
| 還原快照。 | 切換到目標 AWS 區域。在 Amazon RDS 主控台的**快照**窗格中，選擇**由我擁有**。選取複製的快照，並將其還原至 Amazon RDS for Oracle 資料庫執行個體。如需詳細資訊，請參閱[從資料庫快照還原](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html)。 | AWS IAM 使用者 | 

### 準備您的來源資料庫以進行持續複寫
<a name="prepare-your-source-database-for-ongoing-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立具有適當許可的 Oracle 使用者。 | 建立具有 Oracle 所需權限的 Oracle 使用者做為來源 AWS DMS。如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。 | DBA | 
| 設定 Oracle LogMiner 或 Oracle Binary Reader 的來源資料庫。 |  | DBA | 

### 準備您的目標資料庫以進行持續複寫
<a name="prepare-your-target-database-for-ongoing-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立具有適當許可的 Oracle 使用者。 | 建立具有 Oracle 所需權限的 Oracle 使用者做為目標 AWS DMS。如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Oracle.html#CHAP_Target.Oracle.Privileges)。 | DBA | 

### 建立 AWS DMS 元件
<a name="create-dms-components"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在目標中建立複寫執行個體 AWS 區域。 | 在目標的 VPC 中建立複寫執行個體 AWS 區域。如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html#CHAP_GettingStarted.ReplicationInstance)。 | AWS IAM 使用者 | 
| 使用必要的加密和測試連線來建立來源和目標端點。 | 如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html#CHAP_GettingStarted.Endpoints)。 | DBA | 
| 建立複寫任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication.html)如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html#CHAP_GettingStarted.Tasks)。 | IAM 使用者 | 
| 啟動任務並監控它們。 | 如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html)。 | AWS IAM 使用者 | 
| 視需要對任務啟用驗證。 | 請注意，啟用驗證確實會對複寫產生效能影響。如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | AWS IAM 使用者 | 

## 相關資源
<a name="migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication-resources"></a>
+ [變更金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-modifying.html#key-policy-modifying-external-accounts)
+ [建立手動 Amazon RDS 資料庫快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateSnapshot.html)
+ [共用手動 Amazon RDS 資料庫快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ShareSnapshot.html)
+ [複製快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CopySnapshot.html) 
+ [從 Amazon RDS 資料庫快照還原](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html) 
+ [入門 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html) 
+ [使用 Oracle 資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html) 
+ [使用 Oracle 資料庫做為 的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Oracle.html) 
+ [AWS DMS 使用 VPC 對等互連進行設定](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.VPC.html#CHAP_ReplicationInstance.VPC.Configurations.ScenarioVPCPeer) 
+ [如何與另一個 共用手動 Amazon RDS 資料庫快照或資料庫叢集快照 AWS 帳戶？](https://aws.amazon.com/premiumsupport/knowledge-center/rds-snapshots-share-account/) (AWS 知識中心文章） 

# 將 Amazon RDS 資料庫執行個體遷移至另一個 VPC 或帳戶
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account"></a>

*Dhrubajyoti Mukherjee，Amazon Web Services*

## 總結
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-summary"></a>

此模式提供將 Amazon Relational Database Service (Amazon RDS) 資料庫執行個體從一個虛擬私有雲端 (VPC) 遷移至相同 AWS 帳戶中另一個，或從一個 AWS 帳戶遷移至另一個 AWS 帳戶的指引。

如果您想要將 Amazon RDS 資料庫執行個體遷移到另一個 VPC 或帳戶，基於分離或安全原因 （例如，當您想要將應用程式堆疊和資料庫放置在不同的 VPCs時），此模式非常有用。 

將資料庫執行個體遷移至另一個 AWS 帳戶需要採取一些步驟，例如手動快照、共用快照，以及還原目標帳戶中的快照。視資料庫變更和交易費率而定，此程序可能非常耗時。這也會導致資料庫停機，因此請事先規劃遷移。請考慮藍/綠部署策略，將停機時間降至最低。或者，您可以評估 AWS Data Migration Service (AWS DMS)，將變更的停機時間降至最低。不過，此模式不會涵蓋此選項。若要進一步了解，請參閱 [AWS DMS 文件。](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)

## 先決條件和限制
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ VPC、子網路和 Amazon RDS 主控台所需的 AWS Identity and Access Management (IAM) 許可

**限制**
+ 變更 VPC 會導致資料庫重新啟動，導致應用程式中斷。建議您在低尖峰時間進行遷移。
+ 將 Amazon RDS 遷移至另一個 VPC 的限制：
  + 您要遷移的資料庫執行個體必須是沒有待命的單一執行個體。它不能是叢集的成員。
  + Amazon RDS 不得位於多個可用區域。
  + Amazon RDS 不得有任何僅供讀取複本。
  + 在目標 VPC 中建立的子網路群組必須具有來源資料庫執行所在可用區域的子網路。
+ 將 Amazon RDS 遷移至另一個 AWS 帳戶時的限制：
  + 目前不支援共用使用 Amazon RDS 預設服務金鑰加密的快照。

## Architecture
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-architecture"></a>

**遷移至相同 AWS 帳戶中的 VPC**

下圖顯示將 Amazon RDS 資料庫執行個體遷移至相同 AWS 帳戶中不同 VPC 的工作流程。

![\[將 Amazon RDS 資料庫執行個體遷移至相同 AWS 帳戶中不同 VPC 的工作流程\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/dabcee69-9cc6-47f9-9964-635e349caaaf/images/73e16544-6276-4f03-9ae2-42b8c7c20315.png)


步驟包含下列項目。如需詳細說明，請參閱 [Epics](#migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-epics) 一節。

1. 在目標 VPC 中建立資料庫子網路群組。資料庫子網路群組是子網路的集合，您可以在建立資料庫執行個體時用來指定特定的 VPC。

1. 在來源 VPC 中設定 Amazon RDS 資料庫執行個體，以使用新的資料庫子網路群組。

1. 套用變更，將 Amazon RDS 資料庫遷移至目標 VPC。

**遷移至不同的 AWS 帳戶**

下圖顯示將 Amazon RDS 資料庫執行個體遷移至不同 AWS 帳戶的工作流程。

![\[將 Amazon RDS 資料庫執行個體遷移至不同 AWS 帳戶的工作流程\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/dabcee69-9cc6-47f9-9964-635e349caaaf/images/5536e69e-3965-4ca2-8a0b-2573659b5f8f.png)


步驟包含下列項目。如需詳細說明，請參閱 [Epics](#migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-epics) 一節。

1. 存取來源 AWS 帳戶中的 Amazon RDS 資料庫執行個體。

1. 在來源 AWS 帳戶中建立 Amazon RDS 快照。

1. 與目標 AWS 帳戶共用 Amazon RDS 快照。

1. 存取目標 AWS 帳戶中的 Amazon RDS 快照。

1. 在目標 AWS 帳戶中建立 Amazon RDS 資料庫執行個體。

## 工具
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-tools"></a>

**AWS 服務**
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。這個虛擬網路類似於您在自己的資料中心內操作的傳統網路，具有使用可擴展的 AWS 基礎設施的優勢。

## 最佳實務
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-best-practices"></a>
+ 如果將 Amazon RDS 資料庫執行個體遷移至另一個 帳戶時需要考慮資料庫停機時間，我們建議您使用 [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)。此服務提供資料複寫，這會導致不到五分鐘的中斷時間。

## 史詩
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-epics"></a>

### 遷移至相同 AWS 帳戶中的不同 VPC
<a name="migrate-to-a-different-vpc-in-the-same-aws-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立新 VPC | 在 [Amazon VPC 主控台](https://console.aws.amazon.com/vpc/)上，建立具有所需屬性和 IP 地址範圍的新 VPC 和子網路。如需詳細說明，請參閱 [Amazon VPC 文件](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html)。 | 管理員 | 
| 建立資料庫子網路群組。 | 在 [Amazon RDS 主控台](https://console.aws.amazon.com/rds/)上：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-amazon-rds-db-instance-to-another-vpc-or-account.html)如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html#USER_VPC.CreateDBSubnetGroup)。 | 管理員 | 
| 修改 Amazon RDS 資料庫執行個體以使用新的子網路群組。 | 在 Amazon RDS 主控台上：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-amazon-rds-db-instance-to-another-vpc-or-account.html)當遷移至目標 VPC 完成時，目標 VPC 的預設安全群組會指派給 Amazon RDS 資料庫執行個體。您可以使用資料庫執行個體所需的傳入和傳出規則，為該 VPC 設定新的安全群組。或者，使用 AWS Command Line Interface (AWS CLI)，透過明確提供新的 VPC 安全群組 ID 來執行目標 VPC 的遷移。例如：<pre>aws rds modify-db-instance \<br />    --db-instance-identifier testrds \<br />    --db-subnet-group-name new-vpc-subnet-group \<br />    --vpc-security-group-ids sg-idxxxx \<br />    --apply-immediately</pre> | 管理員 | 

### 遷移至不同的 AWS 帳戶
<a name="migrate-to-a-different-aws-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在目標 AWS 帳戶中建立新的 VPC 和子網路群組。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-amazon-rds-db-instance-to-another-vpc-or-account.html) | 管理員 | 
| 共用資料庫的手動快照，並與目標帳戶共用。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-amazon-rds-db-instance-to-another-vpc-or-account.html) | 管理員 | 
| 啟動新的 Amazon RDS 資料庫執行個體。 | 從目標 AWS 帳戶中的共用快照啟動新的 Amazon RDS 資料庫執行個體。如需說明，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html)。 | 管理員 | 

## 相關資源
<a name="migrate-an-amazon-rds-db-instance-to-another-vpc-or-account-resources"></a>
+ [Amazon VPC 文件](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)
+ [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html)
+ [如何變更 RDS 資料庫執行個體的 VPC？](https://aws.amazon.com/premiumsupport/knowledge-center/change-vpc-rds-db-instance/) (AWS re：Post 文章）
+ [如何將 Amazon RDS 資源的所有權轉移到不同的 AWS 帳戶？](https://aws.amazon.com/premiumsupport/knowledge-center/account-transfer-rds/) (AWS re：Post 文章）
+ [如何與其他 AWS 帳戶共用手動 Amazon RDS 資料庫快照或 Aurora 資料庫叢集快照？](https://aws.amazon.com/premiumsupport/knowledge-center/rds-snapshots-share-account/) (AWS re：Post 文章）
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)

# 將 Amazon Redshift 叢集遷移至中國的 AWS 區域
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china"></a>

*Jing Yan，Amazon Web Services*

## 總結
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-summary"></a>

此模式提供step-by-step方法，將 Amazon Redshift 叢集從另一個 AWS 區域遷移至中國的 AWS 區域。

此模式使用 SQL 命令重新建立所有資料庫物件，並使用 UNLOAD 命令將此資料從 Amazon Redshift 移至來源區域中的 Amazon Simple Storage Service (Amazon S3) 儲存貯體。然後，資料會遷移至中國 AWS 區域中的 S3 儲存貯體。COPY 命令用於從 S3 儲存貯體載入資料，並將其傳輸至目標 Amazon Redshift 叢集。

Amazon Redshift 目前不支援跨區域功能，例如快照複製到中國的 AWS 區域。此模式提供了解決該限制的方法。您也可以反轉此模式中的步驟，將資料從中國的 AWS 區域遷移到另一個 AWS 區域。

## 先決條件和限制
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-prereqs"></a>

*先決條件*
+ 中國區域和中國以外 AWS 區域的作用中 AWS 帳戶
+ 中國區域和中國以外 AWS 區域中現有的 Amazon Redshift 叢集

*限制*
+ 這是離線遷移，這表示來源 Amazon Redshift 叢集無法在遷移期間執行寫入操作。

## Architecture
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-architecture"></a>

**來源技術堆疊**
+ 中國以外 AWS 區域中的 Amazon Redshift 叢集

**目標技術堆疊**
+ 中國 AWS 區域中的 Amazon Redshift 叢集

**目標架構**

![\[將 AWS 區域中 S3 儲存貯體中的 Amazon Redshift 叢集資料遷移至中國區域中的儲存貯體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f7d241d9-b700-406b-95a0-3e47e7f0fa60/images/b6016e3d-76db-4176-8f99-f804da94d3f2.png)


## 工具
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-tools"></a>

**工具**
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/gsg/GetStartedWithS3.html) – Amazon Simple Storage Service (Amazon S3) 是一種物件儲存服務，可提供可擴展性、資料可用性、安全性和效能。您可以使用 Amazon S3 從 Amazon Redshift 存放資料，也可以將資料從 S3 儲存貯體複製到 Amazon Redshift。
+ [Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/mgmt/welcome.html) – Amazon Redshift 是雲端中全受管的 PB 級資料倉儲服務。 
+ [psql](https://www.postgresql.org/docs/8.4/app-psql.html) – psql 是 PostgreSQL 的終端型前端。 

## 史詩
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-epics"></a>

### 準備在來源區域中遷移
<a name="prepare-for-migration-in-the-source-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源區域中啟動和設定 EC2 執行個體。 | 登入 AWS 管理主控台並開啟 Amazon Elastic Compute Cloud (Amazon EC2) 主控台。您目前的區域會顯示在畫面頂端的導覽列中。此區域不能是中國的 AWS 區域。從 Amazon EC2 主控台儀表板中，選擇「啟動執行個體」，然後建立和設定 EC2 執行個體。重要：確保您的傳入規則的 EC2 安全群組允許從來源機器無限制存取 TCP 連接埠 22。如需如何啟動和設定 EC2 執行個體的說明，請參閱「相關資源」一節。 | DBA、開發人員 | 
| 安裝 psql 工具。 | 下載並安裝 PostgreSQL。Amazon Redshift 不提供 psql 工具，它會與 PostgreSQL 一起安裝。如需使用 psql 和安裝 PostgreSQL 工具的詳細資訊，請參閱「相關資源」一節。 | DBA | 
| 記錄 Amazon Redshift 叢集詳細資訊。 | 開啟 Amazon Redshift 主控台，然後在導覽窗格中選擇「叢集」。然後從清單中選擇 Amazon Redshift 叢集名稱。在「屬性」索引標籤的「資料庫組態」區段中，記錄「資料庫名稱」和「連接埠」。開啟「連線詳細資訊」區段，並記錄「端點」，其格式為「端點：＜連接埠>/<資料庫名稱＞」。重要：確保您的傳入規則的 Amazon Redshift 安全群組允許從 EC2 執行個體無限制存取 TCP 連接埠 5439。 | DBA | 
| 將 psql 連接至 Amazon Redshift 叢集。 | 在命令提示字元中，執行「psql -h <endpoint> -U <userid> -d <databasename> -p <port>」命令來指定連線資訊。在 psql 密碼提示中，輸入 "<userid>" 使用者的密碼。您接著會連線至 Amazon Redshift 叢集，並以互動方式輸入命令。 | DBA | 
| 建立 S3 儲存貯體。 | 開啟 Amazon S3 主控台，並建立 S3 儲存貯體以存放從 Amazon Redshift 匯出的檔案。如需如何建立 S3 儲存貯體的說明，請參閱「相關資源」一節。 | DBA、AWS General | 
| 建立支援卸載資料的 IAM 政策。 | 開啟 AWS Identity and Access Management (IAM) 主控台，然後選擇「政策」。選擇「建立政策」，然後選擇「JSON」索引標籤。複製並貼上從「其他資訊」區段卸載資料的 IAM 政策。重要：將 "s3\$1bucket\$1name" 取代為您的 S3 儲存貯體名稱。選擇「檢閱政策」，然後輸入政策的名稱和描述。選擇「建立政策」。 | DBA | 
| 建立 IAM 角色以允許 Amazon Redshift 的 UNLOAD 操作。 | 開啟 IAM 主控台並選擇「角色」。選擇「建立角色」，然後在「選取信任實體類型」中選擇「AWS 服務」。為服務選擇 "Redshift"，選擇 "Redshift – Customizable"，然後選擇 "Next"。選擇您先前建立的「卸載」政策，然後選擇「下一步」。輸入「角色名稱」，然後選擇「建立角色」。 | DBA | 
| 將 IAM 角色與 Amazon Redshift 叢集建立關聯。 | 開啟 Amazon Redshift 主控台，然後選擇「管理 IAM 角色」。從下拉式選單中選擇「可用角色」，然後選擇您先前建立的角色。選擇「套用變更」。當「管理 IAM 角色」上 IAM 角色的「狀態」顯示為「同步中」時，您可以執行 UNLOAD 命令。 | DBA | 
| 停止對 Amazon Redshift 叢集的寫入操作。 | 您必須記得停止對來源 Amazon Redshift 叢集的所有寫入操作，直到遷移完成為止。 | DBA | 

### 準備在目標區域中遷移
<a name="prepare-for-migration-in-the-target-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在目標區域中啟動並設定 EC2 執行個體。 | 登入中國區域的 AWS 管理主控台，可以是北京或寧夏。從 Amazon EC2 主控台中，選擇「啟動執行個體」，然後建立和設定 EC2 執行個體。重要：確定傳入規則的 Amazon EC2 安全群組允許從來源機器無限制存取 TCP 連接埠 22。如需如何啟動和設定 EC2 執行個體的進一步指示，請參閱「相關資源」一節。 | DBA | 
| 記錄 Amazon Redshift 叢集詳細資訊。 | 開啟 Amazon Redshift 主控台，然後在導覽窗格中選擇「叢集」。然後從清單中選擇 Amazon Redshift 叢集名稱。在「屬性」索引標籤的「資料庫組態」區段中，記錄「資料庫名稱」和「連接埠」。開啟「連線詳細資訊」區段，並記錄「端點」，其格式為「端點：＜連接埠>/<資料庫名稱＞」。重要：請確定傳入規則的 Amazon Redshift 安全群組允許從 EC2 執行個體無限制存取 TCP 連接埠 5439。 | DBA | 
| 將 psql 連接至 Amazon Redshift 叢集。 | 在命令提示字元中，執行「psql -h <endpoint> -U <userid> -d <databasename> -p <port>」命令來指定連線資訊。在 psql 密碼提示中，輸入 "<userid>" 使用者的密碼。您接著會連線至 Amazon Redshift 叢集，並以互動方式輸入命令。 | DBA | 
| 建立 S3 儲存貯體。 | 開啟 Amazon S3 主控台，並建立 S3 儲存貯體以保留從 Amazon Redshift 匯出的檔案。如需此案例和其他案例的協助，請參閱「相關資源」一節。 | DBA | 
| 建立支援複製資料的 IAM 政策。 | 開啟 IAM 主控台並選擇「政策」。選擇「建立政策」，然後選擇「JSON」索引標籤。複製並貼上從「其他資訊」區段複製資料的 IAM 政策。重要：使用 S3 儲存貯體的名稱取代 "s3\$1bucket\$1name"。選擇「檢閱政策」，輸入政策的名稱和描述。選擇「建立政策」。 | DBA | 
| 建立 IAM 角色以允許 Amazon Redshift 的 COPY 操作。 | 開啟 IAM 主控台並選擇「角色」。選擇「建立角色」，然後在「選取信任實體類型」中選擇「AWS 服務」。為服務選擇「Redshift」，選擇「Redshift – 可自訂」，然後選擇「下一步」。選擇您先前建立的「複製」政策，然後選擇「下一步」。輸入「角色名稱」，然後選擇「建立角色」。 | DBA | 
| 將 IAM 角色與 Amazon Redshift 叢集建立關聯。 | 開啟 Amazon Redshift 主控台，然後選擇「管理 IAM 角色」。從下拉式選單中選擇「可用角色」，然後選擇您先前建立的角色。選擇「套用變更」。當「管理 IAM 角色」上 IAM 角色的「狀態」顯示為「 In-sync」時，您可以執行「COPY」命令。 | DBA | 

### 在開始遷移之前驗證來源資料和物件資訊
<a name="verify-source-data-and-object-information-before-beginning-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源 Amazon Redshift 資料表中的資料列。 | 使用「其他資訊」區段中的指令碼來驗證和記錄來源 Amazon Redshift 資料表中的資料列數。請記得平均分割 UNLOAD 和 COPY 指令碼的資料。這將改善資料卸載和載入效率，因為每個指令碼涵蓋的資料數量將會平衡。 | DBA | 
| 驗證來源 Amazon Redshift 叢集中的資料庫物件數量。 | 使用「其他資訊」區段中的指令碼來驗證和記錄來源 Amazon Redshift 叢集中的資料庫、使用者、結構描述、資料表、檢視和使用者定義函數 (UDFs) 的數量。 | DBA | 
| 在遷移之前驗證 SQL 陳述式結果。 | 某些用於資料驗證的 SQL 陳述式應根據實際業務和資料情況進行排序。這是為了驗證匯入的資料，以確保其一致且正確顯示。 | DBA | 

### 將資料和物件遷移至目標區域
<a name="migrate-data-and-objects-to-the-target-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 產生 Amazon Redshift DDL 指令碼。 | 使用「SQL 陳述式」區段中的連結來查詢 Amazon Redshift，以產生資料定義語言 (DDL) 指令碼。這些 DDL 指令碼應包含 "create user"、"create schema"、"privileges on schema to user"、"create table/view"、"privileges on object to user" 和 "create function" 查詢。 | DBA | 
| 在目標區域的 Amazon Redshift 叢集中建立物件。 | 在中國的 AWS 區域中，使用 AWS 命令列界面 (AWS CLI) 執行 DDL 指令碼。這些指令碼會在目標區域的 Amazon Redshift 叢集中建立物件。 | DBA | 
| 將來源 Amazon Redshift 叢集資料卸載至 S3 儲存貯體。 | 執行 UNLOAD 命令，將資料從來源區域中的 Amazon Redshift 叢集卸載至 S3 儲存貯體。 | DBA、開發人員  | 
| 將來源區域 S3 儲存貯體資料傳輸至目標區域 S3 儲存貯體。 | 將資料從來源區域 S3 儲存貯體傳輸到目標 S3 儲存貯體。由於無法使用「\$1 aws s3 同步」命令，請務必使用「相關資源」區段中的「將 Amazon S3 資料從 AWS 區域轉移到中國的 AWS 區域」文章中概述的程序。 | 開發人員 | 
|  將資料載入目標 Amazon Redshift 叢集。 | 在目標區域的 psql 工具中，執行 COPY 命令，將資料從 S3 儲存貯體載入目標 Amazon Redshift 叢集。 | DBA | 

### 在遷移後驗證來源和目標區域中的資料
<a name="verify-the-data-in-the-source-and-target-regions-after-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證並比較來源和目標資料表中的資料列數。 | 驗證並比較來源和目標區域中的資料表資料列數目，以確保全部都已遷移。 | DBA | 
| 驗證並比較來源和目標資料庫物件的數量。 | 驗證並比較來源和目標區域中的所有資料庫物件，以確保全部都已遷移。 | DBA | 
| 驗證和比較來源和目標區域中的 SQL 指令碼結果。 | 執行遷移之前準備的 SQL 指令碼。驗證並比較資料，以確保 SQL 結果正確。 | DBA | 
| 重設目標 Amazon Redshift 叢集中所有使用者的密碼。 | 遷移完成且所有資料都經過驗證後，您應該重設中國 AWS 區域中 Amazon Redshift 叢集的所有使用者密碼。 | DBA | 

## 相關資源
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-resources"></a>
+ [將 Amazon S3 資料從 AWS 區域傳輸到中國的 AWS 區域](https://aws.amazon.com/cn/blogs/storage/transferring-amazon-s3-data-from-aws-regions-to-aws-regions-in-china/)
+ [建立 S3 儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html)
+ [重設 Amazon Redshift 使用者密碼](https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_USER.html)
+ [psql 文件](https://www.postgresql.org/docs/8.4/static/app-psql.html)

## 其他資訊
<a name="migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china-additional"></a>

*用於卸載資料的 IAM 政策*

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket"],
      "Resource": ["arn:aws:s3:::s3_bucket_name"]
    },
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:DeleteObject"],
      "Resource": ["arn:aws:s3:::s3_bucket_name/*"]
    }
  ]
}
```

*用於複製資料的 IAM 政策*

```
{
  "Version": "2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:ListBucket"],
      "Resource": ["arn:aws:s3:::s3_bucket_name"]
    },
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": ["arn:aws:s3:::s3_bucket_name/*"]
    }
  ]
}
```

*查詢 Amazon Redshift 的 SQL 陳述式*

```
##Database

select * from pg_database where datdba>1;

##User

select * from pg_user where usesysid>1;

##Schema

SELECT n.nspname AS "Name",

  pg_catalog.pg_get_userbyid(n.nspowner) AS "Owner"

FROM pg_catalog.pg_namespace n

WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'

ORDER BY 1;

##Table

select count(*) from pg_tables where schemaname not in ('pg_catalog','information_schema');

select schemaname,count(*) from pg_tables where schemaname not in ('pg_catalog','information_schema') group by schemaname order by 1;

##View

SELECT 

    n.nspname AS schemaname,c.relname AS viewname,pg_catalog.pg_get_userbyid(c.relowner) as "Owner"

FROM 

    pg_catalog.pg_class AS c

INNER JOIN

    pg_catalog.pg_namespace AS n

    ON c.relnamespace = n.oid

WHERE relkind = 'v' and n.nspname not in ('information_schema','pg_catalog');

##UDF

SELECT 

   n.nspname AS schemaname,

   p.proname AS proname,

   pg_catalog.pg_get_userbyid(p.proowner) as "Owner"

FROM pg_proc p

LEFT JOIN pg_namespace n on n.oid = p.pronamespace

WHERE p.proowner != 1;
```

*產生 DDL 陳述式的 SQL 指令碼*
+ [Get\$1schema\$1priv\$1by\$1user 指令碼](https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_get_schema_priv_by_user.sql)
+ [Generate\$1tbl\$1ddl 指令碼](https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_generate_tbl_ddl.sql)
+ [Generate\$1view\$1ddl](https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_generate_view_ddl.sql)
+ [Generate\$1user\$1grant\$1revoke\$1ddl](https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_generate_user_grant_revoke_ddl.sql)
+ [Generate\$1udf\$1ddl](https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_generate_udf_ddl.sql)

# 使用 pg\$1transport 在兩個 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport"></a>

*Raunak Rishabh 和 Jitender Kumar，Amazon Web Services*

## 總結
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport-summary"></a>

此模式說明使用 **pg\$1transport** 擴充功能，在兩個 Amazon Relational Database Service (Amazon RDS) for PostgreSQL 資料庫執行個體之間遷移極大型資料庫的步驟。此擴充套件提供實體的傳輸機制來移動每個資料庫。透過以最少的處理方式串流資料庫檔案，它提供非常快速的方法，可在資料庫執行個體之間遷移大型資料庫，並將停機時間降至最低。此延伸模組使用提取模型，其中目標資料庫執行個體會從來源資料庫執行個體匯入資料庫。

## 先決條件和限制
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport-prereqs"></a>

**先決條件**
+ 兩個資料庫執行個體都必須執行相同的 PostgreSQL 主要版本。
+ 資料庫不得存在於目標上。否則，傳輸會失敗。
+ 來源資料庫中不得啟用 **pg\$1transport** 以外的擴充功能。
+ 所有來源資料庫物件都必須位於預設 **pg\$1default** 資料表空間中。
+ 來源資料庫執行個體的安全群組應允許來自目標資料庫執行個體的流量。
+ 安裝 PostgreSQL 用戶端，例如 [psql](https://www.postgresql.org/docs/11/app-psql.html) 或 [PgAdmin](https://www.pgadmin.org/)，以使用 Amazon RDS PostgreSQL 資料庫執行個體。您可以在本機系統中安裝用戶端，或使用 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。在此模式中，我們在 EC2 執行個體上使用 psql。

**限制**
+ 您無法在 Amazon RDS for PostgreSQL 的不同主要版本之間傳輸資料庫。
+ 來源資料庫的存取權限和擁有權不會傳輸至目標資料庫。
+ 您無法在僅供讀取複本或僅供讀取複本的父執行個體上傳輸資料庫。
+ 您無法在計劃使用此方法傳輸的任何資料庫資料表中使用 **reg** 資料類型。
+ 在資料庫執行個體上，您最多可以同時執行總共 32 個傳輸 （包括匯入和匯出）。
+ 您無法重新命名或包含/排除資料表。一切都會照原樣遷移。

**注意**
+ 在移除擴充功能之前進行備份，因為移除擴充功能也會移除相依物件和一些對資料庫操作至關重要的資料。
+ 當您判斷 **pg\$1transport** 的工作者數量和`work_mem`值時，請考慮在來源執行個體的其他資料庫上執行的執行個體類別和程序。
+ 傳輸開始時，來源資料庫上的所有連線都會結束，且資料庫會進入唯讀模式。

**注意**  
當傳輸在一個資料庫上執行時，不會影響相同伺服器上的其他資料庫。** **

**產品版本**
+ Amazon RDS for PostgreSQL 10.10 及更新版本，以及 Amazon RDS for PostgreSQL 11.5 及更新版本。如需最新版本的資訊，請參閱 Amazon RDS 文件中的在[資料庫執行個體之間傳輸 PostgreSQL 資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.TransportableDB.html)。

## Architecture
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport-architecture"></a>

![\[在 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d5fb7ea3-32b7-4602-b382-3cf5c075c7c9/images/aec4d8d2-37a8-4136-9042-f9667ac4aebb.png)


## 工具
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport-tools"></a>
+ **pg\$1transport** 提供實體傳輸機制來移動每個資料庫。透過以最少的處理方式串流資料庫檔案，實體傳輸會比傳統傾印和載入程序更快地移動資料，並且需要最少的停機時間。PostgreSQL 可傳輸的資料庫使用提取模式，也就是目的地的資料庫執行個體從來源資料庫執行個體輸入資料庫。當您準備來源和目標環境時，您可以在資料庫執行個體上安裝此延伸模組，如此模式所述。
+ [psql](https://www.postgresql.org/docs/11/app-psql.html) 可讓您連線至 PostgreSQL 資料庫執行個體並加以使用。若要在您的系統上安裝 **psql**，請參閱 [PostgreSQL 下載](https://www.postgresql.org/download/)頁面。

## 史詩
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport-epics"></a>

### 建立目標參數群組
<a name="create-the-target-parameter-group"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立目標系統的參數群組。 | 指定可識別為目標參數群組的群組名稱，例如 `pgtarget-param-group`。如需說明，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithDBInstanceParamGroups.html#USER_WorkingWithParamGroups.Creating)。 | DBA | 
| 修改參數群組的參數。 | 設定下列參數：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.html)如需這些參數的詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.TransportableDB.html)。 | DBA | 

### 建立來源參數群組
<a name="create-the-source-parameter-group"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立來源系統的參數群組。 | 指定群組名稱，將其識別為來源參數群組；例如 `pgsource-param-group`。如需說明，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithDBInstanceParamGroups.html#USER_WorkingWithParamGroups.Creating)。 | DBA | 
| 修改參數群組的參數。 | 設定下列參數：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.html)如需這些參數的詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.TransportableDB.html)。 | DBA | 

### 準備目標環境
<a name="prepare-the-target-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立新的 Amazon RDS for PostgreSQL 資料庫執行個體以傳輸來源資料庫。 | 根據您的業務需求決定執行個體類別和 PostgreSQL 版本。 | DBA、系統管理員、資料庫架構師 | 
| 修改目標的安全群組，以允許來自 EC2 執行個體的資料庫執行個體連接埠連線。 | 根據預設，PostgreSQL 執行個體的連接埠為 5432。如果您使用另一個連接埠，則必須為 EC2 執行個體開啟該連接埠的連線。 | DBA，系統管理員 | 
| 修改執行個體，並指派新的目標參數群組。 | 例如 `pgtarget-param-group`。 | DBA | 
| 重新啟動目標 Amazon RDS 資料庫執行個體。 | 參數 `shared_preload_libraries`和 `max_worker_processes`是靜態參數，需要重新啟動執行個體。 | DBA，系統管理員 | 
| 使用 psql 從 EC2 執行個體連線至資料庫。 | 使用 命令： <pre>psql -h <rds_end_point> -p PORT -U username -d database -W</pre> | DBA | 
| 建立 pg\$1transport 擴充功能。 | 以具有 `rds_superuser`角色的使用者身分執行下列查詢：<pre>create extension pg_transport;</pre> | DBA | 

### 準備來源環境
<a name="prepare-the-source-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修改來源的安全群組，以允許來自 Amazon EC2 執行個體和目標資料庫執行個體的資料庫執行個體連接埠連線 | 根據預設，PostgreSQL 執行個體的連接埠為 5432。如果您使用另一個連接埠，則必須為 EC2 執行個體開啟該連接埠的連線。 | DBA，系統管理員 | 
| 修改執行個體並指派新的來源參數群組。 | 例如 `pgsource-param-group`。 | DBA | 
| 重新啟動來源 Amazon RDS 資料庫執行個體。 | 參數 `shared_preload_libraries`和 `max_worker_processes`是靜態參數，需要重新啟動執行個體。 | DBA | 
| 使用 psql 從 EC2 執行個體連線至資料庫。 | 使用 命令： <pre>psql -h <rds_end_point> -p PORT -U username -d database -W</pre> | DBA | 
| 建立 pg\$1transport 擴充功能，並從要傳輸的資料庫移除所有其他擴充功能。 | 如果來源資料庫上安裝 **pg\$1transport** 以外的任何延伸項目，則傳輸會失敗。此命令必須由具有 `rds_superuser`角色的使用者執行。 | DBA | 

### 執行傳輸
<a name="perform-the-transport"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行試轉。 | 使用 `transport.import_from_server`函數先執行試轉：<pre>SELECT transport.import_from_server( 'source-db-instance-endpoint', source-db-instance-port, 'source-db-instance-user', 'source-user-password', 'source-database-name', 'destination-user-password', 'true');</pre>此函數的最後一個參數 （設定為 `true`) 會定義試轉。此函數會顯示您在執行主要傳輸時會看到的任何錯誤。在執行主要傳輸之前解決錯誤。 | DBA | 
| 如果試轉成功，請啟動資料庫傳輸。 | 執行 `transport.import_from_server`函數以執行傳輸。它連接到來源並匯入資料。 <pre>SELECT transport.import_from_server( 'source-db-instance-endpoint', source-db-instance-port, 'source-db-instance-user', 'source-user-password', 'source-database-name', 'destination-user-password', false);</pre>此函數的最後一個參數 （設定為 `false`) 表示這不是試轉。 | DBA | 
| 執行傳輸後步驟。 | 資料庫傳輸完成後：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.html) | DBA | 

## 相關資源
<a name="transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport-resources"></a>
+ [Amazon RDS 文件](https://docs.aws.amazon.com/rds/)
+ [pg\$1transport 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html#PostgreSQL.TransportableDB.Setup)
+ [使用 RDS PostgreSQL 可傳輸資料庫遷移資料庫 ](https://aws.amazon.com/blogs/database/migrating-databases-using-rds-postgresql-transportable-databases/)（部落格文章）
+ [PostgreSQL 下載](https://www.postgresql.org/download/linux/redhat/)
+ [psql 公用程式](https://www.postgresql.org/docs/11/app-psql.html)
+ [建立資料庫參數群組](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithParamGroups.html#USER_WorkingWithParamGroups.Creating)
+ [修改資料庫參數群組中的參數](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithParamGroups.html#USER_WorkingWithParamGroups.Modifying)
+ [PostgreSQL 下載](https://www.postgresql.org/download/)

# 平台重建
<a name="migration-replatform-pattern-list"></a>

**Topics**
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫匯出至 Amazon S3](export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms.md)
+ [將 Oracle CLOB 值遷移至 AWS 上的 PostgreSQL 中的個別資料列](migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws.md)
+ [將 Oracle PeopleSoft 遷移至 Amazon RDS Custom](migrate-oracle-peoplesoft-to-amazon-rds-custom.md)
+ [將 Oracle ROWID 功能遷移至 AWS 上的 PostgreSQL](migrate-oracle-rowid-functionality-to-postgresql-on-aws.md)
+ [將 Oracle 資料庫錯誤代碼遷移至與 Amazon Aurora PostgreSQL 相容的資料庫](migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon EC2 上的 SAP ASE 遷移至與 Amazon Aurora PostgreSQL 相容](migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms.md)
+ [使用 ACM 將 Windows SSL 憑證遷移至 Application Load Balancer](migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.md)
+ [將訊息佇列從 Microsoft Azure Service Bus 遷移至 Amazon SQS](migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs.md)
+ [使用 Oracle Data Pump 和 AWS DMS 將 Oracle JD Edwards EnterpriseOne 資料庫遷移至 AWS](migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.md)
+ [使用 AWS DMS 將 Oracle PeopleSoft 資料庫遷移至 AWS](migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.md)
+ [將內部部署 MySQL 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server.md)
+ [使用 Rclone 將資料從 Microsoft Azure Blob 遷移至 Amazon S3](migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone.md)
+ [從 Couchbase Server 遷移至 AWS 上的 Couchbase Capella](migrate-from-couchbase-server-to-couchbase-capella-on-aws.md)
+ [從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat](migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2.md)
+ [使用 Auto Scaling 從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat](migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling.md)
+ [將 .NET 應用程式從 Microsoft Azure App Service 遷移至 AWS Elastic Beanstalk](migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk.md)
+ [在 Amazon ECS 上從 Oracle WebLogic 遷移至 Apache Tomcat (TomEE)](migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs.md)
+ [使用 AWS DMS 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms.md)
+ [使用 Logstash 將內部部署 Oracle 資料庫遷移至 Amazon OpenSearch Service](migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump.md)
+ [使用 pglogical 從 Amazon EC2 上的 PostgreSQL 遷移至 Amazon RDS for PostgreSQL Amazon EC2](migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical.md)
+ [將內部部署 PostgreSQL 資料庫遷移至 Aurora PostgreSQL](migrate-an-on-premises-postgresql-database-to-aurora-postgresql.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至執行 Linux 的 Amazon EC2 上的 Microsoft SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux.md)
+ [使用連結的伺服器將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers.md)
+ [使用原生備份和還原方法，將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods.md)
+ [使用 AWS DMS 和 AWS SCT 將 Microsoft SQL Server 資料庫遷移至 Aurora MySQL](migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct.md)
+ [使用原生工具將內部部署 MariaDB 資料庫遷移至 Amazon RDS for MariaDB](migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools.md)
+ [將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-an-on-premises-mysql-database-to-aurora-mysql.md)
+ [使用 Percona XtraBackup、Amazon EFS 和 Amazon S3 將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3.md)
+ [使用 AWS App2Container 將內部部署 Java 應用程式遷移至 AWS](migrate-on-premises-java-applications-to-aws-using-aws-app2container.md)
+ [在 AWS 大型遷移中遷移共用檔案系統](migrate-shared-file-systems-in-an-aws-large-migration.md)
+ [使用 Oracle GoldenGate 平面檔案轉接器，將 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters.md)
+ [變更 Python 和 Perl 應用程式，以支援從 Microsoft SQL Server 到 Amazon Aurora PostgreSQL 相容版本的資料庫遷移](change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.md)

# 使用 AWS DMS 將 Microsoft SQL Server 資料庫匯出至 Amazon S3
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms"></a>

*Sweta Krishna，Amazon Web Services*

## 總結
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-summary"></a>

組織通常需要將資料庫複製到 Amazon Simple Storage Service (Amazon S3)，以進行資料庫遷移、備份和還原、資料封存和資料分析。此模式說明如何將 Microsoft SQL Server 資料庫匯出至 Amazon S3。來源資料庫可以在內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) 或 Amazon Web Services (AWS) Cloud 上 Microsoft SQL Server 的 Amazon Relational Database Service (Amazon RDS) 上託管。

使用 AWS Database Migration Service (AWS DMS) 匯出資料。根據預設，AWS DMS 會以逗號分隔值 (.csv) 格式寫入完全載入和變更資料擷取 (CDC) 資料。對於更精簡的儲存和更快的查詢選項，此模式使用 Apache Parquet (.parquet) 格式選項。

## 先決條件和限制
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 帳戶 AWS Identity and Access Management (IAM) 角色，具有目標 S3 儲存貯體的寫入、刪除和標記存取權，而 AWS DMS (`dms.amazonaws.com`) 已新增為此 IAM 角色的信任實體
+ 內部部署 Microsoft SQL Server 資料庫 （或 EC2 執行個體或 Amazon RDS for SQL Server 資料庫上的 Microsoft SQL Server)
+ AWS 上的虛擬私有雲端 (VPC) 與 AWS Direct Connect 或虛擬私有網路 (VPN) 提供的內部部署網路之間的網路連線

**限制**
+ AWS DMS 3.4.7 之前的版本目前不支援啟用 VPC （閘道 VPC) S3 儲存貯體。
+ 不支援在完全載入階段變更來源資料表結構。
+ 不支援 AWS DMS 完整大型二進位物件 (LOB) 模式。

**產品版本**
+ 適用於 Enterprise、Standard、Workgroup 和 Developer 版本的 Microsoft SQL Server 2005 版或更新版本。
+ AWS DMS 3.3.2 版及更新版本提供 Microsoft SQL Server 2019 版做為來源的支援。

## Architecture
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ 內部部署 Microsoft SQL Server 資料庫 （或 EC2 執行個體或 Amazon RDS for SQL Server 資料庫上的 Microsoft SQL Server)**** 

**目標技術堆疊**
+ AWS Direct Connect
+ AWS DMS
+ Amazon S3

**目標架構**

![\[資料會透過 Direct Connect 從 SQL Server 資料庫遷移至 AWS DMS，然後遷移至 S3 儲存貯體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/75b8b20f-a1a8-4633-9816-1b370cc7e92c/images/85bd433c-4a0a-4825-8661-e53f53265191.png)


## 工具
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 透過標準乙太網路光纖纜線，將您的內部網路連結至 Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的虛擬介面，同時略過網路路徑中的網際網路服務供應商。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

## 史詩
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料庫版本。 | 驗證來源資料庫版本，並確認 AWS DMS 支援該版本。如需有關支援的 SQL Server 資料庫版本的資訊，請參閱[使用 Microsoft SQL Server 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html)。 | DBA | 
| 建立 VPC 和安全群組。 | 在您的 AWS 帳戶中，建立 VPC 和安全群組。如需詳細資訊，請參閱 [Amazon VPC 文件](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)。 | 系統管理員 | 
| 為 AWS DMS 任務建立使用者。 | 在來源資料庫中建立 AWS DMS 使用者，並授予其讀取許可。AWS DMS 將使用此使用者。 | DBA | 
| 測試資料庫連線。 | 從 AWS DMS 使用者測試 SQL Server 資料庫執行個體的連線。 | DBA | 
| 建立 S3 儲存貯體。 | 建立目標 S3 儲存貯體。此儲存貯體將保留遷移的資料表資料。 | 系統管理員 | 
| 建立 IAM 政策和角色。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms.html) | 系統管理員 | 

### 使用 AWS DMS 遷移資料
<a name="migrate-data-by-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 複寫執行個體。 | 登入 AWS 管理主控台，然後開啟 AWS DMS 主控台。在導覽窗格中，選擇**複寫執行個體**、**建立複寫執行個體**。如需說明，請參閱 AWS DMS 文件中的[步驟 1](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Replication.html#CHAP_GettingStarted.Replication.ReplicationInstance)。 | DBA | 
| 建立來源和目標端點。 | 建立來源和目標端點。測試從複寫執行個體到來源和目標端點的連線。如需說明，請參閱 AWS DMS 文件中的[步驟 2](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Replication.html#CHAP_GettingStarted.Replication.Endpoints)。 | DBA | 
| 建立複寫任務。 | 建立複寫任務，然後選取具有變更資料擷取 (CDC) 的完全載入或完全載入，將資料從 SQL Server 遷移至 S3 儲存貯體。如需說明，請參閱 AWS DMS 文件中的[步驟 3](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Replication.html#CHAP_GettingStarted.Replication.Tasks)。 | DBA | 
| 啟動資料複寫。 | 啟動複寫任務，並監控日誌是否有任何錯誤。 | DBA | 

### 驗證資料
<a name="validate-the-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證遷移的資料。 | 在 主控台上，導覽至您的目標 S3 儲存貯體。開啟與來源資料庫同名的子資料夾。確認資料夾包含從來源資料庫遷移的所有資料表。 | DBA | 

### 清除資源
<a name="clean-up-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉並刪除臨時 AWS 資源。 | 關閉您為資料遷移建立的臨時 AWS 資源，例如 AWS DMS 複寫執行個體，並在驗證匯出後將其刪除。 | DBA | 

## 相關資源
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-resources"></a>
+ [AWS Database Migration Service 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [使用 Microsoft SQL Server 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html)
+ [使用 Amazon S3 做為 AWS Database Migration Service 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.S3.html)
+ [使用 S3 儲存貯體做為 AWS DMS 目標](https://repost.aws/knowledge-center/s3-bucket-dms-target) (AWS re：Post)

## 其他資訊
<a name="export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms-additional"></a>

使用下列程式碼，為 AWS DMS 角色新增具有 S3 儲存貯體許可的 IAM 政策。用您的儲存貯體名稱取代 `bucketname`。

```
{
     "Version": "2012-10-17",		 	 	 
     "Statement": [
         {
             "Effect": "Allow",
             "Action": [
                 "s3:PutObject",
                 "s3:DeleteObject"
             ],
             "Resource": [
                 "arn:aws:s3:::bucketname*"
             ]
         },
         {
             "Effect": "Allow",
             "Action": [
                 "s3:ListBucket"
             ],
             "Resource": [
                 "arn:aws:s3:::bucketname*"
             ]
         }
     ]
 }
```

# 將 Oracle CLOB 值遷移至 AWS 上的 PostgreSQL 中的個別資料列
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws"></a>

*Sai Krishna Namburu 和 Sindhusha Paturu，Amazon Web Services*

## 總結
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-summary"></a>

此模式說明如何將 Oracle 字元大型物件 (CLOB) 值分割為適用於 PostgreSQL 的 Amazon Aurora PostgreSQL 相容版本和 Amazon Relational Database Service (Amazon RDS) PostgreSQL 中的個別資料列。PostgreSQL 不支援 CLOB 資料類型。

具有間隔分割區的資料表會在來源 Oracle 資料庫中識別，而資料表名稱、分割區類型、分割區的間隔，以及其他中繼資料會擷取並載入目標資料庫。您可以使用 AWS Database Migration Service (AWS DMS) 將大小小於 1 GB 的 CLOB 資料以文字形式載入目標資料表，也可以匯出 CSV 格式的資料、將其載入 Amazon Simple Storage Service (Amazon S3) 儲存貯體，然後將其遷移至目標 PostgreSQL 資料庫。

遷移後，您可以使用此模式隨附的自訂 PostgreSQL 程式碼，根據新的行字元識別符 (`CHR(10)`) 將 CLOB 資料分割為個別資料列，並填入目標****資料表。 

## 先決條件和限制
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-prereqs"></a>

**先決條件**
+ 具有間隔分割區和 CLOB 資料類型記錄的 Oracle 資料庫資料表。
+ Aurora PostgreSQL 相容或 Amazon RDS for PostgreSQL 資料庫，其資料表結構類似於來源資料表 （相同的資料欄和資料類型）。

**限制**
+ CLOB 值不能超過 1 GB。
+ 目標資料表中的每一列都必須有新的行字元識別符。

**產品版本**
+ Oracle 12c
+ Aurora Postgres 11.6

## Architecture
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-architecture"></a>

下圖顯示具有 CLOB 資料的來源 Oracle 資料表，以及 Aurora PostgreSQL 相容 11.6 版中的同等 PostgreSQL 資料表。

![\[來源 CLOB 資料表和對等目標 PostgreSQL 資料表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/55806ee7-6a9f-4058-9a47-a07de68223ca/images/79b9d4b9-6f20-4db5-8ca8-2a599769a498.png)


## 工具
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管且符合 ACID 規範的關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**其他工具**

您可以使用下列用戶端工具來連接、存取和管理 Aurora PostgreSQL 相容和 Amazon RDS for PostgreSQL 資料庫。（這些工具不會在此模式中使用。)
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。
+ [DBeaver](https://dbeaver.io/) 是開發人員和資料庫管理員的開放原始碼資料庫工具。您可以使用 工具來操作、監控、分析、管理和遷移資料。

## 最佳實務
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-best-practices"></a>

如需將資料庫從 Oracle 遷移至 PostgreSQL 的最佳實務，請參閱 AWS 部落格文章[將 Oracle 資料庫遷移至 Amazon RDS PostgreSQL 或 Amazon Aurora PostgreSQL 的最佳實務：遷移程序和基礎設施考量](https://aws.amazon.com/blogs/database/best-practices-for-migrating-an-oracle-database-to-amazon-rds-postgresql-or-amazon-aurora-postgresql-migration-process-and-infrastructure-considerations/)。

如需設定 AWS DMS 任務以遷移大型二進位物件的最佳實務，請參閱 AWS DMS 文件中的[遷移大型二進位物件 (LOBs)](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.html#CHAP_BestPractices.LOBS)。

## 史詩
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-epics"></a>

### 識別 CLOB 資料
<a name="identify-the-clob-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 分析 CLOB 資料。 | 在來源 Oracle 資料庫中，分析 CLOB 資料，以查看它是否包含資料欄標頭，讓您可以判斷將資料載入目標資料表的方法。 若要分析輸入資料，請使用下列查詢。`SELECT * FROM clobdata_or;  ` | 開發人員 | 
| 將 CLOB 資料載入目標資料庫。 | 將具有 CLOB 資料的資料表遷移至 Aurora 或 Amazon RDS 目標資料庫中的臨時 （預備） 資料表。您可以使用 AWS DMS 或將資料作為 CSV 檔案上傳至 Amazon S3 儲存貯體。如需針對此任務使用 AWS DMS 的詳細資訊，請參閱 AWS DMS 文件中的[使用 Oracle 資料庫做為來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)和[使用 PostgreSQL 資料庫做為目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)。如需針對此任務使用 Amazon S3 的詳細資訊，請參閱 AWS DMS 文件中的[使用 Amazon S3 做為目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.S3.html)。 | 遷移工程師，DBA | 
| 驗證目標 PostgreSQL 資料表。 | 使用目標資料庫中的下列查詢，針對來源資料驗證目標資料，包括標頭。<pre>SELECT * FROM clobdata_pg;<br />SELECT * FROM clobdatatarget;</pre>將結果與來源資料庫的查詢結果進行比較 （從第一個步驟）。 | 開發人員 | 
| 將 CLOB 資料分割成不同的資料列。 | 執行[其他資訊](#migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-additional)區段中提供的自訂 PostgreSQL 程式碼，以分割 CLOB 資料，並將其插入目標 PostgreSQL 資料表中的個別資料列。 | 開發人員 | 

### 驗證資料。
<a name="validate-the-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證目標資料表中的資料。 | 使用以下查詢驗證插入目標資料表的資料。<pre>SELECT * FROM clobdata_pg;<br />SELECT * FROM clobdatatarget;</pre> | 開發人員 | 

## 相關資源
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-resources"></a>
+ [CLOB 資料類型](https://docs.oracle.com/database/121/SQLRF/sql_elements001.htm#SQLRF0021) (Oracle 文件）
+ [資料類型 ](https://www.postgresql.org/docs/11/datatype.html)(PostgreSQL 文件）

## 其他資訊
<a name="migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws-additional"></a>

**用於分割 CLOB 資料的 PostgreSQL 函數**

```
do
$$
declare
totalstr varchar;
str1 varchar;
str2 varchar;
pos1 integer := 1;
pos2 integer ;
len integer;


begin
        select rawdata||chr(10) into totalstr from clobdata_pg;
        len :=  length(totalstr) ;
        raise notice 'Total length : %',len;
        raise notice 'totalstr : %',totalstr;
        raise notice 'Before while loop';


        while pos1 < len  loop


                  select position (chr(10) in totalstr) into pos2;
                 raise notice '1st position of new line : %',pos2;


                str1 := substring (totalstr,pos1,pos2-1);
                raise notice 'str1 : %',str1;


                   insert into clobdatatarget(data) values (str1);
                   totalstr := substring(totalstr,pos2+1,len);
                   raise notice 'new totalstr :%',totalstr;
                len :=  length(totalstr) ;


        end loop;
end
$$
LANGUAGE 'plpgsql' ;
```

**輸入和輸出範例**

您可以使用下列範例，在遷移資料之前嘗試 PostgreSQL 程式碼。

建立具有三個輸入列的 Oracle 資料庫。

```
CREATE TABLE clobdata_or (
id INTEGER GENERATED ALWAYS AS IDENTITY,
rawdata clob  );


insert into clobdata_or(rawdata) values (to_clob('test line 1') || chr(10) || to_clob('test line 2') || chr(10) || to_clob('test line 3') || chr(10));
COMMIT;


SELECT * FROM clobdata_or;
```

這會顯示下列輸出。


|  |  | 
| --- |--- |
| id | 原始資料 | 
| 1 | 測試列 1 測試列 2 測試列 3 | 

將來源資料載入 PostgreSQL 預備資料表 (`clobdata_pg`) 進行處理。

```
SELECT * FROM clobdata_pg;

CREATE TEMP TABLE clobdatatarget (id1 SERIAL,data VARCHAR );

<Run the code in the additional information section.>

SELECT * FROM clobdatatarget;
```

這會顯示下列輸出。


|  |  | 
| --- |--- |
| id1 | data | 
| 1 | 測試列 1 | 
| 2 | 測試列 2 | 
| 3 | 測試列 3 | 

# 將 Oracle PeopleSoft 遷移至 Amazon RDS Custom
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom"></a>

*Gaurav Gupta，Amazon Web Services*

## 摘要
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-summary"></a>

[Oracle PeopleSoft](https://www.oracle.com/applications/peoplesoft/) 是適用於整個企業程序的企業資源規劃 (ERP) 解決方案。PeopleSoft 具有三層架構：用戶端、應用程式和資料庫。PeopleSoft 可以在 [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 上執行。現在，您也可以在 [Amazon RDS Custom](https://aws.amazon.com/rds/custom/) 上執行 PeopleSoft，這可讓您存取基礎作業系統。

[Amazon RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/working-with-custom-oracle.html) 是一種受管資料庫服務，適用於需要存取基礎作業系統和資料庫環境的舊版、自訂和封裝應用程式。當您將 Oracle 資料庫遷移至 Amazon RDS Custom 時，Amazon Web Services (AWS) 可以管理備份任務和高可用性，同時可以專注於維護 PeopleSoft 應用程式和功能。如需考慮遷移的關鍵因素，請參閱 AWS 方案指引中的 [Oracle 資料庫遷移策略](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/strategies.html)。

此模式著重於使用 Oracle Recovery Manager (RMAN) 備份，將 Amazon Elastic Compute Cloud (Amazon EC2) 上的 PeopleSoft 資料庫遷移至 Amazon RDS Custom 的步驟。它在 EC2 執行個體和 [Amazon RDS Custom 之間使用 Amazon Elastic File System (Amazon EFS)](https://aws.amazon.com/efs/) 共用檔案系統，但您也可以使用 Amazon FSx 或任何共用磁碟機。模式使用 RMAN 完整備份 （有時稱為層級 0 備份）。

## 先決條件和限制
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-prereqs"></a>

**先決條件**
+ 使用 Oracle Linux 7、Oracle Linux 8、Red Hat Enterprise Linux (RHEL) 7 或 RHEL 8 在 Amazon EC2 上執行的 Oracle 19C 版來源資料庫。在此模式範例中，來源資料庫名稱為 `FSDMO92`，但這並非必要項目。
**注意**  
您也可以將此模式與現場部署 Oracle 來源資料庫搭配使用。您必須擁有內部部署網路與虛擬私有雲端 (VPC) 之間的適當網路連線。
+ PeopleSoft 9.2 示範執行個體。
+ 單一 PeopleSoft 應用程式層。不過，您可以調整此模式以使用多個應用程式層。
+ Amazon RDS Custom 已設定至少 8 GB 的交換空間。

**限制**

此模式不支援下列組態：
+ 將資料庫`ARCHIVE_LAG_TARGET`參數設定為 60–7200 範圍以外的值
+ 停用資料庫執行個體日誌模式 (`NOARCHIVELOG`)
+ 關閉 EC2 執行個體的 Amazon Elastic Block Store (Amazon EBS) 最佳化屬性
+ 修改連接至 EC2 執行個體的原始 EBS 磁碟區
+ 新增 EBS 磁碟區，或將磁碟區類型從 gp2 變更為 gp3
+ 變更 `LOG_ARCHIVE_FORMAT` 參數的延伸格式 （需要 `*.arc`)
+ 多工或變更控制檔案位置和名稱 （必須是 `/rdsdbdata/db/*DBNAME*/controlfile/control-01.ctl`)

如需有關這些和其他不支援組態的其他資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-troubleshooting.html#custom-troubleshooting.fix-unsupported)。

**產品版本**

對於 Amazon RDS Custom 支援的 Oracle 資料庫版本和執行個體類別，請參閱 [Amazon RDS Custom for Oracle 的需求和限制。](https://docs.amazonaws.cn/en_us/AmazonRDS/latest/UserGuide/custom-reqs-limits.html)

## Architecture
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-architecture"></a>

**目標技術堆疊**
+ Application Load Balancer
+ Amazon EFS
+ Amazon RDS Custom for Oracle
+ AWS Secrets Manager
+ Amazon Simple Storage Service (Amazon S3)

**目標架構**

下列架構圖代表在 AWS 上單一[可用區域中](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html)執行的 PeopleSoft 系統。應用程式層是透過 [Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/) 存取。應用程式和資料庫都位於私有子網路中，Amazon RDS Custom 和 Amazon EC2 資料庫執行個體會使用 Amazon EFS 共用檔案系統來存放和存取 RMAN 備份檔案。Amazon S3 用於建立自訂 RDS Oracle 引擎和儲存重做日誌中繼資料。

![\[Web 伺服器、應用程式伺服器、Amazon RDS Custom、EC2 資料庫執行個體和私有子網路中的 Amazon EFS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bd423dfe-f3c8-42d9-ac84-bf3d093c52bc/images/0e9a6431-e6c7-4047-ae6c-85311938041f.jpeg)


## 工具
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-tools"></a>

**工具**

*AWS 服務*
+ [Amazon RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/working-with-custom-oracle.html) 是一種受管資料庫服務，適用於需要存取基礎作業系統和資料庫環境的舊版、自訂和封裝應用程式。它可自動化資料庫管理任務，例如備份和高可用性。 
+ [Amazon Elastic File System (Amazon EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) 可協助您在 AWS 雲端中建立和設定共用檔案系統。此模式使用 Amazon EFS 共用檔案系統來存放和存取 RMAN 備份檔案。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您使用以程式設計方式擷取秘密的 API 呼叫取代程式碼中的硬式編碼登入資料，包括密碼。在此模式中，您會從 Secrets Manager 擷取資料庫使用者密碼，以建立 `RDSADMIN`和 `ADMIN`使用者，以及變更 `sys`和 `system`密碼。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [Elastic Load Balancing (ELB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) 會將傳入的應用程式或網路流量分散到多個目標。例如，您可以將流量分散到一或多個可用區域中的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體、容器和 IP 地址。此模式使用 Application Load Balancer。

*其他工具*
+ Oracle Recovery Manager (RMAN) 提供 Oracle 資料庫的備份和復原支援。此模式使用 RMAN 在 Amazon EC2 上執行在 Amazon RDS Custom 上還原的來源 Oracle 資料庫熱備份。

## 最佳實務
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-best-practices"></a>
+ 對於資料庫初始化參數，自訂 Amazon RDS Custom 資料庫執行個體為 PeopleSoft 提供的標準 pfile，而不是使用 Oracle 來源資料庫中的 spfile。這是因為在 Amazon RDS Custom 中建立僅供讀取複本時，空格和註解會導致問題。如需資料庫初始化參數的詳細資訊，請參閱 Oracle Support Note 1100831.1 （需要 [Oracle Support](https://support.oracle.com/portal/) 帳戶）。
+ 根據預設，Amazon RDS Custom 會使用 Oracle 自動記憶體管理。如果您想要使用 Hugemem 核心，您可以將 Amazon RDS Custom 設定為改用自動共用記憶體管理。
+ 預設為啟用 `memory_max_target` 參數。框架會在背景使用此項目來建立僅供讀取複本。
+ 啟用 Oracle Flashback 資料庫。此功能在容錯移轉 （非切換） 測試案例中恢復待命時非常有用。

## 史詩
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-epics"></a>

### 設定資料庫執行個體和檔案系統
<a name="set-up-the-db-instance-and-file-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料庫執行個體。 | 在 Amazon RDS 主控台中，使用稱為 FSDMO92 （或您的來源資料庫名稱） 的資料庫名稱建立 Amazon RDS Custom for Oracle 資料庫執行個體。如需說明，請參閱 AWS 文件中的[使用 Amazon RDS Custom](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-custom.html) 和[資料庫環境部落格文章中的 Amazon RDS Custom for Oracle – 新控制功能](https://aws.amazon.com/blogs/aws/amazon-rds-custom-for-oracle-new-control-capabilities-in-database-environment/)。這可確保資料庫名稱設定為與來源資料庫相同的名稱。（如果保持空白，EC2 執行個體和資料庫名稱將設定為 `ORCL`。) | DBA | 

### 執行來源 Amazon EC2 資料庫的 RMAN 完整備份
<a name="perform-an-rman-full-backup-of-the-source-amazon-ec2-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立備份指令碼。 | 建立 RMAN 備份指令碼 ，將資料庫備份到您掛載的 Amazon EFS 檔案系統 (`/efs`在下列範例中）。您可以使用範例程式碼或執行其中一個現有的 RMAN 指令碼。<pre>#!/bin/bash<br />Dt=`date +'%Y%m%d-%H%M'`<br />BACKUP_LOG="rman-${ORACLE_SID}-$Dt"<br />export TAGDATE=`date +%Y%m%d%H%M`;<br />LOGPATH=/u01/scripts/logs<br />rman target / >> $LOGPATH/rman-${ORACLE_SID}-$Dt << EOF<br />SQL "ALTER SYSTEM SWITCH LOGFILE";<br />SQL "ALTER SESSION SET NLS_DATE_FORMAT="DD.MM.YYYY HH24:MI:SS"";<br />RUN<br />{<br />  ALLOCATE CHANNEL ch11 TYPE DISK MAXPIECESIZE 5G;<br />  ALLOCATE CHANNEL ch12 TYPE DISK MAXPIECESIZE 5G;<br />  BACKUP AS COMPRESSED BACKUPSET FULL DATABASE FORMAT '/efs/rman_backup/FSCM/%d_%T_%s_%p_FULL' ;<br />  SQL "ALTER SYSTEM ARCHIVE LOG CURRENT";<br />  BACKUP FORMAT '/efs/rman_backup/FSCM/%d_%T_%s_%p_ARCHIVE' ARCHIVELOG ALL DELETE ALL INPUT ;<br />  BACKUP CURRENT CONTROLFILE FORMAT '/efs/rman_backup/FSCM/%d_%T_%s_%p_CONTROL';<br />}<br />EXIT;<br />EOF<br />  </pre> | DBA | 
| 執行備份指令碼。 | 若要執行 RMAN 備份指令碼，請以 Oracle Home User 身分登入，然後執行指令碼。<pre>$  chmod a+x rman_backup.sh<br />$ ./rman_backup.sh &</pre> | DBA | 
| 檢查是否有錯誤，並記下備份檔案的名稱。 | 檢查 RMAN 日誌檔案是否有錯誤。如果一切正常，請執行下列命令列出控制檔案的備份。<pre>RMAN> list backup of controlfile;<br /><br />using target database control file instead of recovery catalog<br /></pre>請記下輸出檔案的名稱。<pre>List of Backup Sets<br />===================<br /><br />BS Key  Type LV Size       Device Type Elapsed Time Completion Time<br />------- ---- -- ---------- ----------- ------------ ---------------<br />12      Full    21.58M     DISK        00:00:01     13-JUL-22<br />        BP Key: 12   Status: AVAILABLE  Compressed: NO  Tag: TAG20220713T150155<br />        Piece Name: /efs/rman_backup/FSCM/FSDMO92_20220713_12_1_CONTROL<br /> Control File Included: Ckp SCN: 16559159985898   Ckp time: 13-JUL-22<br /></pre>當您在 Amazon RDS Custom 上還原資料庫`/efs/rman_backup/FSCM/FSDMO92_20220713_12_1_CONTROL`時，將使用備份控制檔案。 | DBA | 

### 關閉來源應用程式層
<a name="shut-down-the-source-application-tier"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉應用程式。 | 若要關閉來源應用程式層，請使用 `psadmin`公用程式或`psadmin`命令列公用程式。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA，PeopleSoft 管理員 | 

### 設定目標 Amazon RDS Custom 資料庫
<a name="configure-the-target-amazon-rds-custom-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 nfs-utils rpm 套件。 | 若要安裝`nfs-utils rpm`套件，請執行下列命令。<pre>$ yum install -y nfs-utils<br /></pre> | DBA | 
| 掛載 EFS 儲存體。 | 從 Amazon EFS 主控台頁面取得 Amazon EFS 掛載命令。使用網路檔案系統 (NFS) 用戶端在 Amazon RDS 執行個體上掛載 EFS 檔案系統。<pre>sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-xxxxxxxxxx.efs.eu-west-1.amazonaws.com:/ /efs<br />sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-xxxxxxxxxx.efs.eu-west-1.amazonaws.com:/ /efs</pre> | DBA | 

### 捨棄入門資料庫並建立目錄以存放資料庫檔案
<a name="drop-the-starter-database-and-create-the-directories-to-store-the-database-files"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 暫停自動化模式。 | 您必須先暫停 Amazon RDS Custom 資料庫執行個體上的[自動化模式](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-managing.html#custom-managing.pausing)，才能繼續後續步驟，以確保自動化不會干擾 RMAN 還原活動。您可以使用 AWS 主控台或 AWS 命令列界面 (AWS CLI) 命令 （請確定您已先[設定 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)) 來暫停自動化。<pre>aws rds modify-db-instance \<br />--db-instance-identifier peoplesoft-fscm-92 \<br />--automation-mode all-paused \<br />--resume-full-automation-mode-minute 360 \<br />--region eu-west-1<br /></pre>當您指定暫停的持續時間時，請確定您有足夠的時間進行 RMAN 還原。這取決於來源資料庫的大小，因此請相應地修改 360 值。此外，請確定暫停自動化的總時間不會與資料庫的備份或維護時段重疊。 | DBA | 
| 建立和修改 PeopleSoft 的參數檔案 | 若要建立和修改 PeopleSoft 的 pfile， 請使用使用 Amazon RDS Custom 資料庫執行個體建立的標準 pfile。新增 PeopleSoft 所需的參數。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA | 
| 捨棄入門資料庫。 | 若要捨棄現有的 Amazon RDS Custom 資料庫，請使用下列程式碼。<pre>$ sqlplus / as sysdba<br />SQL> shutdown immediate;<br />SQL> startup mount exclusive restrict;<br />SQL> drop database;<br />SQL> exit</pre> |  | 
| 從備份還原 Amazon RDS Custom 資料庫。 | 使用下列指令碼還原資料庫。指令碼會先還原控制檔案，然後從存放在 EFS 掛載上的備份片段還原整個資料庫。<pre>#!/bin/bash<br />Dt=`date +'%Y%m%d-%H%M'`<br />BACKUP_LOG="rman-${ORACLE_SID}-$Dt"<br />export TAGDATE=`date +%Y%m%d%H%M`;<br />LOGPATH=/rdsdbdata/scripts/logs<br />rman target / >> $LOGPATH/rman-${ORACLE_SID}-$Dt << EOF<br />restore controlfile from "/efs/rman_backup/FSCM/FSDMO92_20220713_12_1_CONTROL";<br />alter database mount;<br />run<br />{<br />set newname for database to '/rdsdbdata/db/FSDMO92_A/datafile/%f_%b';<br />SET NEWNAME FOR TEMPFILE 1 TO '/rdsdbdata/db/FSDMO92_A/datafile/%f_%b';<br />RESTORE DATABASE;<br />SWITCH DATAFILE ALL;<br />SWITCH TEMPFILE ALL;<br />RECOVER DATABASE;<br />}<br />EOF<br />sqlplus / as sysdba >> $LOGPATH/rman-${ORACLE_SID}-$Dt<<-EOF<br />ALTER DATABASE RENAME FILE '/u01/psoft/db/oradata/FSDMO92/redo01.log' TO '/rdsdbdata/db/FSDMO92_A/onlinelog/redo01.log';<br />ALTER DATABASE RENAME FILE '/u01/psoft/db/oradata/FSDMO92/redo02.log' TO '/rdsdbdata/db/FSDMO92_A/onlinelog/redo02.log';<br />ALTER DATABASE RENAME FILE '/u01/psoft/db/oradata/FSDMO92/redo03.log' TO '/rdsdbdata/db/FSDMO92_A/onlinelog/redo03.log';<br />alter database clear unarchived logfile group 1;<br />alter database clear unarchived logfile group 2;<br />alter database clear unarchived logfile group 3;<br />alter database open resetlogs;<br />EXIT<br />EOF<br /></pre> | DBA | 

### 從 Secrets Manager 擷取密碼、建立使用者和變更密碼
<a name="retrieve-passwords-from-secrets-manager-create-users-and-change-passwords"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Secrets Manager 擷取密碼。 | 您可以使用 AWS 主控台或 AWS CLI 來執行此步驟。下列步驟顯示 主控台的指示。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA | 
| 建立 RDSADMIN 使用者。 | `RDSADMIN` 是用於監控和協調 Amazon RDS Custom 資料庫執行個體的資料庫使用者。由於啟動者資料庫已捨棄，且目標資料庫已使用 RMAN 從來源還原，因此您必須在還原操作後重新建立此使用者，以確保 Amazon RDS Custom 監控如預期般運作。您也必須為`RDSADMIN`使用者建立單獨的設定檔和資料表空間。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA | 
| 建立主要使用者。 | 由於啟動者資料庫已捨棄，且目標資料庫已使用 RMAN 從來源還原，因此您必須重新建立主要使用者。在此範例中，主要使用者名稱為 `admin`。<pre>SQL> create user admin identified by <password>;<br />SQL> grant dba to admin</pre> | DBA | 
| 變更系統密碼。 | 使用您從 Secrets Manager 擷取的密碼來變更系統密碼。<pre>SQL> alter user sys identified by xxxxxxxxxxx;<br />SQL> alter user system identified by xxxxxxxxxx;</pre>如果您不變更這些密碼，Amazon RDS Custom 會顯示錯誤訊息「資料庫監控使用者或使用者登入資料已變更」。 | DBA | 

### 設定 Amazon RDS Custom 和 PeopleSoft 的 TNS 項目
<a name="configure-the-tns-entries-for-amazon-rds-custom-and-peoplesoft"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 tnsnames 檔案。 | 若要從應用程式層連線至資料庫，請設定 `tnsnames.ora` 檔案，以便從應用程式層連線至資料庫。在下列範例中，您可以看到 `tnsnames.ora` 檔案有軟連結，但檔案預設為空白。 <pre>$ cd /rdsdbbin/oracle/network/admin<br />$ ls -ltr<br />-rw-r--r-- 1 rdsdb database 1536 Feb 14  2018 shrept.lst<br />lrwxrwxrwx 1 rdsdb database   30 Apr  5 13:19 listener.ora -> /rdsdbdata/config/listener.ora<br />lrwxrwxrwx 1 rdsdb database   28 Apr  5 13:19 sqlnet.ora -> /rdsdbdata/config/sqlnet.ora<br />lrwxrwxrwx 1 rdsdb database   30 Apr  5 13:19 tnsnames.ora -> /rdsdbdata/config/tnsnames.ora</pre>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA | 

### 建立 spfile softlink
<a name="create-the-spfile-softlink"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 spfile softlink。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA | 

### 執行遷移後步驟
<a name="perform-post-migration-steps"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證結構描述、連線和維護任務。 | 若要完成遷移，請執行下列任務。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) | DBA | 

## 相關資源
<a name="migrate-oracle-peoplesoft-to-amazon-rds-custom-resources"></a>
+ [使用 Amazon RDS Custom](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-custom.html)
+ [Amazon RDS Custom for Oracle – 資料庫環境中的新控制功能 ](https://aws.amazon.com/blogs/aws/amazon-rds-custom-for-oracle-new-control-capabilities-in-database-environment/)（部落格文章）
+ [將 Amazon RDS Custom for Oracle 與 Amazon EFS 整合 ](https://aws.amazon.com/blogs/database/integrate-amazon-rds-custom-for-oracle-with-amazon-efs/)（部落格文章）
+ [將 Amazon RDS 設定為 Oracle PeopleSoft 資料庫](https://d1.awsstatic.com/whitepapers/configuring-amazon-rds-as-peoplesoft-database.pdf) (AWS 白皮書）

# 將 Oracle ROWID 功能遷移至 AWS 上的 PostgreSQL
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws"></a>

*Rakesh Raghav 和 Ramesh Pathuri，Amazon Web Services*

## 總結
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-summary"></a>

此模式說明將 Oracle 資料庫中的`ROWID`虛擬資料欄功能遷移至 PostgreSQL (Amazon Relational Database Service RDS) for PostgreSQL、Amazon Aurora PostgreSQL 相容版本或 Amazon Elastic Compute Cloud (Amazon EC2) 中 PostgreSQL 資料庫的選項。

在 Oracle 資料庫中，`ROWID`虛擬資料欄是資料表中資料列的實體地址。即使資料表上沒有主索引鍵，此虛擬資料欄也會用來唯一識別資料列。PostgreSQL 具有稱為 的類似虛擬資料欄`ctid`，但無法用作 `ROWID`。如 [PostgreSQL 文件](https://www.postgresql.org/docs/current/ddl-system-columns.html)所述，如果更新或在每次`VACUUM`程序之後， `ctid`可能會變更。

您可以透過三種方式在 PostgreSQL `ROWID` 中建立虛擬資料欄功能：
+ 使用主索引鍵欄而非 `ROWID`來識別資料表中的資料列。
+ 在 資料表中使用邏輯主要/唯一金鑰 （可能是複合金鑰）。 
+ 新增具有自動產生值的資料欄，使其成為要模擬的主要/唯一金鑰`ROWID`。

此模式會逐步解說這三個實作，並說明每個選項的優點和缺點。

## 先決條件和限制
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 程序語言/PostgreSQL (PL/pgSQL) 編碼專業知識
+ 來源 Oracle 資料庫
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容叢集，或託管 PostgreSQL 資料庫的 EC2 執行個體

**限制**
+ 此模式提供 `ROWID`功能的解決方法。PostgreSQL 在 `ROWID` Oracle 資料庫中不提供 的同等 。

**產品版本**
+ PostgreSQL 11.9 或更新版本

## Architecture
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-architecture"></a>

**來源技術堆疊**
+ Oracle Database

**目標技術堆疊**
+ Aurora PostgreSQL 相容、Amazon RDS for PostgreSQL 或具有 PostgreSQL 資料庫的 EC2 執行個體

![\[將 Oracle 資料庫轉換為 AWS 上的 PostgreSQL\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9a2ce994-4f68-4975-aab2-796cc20a3c82/images/6e7c2ef6-f440-476a-9003-f1f166718e15.png)


**實作選項**

根據您的資料表是否具有主索引鍵或唯一索引、邏輯主索引鍵或身分屬性，有三種選項可以解決 PostgreSQL 中缺乏`ROWID`支援的問題。您的選擇取決於您的專案時間表、目前的遷移階段，以及應用程式和資料庫程式碼的相依性。


| 
| 
| 選項 | Description | 優點 | 缺點 | 
| --- |--- |--- |--- |
| **主索引鍵或唯一索引** | 如果您的 Oracle 資料表具有主索引鍵，您可以使用此索引鍵的屬性來唯一識別資料列。  | 不依賴專屬資料庫功能。對效能的影響最小，因為主索引鍵欄位會編製索引。 | 需要變更依賴 `ROWID`切換到主索引鍵欄位的應用程式和資料庫程式碼。  | 
| **邏輯主要/唯一金鑰** | 如果您的 Oracle 資料表具有邏輯主索引鍵，您可以使用此索引鍵的屬性來唯一識別資料列。邏輯主索引鍵由屬性或一組屬性組成，這些屬性可以唯一識別資料列，但不會透過限制在資料庫上強制執行。 | 不依賴專屬資料庫功能。 | 需要變更依賴 `ROWID`切換到主索引鍵欄位的應用程式和資料庫程式碼。如果邏輯主索引鍵的屬性未編製索引，會對效能造成重大影響。不過，您可以新增唯一的索引以防止效能問題。 | 
| **身分屬性** | 如果您的 Oracle 資料表沒有主索引鍵，您可以將其他欄位建立為 `GENERATED ALWAYS AS IDENTITY`。此屬性會在資料插入資料表時產生唯一值，因此可用於唯一識別資料控制語言 (DML) 操作的資料列。 | 不依賴專屬資料庫功能。PostgreSQL 資料庫會填入 屬性並維護其唯一性。 | 需要變更依賴 `ROWID`切換到身分屬性的應用程式和資料庫程式碼。如果其他欄位未編製索引，則對效能有重大影響。不過，您可以新增索引以防止效能問題。 | 

## 工具
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-tools"></a>
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。在此模式中，您可以使用 AWS CLI 透過 **pgAdmin** 執行 SQL 命令。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。

## 史詩
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-epics"></a>

### 識別來源資料表
<a name="identify-the-source-tables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別使用 `ROWID` 屬性的 Oracle 資料表。 | 使用 AWS Schema Conversion Tool (AWS SCT) 來識別具有 `ROWID`功能的 Oracle 資料表。如需詳細資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.ToPostgreSQL.html#CHAP_Source.Oracle.ToPostgreSQL.ConvertRowID)。—或—在 Oracle 中，使用 `DBA_TAB_COLUMNS` 檢視來識別具有 `ROWID` 屬性的資料表。這些欄位可用於存放英數 10 位元組字元。判斷用量，並適時將其轉換為`VARCHAR`欄位。 | DBA 或開發人員 | 
| 識別參考這些資料表的程式碼。 | 使用 AWS SCT 產生遷移評估報告，以識別受 影響的程序`ROWID`。如需詳細資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_AssessmentReport.html)。—或—在來源 Oracle 資料庫中，使用`dba_source`資料表的文字欄位來識別使用 `ROWID`功能的物件。 | DBA 或開發人員 | 

### 判斷主索引鍵用量
<a name="determine-primary-key-usage"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別沒有主索引鍵的資料表。 | 在來源 Oracle 資料庫中，使用 `DBA_CONSTRAINTS` 來識別沒有主索引鍵的資料表。此資訊將協助您判斷每個資料表的策略。例如：<pre>select dt.*<br />from dba_tables dt<br />where not exists (select 1<br />                  from all_constraints ct<br />                  where ct.owner = Dt.owner<br />                    and ct.table_name = Dt.table_name<br />                    and ct.constraint_type = 'P'<br />                  )<br />and dt.owner = '{schema}'</pre> | DBA 或開發人員 | 

### 識別並套用解決方案
<a name="identify-and-apply-the-solution"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 針對具有已定義或邏輯主索引鍵的資料表套用變更。 | 進行[其他資訊](#migrate-oracle-rowid-functionality-to-postgresql-on-aws-additional)區段中顯示的應用程式和資料庫程式碼變更，以使用唯一的主索引鍵或邏輯主索引鍵來識別資料表中的資料列。 | DBA 或開發人員 | 
| 將其他欄位新增至沒有已定義或邏輯主索引鍵的資料表。 | 新增 類型的屬性`GENERATED ALWAYS AS IDENTITY`。進行[其他資訊](#migrate-oracle-rowid-functionality-to-postgresql-on-aws-additional)區段中顯示的應用程式和資料庫程式碼變更。 | DBA 或開發人員 | 
| 視需要新增索引。 | 將索引新增至其他欄位或邏輯主索引鍵，以改善 SQL 效能。 | DBA 或開發人員 | 

## 相關資源
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-resources"></a>
+ [PostgreSQL CTID](https://www.postgresql.org/docs/current/ddl-system-columns.html) (PostgreSQL 文件）
+ [產生的資料欄 ](https://www.postgresql.org/docs/current/ddl-generated-columns.html)(PostgreSQL 文件）
+ [ROWID 虛擬資料欄 ](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/ROWID-Pseudocolumn.html#GUID-F6E0FBD2-983C-495D-9856-5E113A17FAF1)(Oracle 文件）

## 其他資訊
<a name="migrate-oracle-rowid-functionality-to-postgresql-on-aws-additional"></a>

下列各節提供 Oracle 和 PostgreSQL 程式碼範例，以說明這三種方法。

**案例 1：使用主要唯一金鑰**

在下列範例中，您會使用 建立`testrowid_s1`資料表`emp_id`做為主索引鍵。

*Oracle 程式碼：*

```
create table testrowid_s1 (emp_id integer, name varchar2(10), CONSTRAINT testrowid_pk PRIMARY KEY (emp_id));
INSERT INTO testrowid_s1(emp_id,name) values (1,'empname1');
INSERT INTO testrowid_s1(emp_id,name) values (2,'empname2');
INSERT INTO testrowid_s1(emp_id,name) values (3,'empname3');
INSERT INTO testrowid_s1(emp_id,name) values (4,'empname4');
commit;

SELECT rowid,emp_id,name FROM testrowid_s1;
ROWID                  EMP_ID NAME
------------------ ---------- ----------
AAAF3pAAAAAAAMOAAA          1 empname1
AAAF3pAAAAAAAMOAAB          2 empname2
AAAF3pAAAAAAAMOAAC          3 empname3
AAAF3pAAAAAAAMOAAD          4 empname4

UPDATE testrowid_s1 SET name = 'Ramesh' WHERE rowid = 'AAAF3pAAAAAAAMOAAB' ;
commit;

SELECT rowid,emp_id,name FROM testrowid_s1;
ROWID                  EMP_ID NAME
------------------ ---------- ----------
AAAF3pAAAAAAAMOAAA          1 empname1
AAAF3pAAAAAAAMOAAB          2 Ramesh
AAAF3pAAAAAAAMOAAC          3 empname3
AAAF3pAAAAAAAMOAAD          4 empname4
```

*PostgreSQL 程式碼：*

```
CREATE TABLE public.testrowid_s1
(
    emp_id integer,
    name character varying,
    primary key (emp_id)
);

insert into public.testrowid_s1 (emp_id,name) values 
(1,'empname1'),(2,'empname2'),(3,'empname3'),(4,'empname4');

select emp_id,name from testrowid_s1;
 emp_id |   name   
--------+----------
      1 | empname1
      2 | empname2
      3 | empname3
      4 | empname4

update testrowid_s1 set name = 'Ramesh' where emp_id = 2 ;

select emp_id,name from testrowid_s1;
 emp_id |   name   
--------+----------
      1 | empname1
      3 | empname3
      4 | empname4
      2 | Ramesh
```

**案例 2：使用邏輯主索引鍵**

在下列範例中，您會使用 建立資料表`testrowid_s2``emp_id`做為邏輯主索引鍵。

*Oracle 程式碼：*

```
create table testrowid_s2 (emp_id integer, name varchar2(10) );
INSERT INTO testrowid_s2(emp_id,name) values (1,'empname1');
INSERT INTO testrowid_s2(emp_id,name) values (2,'empname2');
INSERT INTO testrowid_s2(emp_id,name) values (3,'empname3');
INSERT INTO testrowid_s2(emp_id,name) values (4,'empname4');
commit;

SELECT rowid,emp_id,name FROM testrowid_s2;
ROWID                  EMP_ID NAME
------------------ ---------- ----------
AAAF3rAAAAAAAMeAAA          1 empname1
AAAF3rAAAAAAAMeAAB          2 empname2
AAAF3rAAAAAAAMeAAC          3 empname3
AAAF3rAAAAAAAMeAAD          4 empname4

UPDATE testrowid_s2 SET name = 'Ramesh' WHERE rowid = 'AAAF3rAAAAAAAMeAAB' ;
commit;

SELECT rowid,emp_id,name FROM testrowid_s2;
ROWID                  EMP_ID NAME
------------------ ---------- ----------
AAAF3rAAAAAAAMeAAA          1 empname1
AAAF3rAAAAAAAMeAAB          2 Ramesh
AAAF3rAAAAAAAMeAAC          3 empname3
AAAF3rAAAAAAAMeAAD          4 empname4
```

*PostgreSQL 程式碼：*

```
CREATE TABLE public.testrowid_s2
(
    emp_id integer,
    name character varying
);

insert into public.testrowid_s2 (emp_id,name) values 
(1,'empname1'),(2,'empname2'),(3,'empname3'),(4,'empname4');

select emp_id,name from testrowid_s2;
 emp_id |   name   
--------+----------
      1 | empname1
      2 | empname2
      3 | empname3
      4 | empname4

update testrowid_s2 set name = 'Ramesh' where emp_id = 2 ;

select emp_id,name from testrowid_s2;
 emp_id |   name   
--------+----------
      1 | empname1
      3 | empname3
      4 | empname4
      2 | Ramesh
```

**案例 3：使用身分屬性**

在下列範例中，您使用身分屬性建立不含主索引鍵的資料表`testrowid_s3`。

*Oracle 程式碼：*

```
create table testrowid_s3 (name varchar2(10));
INSERT INTO testrowid_s3(name) values ('empname1');
INSERT INTO testrowid_s3(name) values ('empname2');
INSERT INTO testrowid_s3(name) values ('empname3');
INSERT INTO testrowid_s3(name) values ('empname4');
commit;

SELECT rowid,name FROM testrowid_s3;
ROWID              NAME
------------------ ----------
AAAF3sAAAAAAAMmAAA empname1
AAAF3sAAAAAAAMmAAB empname2
AAAF3sAAAAAAAMmAAC empname3
AAAF3sAAAAAAAMmAAD empname4

UPDATE testrowid_s3 SET name = 'Ramesh' WHERE rowid = 'AAAF3sAAAAAAAMmAAB' ;
commit;

SELECT rowid,name FROM testrowid_s3;
ROWID              NAME
------------------ ----------
AAAF3sAAAAAAAMmAAA empname1
AAAF3sAAAAAAAMmAAB Ramesh
AAAF3sAAAAAAAMmAAC empname3
AAAF3sAAAAAAAMmAAD empname4
```

*PostgreSQL 程式碼：*

```
CREATE TABLE public.testrowid_s3
(
    rowid_seq bigint generated always as identity,
    name character varying
);

insert into public.testrowid_s3 (name) values 
('empname1'),('empname2'),('empname3'),('empname4');

select rowid_seq,name from testrowid_s3;
 rowid_seq |   name   
-----------+----------
         1 | empname1
         2 | empname2
         3 | empname3
         4 | empname4

update testrowid_s3 set name = 'Ramesh' where rowid_seq = 2 ;

select rowid_seq,name from testrowid_s3;
 rowid_seq |   name   
-----------+----------
         1 | empname1
         3 | empname3
         4 | empname4
         2 | Ramesh
```

# 將 Oracle 資料庫錯誤代碼遷移至與 Amazon Aurora PostgreSQL 相容的資料庫
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database"></a>

*Sai Parthasaradhi 和 Veeranjaneyulu Grandhi，Amazon Web Services*

## 總結
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database-summary"></a>

此模式說明如何使用預先定義的中繼資料表，將 Oracle 資料庫錯誤代碼遷移至 [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)資料庫。

Oracle 資料庫錯誤代碼不一定有對應的 PostgreSQL 錯誤代碼。這種錯誤代碼的差異可能會使得設定目標 PostgreSQL 架構中程序或函數的處理邏輯變得困難。

您可以將對 PL/pgSQL 程式有意義的來源和目標資料庫錯誤代碼儲存在中繼資料表中，以簡化程序。然後，將資料表設定為標記有效的 Oracle 資料庫錯誤代碼，並將其映射至其 PostgreSQL 對等項目，然後再繼續剩餘的程序邏輯。如果 Oracle 資料庫錯誤碼不在中繼資料資料表中，則程序會因例外狀況而結束。然後，如果您的程式需要，您可以手動檢閱錯誤詳細資訊，並將新的錯誤代碼新增至資料表。

透過使用此組態，Amazon Aurora PostgreSQL 相容資料庫可以像來源 Oracle 資料庫一樣處理錯誤。

**注意**  
設定 PostgreSQL 資料庫以正確處理 Oracle 資料庫錯誤碼通常需要變更資料庫和應用程式碼。

## 先決條件和限制
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 啟動和執行執行個體和接聽程式服務的來源 Oracle 資料庫
+ 已啟動並執行的 Amazon Aurora PostgreSQL 相容叢集
+ 熟悉 Oracle 資料庫
+ 熟悉 PostgreSQL 資料庫

## Architecture
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database-architecture"></a>

下圖顯示資料錯誤碼驗證和處理的 Amazon Aurora PostgreSQL 相容資料庫工作流程範例：

![\[Aurora PostgreSQL 相容資料庫的資料錯誤碼驗證和處理。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/82751f40-2fd9-4ce7-ab61-0874552d857b/images/b7ab627e-8f34-4635-8660-93c5c80ce38d.png)


該圖顯示以下工作流程：

1. 資料表包含 Oracle 資料庫錯誤代碼和分類，以及其同等 PostgreSQL 錯誤代碼和分類。資料表包含 **valid\$1error** 資料欄，可分類特定預先定義的錯誤代碼是否有效。

1. 當 PL/pgSQL 函數 (**func\$1processdata**) 擲回例外狀況時，它會叫用第二個 PL/pgSQL 函數 (**error\$1validation**)。

1. **error\$1validation** 函數接受 Oracle 資料庫錯誤代碼作為輸入引數。然後，函數會對照資料表檢查傳入的錯誤代碼，以查看錯誤是否包含在資料表中。

1. 如果資料表中包含 Oracle 資料庫錯誤代碼，則 **error\$1validation** 函數會傳回 **TRUE** 值，且程序邏輯會繼續。如果錯誤碼不包含在資料表中，則函數會傳回 **FALSE** 值，且程序邏輯會因例外狀況而結束。

1. 當函數傳回 **FALSE** 值時，應用程式的功能主管會手動檢閱錯誤詳細資訊，以判斷其有效性。

1. 然後，新的錯誤代碼要不是手動新增到資料表。如果錯誤代碼有效並新增至資料表，則 **error\$1validation** 函數會在下次發生例外狀況時傳回 **TRUE** 值。如果錯誤碼無效，且程序必須在發生例外狀況時失敗，則錯誤碼不會新增至資料表。

**技術堆疊**
+ Amazon Aurora PostgreSQL
+ pgAdmin
+ Oracle SQL Developer

## 工具
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database-tools"></a>
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理和開發工具。它提供圖形界面，可簡化資料庫物件的建立、維護和使用。
+ [Oracle SQL Developer](https://www.oracle.com/in/database/technologies/appdev/sqldeveloper-landing.html) 是免費的整合開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。

## 史詩
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database-epics"></a>

### 將 Oracle 資料庫錯誤代碼遷移至與 Amazon Aurora PostgreSQL 相容的資料庫
<a name="migrate-oracle-database-error-codes-to-your-amazon-aurora-postgresql-compatible-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon Aurora PostgreSQL 相容資料庫中建立資料表。 | 執行下列 PostgreSQL [CREATE TABLE](https://www.postgresql.org/docs/current/sql-createtable.html) 命令：<pre>(<br /><br />    source_error_code numeric NOT NULL,<br /><br />    target_error_code character varying NOT NULL,<br /><br />    valid_error character varying(1) NOT NULL<br /><br />); </pre> | PostgreSQL 開發人員、Oracle、RDS/Aurora for PostgreSQL | 
| 將 PostgreSQL 錯誤代碼及其對應的 Oracle 資料庫錯誤代碼新增至資料表。 | 執行 PostgreSQL [INSERT](https://www.postgresql.org/docs/current/sql-insert.html) 命令，將所需的錯誤代碼值新增至 **error\$1codes** 資料表。PostgreSQL 錯誤代碼必須使用不同字元的資料類型 (**SQLSTATE** 值）。Oracle 錯誤代碼必須使用數值資料類型 (**SQLCODE** 值）。**插入陳述式範例：**<pre>insert into error_codes values (-1817,'22007','Y');<br />insert into error_codes values (-1816,'22007','Y');<br />insert into error_codes values (-3114,'08006','N');</pre>如果您發現 Oracle 特定的 Java 資料庫連線 (JDBC) 例外狀況，您必須以一般跨資料庫例外狀況取代這些例外狀況，或切換到 PostgreSQL 特定的例外狀況。 | PostgreSQL 開發人員、Oracle、RDS/Aurora for PostgreSQL | 
| 建立 PL/pgSQL 函數以驗證錯誤代碼。 | 執行 PostgreSQL CREATE FUNCTION 命令來建立 PL/pgSQL [https://www.postgresql.org/docs/current/sql-createfunction.html](https://www.postgresql.org/docs/current/sql-createfunction.html)函數。 PostgreSQL 請確定函數執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database.html) | PostgreSQL 開發人員、Oracle、RDS/Aurora for PostgreSQL | 
| 手動檢閱由 PL/pgSQL 函數記錄的新錯誤代碼。 | 手動檢閱新的錯誤代碼。如果新的錯誤代碼對您的使用案例有效，請執行 PostgreSQL **INSERT** 命令將其新增至 **error\$1codes** 資料表。-或-如果新的錯誤碼對您的使用案例無效，請勿將其新增至資料表。發生錯誤時，程序邏輯將繼續失敗並結束，但有例外。 | PostgreSQL 開發人員、Oracle、RDS/Aurora for PostgreSQL | 

## 相關資源
<a name="migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database-resources"></a>

[附錄 A. PostgreSQL 錯誤代碼 ](https://www.postgresql.org/docs/11/errcodes-appendix.html)(PostgreSQL 文件）

[資料庫錯誤訊息 ](https://docs.oracle.com/cd/E11882_01/server.112/e17766/toc.htm)(Oracle 資料庫文件）

# 使用 AWS SCT 和 AWS DMS 將 Amazon EC2 上的 SAP ASE 遷移至與 Amazon Aurora PostgreSQL 相容
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms"></a>

*Amit Kumar 和 Ankit Gupta，Amazon Web Services*

## 總結
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms-summary"></a>

此模式說明如何使用 AWS Schema Conversion Tool (AWS SCT) 和 AWS Database Migration Service (AWS DMS)，將託管在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 SAP Adaptive Server Enterprise (SAP ASE) 資料庫遷移至 Amazon Aurora PostgreSQL 相容版本。 AWS Database Migration Service 模式著重於儲存物件和資料遷移的資料定義語言 (DDL) 轉換。

Aurora PostgreSQL 相容支援線上交易處理 (OLTP) 工作負載。此受管服務提供可自動隨需擴展的組態。它可以根據您的應用程式需求自動啟動、關閉、擴展或縮減資料庫。您可以在雲端中執行資料庫，而無需管理任何資料庫執行個體。Aurora PostgreSQL 相容為不常見、間歇性或無法預測的工作負載提供經濟實惠的選項。

遷移程序包含兩個主要階段：
+ 使用 AWS SCT 轉換資料庫結構描述
+ 使用 AWS DMS 遷移資料

這兩個階段的詳細指示會在 *Epics* 區段中提供。如需有關將 AWS DMS 與 SAP ASE 資料庫搭配使用的特定問題疑難排解的資訊，請參閱 AWS DMS 文件中的 [SAP ASE 問題疑難排解](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Troubleshooting.html#CHAP_Troubleshooting.SAP)。

## 先決條件和限制
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ EC2 執行個體上的來源 SAP ASE 資料庫，可啟動和執行伺服器、資料庫和接聽程式服務
+ 目標 Aurora PostgreSQL 相容資料庫

**限制**
+ 連線的連接埠號碼必須為 5432。
+ [huge\$1pages](https://www.postgresql.org/docs/9.6/static/runtime-config-resource.html) 功能預設為開啟，但可以修改。
+ Point-in-time復原 (PITR) 精細程度為 5 分鐘。
+ 跨區域複寫目前無法使用。
+ Aurora 資料庫的儲存大小上限為 128 TiB。
+ 您最多可以建立 15 個僅供讀取複本。
+ 資料表大小限制僅受限於 Aurora 叢集磁碟區的大小，因此 Aurora PostgreSQL 相容資料庫叢集的資料表大小上限為 32 TiB。建議您遵循資料表設計的最佳實務，例如分割大型資料表。

**產品版本**
+ 來源資料庫：AWS DMS 目前支援 SAP ASE 15、15.5、15.7 和 16.x。如需 SAP [ASE 版本支援的最新資訊，請參閱 AWS DMS 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SAP.html)。
+ 目標資料庫：PostgreSQL 9.4 和更新版本 （適用於 9.x 版）、10.x、11.x、12.x、13.x 和 14.x。如需最新支援的 PostgreSQL 版本，請參閱 [AWS DMS 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html)。
+ Amazon Aurora 1.x 或更新版本。如需最新資訊，請參閱 [Aurora 文件中的 Aurora PostgreSQL 相容版本和引擎版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html)。

## Architecture
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms-architecture"></a>

**來源技術堆疊**
+ 在 Amazon EC2 上執行的 SAP ASE 資料庫

**目標技術堆疊**
+ Aurora PostgreSQL 相容資料庫

**遷移架構**

![\[使用 AWS SCT 和 AWS DMS 將 SAP ASE 資料庫遷移至 Aurora PostgreSQL 相容。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/07fbdea1-0242-40ae-8e5f-2ce4a620a047/images/a3b018f3-2e7b-4c37-a218-870c56132acb.png)


## 工具
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms-tools"></a>
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 支援數個不同的來源和目標資料庫。如需詳細資訊，請參閱 AWS DMS 文件中的[資料遷移來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.html)和[資料遷移目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.html)。如需最全面的版本和功能支援，建議您使用最新版本的 AWS DMS。 

## 史詩
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms-epics"></a>

### 設定環境
<a name="set-up-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源 EC2 執行個體中設定網路存取。 | 在託管來源 SAP ASE 資料庫的 EC2 執行個體中設定安全群組。如需說明，請參閱 [Amazon EC2 文件中的 Linux 執行個體的 Amazon EC2 安全群組](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html?icmpid=docs_ec2_console)。 Amazon EC2  | 系統管理員 | 
| 建立您的目標 Aurora PostgreSQL 相容資料庫叢集。 | 為您的目標資料庫安裝、設定和啟動 Aurora PostgreSQL 相容叢集。如需詳細資訊，請參閱 [Aurora 文件中的建立 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html)。 | DBA | 
| 設定目標資料庫叢集的授權。 | 設定目標資料庫的安全群組和防火牆。如需說明，請參閱 [Aurora 文件中的建立 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html)。 | DBA，系統管理員 | 

### 使用 AWS SCT 轉換資料庫結構描述
<a name="convert-your-database-schema-with-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 AWS SCT。 | 依照 AWS SCT [文件中的指示啟動 AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_GettingStarted.html)。AWS SCT 提供專案型使用者介面，可將 SAP ASE 來源資料庫的資料庫結構描述自動轉換為與您目標 Aurora PostgreSQL 相容資料庫執行個體相容的格式。 | DBA | 
| 建立 AWS SCT 端點。 | 建立來源 SAP ASE 和目標 PostgreSQL 資料庫的端點。如需說明，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.AddServers)。 | DBA | 
| 建立評估報告。 | 建立資料庫遷移評估報告，以評估遷移並偵測任何不相容的物件和函數。如需說明，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html#CHAP_UserInterface.AssessmentReport)。 | DBA | 
| 轉換結構描述。 | 遵循 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Converting.html)中的指示轉換資料庫結構描述。 | DBA | 
| 驗證資料庫物件。 | 如果 AWS SCT 無法轉換資料庫物件，它會識別其名稱和其他詳細資訊。您必須手動轉換這些物件。若要識別這些不相符項目，請依照 AWS 部落格文章中的指示，在[從 SAP ASE 遷移至 Amazon RDS for PostgreSQL 或 Amazon Aurora PostgreSQL 之後驗證資料庫物件](https://aws.amazon.com/blogs/database/validate-database-objects-after-migrating-from-sap-ase-to-amazon-rds-for-postgresql-or-amazon-aurora-postgresql/)。 | DBA | 

### 分析 AWS DMS 遷移
<a name="analyze-the-aws-dms-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本。 | 檢查 SAP ASE 資料庫版本與 AWS DMS 的相容性。如需詳細資訊，請參閱 [AWS DMS 文件中的 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.Sources.html#CHAP_Introduction.Sources.title)和 [AWS ](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.Targets.html)DMS 的目標。 | DBA | 
| 識別儲存類型和容量的需求。 | 根據來源資料庫的大小，為目標資料庫選擇適當的儲存容量。 | DBA，系統管理員 | 
| 選擇複寫執行個體的執行個體類型、容量和其他功能。 | 選擇符合您需求的執行個體類型、容量、儲存功能和網路功能。如需指引，請參閱 [AWS DMS 文件中的為您的遷移選擇正確的 AWS DMS 複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.Types.html)。 | DBA，系統管理員 | 
| 識別網路存取安全需求。 | 識別來源和目標資料庫的網路存取安全需求。遵循 AWS DMS 文件中[設定複寫執行個體網路](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.VPC.html)的指引。 | DBA，系統管理員 | 

### 遷移資料
<a name="migrate-the-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS DMS 中建立遷移任務來遷移資料。 | 若要遷移資料，請建立任務並遵循 [AWS DMS 文件中的指示。](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。 | DBA | 
| 驗證資料。 | 若要驗證您的資料是否已正確從來源資料庫遷移至目標資料庫，請遵循 AWS DMS 文件中提供[的資料驗證準則](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別應用程式遷移策略。 | 選擇[七種策略之一 (7R)](https://docs.aws.amazon.com/prescriptive-guidance/latest/strategy-database-migration/planning-phase.html) 將應用程式遷移至雲端。 | DBA、應用程式擁有者、系統管理員 | 
| 遵循應用程式遷移策略。 | 完成應用程式團隊識別的資料庫任務，包括更新目標資料庫的 DNS 連線詳細資訊，以及更新動態查詢。  | DBA、應用程式擁有者、系統管理員 | 

### 切換到目標資料庫
<a name="cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 | 將連線從來源資料庫切換到目標資料庫。如需詳細資訊，請參閱*關聯式資料庫遷移策略*的[剪下](https://docs.aws.amazon.com/prescriptive-guidance/latest/strategy-database-migration/cut-over.html)區段。 | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 | 終止所有遷移任務、複寫執行個體、端點和其他 AWS SCT 和 AWS DMS 資源。如需詳細資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.Replication.html#CHAP_GettingStarted.Replication.Deleting)。 | DBA，系統管理員 | 
| 檢閱並驗證專案文件。 | 驗證專案文件中的所有步驟，以確保所有任務都已成功完成。 | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案。 | 關閉遷移專案並提供任何意見回饋。 | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms-resources"></a>

**參考**
+ [在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線 ](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)(AWS 規範性指導）
+ [使用 pg\$1transport 在兩個 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫 ](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg_transport.html)(AWS 規範性指導）
+ [Amazon Aurora 定價](https://aws.amazon.com/rds/aurora/pricing/)
+ [Amazon Aurora PostgreSQL 相容版本的最佳實務 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraPostgreSQL.BestPractices.html)(Amazon Aurora 文件）
+ [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [使用 SAP ASE 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SAP.html)

**教學課程和影片**
+ [AWS Database Migration Service 入門](https://aws.amazon.com/dms/getting-started/)
+ [AWS Database Migration Service](https://www.youtube.com/watch?v=zb4GcjEdl8U) （影片）

# 使用 ACM 將 Windows SSL 憑證遷移至 Application Load Balancer
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm"></a>

*Chandra Sekhar Yaratha 和 Igor Kovalchuk，Amazon Web Services*

## 總結
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-summary"></a>

模式提供使用 AWS Certificate Manager (ACM) 將現有 Secure Sockets Layer (SSL) 憑證從託管在內部部署伺服器或 Microsoft Internet Information Services (IIS) 上的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的網站遷移的指引。然後，SSL 憑證可以與 AWS 上的 Elastic Load Balancing 搭配使用。

SSL 可保護您的資料、確認您的身分、提供更好的搜尋引擎排名、協助滿足支付卡產業資料安全標準 (PCI DSS) 要求，並改善客戶信任。管理這些工作負載的開發人員和 IT 團隊希望其 Web 應用程式和基礎設施，包括 IIS 伺服器和 Windows Server，保持符合其基準政策。

此模式涵蓋從 Microsoft IIS 手動匯出現有的 SSL 憑證、將它們從個人資訊交換 (PFX) 格式轉換為 ACM 支援的 Private Enhanced Mail (PEM) 格式，然後將它們匯入 AWS 帳戶中的 ACM。它也說明如何為您的應用程式建立 Application Load Balancer，並將 Application Load Balancer 設定為使用匯入的憑證。然後，在 Application Load Balancer 上終止 HTTPS 連線，您不需要在 Web 伺服器上進一步設定額外負荷。如需詳細資訊，請參閱[建立 Application Load Balancer 的 HTTPS 接聽程式](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html)。

Windows 伺服器使用 .pfx 或 .p12 檔案來包含公有金鑰檔案 (SSL 憑證） 及其唯一的私有金鑰檔案。Certificate Authority (CA) 為您提供公有金鑰檔案。您可以使用伺服器來產生建立憑證簽署請求 (CSR) 的相關聯私有金鑰檔案。

## 先決條件和限制
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ AWS 上的虛擬私有雲端 (VPC)，在目標使用的每個可用區域中至少有一個私有和一個公有子網路
+ 在 Windows Server 2012 或更新版本上執行的 IIS 8.0 版或更新版本
+ 在 IIS 上執行的 Web 應用程式
+ IIS 伺服器的管理員存取權

## Architecture
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-architecture"></a>

**來源技術堆疊**
+ 使用 SSL 實作 IIS Web 伺服器，以確保在加密連線 (HTTPS) 中安全地傳輸資料 

**來源架構**

![\[使用 ACM 將 Windows SSL 憑證遷移至 Application Load Balancer 的來源架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cad6e465-da39-4819-970e-10e1c30e0a1f/images/e63efb6f-205b-4e20-a043-6bc954470191.png)


**目標技術堆疊**
+ 您 AWS 帳戶中的 ACM 憑證
+ 設定為使用匯入憑證的 Application Load Balancer 
+ 私有子網路中的 Windows Server 執行個體

**目標架構**

![\[使用 ACM 將 Windows SSL 憑證遷移至 Application Load Balancer 的目標架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/cad6e465-da39-4819-970e-10e1c30e0a1f/images/45ac7fba-fbad-4c74-9b1f-80ca212dae08.png)


 

## 工具
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-tools"></a>
+ [AWS Certificate Manager (ACM)](https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html) 可協助您建立、存放和續約公有和私有 SSL/TLS X.509 憑證和金鑰，以保護 AWS 網站和應用程式。
+ [Elastic Load Balancing (ELB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) 會將傳入的應用程式或網路流量分配到多個目標。例如，您可以在一或多個可用區域中跨 EC2 執行個體、容器和 IP 地址分配流量。

## 最佳實務
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-best-practices"></a>
+ 強制流量從 HTTP 重新導向至 HTTPS。
+ 為您的 Application Load Balancer 正確設定安全群組，以僅允許特定連接埠的傳入流量。
+ 在不同的可用區域中啟動 EC2 執行個體，以確保高可用性。
+ 將應用程式的網域設定為指向 Application Load Balancer 的 DNS 名稱，而不是其 IP 地址。
+ 確定 Application Load Balancer 已設定應用程式層[運作狀態檢查](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html)。
+ 設定運作狀態檢查的閾值。
+ 使用 [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) 監控 Application Load Balancer。

## 史詩
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-epics"></a>

### 匯出 .pfx 檔案
<a name="export-a-pfx-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Windows Server 匯出 .pfx 檔案。 | 若要從 Windows Server 中的現場部署 IIS 管理員將 SSL 憑證匯出為 .pfx 檔案：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.html)您的 .pfx 檔案現在應儲存至您指定的位置和路徑。 | 系統管理員 | 

### 將 PFX 編碼憑證轉換為 PEM 格式
<a name="convert-the-pfx-encoded-certificate-to-pem-format"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載並安裝 OpenSSL 工具組。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.html) | 系統管理員 | 
| 將 PFX 編碼憑證轉換為 PEM 格式。 | 下列步驟會將 PFX 編碼的簽章憑證檔案轉換為三個 PEM 格式的檔案：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.html)若要轉換 PFX 編碼憑證：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.html) | 系統管理員 | 

### 將憑證匯入 ACM
<a name="import-a-certificate-into-acm"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備匯入憑證。 | 在 [ACM 主控台](https://console.aws.amazon.com/acm/home)上，選擇**匯入憑證**。 | 雲端管理員 | 
| 提供憑證內文。 | 針對**憑證內文**，貼上您要匯入的 PEM 編碼憑證。如需此範例和其他任務中所述命令和步驟的詳細資訊，請參閱 ACM 文件中的[匯入憑證](https://docs.aws.amazon.com/acm/latest/userguide/import-certificate-api-cli.html)。 | 雲端管理員 | 
| 提供憑證私有金鑰。 | 對於 **Certificate private key (憑證私有金鑰)**，貼上與憑證公有金鑰相符的 PEM 編碼、未加密私有金鑰。 | 雲端管理員 | 
| 提供憑證鏈。 | 對於**憑證鏈**，請貼上存放在 `CertificateChain.pem` 檔案中的 PEM 編碼憑證鏈。 | 雲端管理員 | 
| 匯入憑證。 | 選擇 **Review and import** (檢閱和匯入)。確認憑證的相關資訊正確無誤，然後選擇**匯入**。 | 雲端管理員 | 

### 建立 Application Load Balancer
<a name="create-an-application-load-balancer"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立和設定負載平衡器和接聽程式。 | 遵循 [Elastic Load Balancing 文件](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html)中的指示來設定目標群組、註冊目標，以及建立 Application Load Balancer 和接聽程式。新增連接埠 443 的第二個接聽程式 (HTTPS)。 | 雲端管理員 | 

## 疑難排解
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Windows PowerShell 無法辨識 OpenSSL 命令，即使您將其新增至系統路徑。 | 檢查`$env:path`以確保它包含 OpenSSL 二進位檔的位置。如果沒有，請在 PowerShell 中執行下列命令：<pre>$env:path = $env:path + ";C:\OpenSSL-Win64\bin"</pre> | 

## 相關資源
<a name="migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm-resources"></a>

**將憑證匯入 ACM**
+ [ACM 主控台](https://console.aws.amazon.com/acm/home)
+ [用於匯入的憑證和金鑰格式](https://docs.aws.amazon.com/acm/latest/userguide/import-certificate-format.html)
+ [匯入憑證](https://aws.amazon.com/blogs/security/how-to-import-pfx-formatted-certificates-into-aws-certificate-manager-using-openssl/)
+ [AWS Certificate Manager 使用者指南](https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html)

**建立 Application Load Balancer**
+ [建立 Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-application-load-balancer.html)
+ [Application Load Balancer 使用者指南](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html)

# 將訊息佇列從 Microsoft Azure Service Bus 遷移至 Amazon SQS
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs"></a>

*Nisha Gambhir，Amazon Web Services*

## 總結
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-summary"></a>

此模式說明如何將 .NET Framework 或 .NET Core Web 或主控台應用程式從使用 Microsoft Azure Service 匯流排佇列傳訊平台遷移至 Amazon Simple Queue Service (Amazon SQS)。

應用程式使用簡訊服務將資料傳送至其他應用程式，以及從其他應用程式接收資料。這些服務有助於在雲端中建置解耦、高度可擴展的微服務、分散式系統和無伺服器應用程式。

Azure 服務匯流排佇列是更廣泛的 Azure 訊息基礎設施的一部分，支援佇列和發佈/訂閱訊息。 

Amazon SQS 是一種全受管訊息佇列服務，可讓您解耦和擴展微服務、分散式系統和無伺服器應用程式。Amazon SQS 消除了與管理和操作訊息導向中介軟體相關的複雜性和額外負荷，並使開發人員能夠專注於區分工作。使用 Amazon SQS，您可以在任何磁碟區中傳送、存放和接收軟體元件之間的訊息，而不會遺失訊息或需要其他 服務。

## 先決條件和限制
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-prerequisites-and-limitations"></a>

**先決條件**
+ 作用中的 AWS 帳戶 
+ 使用 Azure Service Bus 佇列的 .NET Framework 或 .NET Core Web 或主控台應用程式 （附加範例程式碼）

**產品版本**
+ .NET Framework 3.5 或更新版本，或 .NET Core 1.0.1、2.0.0 或更新版本

## Architecture
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-architecture"></a>

**來源技術堆疊**
+ 使用 Azure 服務匯流排佇列傳送訊息的 .NET （核心或架構） Web 或主控台應用程式

 

**目標技術堆疊**
+ Amazon SQS

## 工具
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-tools"></a>

**工具**
+ Microsoft Visual Studio

**Code**

若要為 Amazon SQS 建立 AWS Identity and Access Management (IAM) 政策：

1. 登入 AWS 管理主控台，然後前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

2. 在左邊的導覽窗格中，選擇 **Policies** (政策)，然後選擇 **Create policy** (建立政策)。

3. 選擇 **JSON** 索引標籤，然後貼上下列程式碼：

```
{
   "Version": "2012-10-17",		 	 	 
   "Statement": [
      {
         "Sid": "VisualEditor0",
         "Effect": "Allow",
         "Action": [
            "sqs:DeleteMessage",
            "sqs:GetQueueUrl",
            "sqs:ChangeMessageVisibility",
            "sqs:SendMessageBatch",
            "sqs:ReceiveMessage",
            "sqs:SendMessage",
            "sqs:GetQueueAttributes",
            "sqs:ListQueueTags",
            "sqs:ListDeadLetterSourceQueues",
            "sqs:DeleteMessageBatch",
            "sqs:PurgeQueue",
            "sqs:DeleteQueue",
            "sqs:CreateQueue",
            "sqs:ChangeMessageVisibilityBatch",
            "sqs:SetQueueAttributes"
         ],
         "Resource": "arn:aws:sqs:*:<AccountId>:*"
      },
      {
         "Sid": "VisualEditor1",
         "Effect": "Allow",
         "Action": "sqs:ListQueues",
         "Resource": "*"
      }
   ]
}
```

4. 選擇**檢閱政策**，輸入名稱，然後選擇**建立政策**。

5. 將新建立的政策連接到現有的 IAM 角色或建立新的角色。

## 史詩
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-epics"></a>

### 在 AWS 中設定 Amazon SQS
<a name="set-up-amazon-sqs-in-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 Amazon SQS 建立 IAM 政策。 | 建立提供 Amazon SQS 存取權的 IAM 政策。如需範例政策，請參閱程式碼一節。 | 系統工程師 | 
| 建立 AWS 設定檔。 | 透過執行 AWS Tools for PowerShell 命令 Set-AWSCredential 建立新的設定檔。此命令會將您的存取金鑰和私密金鑰存放在您指定的設定檔名稱下的預設登入資料檔案中。連結您先前使用此帳戶建立的 Amazon SQS 政策。保留 AWS 存取金鑰 ID 和私密存取金鑰。這些是後續步驟的必要項目。 | 系統工程師 | 
| 建立 SQS 佇列。 | 您可以建立標準佇列或先進先出 (FIFO) 佇列。如需說明，請參閱參考區段中的連結。 | 系統工程師 | 

### 修改您的 .NET 應用程式程式碼
<a name="revise-your-net-application-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS Toolkit for Visual Studio。 | 此工具組是 Microsoft Visual Studio 的延伸，可讓您更輕鬆地在 AWS 中建置和部署 .NET 應用程式。如需安裝和使用說明，請參閱參考章節中的連結。 | 應用程式開發人員 | 
| 安裝 AWSSDK.SQS NuGet 套件。 | 您可以在 Visual Studio AWSSDK 中選擇「管理 NuGet 套件」，或執行命令「Install-Package AWSSDK.SQS」來安裝 AWSSDK.SQS。 | 應用程式開發人員 | 
| 在 .NET 應用程式中建立 AWSCredentials 物件。 | 附件中的範例應用程式示範如何建立從 AWSCredentials 繼承的 BasicAWSCredentials 物件。您可以使用舊版的存取金鑰 ID 和私密存取金鑰，或讓物件從 .aws 資料夾挑選這些金鑰，做為執行時間使用者設定檔的一部分。 | 應用程式開發人員 | 
| 建立 SQS 用戶端物件。 | 為 .NET Framework 建立 SQS 用戶端物件 (AmazonSQSClient)。這是 Amazon.SQS 命名空間的一部分。此物件是必要物件，而非屬於 Microsoft.Azure.ServiceBus 命名空間的 IQueueClient。 | 應用程式開發人員 | 
| 呼叫 SendMessageAsync 方法，將訊息傳送至 SQS 佇列。 | 變更將訊息傳送至佇列的程式碼，以使用 amazonSqsClient.SendMessageAsync 方法。如需詳細資訊，請參閱連接的程式碼範例。 | 應用程式開發人員 | 
| 呼叫 ReceiveMessageAsync 方法來接收來自 SQS 佇列的訊息。 | 變更接收訊息的程式碼，以使用 amazonSqsClient.ReceiveMessageAsync 方法。如需詳細資訊，請參閱連接的程式碼範例。 | 應用程式開發人員 | 
| 呼叫 DeleteMessageAsync 方法，從 SQS 佇列刪除訊息。 | 若要刪除訊息，請將 queueClient.CompleteAsync 方法的程式碼變更為 amazonSqsClient.DeleteMessageAsync 方法。如需詳細資訊，請參閱連接的程式碼範例。 | 應用程式開發人員 | 

## 相關資源
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-related-resources"></a>
+ [適用於 .NET 開發人員的 AWS 開發套件](https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/welcome.html)
+ [使用 Amazon SQS 傳送訊息](https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/sqs-apis-intro.html)
+ [使用適用於 .NET 的 AWS 開發套件建立和使用 Amazon SQS 佇列](https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/how-to-sqs.html)
+ [傳送 Amazon SQS 訊息](https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/SendMessage.html)
+ [從 Amazon SQS 佇列接收訊息](https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/ReceiveMessage.html)
+ [從 Amazon SQS 佇列刪除訊息](https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/DeleteMessage.html)
+ [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html)

## 其他資訊
<a name="migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs-additional-information"></a>

此模式包含兩個範例應用程式 （請參閱附件區段）：
+ **AzureSbTestApp** 包含使用 Azure 服務匯流排佇列的程式碼。
+ **AmazonSqsTestApp** 使用 Amazon SQS。這是使用 .NET Core 2.2 的主控台應用程式，其中包含傳送和接收訊息的範例。

備註：
+ queueClient 是 IQueueClient 的物件，屬於 Microsoft.Azure.ServiceBus 命名空間 （包含在 Microsoft.Azure.ServiceBus NuGet 套件中）。
+ amazonSqsClient 是 AmazonSQSClient 的物件，屬於 Amazon.SQS 命名空間 （包含在 AWSSDK.SQS NuGet 套件中）。
+ 根據程式碼的執行位置，假設其是否在 EC2 上執行，角色需要有寫入 SQS 佇列的許可。

## 附件
<a name="attachments-25334709-7000-4f60-87ed-ea41acb41a99"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/25334709-7000-4f60-87ed-ea41acb41a99/attachments/attachment.zip)

# 使用 Oracle Data Pump 和 AWS DMS 將 Oracle JD Edwards EnterpriseOne 資料庫遷移至 AWS
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms"></a>

*Thanigaivel Thirumalai，Amazon Web Services*

## 摘要
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-summary"></a>

您可以在 Amazon Relational Database Service (Amazon RDS) 上遷移和執行 JD Edwards EnterpriseOne 資料庫。 [Amazon Relational Database Service ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 當您將資料庫遷移至 Amazon RDS 時，AWS 可以處理備份任務和高可用性設定，因此您可以專注於維護 EnterpriseOne 應用程式及其功能。如需遷移程序期間要考量之關鍵因素的完整清單，請參閱 AWS 方案指引中的 [Oracle 資料庫遷移策略](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/strategies.html)。

有多種方法可以遷移 EnterpriseOne 資料庫，包括：
+ 使用 Oracle Universal Batch Engine (UBE) R98403 建立結構描述和資料表，並使用 AWS Database Migration Service (AWS DMS) 進行遷移
+ 使用資料庫原生工具建立結構描述和資料表，並使用 AWS DMS 進行遷移
+ 使用資料庫原生工具遷移現有資料 （完全載入），並使用 AWS DMS 進行變更資料擷取 (CDC) 任務

此模式涵蓋第三個選項。它說明如何使用 Oracle Data Pump 搭配 [AWS DMS ](https://aws.amazon.com/dms)及其 CDC 功能，將內部部署 EnterpriseOne 資料庫遷移至 Amazon RDS for Oracle。

[Oracle JD Edwards EnterpriseOne](https://www.oracle.com/applications/jd-edwards-enterpriseone/) 是企業資源規劃 (ERP) 解決方案，適用於生產、建構、分發、服務或管理產品或實體資產的組織。JD Edwards EnterpriseOne 支援各種硬體、作業系統和資料庫平台。

當您遷移 JD Edwards EnterpriseOne 等關鍵的 ERP 應用程式時，將停機時間降至最低是關鍵。AWS DMS 支援從來源資料庫到目標資料庫的完全載入和持續複寫，將停機時間降至最低。AWS DMS 也為遷移提供即時監控和記錄，這可協助您識別和解決可能導致停機的任何問題。

當您使用 AWS DMS 複寫變更時，您必須指定時間或系統變更號碼 (SCN) 做為從資料庫日誌讀取變更的起點。請務必在伺服器上保留一段指定的時間 （建議 15 天） 來存取這些日誌，以確保 AWS DMS 可以存取這些變更。

## 先決條件和限制
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-prereqs"></a>

**先決條件**
+ 在您的 AWS 雲端環境中佈建為目標資料庫的 Amazon RDS for Oracle 資料庫。如需說明，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.Oracle.html)。
+ 在內部部署或 AWS 上的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行的 EnterpriseOne 資料庫。
**注意**  
此模式專為從現場部署遷移到 AWS 而設計，但在 EC2 執行個體上使用 EnterpriseOne 資料庫進行測試。如果您計劃從內部部署環境遷移，則必須設定適當的網路連線。
+ 結構描述詳細資訊。識別您計劃為 EnterpriseOne 遷移的 Oracle 資料庫結構描述 （例如 DV920)。開始遷移程序之前，請收集下列有關結構描述的詳細資訊：
  + 結構描述大小
  + 每個物件類型的物件數量
  + 無效物件的數量

**限制**
+ 您必須在目標 Amazon RDS for Oracle 資料庫上建立您想要的任何結構描述，AWS DMS 不會為您建立這些結構描述。([Epics](#migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-epics) 區段說明如何使用 Data Pump 匯出和匯入結構描述。) 目標 Oracle 資料庫的結構描述名稱必須已存在。來源結構描述中的資料表會匯入使用者或結構描述，而 AWS DMS 會使用管理員或系統帳戶來連線至目標執行個體。若要遷移多個結構描述，您可以建立多個複寫任務。您也可以將資料遷移到目標執行個體上的不同結構描述。若要這樣做，請在 AWS DMS 資料表映射上使用結構描述轉換規則。
+ 此模式已使用示範資料集進行測試。我們建議您驗證資料集和自訂的相容性。
+ 此模式使用在 Microsoft Windows 上執行的 EnterpriseOne 資料庫。不過，您可以將相同的程序與 AWS DMS 支援的其他作業系統搭配使用。

## Architecture
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-architecture"></a>

下圖顯示在 Oracle 資料庫上執行 EnterpriseOne 做為來源資料庫的系統，以及做為目標資料庫的 Amazon RDS for Oracle 資料庫。資料會從來源 Oracle 資料庫匯出，並使用 Oracle Data Pump 匯入目標 Amazon RDS for Oracle 資料庫，並使用 AWS DMS 複寫以進行 CDC 更新。

![\[Diagram showing data replication from on-premises Oracle to Amazon RDS using AWS DMS.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/c8ec3789-f80e-4f3a-a3f4-72a4541316b0/images/4e3e3477-2fe0-4a5d-b95e-05a8aafe8b68.png)


1. Oracle Data Pump 從來源資料庫擷取資料，並將資料傳送至 Amazon RDS for Oracle 資料庫目標。

1. CDC 資料會從來源資料庫傳送至 AWS DMS 中的來源端點。

1. 從來源端點，資料會傳送至執行複寫任務的 AWS DMS 複寫執行個體。

1. 複寫任務完成後，資料會傳送至 AWS DMS 中的目標端點。

1. 從目標端點，資料會傳送至 Amazon RDS for Oracle 資料庫執行個體。

## 工具
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-tools"></a>

**AWS 服務**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 可協助您在 AWS 雲端中設定、操作和擴展 Oracle 關聯式資料庫。

**其他服務**
+ [Oracle Data Pump](https://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_overview.htm) 可協助您以高速將資料和中繼資料從一個資料庫移至另一個資料庫。

## 最佳實務
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-best-practices"></a>

**遷移 LOBs**

如果您的來源資料庫包含需要遷移至目標資料庫的大型二進位物件 (LOBs)，AWS DMS 會提供下列選項：
+ **完整 LOB 模式** – AWS DMS 會將來源的所有 LOBs 遷移至目標資料庫，無論其大小為何。雖然遷移速度比其他模式慢，但優點是資料不會被截斷。為了獲得更好的效能，您可以在新的複寫執行個體上建立單獨的任務，以遷移 LOBs 大於幾個 MB 的資料表。
+ **有限 LOB 模式** – 您可以指定 LOB 資料欄資料的大小上限，這可讓 AWS DMS 預先配置資源並大量套用 LOBs。如果 LOB 資料欄的大小超過任務中指定的大小，AWS DMS 會截斷資料，並將警告傳送至 AWS DMS 日誌檔案。如果您的 LOB 資料大小在有限的 LOB 大小內，您可以使用有限的 LOB 模式來改善效能。
+ **內嵌 LOB 模式** – 您可以透過複寫小型和大型 LOBs 來遷移 LOBs而無需截斷資料或降低任務的效能。首先，指定 `InlineLobMaxSize` 參數的值，只有在完整 LOB 模式設定為 時才能使用`true`。AWS DMS 任務會內嵌傳輸小型 LOBs，這更有效率。然後，AWS DMS 會透過從來源資料表執行查詢來遷移大型 LOBs。不過，內嵌 LOB 模式僅適用於完全載入階段。

**產生序列值**

在 AWS DMS CDC 程序期間，不會從來源資料庫複寫增量序號。為了避免序列值的差異，您必須從所有序列的來源產生最新的序列值，並將其套用至目標 Amazon RDS for Oracle 資料庫。

**AWS Secrets Manager**

為了協助管理您的登入資料，建議您遵循部落格文章中的指示， [使用 AWS Secrets Manager 管理您的 AWS DMS 端點登入](https://aws.amazon.com/blogs/database/manage-your-aws-dms-endpoint-credentials-with-aws-secrets-manager/)資料。

**效能**
+ **複寫執行個體** ‒ 如需選擇最佳執行個體大小的指引，請參閱 AWS DMS 文件中的[為複寫執行個體選取最佳大小](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.SizingReplicationInstance.html)。
+ **連線選項** ‒ 為了避免延遲問題，我們建議您選擇正確的連線選項。AWS Direct Connect 提供 AWS 資源的最短路徑，因為它是公司資料中心與 AWS 之間的專用連線。傳輸時，您的網路流量會保留在 AWS 全球網路上，永遠不會透過網際網路。相較於使用 VPN 或公有網際網路，這可降低遇到瓶頸或意外增加延遲的機會。
+ **網路頻寬** ‒ 若要最佳化效能，請確認您的網路輸送量快速。如果您在內部部署來源資料庫和 AWS DMS 之間使用 VPN 通道，請確定頻寬足以滿足您的工作負載。
+ **任務平行處理** – 您可以在完全載入期間平行載入多個資料表，以加速資料複寫。此模式使用 RDBMS 端點，因此此選項僅適用於完全載入程序。任務平行處理是由 `MaxFullLoadSubTasks` 參數控制，這會決定平行執行多少個完全載入子任務。根據預設，此參數設定為 8，這表示在完整模式期間，八個資料表 （如果在資料表映射中選取） 會一起載入。您可以在任務 JSON 指令碼的完全載入任務設定區段中調整此參數。
+ **資料表平行處理** – AWS DMS 也可讓您使用多個平行執行緒載入單一大型資料表。這對於擁有數十億筆記錄以及多個分割區和子分割區的 Oracle 來源資料表特別有用。如果來源資料表未分割，您可以使用平行載入的資料欄邊界。
+ **分割負載** ‒ 當您將負載分割到多個任務或 AWS DMS 執行個體時，請在擷取變更時記住交易界限。

## 史詩
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-epics"></a>

### 使用 Oracle Data Pump 匯出 EnterpriseOne 結構描述
<a name="use-oracle-data-pump-to-export-the-enterpriseone-schema"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 產生 SCN。 | 當來源資料庫處於作用中狀態且由 EnterpriseOne 應用程式使用時，請使用 Oracle Data Pump 啟動資料匯出。您必須先從來源資料庫產生系統變更編號 (SCN)，以便在使用 Oracle Data Pump 匯出期間達到資料一致性，並做為 AWS DMS 中 CDC 的起點。若要從來源資料庫產生目前的 SCN，請使用下列 SQL 陳述式：<pre>SQL> select current_scn from v$database;<br /><br />CURRENT_SCN<br />-----------<br />   30009727</pre>儲存產生的 SCN。當您匯出資料和建立 AWS DMS 複寫任務時，將使用 SCN。 | DBA | 
| 建立 參數檔案。 | 若要建立參數檔案以匯出結構描述，您可以使用下列程式碼。<pre>directory=DMS_DATA_PUMP_DIR<br />logfile=export_dms.log<br />dumpfile=export_dms_data.dmp<br />schemas=<schema name><br />flashback_scn=<SCN from previous command></pre>您也可以根據您的需求`DATA_PUMP_DIR`，使用以下命令來定義自己的命令。<pre>SQL> CREATE OR REPLACE DIRECTORY DMS_DATA_PUMP_DIR AS '<Directory for dump>';<br />Directory created.<br /><br />SQL> GRANT READ, WRITE ON DIRECTORY DMS_DATA_PUMP_DIR TO SYSTEM;<br />Grant succeeded.</pre> | DBA | 
| 匯出結構描述。 | 若要執行匯出，請使用 `expdp`公用程式，如下所示：<pre>C:\Users\Administrator>expdp system/********@<DB Name> PARFILE='<Path to PAR file create above>'<br /><br />Export: Release 19.0.0.0.0 - Production on *** *** ** **:**:** ****<br />Version 19.3.0.0.0<br /><br />Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.<br /><br />Connected to: Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production<br />Starting "SYSTEM"."SYS_EXPORT_SCHEMA_02":  system/********@<DB Name>PARFILE='E:\exp_dms_datapump.par'<br />Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA<br />Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS<br />Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS<br />Processing object type SCHEMA_EXPORT/STATISTICS/MARKER<br />Processing object type SCHEMA_EXPORT/USER<br />Processing object type SCHEMA_EXPORT/ROLE_GRANT<br />Processing object type SCHEMA_EXPORT/DEFAULT_ROLE<br />Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA<br />Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA<br />Processing object type SCHEMA_EXPORT/TABLE/TABLE<br />Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT<br />Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX<br />Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT<br />. . exported "<Schema Name>"."<Table Name>"                            228.9 MB  496397 rows</pre><pre>Master table "SYSTEM"."SYS_EXPORT_SCHEMA_02" successfully loaded/unloaded<br />******************************************************************************<br />Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_02 is:<br />  E:\DMSDUMP\EXPORT_DMS_DATA.DMP<br />Job "SYSTEM"."SYS_EXPORT_SCHEMA_02" successfully completed at *** *** ** **:**:** **** elapsed 0 00:01:57</pre> | DBA | 

### 使用 Oracle Data Pump 匯入 EnterpriseOne 結構描述
<a name="use-oracle-data-pump-to-import-the-enterpriseone-schema"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將傾印檔案傳輸至目標執行個體。 | 若要使用 `DBMS_FILE_TRANSFER`公用程式傳輸檔案，您需要建立從來源資料庫到 Amazon RDS for Oracle 執行個體的資料庫連結。建立連結後，您可以使用 公用程式將 Data Pump 檔案直接傳輸到 Amazon RDS 執行個體。或者，您可以將 Data Pump 檔案傳輸至 [Amazon Simple Storage Service (Amazon S3)](https://aws.amazon.com/s3/)，然後將其匯入 Amazon RDS for Oracle 執行個體。如需此選項的詳細資訊，請參閱[其他資訊](#migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-additional)一節。若要在目標資料庫執行個體建立`ORARDSDB`連線至 Amazon RDS 主要使用者的資料庫連結，請在來源資料庫上執行下列命令：<pre>sqlplus / as sysdba<br /><br />SQL*Plus: Release 19.0.0.0.0 on *** *** ** **:**:** ****<br />Version 19.3.0.0.0<br /><br />Copyright (c) 1982, 2019, Oracle.  All rights reserved.<br /><br />Connected to:<br />Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0<br />Version 19.3.0.0.0<br /><br />SQL> create database link orardsdb connect to admin identified by "******" using '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = orcl.******.us-east-1.rds.amazonaws.com)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))';<br /><br />Database link created.<br /><br />SQL></pre> | DBA | 
| 測試資料庫連結。 | 測試資料庫連結，以確保您可以使用 連線至 Amazon RDS for Oracle 目標資料庫`sqlplus`。<pre>SQL> select name from v$database@orardsdb;<br /><br />NAME<br />---------<br />ORCL<br /></pre> | DBA | 
| 將傾印檔案傳輸到目標資料庫。 | 若要將傾印檔案複製到 Amazon RDS for Oracle 資料庫，您可以使用預設`DATA_PUMP_DIR`目錄，或使用下列程式碼建立自己的目錄，該程式碼必須在目標 Amazon RDS 執行個體上執行：<pre>exec rdsadmin.rdsadmin_util.create_directory(p_directory_name => 'DMS_TARGET_PUMP_DIR');<br /><br />PL/SQL procedure successfully completed.</pre>下列指令碼會使用名為 的資料庫連結，將名為 的傾印檔案`EXPORT_DMS_DATA.DMP`從來源執行個體複製到目標 Amazon RDS for Oracle 資料庫`orardsdb`。您必須在來源資料庫執行個體上執行指令碼。<pre>BEGIN<br />DBMS_FILE_TRANSFER.PUT_FILE(<br />source_directory_object => 'DMS_DATA_PUMP_DIR',<br />source_file_name => 'EXPORT_DMS_DATA.DMP',<br />destination_directory_object => 'DMS_TARGET_PUMP_DIR',<br />destination_file_name => 'EXPORT_DMS_DATA.DMP',<br />destination_database => 'orardsdb');<br />END;<br /><br />PL/SQL procedure successfully completed.</pre> | DBA | 
| 列出目標資料庫中的傾印檔案。 | PL/SQL 程序完成後，您可以使用下列程式碼，在 Amazon RDS for Oracle 資料庫中列出資料傾印檔案：<pre>select * from table (rdsadmin.rds_file_util.listdir(p_directory => 'DMS_TARGET_PUMP_DIR'));</pre> | DBA | 
| 在目標執行個體中建立 JDE 特定使用者。 | 在目標執行個體中使用這些命令來建立 JD Edwards 描述檔和角色：<pre>SQL> CREATE PROFILE "JDEPROFILE" LIMIT IDLE_TIME 15;<br />Profile created.<br /><br />SQL> CREATE ROLE "JDE_ROLE";<br />Role created.<br /><br />SQL> CREATE ROLE "JDEADMIN";<br />CREATE ROLE "JDEUSER";<br />Role created.<br />Role created.</pre>將必要的許可授予角色：<pre>SQL> GRANT CREATE ANY SEQUENCE TO JDE_ROLE;<br /> GRANT DROP ANY SEQUENCE TO JDE_ROLE;<br /> GRANT CREATE ANY TRIGGER TO JDE_ROLE;<br /> GRANT DROP ANY TRIGGER TO JDE_ROLE;<br /></pre> | DBA、JDE CNC | 
| 在目標執行個體中建立資料表空間。 | 針對涉及此遷移的結構描述，使用下列命令，在目標執行個體中建立所需的資料表空間：<pre>SQL> CREATE TABLESPACE <Tablespace Name for Tables>;<br />Tablespace created.<br /><br />SQL> CREATE TABLESPACE <Tablespace Name for Indexes>;<br />Tablespace created.</pre> | DBA、JDE CNC | 
| 在目標資料庫上啟動匯入。 | 開始匯入程序之前，請使用資料傾印檔案，在目標 Amazon RDS for Oracle 資料庫上設定角色、結構描述和資料表空間。若要執行匯入，請使用 Amazon RDS 主要使用者帳戶存取目標資料庫，並使用 `tnsnames.ora` 檔案中的連線字串名稱，其中包含 Amazon RDS for Oracle Database`tns-entry`。如有必要，您可以包含重新映射選項，以將資料傾印檔案匯入不同的資料表空間，或在不同的結構描述名稱下匯入。若要開始匯入，請使用下列程式碼：<pre>impdp admin@orardsdb directory=DMS_TARGET_PUMP_DIR logfile=import.log dumpfile=EXPORT_DMS_DATA.DMP</pre>為了確保成功匯入，請檢查匯入日誌檔案是否有任何錯誤，並檢閱物件計數、資料列計數和無效物件等詳細資訊。如果有任何無效的物件，請重新編譯。此外，比較來源和目標資料庫物件，以確認它們相符。 | DBA | 

### 使用來源和目標端點佈建 AWS DMS 複寫執行個體
<a name="provision-an-aws-dms-replication-instance-with-the-source-and-target-endpoints"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 範本。 | 下載 AWS CloudFormation [DMS\$1instance.yaml](https://aws-database-blog.s3.amazonaws.com/artifacts/Migrating_oracle_using_DMS/DMS_Instance.yaml) 範本，以佈建 AWS DMS 複寫執行個體及其來源和目標端點。 | 雲端管理員，DBA | 
| 開始建立堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html) | 雲端管理員，DBA | 
| 指定參數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html) | 雲端管理員，DBA | 
| 建立堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html)佈建應該會在大約 5-10 分鐘內完成。當 AWS CloudFormation Stacks 頁面顯示 **CREATE\$1COMPLETE** 時即完成。 | 雲端管理員，DBA | 
| 設定端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html) | 雲端管理員，DBA | 
| 測試連線能力。 | 來源和目標端點將狀態顯示為**作用中**之後，請測試連線。針對每個端點 （來源和目標） 選擇**執行測試**，以確保狀態顯示為成功。 | 雲端管理員，DBA | 

### 建立即時複寫的 AWS DMS 複寫任務
<a name="create-an-aws-dms-replication-task-for-live-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立複寫任務。 | 使用下列步驟建立 AWS DMS 複寫任務：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html)建立任務後，AWS DMS 會從您在 CDC 啟動模式下提供的 SCN 遷移持續變更至 Amazon RDS for Oracle 資料庫執行個體。您也可以檢閱 CloudWatch 日誌來驗證遷移。 | 雲端管理員，DBA | 
| 重複複寫任務。 | 重複上述步驟，為屬於遷移一部分的其他 JD Edwards 結構描述建立複寫任務。 | 雲端管理員、DBA、JDE CNC 管理員 | 

### 驗證目標 Amazon RDS for Oracle 資料庫上的資料庫結構描述
<a name="validate-the-database-schema-on-the-target-amazon-rds-for-oracle-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料傳輸。 | AWS DMS 任務啟動後，您可以查看**任務頁面上的****資料表統計資料**索引標籤，以查看對資料所做的變更。您可以在**資料庫遷移任務**頁面的 主控台中監控進行中複寫的狀態。如需詳細資訊，請參閱 [AWS DMS 資料驗證](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | 雲端管理員，DBA | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止複寫。 | 停止複寫程序並停止來源應用程式服務。 | 雲端管理員，DBA | 
| 啟動 JD Edwards 應用程式。 | 在 AWS 上啟動目標 JD Edwards 簡報和邏輯層應用程式，並將其導向至 Amazon RDS for Oracle 資料庫。當您存取應用程式時，應該會注意到所有連線現在都已透過 Amazon RDS for Oracle 資料庫建立。 | DBA、JDE CNC 管理員 | 
| 關閉來源資料庫。 | 確認沒有更多連線後，您可以關閉來源資料庫。 | DBA | 

## 疑難排解
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 您會收到警告訊息，以在來源資料庫中啟用[補充記錄](https://docs.oracle.com/database/121/SUTIL/GUID-D2DDD67C-E1CC-45A6-A2A7-198E4C142FA3.htm#SUTIL1583)以進行持續複寫 | 輸入這些命令以啟用補充記錄：<pre>SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;<br />SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;<br />SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;<br />SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS;<br />SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;<br />SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;</pre> | 
| AWS DMS 已關閉補充記錄。 | AWS DMS 中的補充記錄預設為關閉。若要為來源 Oracle 端點開啟它：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html) | 
| CDB 層級未啟用補充記錄。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.html) | 
| 您收到錯誤訊息：「測試端點失敗：Application-Status：1020912、Application-Message：Oracle PDB 環境端點初始化失敗，不支援 LogMiner。」 | 如果您遇到此錯誤訊息，您可以使用 Binary Reader 而非 LogMiner。在**端點設定**下，將此行新增至來源資料庫的額外連線屬性：<pre>useLogMinerReader=N;useBfile=Y;</pre> | 

## 相關資源
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-resources"></a>
+ [AWS Database Migration Service 入門](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html)
+ [AWS Database Migration Service 的最佳實務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.html)
+ [將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html)
+ [AWS CloudFormation 的 AWS Database Migration Service 資源類型參考 AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_DMS.html)
+ [使用 AWS Secrets Manager 管理您的 AWS DMS 端點憑證](https://aws.amazon.com/blogs/database/manage-your-aws-dms-endpoint-credentials-with-aws-secrets-manager/)
+ [對 AWS Database Migration Service 中的遷移任務進行故障診斷](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Troubleshooting.html#CHAP_Troubleshooting.Oracle.RecordsMissing)
+ [AWS Database Migration Service 的最佳實務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.html)

## 其他資訊
<a name="migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms-additional"></a>

**使用 Amazon S3 傳輸檔案**

若要將檔案傳輸至 Amazon S3，您可以使用 AWS CLI 或 Amazon S3 主控台。將檔案傳輸至 Amazon S3 之後，您可以使用 Amazon RDS for Oracle 執行個體從 Amazon S3 匯入 Data Pump 檔案。

如果您選擇使用 Amazon S3 整合做為替代方法傳輸傾印檔案，請執行下列步驟：

1. 建立 S3 儲存貯體。

1. 使用 Oracle Data Pump 從來源資料庫匯出資料。

1. 將 Data Pump 檔案上傳至 S3 儲存貯體。

1. 將 Data Pump 檔案從 S3 儲存貯體下載至目標 Amazon RDS for Oracle 資料庫。

1. 使用 Data Pump 檔案執行匯入。

**注意**  
若要在 S3 和 RDS 執行個體之間傳輸大型資料檔案，建議您使用 [Amazon S3 Transfer Acceleration](https://docs.aws.amazon.com/AmazonS3/latest/userguide/transfer-acceleration.html) 功能。

# 使用 AWS DMS 將 Oracle PeopleSoft 資料庫遷移至 AWS
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms"></a>

*sampath kathirvel，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-summary"></a>

[Oracle PeopleSoft](https://www.oracle.com/applications/peoplesoft/) 是適用於整個企業程序的企業資源規劃 (ERP) 解決方案。PeopleSoft 具有三層架構：用戶端、應用程式和資料庫。PeopleSoft 可以在 [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 上執行。

如果您將 Oracle 資料庫遷移至 Amazon RDS，Amazon Web Services (AWS) 可以處理備份任務和高可用性，讓您可以專心維護 PeopleSoft 應用程式及其功能。如需遷移程序期間要考量之關鍵因素的完整清單，請參閱 AWS 方案指引中的 [Oracle 資料庫遷移策略](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/strategies.html)。

此模式提供使用 Oracle Data Pump 搭配 [AWS Database Migration Service (AWS DMS) ](https://aws.amazon.com/dms)及其變更資料擷取 (CDC) 功能，將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle 的解決方案。

遷移 Oracle PeopleSoft 等重要 ERP 應用程式時，將停機時間降至最低是關鍵。AWS DMS 支援完全載入和持續複寫，將停機時間降至最低。 從來源資料庫到目標資料庫。AWS DMS 也提供即時監控和記錄遷移，這可協助您識別和解決可能導致停機的任何問題。

使用 AWS DMS 複寫變更時，您必須指定時間或系統變更號碼 (SCN) 做為起點，AWS DMS 才能從資料庫日誌讀取變更。請務必在伺服器上保留一段指定的時間來存取這些日誌，以確保 AWS DMS 可以存取這些變更。

## 先決條件和限制
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 在您 AWS 雲端環境中佈建的 Amazon RDS for Oracle 資料庫做為目標資料庫。
+ 在 AWS 雲端內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) 上執行的 Oracle PeopleSoft 資料庫。
**注意**  
此模式專為從現場部署遷移到 AWS 而設計，但在 Amazon EC2 執行個體上使用 Oracle Database 進行測試。若要從內部部署遷移，您需要設定適當的網路連線。
+ 結構描述詳細資訊。將 Oracle PeopleSoft 應用程式遷移至 Amazon RDS for Oracle 時，必須識別要遷移的 Oracle 資料庫結構描述 （例如 `SYSADM`)。開始遷移程序之前，請收集下列有關結構描述的詳細資訊：
  + 大小
  + 每個物件類型的物件數量
  + 無效物件的數量。

  此資訊將有助於遷移程序。

**限制**
+ 此案例僅使用 PeopleSoft DEMO 資料庫進行測試。它尚未使用大型資料集進行測試。

## Architecture
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-architecture"></a>

下圖顯示執行 Oracle 資料庫做為來源資料庫的執行個體，以及執行 Amazon RDS for Oracle 資料庫做為目標資料庫的執行個體。資料會使用 Oracle Data Pump 從來源 Oracle 資料庫匯出和匯入至目標 Amazon RDS for Oracle 資料庫，並使用 AWS DMS 複寫 CDC 變更。

![\[從內部部署資料庫執行個體到 Amazon RDS 的五個步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/c8ec3789-f80e-4f3a-a3f4-72a4541316b0/images/4e3e3477-2fe0-4a5d-b95e-05a8aafe8b68.png)


1. 初始步驟涉及使用 Oracle Data Pump 從來源資料庫擷取資料，然後傳送至 Amazon RDS for Oracle 資料庫目標。

1. 資料會從來源資料庫傳送至 AWS DMS 中的來源端點。

1. 從來源端點，資料會傳送至執行複寫任務的 AWS DMS 複寫執行個體。

1. 複寫任務完成後，資料會傳送至 AWS DMS 中的目標端點。

1. 從目標端點，資料會傳送至 Amazon RDS for Oracle 資料庫執行個體。

## 工具
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-tools"></a>

**AWS 服務**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 可協助您在 AWS 雲端中設定、操作和擴展 Oracle 關聯式資料庫。

**其他服務**
+ [Oracle Data Pump](https://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_overview.htm) 可協助您以高速將資料和中繼資料從一個資料庫移至另一個資料庫。

## 最佳實務
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-best-practices"></a>

**遷移 LOBs**

如果您的來源資料庫包含需要遷移至目標資料庫的大型二進位物件 (LOBs)，AWS DMS 會提供下列選項：
+ **完整 LOB 模式** – AWS DMS 會將來源的所有 LOBs 遷移至目標資料庫，無論其大小為何。雖然遷移速度較慢，但優點是資料不會被截斷。為了獲得更好的效能，您可以在新的複寫執行個體上建立單獨的任務，以遷移 LOBs 大於數個 MB 的資料表。
+ **有限 LOB 模式** – 您可以指定 LOB 資料欄資料的大小上限，這可讓 AWS DMS 預先配置資源並大量套用 LOBs。如果 LOB 資料欄的大小超過任務中指定的大小，AWS DMS 會截斷資料，並將警告傳送至 AWS DMS 日誌檔案。如果您的 LOB 資料大小在有限 LOB 大小內，您可以使用有限 LOB 模式來改善效能。
+ **內嵌 LOB 模式** – 您可以透過複寫小型和大型 LOBs 來遷移 LOBs而無需截斷資料或降低任務的效能。首先，指定 InlineLobMaxSize 參數的值，只有在完整 LOB 模式設定為 true 時才能使用。AWS DMS 任務會內嵌傳輸小型 LOBs，這更有效率。然後，AWS DMS 會透過從來源資料表執行查詢來遷移大型 LOBs。不過，內嵌 LOB 模式僅適用於完全載入階段。

**產生序列值**

請記住，在 AWS DMS 的變更資料擷取過程中，不會從來源資料庫複寫增量序號。為了避免序列值的差異，您必須從所有序列的來源產生最新的序列值，並將其套用至目標 Amazon RDS for Oracle 資料庫。

**登入資料管理**

為了協助保護您的 AWS 資源，建議您遵循 AWS Identity and Access Management (IAM) 的[最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)。

## 史詩
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-epics"></a>

### 使用來源和目標端點佈建 AWS DMS 複寫執行個體
<a name="provision-an-aws-dms-replication-instance-with-the-source-and-target-endpoints"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 範本。 | 下載 [DMS\$1instance.yaml](https://aws-database-blog.s3.amazonaws.com/artifacts/Migrating_oracle_using_DMS/DMS_Instance.yaml) AWS CloudFormation 範本，以佈建 AWS DMS 複寫執行個體及其來源和目標端點。 | 雲端管理員，DBA | 
| 開始建立堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.html) | 雲端管理員，DBA | 
| 指定參數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.html) | 雲端管理員，DBA | 
| 建立堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.html)佈建應該會在大約 5-10 分鐘內完成。當 AWS CloudFormation Stacks 頁面顯示 **CREATE\$1COMPLETE** 時即完成。 | 雲端管理員，DBA | 
| 設定端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.html) | 雲端管理員，DBA | 
| 測試連線能力。 | 來源和目標端點將狀態顯示為作用中之後，請測試連線能力。針對每個端點 （來源和目標） 選擇**執行測試**，以確保狀態顯示為成功。 | 雲端管理員，DBA | 

### 使用 Oracle Data Pump 從現場部署 Oracle 資料庫匯出 PeopleSoft 結構描述
<a name="export-the-peoplesoft-schema-from-the-on-premises-oracle-database-by-using-oracle-data-pump"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 產生 SCN。 | 當來源資料庫處於作用中狀態且應用程式正在使用中時，請使用 Oracle Data Pump 啟動資料匯出。您必須先從來源資料庫產生系統變更編號 (SCN)，以便在使用 Oracle Data Pump 匯出期間達到資料一致性，並做為 AWS DMS 中擷取變更資料的起點。若要從來源資料庫產生目前的 SCN，請輸入下列 SQL 陳述式。<pre>SQL> select name from v$database;<br />SQL> select name from v$database;<br />NAME<br />---------<br />PSFTDMO<br />SQL> SELECT current_scn FROM v$database;<br />CURRENT_SCN<br />-----------<br />23792008</pre>儲存產生的 SCN，以便在匯出資料和建立 AWS DMS 複寫任務時使用。 | DBA | 
| 建立 參數檔案。 | 若要建立參數檔案以匯出結構描述，您可以使用下列程式碼。<pre>$ cat exp_datapmp.par<br />userid=system/*******<br />directory=DATA_PUMP_DIR<br />logfile=export_dms_sample_user.log<br />dumpfile=export_dms_sample_data_%U.dmp<br />schemas=SYSADM<br />flashback_scn=23792008</pre>您也可以根據您的需求`DATA_PUMP_DIR`，使用以下命令來定義自己的命令。<pre>SQL> CREATE OR REPLACE DIRECTORY DATA_PUMP_DIR AS '/opt/oracle/product/19c/dbhome_1/dmsdump/';<br />Directory created.<br />SQL> GRANT READ, WRITE ON DIRECTORY DATA_PUMP_DIR TO system;<br />Grant succeeded.<br />SQL><br />SQL> SELECT owner, directory_name, directory_path FROM dba_directories WHERE directory_name='DATA_PUMP_DIR';<br />OWNER DIRECTORY_NAME DIRECTORY_PATH<br />------------------------------------------------------------------------------------------------------------------<br />SYS DATA_PUMP_DIR /opt/oracle/product/19c/dbhome_1/dmsdump/</pre> | DBA | 
| 匯出結構描述。 | 若要執行匯出，請使用 `expdp`公用程式。<pre>$ expdp parfile=exp_datapmp.par<br />.......................<br />Transferring the dump file with DBMS_FILE_TRANSFER to Target:<br />. . exported "SYSADM"."PS_XML_TEMPLT_LNG" 6.320 KB 0 rows<br />. . exported "SYSADM"."PS_XML_TEMPLT_LNK" 6.328 KB 0 rows<br />. . exported "SYSADM"."PS_XML_XLATDEF_LNG" 6.320 KB 0 rows<br />. . exported "SYSADM"."PS_XML_XLATITM_LNG" 7.171 KB 0 rows<br />. . exported "SYSADM"."PS_XPQRYRUNCNTL" 7.601 KB 0 rows<br />. . exported "SYSADM"."PS_XPQRYRUNPARM" 7.210 KB 0 rows<br />. . exported "SYSADM"."PS_YE_AMOUNTS" 9.351 KB 0 rows<br />. . exported "SYSADM"."PS_YE_DATA" 16.58 KB 0 rows<br />. . exported "SYSADM"."PS_YE_EE" 6.75 KB 0 rows<br />. . exported "SYSADM"."PS_YE_W2CP_AMOUNTS" 9.414 KB 0 rows<br />. . exported "SYSADM"."PS_YE_W2CP_DATA" 20.94 KB 0 rows<br />. . exported "SYSADM"."PS_YE_W2C_AMOUNTS" 10.27 KB 0 rows<br />. . exported "SYSADM"."PS_YE_W2C_DATA" 20.95 KB 0 rows<br />. . exported "SYSADM"."PS_ZBD_JOBCODE_TBL" 14.60 KB 0 rows<br />. . exported "SYSADM"."PTGRANTTBL" 5.468 KB 0 rows<br />Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded<br />**<br />Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:<br />/opt/oracle/product/19c/dbhome_1/dmsdump/export_dms_sample_data_01.dmp<br />Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Dec 19 20:13:57 2022 elapsed 0 00:38:22</pre> | DBA | 

### 使用 Oracle Data Pump 將 PeopleSoft 結構描述匯入 Amazon RDS for Oracle 資料庫
<a name="import-the-peoplesoft-schema-into-the-amazon-rds-for-oracle-database-by-using-oracle-data-pump"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將傾印檔案傳輸至目標執行個體。 | 若要使用 傳輸檔案`DBMS_FILE_TRANSFER`，您需要建立從來源資料庫到 Amazon RDS for Oracle 執行個體的資料庫連結。建立連結後，您可以使用 公用程式直接將 Data Pump 檔案傳輸到 RDS 執行個體。或者，您可以將 Data Pump 檔案傳輸至 [Amazon Simple Storage Service (Amazon S3)](https://aws.amazon.com/s3/)，然後將其匯入 Amazon RDS for Oracle 執行個體。如需此選項的詳細資訊，請參閱其他資訊一節。若要在目標資料庫執行個體建立`ORARDSDB`連線至 Amazon RDS 主要使用者的資料庫連結，請在來源資料庫上執行下列命令。<pre>$sqlplus / as sysdba<br />$ SQL> create database link orardsdb connect to admin identified by "*****" using '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = testpsft.*******.us-west-2.rds.amazonaws.com)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))';<br />Database link created.</pre> | DBA | 
| 測試資料庫連結。 | 測試資料庫連結，以確保您可以使用 sqlplus 連線到 Amazon RDS for Oracle 目標資料庫。<pre>SQL><br />SQL> select name from v$database@orardsdb;<br />NAME<br />---------<br />ORCL<br />SQL></pre> | DBA | 
| 將傾印檔案傳輸至目標資料庫。 | 若要將傾印檔案複製到 Amazon RDS for Oracle 資料庫，您可以使用預設`DATA_PUMP_DIR`目錄，或使用下列程式碼建立自己的目錄。<pre>exec rdsadmin.rdsadmin_util.create_directory(p_directory_name => ‘TARGET_PUMP_DIR’);</pre>下列指令碼會使用名為 的資料庫連結，將名為 的傾印檔案`export_dms_sample_data_01.dmp`從來源執行個體複製到目標 Amazon RDS for Oracle 資料庫`orardsdb`。<pre>$ sqlplus / as sysdba<br />SQL><br />BEGIN<br />DBMS_FILE_TRANSFER.PUT_FILE(<br />source_directory_object => 'DATA_PUMP_DIR',<br />source_file_name => 'export_dms_sample_data_01.dmp',<br />destination_directory_object => 'TARGET_PUMP_DIR’',<br />destination_file_name => 'export_dms_sample_data_01.dmp',<br />destination_database => 'orardsdb'<br />);<br />END;<br />/<br />PL/SQL procedure successfully completed.</pre> | DBA | 
| 列出目標資料庫中的傾印檔案。 | PL/SQL 程序完成後，您可以使用下列程式碼，在 Amazon RDS for Oracle 資料庫中列出資料傾印檔案。<pre>SQL> select * from table (rdsadmin.rds_file_util.listdir(p_directory => ‘TARGET_PUMP_DIR’));</pre> | DBA | 
| 在目標資料庫上啟動匯入。 | 開始匯入程序之前，請使用資料傾印檔案，在目標 Amazon RDS for Oracle 資料庫上設定角色、結構描述和資料表空間。若要執行匯入，請使用 Amazon RDS 主要使用者帳戶存取目標資料庫，並使用 `tnsnames.ora` 檔案中的連線字串名稱，其中包含 Amazon RDS for Oracle Database `tns-entry`。如有必要，您可以包含重新映射選項，將資料傾印檔案匯入不同的資料表空間或不同的結構描述名稱。若要開始匯入，請使用下列程式碼。<pre>impdp admin@orardsdb directory=TARGET_PUMP_DIR logfile=import.log dumpfile=export_dms_sample_data_01.dmp</pre>為了確保成功匯入，請檢查匯入日誌檔案是否有任何錯誤，並檢閱物件計數、資料列計數和無效物件等詳細資訊。如果有任何無效的物件，請重新編譯。此外，比較來源和目標資料庫物件，以確認它們相符。 | DBA | 

### 使用 CDC 建立 AWS DMS 複寫任務來執行即時複寫
<a name="create-an-aws-dms-replication-task-using-cdc-to-perform-live-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立複寫任務。 | 使用下列步驟建立 AWS DMS 複寫任務：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.html)建立任務之後，它會從您在 CDC 啟動模式下提供的 SCN 將 CDC 遷移至 Amazon RDS for Oracle 資料庫執行個體。您也可以檢閱 CloudWatch 日誌來驗證 。 | 雲端管理員，DBA | 

### 驗證目標 Amazon RDS for Oracle 資料庫上的資料庫結構描述
<a name="validate-the-database-schema-on-the-target-amazon-rds-for-oracle-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料傳輸。 | AWS DMS 任務啟動後，您可以查看**任務頁面上的****資料表統計資料**索引標籤，以查看對資料所做的變更。您可以在**資料庫遷移任務**頁面的 主控台中監控進行中複寫的狀態。如需詳細資訊，請參閱 [AWS DMS 資料驗證](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | 雲端管理員，DBA | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止複寫。 | 停止複寫程序並停止來源應用程式服務。 | 雲端管理員，DBA | 
| 啟動 PeopleSoft 中間層。 | 在 AWS 中啟動目標 PeopleSoft 中層應用程式，並將其導向至最近遷移的 Amazon RDS for Oracle 資料庫。當您存取應用程式時，您應該會注意到所有應用程式連線現在都已與 Amazon RDS for Oracle 資料庫建立。 | DBA，PeopleSoft 管理員 | 
| 關閉來源資料庫。 | 確認不再有來源資料庫的連線後，即可將其關閉。 | DBA | 

## 相關資源
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-resources"></a>
+ [AWS Database Migration Service 入門](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_GettingStarted.html)
+ [AWS Database Migration Service 的最佳實務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_BestPractices.html)
+ [將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html)

## 其他資訊
<a name="migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms-additional"></a>

**使用 Amazon S3 傳輸檔案**

若要將檔案傳輸至 Amazon S3，您可以使用 AWS CLI 或 Amazon S3 主控台。將檔案傳輸至 Amazon S3 之後，您可以使用 Amazon RDS for Oracle 執行個體從 Amazon S3 匯入 Data Pump 檔案。

如果您選擇使用 Amazon S3 整合做為替代方法傳輸傾印檔案，請執行下列步驟：

1. 建立 S3 儲存貯體。

1. 使用 Oracle Data Pump 從來源資料庫匯出資料。

1. 將 Data Pump 檔案上傳至 S3 儲存貯體。

1. 將 Data Pump 檔案從 S3 儲存貯體下載至目標 Amazon RDS for Oracle 資料庫。

1. 使用 Data Pump 檔案執行匯入。

**注意**  
若要在 S3 和 RDS 執行個體之間傳輸大型資料檔案，建議使用 Amazon S3 Transfer Acceleration 功能。

**啟用補充記錄**

如果您收到警告訊息，在來源資料庫中啟用[補充記錄](https://docs.oracle.com/database/121/SUTIL/GUID-D2DDD67C-E1CC-45A6-A2A7-198E4C142FA3.htm#SUTIL1583)以進行持續複寫，請使用下列步驟。

```
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS;
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS
SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;
```

# 將內部部署 MySQL 資料庫遷移至 Amazon RDS for MySQL
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql"></a>

*Lorenzo Mota，Amazon Web Services*

## 摘要
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql-summary"></a>

此模式提供將內部部署 MySQL 資料庫遷移至 MySQL 的 Amazon Relational Database Service (Amazon RDS) MySQL 的指引。模式討論使用 AWS Database Migration Service (AWS DMS) 或原生 MySQL 工具進行完整的資料庫遷移，例如 **mysqldump**。此模式主要用於DBAs解決方案架構師。它可用於小型或大型專案做為測試程序 （我們建議至少有一個測試週期） 或做為最終遷移程序。

## 先決條件和限制
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 內部部署資料中心中的 MySQL 來源資料庫

**限制**
+ 資料庫大小限制：[64 TB](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html)

**產品版本**
+ MySQL 5.5、5.6、5.7、8.0 版。如需支援版本的最新清單，請參閱 AWS 文件中的 [Amazon RDS 上的 MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html)。如果您使用的是 AWS DMS，另請參閱 [使用 MySQL 相容資料庫作為目前支援的 for MySQL 版本的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)  AWS DMS。 MySQL 

## Architecture
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql-architecture"></a>

**來源技術堆疊**
+ 內部部署 MySQL 資料庫

**目標技術堆疊**
+ 執行 MySQL 的 Amazon RDS 資料庫執行個體

**目標架構**

下圖顯示遷移後的目標 Amazon RDS for MySQL 實作。

![\[切換後的目標 Amazon RDS for MySQL 實作。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/808809dd-030f-42af-a5a7-c4ba40456193/images/2e10114e-e389-4d24-9b6a-fa56beee5369.png)


**AWS 資料遷移架構**

**使用 AWS DMS：**

下圖顯示使用 AWS DMS 傳送完整和增量變更時的資料遷移架構，直到切換為止。從內部部署到 的網路連線 AWS 取決於您的需求，且超出此模式的範圍。

![\[當您使用 AWS DMS 時，資料遷移架構至 AWS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/808809dd-030f-42af-a5a7-c4ba40456193/images/ecc9b282-1897-4971-99ed-83223b17000d.png)


** 使用原生 MySQL 工具：**

下圖顯示當您使用原生 MySQL 工具時的資料遷移架構。匯出傾印檔案會複製到 Amazon Simple Storage Service (Amazon S3)，並在切換 AWS 之前匯入 中的 Amazon RDS for MySQL 資料庫。從內部部署到 的網路連線 AWS 取決於您的需求，且超出此模式的範圍。

 

![\[當您使用原生 MySQL 工具時，資料遷移至 AWS 架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/808809dd-030f-42af-a5a7-c4ba40456193/images/3bbec989-c3eb-473e-ba4a-032d6a4271c5.png)


**備註**：
+ 根據停機時間需求和資料庫的大小，使用 AWS DMS 或變更資料擷取 (CDC) 工具可將切換時間降至最低。 AWS DMS 可協助將新目標的切換時間縮短到最短 （通常為 分鐘）。如果資料庫和網路延遲的大小允許短時間，則 **mysqldump **的 離線策略就足夠。（我們建議進行測試以取得大約的時間。)
+ 通常， 等 CDC 策略 AWS DMS 比離線選項需要更多的監控和複雜性。

## 工具
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql-tools"></a>
+ **AWS 服務**：[AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端 或在雲端和內部部署設定的組合之間遷移。如需 支援的 MySQL 來源和 目標資料庫的相關資訊 AWS DMS，請參閱 [將 MySQL 相容資料庫遷移至 AWS](https://docs.aws.amazon.com/dms/latest/sbs/CHAP_MySQL.html)。如果您的來源資料庫不受 支援 AWS DMS，您必須選擇另一種方法來遷移資料。
+ **原生 MySQL 工具**：[mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)
+ **第三方工具**：[Percona XtraBackup](https://www.percona.com/software/mysql-database/percona-xtrabackup)

## 史詩
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料庫版本。 | 驗證來源和目標資料庫版本。 | DBA | 
| 識別硬體需求。 | 識別目標伺服器的硬體需求。 | DBA，系統管理員 | 
| 識別儲存需求。 | 識別目標資料庫的儲存需求 （例如儲存類型和容量）。 | DBA，系統管理員 | 
| 選擇執行個體類型。 | 根據容量、儲存功能和聯網功能選擇目標執行個體類型。 | DBA，系統管理員 | 
| 識別網路存取需求。 | 識別來源和目標資料庫網路存取的安全需求。 | DBA，系統管理員 | 
| 識別不支援的物件。 | 識別不支援的物件 （如果有的話） 並判斷遷移工作。 | DBA | 
| 識別相依性。 | 識別遠端資料庫上的任何相依性。 | DBA | 
| 決定應用程式遷移策略。 | 決定遷移用戶端應用程式的策略。 | DBA、應用程式擁有者、系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) | 設定路由表、網際網路閘道、NAT 閘道和子網路。如需詳細資訊，請參閱 [Amazon RDS 文件中的 VPCs 和](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.html) Amazon RDS。 | 系統管理員 | 
| 建立安全群組。 | 根據您的需求設定連接埠和 CIDR 範圍或特定 IPs。MySQL 的預設連接埠為 3306。如需詳細資訊，請參閱 Amazon RDS 文件中的[使用安全群組控制存取](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html)。 | 系統管理員 | 
| 設定和啟動 Amazon RDS for MySQL 資料庫執行個體。 | 如需說明，請參閱[《Amazon RDS 文件》中的建立 Amazon RDS 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateInstance.html)。檢查支援的版本。 | 系統管理員 | 

### 遷移資料 ‒ 選項 1 （使用原生工具）
<a name="migrate-data-option-1-using-native-tools"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生 MySQL 工具或第三方工具來遷移資料庫物件和資料。 | 如需說明，請參閱 MySQL 工具的文件，例如 [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) 和 [Percona XtraBackup](https://www.percona.com/software/mysql-database/percona-xtrabackup) （適用於實體遷移）。如需選項的詳細資訊，請參閱 [ MySQL 遷移至 Amazon RDS for MySQL 或 Amazon Aurora MySQL ](https://aws.amazon.com/blogs/database/migration-options-for-mysql-to-amazon-rds-for-mysql-or-amazon-aurora-mysql/)的部落格文章。 | DBA | 

### 遷移資料 ‒ 選項 2 （使用 AWS DMS)
<a name="migrate-data-option-2-using-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 遷移資料 AWS DMS。 | 如需說明，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)。 | DBA | 

### 在切換之前執行初步任務
<a name="perform-preliminary-tasks-before-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修正物件計數差異。 | 從來源資料庫和新目標資料庫收集物件計數。修正目標資料庫中的差異。 | DBA | 
| 檢查相依性。 | 檢查往返其他資料庫的相依性 （連結） 是否有效並如預期運作。 | DBA | 
| 執行測試。 | 如果這是一個測試週期，請執行查詢測試、收集指標並修正問題。 | DBA | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 切換到目標資料庫。 | 將用戶端應用程式切換到新的基礎設施。 | DBA、應用程式擁有者、系統管理員 | 
| 提供測試支援。 | 提供功能應用程式測試的支援。 | DBA | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉資源。 | 關閉您為遷移建立的臨時 AWS 資源。 | DBA，系統管理員 | 
| 驗證專案文件。 | 檢閱並驗證專案文件。 | DBA、應用程式擁有者、系統管理員 | 
| 收集指標。 | 收集遷移時間、手動與自動化工作的百分比、節省成本等指標。 | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案。 | 關閉專案並提供意見回饋。 | DBA、應用程式擁有者、系統管理員 | 
| 停用來源資料庫。 | 當所有遷移和切換任務完成時，請停用現場部署資料庫。 | DBA，系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql-resources"></a>

**參考**
+ [關聯式資料庫的遷移策略](https://docs.aws.amazon.com/prescriptive-guidance/latest/strategy-database-migration/welcome.html)
+ [AWS DMS website](https://aws.amazon.com/dms/)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/)
+ [Amazon RDS 文件](https://docs.aws.amazon.com/rds/)
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)
+ [Amazon VPC 和 Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.html)
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/)
+ [使用 Percona XtraBackup、Amazon EFS 和 Amazon S3 將內部部署 MySQL 資料庫遷移至 Aurora MySQL ](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3.html)
+ [Amazon RDS 資料庫執行個體儲存體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html)

**教學課程**
+ [入門 AWS DMS](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)

# 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server"></a>

*Henrique Lobao、Jonathan Pereira Cruz 和 Amazon Web Services Vishal Singh*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-summary"></a>

此模式提供從內部部署 Microsoft SQL Server 資料庫遷移至 SQL Server 的 Amazon Relational Database Service (Amazon RDS) 的指引。其中說明兩種遷移選項：使用 AWS Data Migration Service (AWS DMS) 或使用 Copy Database Wizard 等原生 Microsoft SQL Server 工具。

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的來源 Microsoft SQL Server 資料庫

**限制**
+ 資料庫大小限制：16 TB

**產品版本**
+ 如需支援版本和功能的最新清單，請參閱 AWS 文件中的 [Amazon RDS 上的 Microsoft SQL Server](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.FeatureSupport)。如果您使用的是 AWS DMS，另請參閱[使用 Microsoft SQL Server 資料庫做為 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.SQLServer.html) for SQL Server 版本支援的目標。

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-architecture"></a>

**來源技術堆疊**
+ 內部部署 Microsoft SQL Server 資料庫

**目標技術堆疊**
+ Amazon RDS for SQL Server 資料庫執行個體 

**來源和目標架構**

*使用 AWS DMS： *

![\[使用 AWS DMS 從內部部署 SQL Server 遷移至 Amazon RDS 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/27942833-c294-405c-90e6-32cc197e36ee/images/69b9877c-2d56-4d64-8475-a3dae789c5de.png)


*使用原生 SQL Server 工具： *

![\[使用 SQL Server 工具從內部部署 SQL Server 遷移至 Amazon RDS 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/27942833-c294-405c-90e6-32cc197e36ee/images/45ee14e4-3c7e-4b35-a2c9-3e8e3c7e6cee.png)


## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-tools"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 支援多種類型的來源和目標資料庫。如需詳細資訊，請參閱 [AWS DMS Step-by-Step演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)。如果 AWS DMS 不支援來源資料庫，請選取另一個方法來遷移資料。 
+ 原生 Microsoft SQL Server 工具包括備份和還原、複製資料庫精靈、複製和連接資料庫。

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
| 識別目標伺服器執行個體的硬體需求。 |  | DBA，系統管理員 | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA，系統管理員 | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA，系統管理員 | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA，系統管理員 | 
| 識別應用程式遷移策略。 |  | DBA，系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) |  | 系統管理員 | 
| 建立安全群組。 |  | 系統管理員 | 
| 設定和啟動 Amazon RDS 資料庫執行個體。 |  | DBA，系統管理員 | 

### 遷移資料 - 選項 1
<a name="migrate-data---option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生 SQL Server 工具或第三方工具來遷移資料庫物件和資料。 |  | DBA | 

### 遷移資料 - 選項 2
<a name="migrate-data---option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS DMS 遷移資料。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 |  | DBA、應用程式擁有者、系統管理員 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA，系統管理員 | 
| 檢閱並驗證專案文件。 |  | DBA、應用程式擁有者、系統管理員 | 
| 收集指標，例如遷移時間、手動與自動任務的百分比，以及節省成本。 |  | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案並提供意見回饋。 |  | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-resources"></a>

**參考**
+ [在 Amazon Web Services 上部署 Microsoft SQL Server](https://d1.awsstatic.com/whitepapers/RDS/Deploying_SQLServer_on_AWS.pdf) 
+ [AWS DMS 網站](https://aws.amazon.com/dms/)
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)
+ [AWS 上的 Microsoft 產品](https://aws.amazon.com/windows/products/)
+ [AWS 上的 Microsoft 授權](https://aws.amazon.com/windows/resources/licensing/)
+ [AWS 上的 Microsoft SQL Server](https://aws.amazon.com/windows/products/sql/)
+ [搭配 Microsoft SQL Server 資料庫執行個體使用 Windows 身分驗證](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_SQLServerWinAuth.html)
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/)

**教學課程和影片**
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)
+ [AWS DMS （影片）](https://www.youtube.com/watch?v=zb4GcjEdl8U) 
+ [Amazon RDS （影片）](https://www.youtube.com/watch?v=igRfulrrYCo)  

# 使用 Rclone 將資料從 Microsoft Azure Blob 遷移至 Amazon S3
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone"></a>

*Suhas Basavaraj、Acidian Keane 和 Corey Lane，Amazon Web Services*

## 總結
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-summary"></a>

此模式說明如何使用 [Rclone](https://rclone.org/) 將資料從 Microsoft Azure Blob 物件儲存遷移至 Amazon Simple Storage Service (Amazon S3) 儲存貯體。您可以使用此模式來執行一次性遷移或持續同步資料。Rclone 是以 Go 編寫的命令列程式，用於從雲端提供者跨各種儲存技術移動資料。

## 先決條件和限制
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 存放在 Azure Blob 容器服務中的資料

## Architecture
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-architecture"></a>

**來源技術堆疊**
+ Azure Blob 儲存容器

**目標技術堆疊**
+ Amazon S3 儲存貯體
+ Amazon Elastic Compute Cloud (Amazon EC2) Linux 執行個體

**架構**

![\[將資料從 Microsoft Azure 遷移至 Amazon S3\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6ead815d-7768-4726-b27d-97a70cd21081/images/abe69eee-632f-4ca2-abf6-3223f3f3ec94.png)


## 工具
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-tools"></a>
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [Rclone](https://rclone.org/) 是以 **rsync** 為設計來源的開放原始碼命令列程式。它用於管理多個雲端儲存平台的檔案。

## 最佳實務
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-best-practices"></a>

當您將資料從 Azure 遷移至 Amazon S3 時，請注意這些考量，以避免不必要的成本或緩慢的傳輸速度：
+ 在與 Azure 儲存帳戶和 Blob 容器相同的地理區域中建立 AWS 基礎設施，例如 AWS 區域 `us-east-1`（維吉尼亞北部） 和 Azure 區域 `East US`。
+ 如果可能，請避免使用 NAT Gateway，因為它會同時產生輸入和輸出頻寬的資料傳輸費用。
+ 使用 [Amazon S3 的 VPC 閘道端點](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html)來提高效能。
+ 考慮使用 AWS Graviton2 (ARM) 處理器型 EC2 執行個體，相較於 Intel x86 執行個體，成本更低且效能更高。Rclone 是高度跨編譯的，並提供預先編譯的 ARM 二進位檔。

## 史詩
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-epics"></a>

### 準備 AWS 和 Azure 雲端資源
<a name="prepare-aws-and-azure-cloud-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備目的地 S3 儲存貯體。 | 在適當的 AWS 區域中[建立新的 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體，或選擇現有的儲存貯體做為您要遷移資料的目的地。 | AWS 管理員 | 
| 為 Amazon EC2 建立 IAM 執行個體角色。 | [為 Amazon EC2 建立新的 AWS Identity and Access Management (IAM) 角色](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#working-with-iam-roles)。此角色可讓 EC2 執行個體寫入目的地 S3 儲存貯體。 | AWS 管理員 | 
| 將政策連接至 IAM 執行個體角色。 | 使用 IAM 主控台或 AWS Command Line Interface (AWS CLI) 為 EC2 執行個體角色建立內嵌政策，允許對目的地 S3 儲存貯體的寫入存取許可。如需範例政策，請參閱[其他資訊](#migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-additional)一節。 | AWS 管理員 | 
| 啟動 EC2 執行個體。 | 啟動設定為使用新建立 IAM 服務角色的 Amazon Linux EC2 執行個體。此執行個體也需要透過網際網路存取 Azure 公有 API 端點。 請考慮使用 [AWS Graviton 型 EC2 執行個體](https://docs.aws.amazon.com/compute-optimizer/latest/ug/graviton-recommendations.html)來降低成本。Rclone 提供 ARM 編譯的二進位檔。 | AWS 管理員 | 
| 建立 Azure AD 服務主體。 | 使用 Azure CLI 建立對來源 Azure Blob 儲存容器具有唯讀存取權的 Azure Active Directory (Azure AD) 服務主體。如需說明，請參閱[其他資訊](#migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-additional)一節。將這些登入資料存放在您的 EC2 執行個體上至位置 `~/azure-principal.json`。 | 雲端管理員，Azure | 

### 安裝和設定 Rclone
<a name="install-and-configure-rclone"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載並安裝 Rclone。 | 下載並安裝 Rclone 命令列程式。如需安裝說明，請參閱 [Rclone 安裝文件](https://rclone.org/install/)。 | 一般 AWS、雲端管理員 | 
| 設定 Rclone。 | 複製下列`rclone.conf`範例檔案。`AZStorageAccount` 將 取代為您的 Azure Storage 帳戶名稱，並將 `us-east-1`取代為您的 S3 儲存貯體所在的 AWS 區域。將此檔案儲存至 EC2 執行個體`~/.config/rclone/rclone.conf`上的 位置。<pre>[AZStorageAccount]<br />type = azureblob<br />account = AZStorageAccount<br />service_principal_file = azure-principal.json<br /><br />[s3]<br />type = s3<br />provider = AWS<br />env_auth = true<br />region = us-east-1</pre> | 一般 AWS、雲端管理員 | 
| 驗證 Rclone 組態。 | 若要確認 Rclone 已設定且許可正常運作，請確認 Rclone 可以剖析您的組態檔案，以及可存取 Azure Blob 容器和 S3 儲存貯體中的物件。如需驗證命令範例，請參閱下列內容。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone.html) | 一般 AWS、雲端管理員 | 

### 使用 Rclone 遷移資料
<a name="migrate-data-using-rclone"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從容器遷移資料。 | 執行 Rclone [複製](https://rclone.org/commands/rclone_copy/)或[同步](https://rclone.org/commands/rclone_sync/)命令。 **範例：複製**此命令會將來源 Azure Blob 容器的資料複製到目的地 S3 儲存貯體。<pre>rclone copy AZStorageAccount:blob-container s3:amzn-s3-demo-bucket1</pre>**範例：同步**此命令會同步來源 Azure Blob 容器與目的地 S3 儲存貯體之間的資料。 ** **<pre>rclone sync AZStorageAccount:blob-container s3:amzn-s3-demo-bucket1</pre>當您使用**同步**命令時，來源容器中不存在的資料將從目的地 S3 儲存貯體中刪除。 | 一般 AWS、雲端管理員 | 
| 同步您的容器。 | 初始複製完成後，請執行 Rclone **同步**命令以進行持續遷移，以便僅複製目的地 S3 儲存貯體中遺失的新檔案。 | 一般 AWS、雲端管理員 | 
| 確認資料已成功遷移。 | 若要檢查資料是否已成功複製到目的地 S3 儲存貯體，請執行 Rclone [lsd](https://rclone.org/commands/rclone_lsd/) 和 [ls](https://rclone.org/commands/rclone_ls/) 命令。 | 一般 AWS、雲端管理員 | 

## 相關資源
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-resources"></a>
+ [Amazon S3 使用者指南 ](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)(AWS 文件）
+ [Amazon EC2 的 IAM 角色](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) (AWS 文件）
+ [建立 Microsoft Azure Blob 容器](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal) (Microsoft Azure 文件）
+ [Rclone 命令](https://rclone.org/commands/) (Rclone 文件）

## 其他資訊
<a name="migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone-additional"></a>

**EC2 執行個體的角色政策範例**

此政策可讓 EC2 執行個體讀取和寫入存取您帳戶中的特定儲存貯體。如果您的儲存貯體使用客戶受管金鑰進行伺服器端加密，則政策可能需要額外存取 AWS Key Management Service (AWS KMS)。

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:DeleteObject",
                "s3:GetObject",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
              "arn:aws:s3:::amzn-s3-demo-bucket/*",
              "arn:aws:s3:::amzn-s3-demo-bucket"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "arn:aws:s3:::*"
        }    
    ]
}
```

**建立唯讀 Azure AD 服務主體**

Azure 服務主體是客戶應用程式、服務和自動化工具用來存取特定 Azure 資源的安全身分。將其視為具有特定角色的使用者身分 （登入和密碼或憑證），以及存取 資源的嚴格控制許可。若要建立唯讀服務主體以遵循最低權限許可，並保護 Azure 中的資料免於意外刪除，請遵循下列步驟：

1. 登入您的 Microsoft Azure 雲端帳戶入口網站，並在 PowerShell 中啟動 Cloud Shell，或在工作站上使用 Azure Command-Line Interface (CLI)。

1. 建立服務主體，並使用 Azure Blob 儲存體帳戶的[唯讀](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#storage-blob-data-reader)存取權進行設定。將此命令的 JSON 輸出儲存至名為 的本機檔案`azure-principal.json`。檔案將上傳至您的 EC2 執行個體。使用 Azure 訂閱 ID、資源群組名稱和儲存體帳戶名稱取代以括號 (`{` 和 `}`) 顯示的預留位置變數。

   ```
   az ad sp create-for-rbac `
   --name AWS-Rclone-Reader `
   --role "Storage Blob Data Reader" `
   --scopes /subscriptions/{Subscription ID}/resourceGroups/{Resource Group Name}/providers/Microsoft.Storage/storageAccounts/{Storage Account Name}
   ```

# 從 Couchbase Server 遷移至 AWS 上的 Couchbase Capella
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws"></a>

*Battulga Purevragchaa 和 Saurabh Shanbhag，Amazon Web Services*

*Mark Gamble，無*

## 總結
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-summary"></a>

Couchbase Capella 是完全受管的 NoSQL 資料庫即服務 (DBaaS)，適用於關鍵任務應用程式 （例如，使用者設定檔或線上目錄和庫存管理）。Couchbase Capella 會在 Couchbase 管理的 Amazon Web Services (AWS) 帳戶中管理您的 DBaaS 工作負載。Capella 可讓您在單一界面中輕鬆執行和管理多叢集、多 AWS 區域、多雲端和混合雲端複寫。

Couchbase Capella 可協助您立即擴展 Couchbase Server 應用程式，協助您在幾分鐘內建立多節點叢集。Couchbase Capella 支援所有 Couchbase Server 功能，包括[SQL\$1\$1](https://www.couchbase.com/products/n1ql)、[全文搜尋](https://www.couchbase.com/products/full-text-search)、[事件服務和](https://docs.couchbase.com/server/current/eventing/eventing-overview.html)[分析服務](https://www.couchbase.com/products/analytics)。它也不需要管理安裝、升級、備份和一般資料庫維護。 

此模式說明將自我管理 [Couchbase Server](https://www.couchbase.com/products/server) 環境遷移至 AWS 雲端的步驟和最佳實務。模式提供可重複的程序，將資料和索引從內部部署或雲端執行的 Couchbase Server 叢集遷移至 Couchbase Capella。使用這些步驟可協助您避免在遷移期間發生問題，並加速整體遷移程序。

此模式提供下列兩個遷移選項：
+ 如果您的遷移索引少於 50 個，**則選項 1** 是適當的。 
+ 如果您有超過 50 個要遷移的索引，**則選項 2** 是適當的。 

您也可以在自我管理的 Couchbase 伺服器上[設定範例資料](https://docs.couchbase.com/server/current/manage/manage-settings/install-sample-buckets.html)，以遵循遷移指南。

如果您選擇遷移**選項 2**，或者您使用的是預設值以外的範圍或集合，則必須使用範例組態檔案，其位於*其他資訊*區段中。

## 先決條件和限制
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-prereqs"></a>

**先決條件**
+ 現有的 Couchbase Capella 付費帳戶。您也可以在 [AWS 上建立 Couchbase Capella 帳戶](https://aws.amazon.com/marketplace/pp/prodview-xrhx5zgue5c26)，並使用 Couchbase Capella 免費試用版，然後升級到付費帳戶來設定叢集以進行遷移。若要開始使用試用版，請遵循 [Couchbase Capella 入門](https://docs.couchbase.com/cloud/get-started/create-account.html)中的指示。
+ 在內部部署或部署在雲端服務提供者上的現有自我管理 Couchbase Server 環境。 
+ 對於遷移選項 2、Couchbase Shell 和組態檔案。若要建立組態檔案，您可以使用*其他資訊*區段中的範例檔案。
+ 熟悉管理 Couchbase Server 和 Couchbase Capella。
+ 熟悉在命令列界面 (CLI) 中開啟 TCP 連接埠和執行命令。

遷移程序也需要下表所述的角色和專業知識。


| 
| 
| Role | 專業知識 | 責任 | 
| --- |--- |--- |
| Couchbase 管理員 | 熟悉 Couchbase Server 和 Couchbase Capella基本命令列知識很有幫助，但並非必要 | Couchbase Server 和 Capella 特定任務 | 
| 系統管理員、IT 管理員 | 熟悉自我管理的 Couchbase Server 系統環境和管理 | 在自我管理的 Couchbase Server 叢集節點上開啟連接埠並判斷 IP 地址 | 

 

**限制**
+ 此模式用於將資料、索引和 [Couchbase 全文搜尋](https://docs.couchbase.com/server/current/fts/full-text-intro.html)索引從 Couchbase 伺服器遷移至 AWS 上的 Couchbase Capella。此模式不適用於遷移 [Couchbase Eventing Service](https://docs.couchbase.com/server/current/eventing/eventing-overview.html) 或 [Couchbase Analytics](https://docs.couchbase.com/server/current/analytics/introduction.html)。
+ Couchbase Capella 可在多個 AWS 區域中使用。如需 Capella 支援區域up-to-date，請參閱 Couchbase 文件中的 [Amazon Web Services](https://docs.couchbase.com/cloud/reference/aws.html)。

**產品版本**
+ [Couchbase Server (Community 或 Enterprise) Edition 5.x 版或更新版本](https://docs.couchbase.com/server/current/release-notes/relnotes.html)

## Architecture
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-architecture"></a>

**來源技術堆疊**
+ Couchbase 伺服器

**目標技術堆疊**
+ Couchbase Capella

**目標架構**

![\[Couchbase Capella 會以四個步驟遷移至 AWS 上 Capella 資料平面中的 Couchbase 叢集。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/14ac5a81-eade-4708-9335-f5602fa07824/images/95cd7f33-742e-4d10-8e2c-37c7b4d9df45.png)


1. 您可以使用 Capella **控制平面存取 Couchbase Capella**。您可以使用 Capella 控制平面來執行下列動作：
   + 控制和監控您的帳戶。
   + 管理叢集和資料、索引、使用者和群組、存取許可、監控和事件。

1. 叢集已建立。

1. **Capella Data Plane** 位於 Couchbase 管理的 AWS 帳戶中。建立新叢集之後，Couchbase Capella 會將叢集部署到所選 AWS 區域中的多個可用區域。

1. 您可以在 AWS 帳戶中的 VPC 中開發和部署 Couchbase 應用程式。一般而言，此 VPC 會透過 [VPC 對等](https://docs.couchbase.com/cloud/clouds/private-network.html)互連存取 Capella 資料平面。

## 工具
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-tools"></a>
+ [Couchbase 跨資料中心複寫 (XDCR)](https://docs.couchbase.com/cloud/current/clusters/xdcr/xdcr.html) 有助於跨位於不同雲端提供者和不同資料中心的叢集複寫資料。它用於將資料從自我管理的 Couchbase Server 叢集遷移到 Couchbase Capella。
**注意**  
XDCR 無法與 Couchbase Server Community Edition 搭配使用，以遷移至 Couchbase Capella。反之，您可以使用 [cbexport](https://docs.couchbase.com/server/current/tools/cbexport.html)。如需詳細資訊，請參閱*從 Community Edition Epic 遷移資料*。
+ [Couchbase Shell](https://couchbase.sh/docs/) 是 Couchbase Server 和 Couchbase Capella 存取本機和遠端 Couchbase 叢集的命令列 Shell。在此模式中，Couchbase Shell 用於遷移索引。
+ [cbexport](https://docs.couchbase.com/server/current/tools/cbexport.html) 是用於從 Couchbase 叢集匯出資料的 Couchbase 公用程式。包含在 [Couchbase Server CLI 工具](https://docs.couchbase.com/server/current/cli/cli-intro.html)中。

## 史詩
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-epics"></a>

### 準備遷移
<a name="prepare-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 評估自我管理 Couchbase Server 叢集的大小。 | 登入 [Couchbase Server 的 Couchbase Web 主控台](https://docs.couchbase.com/server/current/manage/manage-ui/manage-ui.html)，並評估自我管理叢集的節點和儲存貯體。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html)您將使用自我管理的 Couchbase Server 叢集組態作為在 Couchbase Capella 上調整和設定目標叢集的一般指南。如需更詳細 Couchbase Capella 大小練習的說明，[請聯絡 Couchbase](https://www.couchbase.com/contact)。 | Couchbase 管理員 | 
| 在自我管理的 Couchbase Server 叢集上記錄 Couchbase Service 分佈。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 
| 記錄自我管理 Couchbase Server 叢集節點的 IP 地址。 | （如果您使用的是 Community Edition，請忽略此步驟。) 記錄叢集中每個節點的 IP 地址。它們稍後會新增至 Couchbase Capella 叢集上的允許清單。 | Couchbase 管理員、系統管理員 | 

### 在 Couchbase Capella 上部署和設定資源
<a name="deploy-and-configure-resources-on-couchbase-capella"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇一個範本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 
| 選擇並設定節點。 | 選擇並設定節點以符合自我管理的 Couchbase Server 叢集環境，包括節點數量、服務分佈、運算或 RAM，以及儲存體。Couchbase Capella 使用[多維度擴展](https://docs.couchbase.com/cloud/clusters/scale-cluster.html#scale-a-cluster)最佳實務。只能根據部署最佳實務來選擇服務和節點。這可能表示您無法完全符合自我管理的 Couchbase Server 叢集組態。 | Couchbase 管理員 | 
| 部署叢集。 | 選擇支援區域和支援套件，然後部署叢集。如需詳細步驟和說明，請參閱 Couchbase 文件中的[建立叢集](https://docs.couchbase.com/cloud/clusters/create-cluster.html)。如果您使用的是 Couchbase Capella 免費試用，您必須在開始遷移之前將其轉換為付費帳戶。若要轉換您的帳戶，請開啟 Couchbase Capella 控制平面的**帳單**區段，然後選擇**新增啟用 ID**。在您與 Couchbase Sales 完成購買協議後，或透過 [AWS Marketplace](https://aws.amazon.com/marketplace/pp/prodview-xrhx5zgue5c26) 進行購買後，啟用 ID 會傳送到您的帳單聯絡人電子郵件地址。 | Couchbase 管理員 | 
| 建立資料庫登入資料使用者。 | 資料庫登入資料使用者專屬於叢集，由使用者名稱、密碼和一組儲存貯體權限組成。建立儲存貯體和存取儲存貯體資料時，需要此使用者。 在 Couchbase Capella 控制平面中，遵循 Couchbase Capella 文件中的[設定資料庫憑證中的指示，為新叢集建立資料庫憑證](https://docs.couchbase.com/cloud/clusters/manage-database-users.html)。如果組織使用者想要從遠端或透過 Couchbase Capella UI 存取特定叢集上的儲存貯體資料，則需要指派給他們的組織角色憑證。這與資料庫登入資料不同，通常由應用程式和整合使用。建立組織使用者可讓您在 Couchbase Capella 叢集上建立和管理目標儲存貯體。 | Couchbase 管理員 | 
| 如果使用遷移選項 2，請安裝 Couchbase Shell。 | 您可以在可存取自我管理 Couchbase Server 和 Couchbase Capella 叢集的任何系統上安裝 Couchbase Shell。如需詳細資訊，請參閱 [Couchbase Shell 文件中的Install Couchbase Shell 1.0.0-beta.5 版](https://couchbase.sh/docs/#_installation)。在命令列終端機中[測試與自我管理叢集的連線，](https://couchbase.sh/docs/#_connecting_to_a_cluster)以確認已安裝 Couchbase Shell。 | Couchbase 管理員、系統管理員 | 
| 允許 IP 地址。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html)如需允許 IP 地址的詳細資訊，請參閱 Couchbase 文件中的[設定允許的 IP 地址](https://docs.couchbase.com/cloud/get-started/configure-cluster-access.html#allow-ip-address)。 | Couchbase 管理員、系統管理員 | 
| 設定憑證。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員、系統管理員 | 
| 建立 Couchbase Shell 的組態檔案。 | 在 Couchbase Shell 安裝的主目錄中建立組態點檔案 （例如，`/<HOME_DIRECTORY>/.cbsh/config`)。如需詳細資訊，請參閱 Couchbase 文件中的[Config dotfiles](https://couchbase.sh/docs/#_the_config_dotfiles)。將來源和目標叢集的連線屬性新增至組態檔案。您可以使用*其他資訊*區段中的範例組態檔案，並編輯叢集的設定。 將具有更新設定的組態檔案儲存至 `.cbsh` 資料夾 （例如，`/<HOME_DIRECTORY>/.cbsh/config`)。 | Couchbase 管理員、系統管理員 | 
| 建立目標儲存貯體。 | 對於每個來源儲存貯體，請遵循 Couchbase 文件中的[建立儲存貯體中的指示，在 Couchbase Capella 叢集中建立一個目標儲存貯體](https://docs.couchbase.com/cloud/clusters/data-service/manage-buckets.html#add-bucket)。您的目標儲存貯體組態必須符合自我管理 Couchbase Server 叢集中儲存貯體的儲存貯體名稱、記憶體設定和衝突解決設定。 | Couchbase 管理員 | 
| 建立範圍和集合。 | 每個儲存貯體都包含具有 金鑰空間 的預設範圍和集合`_default._default`。如果您針對範圍和集合使用任何其他金鑰空間，您必須在目標 Capella 叢集中建立相同的金鑰空間。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html)<pre>scopes --clusters "On-Prem-Cluster" --bucket <BUCKET_NAME> | select scope | where scope != "_default" | each { |it| scopes create $it.scope --clusters "Capella-Cluster" }<br />collections --clusters "On-Prem-Cluster" --bucket <BUCKET_NAME> | select scope collection | where $it.scope != "_default" | where $it.collection != "_default" | each { |it| collections create $it.collection --clusters "Capella-Cluster" --bucket <BUCKET_NAME> --scope $it.scope }</pre> | Couchbase 管理員 | 

### 從 Enterprise Edition 遷移資料
<a name="migrate-the-data-from-enterprise-edition"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在自我管理的 Couchbase Server 叢集節點上開啟 TCP 連接埠。 | 確定在自我管理的 Couchbase Server 叢集節點上開啟 XDCR 通訊的適當連接埠。如需詳細資訊，請參閱 [Couchbase Server 連接埠文件](https://docs.couchbase.com/server/current/install/install-ports.html#ports-listed-by-communication-path)。 | Couchbase 管理員、系統管理員 | 
| 如果您使用的是 Couchbase Server Enterprise Edition，請設定 Couchbase XDCR。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 
| 啟動 Couchbase XDCR。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 

### 使用選項 1 遷移索引
<a name="migrate-the-indexes-by-using-option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將自我管理叢集索引遷移至 Couchbase Capella。 | 如果您有少於 50 個要遷移的索引，建議您執行此程序。如果您有超過 50 個要遷移的索引，建議您使用遷移選項 2。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員、系統管理員 | 

### 使用選項 2 遷移索引
<a name="migrate-the-indexes-by-using-option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遷移索引定義。 | 如果您有超過 50 個要遷移的索引，建議您執行此程序。如果您的遷移索引少於 50 個，建議您使用遷移選項 1。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員、系統管理員 | 
| 建置索引定義。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員、系統管理員 | 

### 遷移全文搜尋索引
<a name="migrate-full-text-search-indexes"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將自我管理叢集全文搜尋索引遷移至 Couchbase Capella。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 

### 從 Couchbase Community Edition 遷移資料
<a name="migrate-data-from-couchbase-community-edition"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從自我管理的 Couchbase Server Community Edition 匯出資料。 | Couchbase Community Edition 不提供加密的 XDCR。您可以從 Couchbase Community Edition 匯出資料，然後將資料手動匯入 Couchbase Capella。若要從來源儲存貯體匯出資料，`cbexport`請在命令列使用 。以下命令提供為範例。<pre>cbexport json \<br />--cluster localhost \<br />--bucket <SOURCE BUCKET NAME> \<br />--format lines \<br />--username <USERNAME> \<br />--password <PASSWORD> \<br />--include-key cbkey \<br />--scope-field cbscope \<br />--collection-field cbcoll \<br />--output cbexported_data.json</pre>請注意，`cbkey`、`cbcoll`、 `cbscope`和 `cbexported_data.json`是任意標籤。稍後會在程序中參考它們，因此如果您選擇以不同的方式命名它們，請記下來。 | Couchbase 管理員 | 
| 將資料匯入 Couchbase Capella。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html)對於大型檔案，Couchbase Capella 支援使用 cURL 匯入命令列。您可以在 Couchbase Capella 文件的匯入[資料中更詳細地探索匯入](https://docs.couchbase.com/cloud/clusters/data-service/import-data-documents.html)選項。 | Couchbase 管理員 | 

### 測試並驗證遷移
<a name="test-and-verify-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料遷移。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 
| 驗證索引遷移。 | 在 Couchbase Capella 控制平面中，在目標叢集**的工具**下拉式清單中，選擇**索引**。確認索引已遷移並建置。 | Couchbase 管理員 | 
| 驗證查詢結果。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 
| 驗證全文搜尋結果 （如果您遷移 FTS 索引，則適用）。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-couchbase-server-to-couchbase-capella-on-aws.html) | Couchbase 管理員 | 

## 相關資源
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-resources"></a>

**準備遷移**
+ [開始使用 Couchbase Capella 免費試用](https://cloud.couchbase.com/sign-up)
+ [Couchbase Capella 的雲端供應商需求](https://docs.couchbase.com/cloud/reference/aws.html)
+ [Couchbase Capella 調整大小準則](https://docs.couchbase.com/cloud/clusters/sizing.html)

**遷移資料和索引**
+ [Couchbase XDCR](https://docs.couchbase.com/cloud/clusters/xdcr/xdcr.html)
+ [Couchbase Shell 文件](https://couchbase.sh/docs/)

**Couchbase Capella SLAs 和支援**
+ [Couchbase Capella 服務層級協議 (SLAs](https://www.couchbase.com/capellasla))
+ [Couchbase Capella Service 支援政策](https://www.couchbase.com/support-policy/cloud)

## 其他資訊
<a name="migrate-from-couchbase-server-to-couchbase-capella-on-aws-additional"></a>

下列程式碼是 [Couchbase Shell 的範例組態檔案](https://couchbase.sh/docs/#_the_config_dotfiles)。 

```
Version = 1
 
[[clusters]]
identifier = "On-Prem-Cluster"
hostnames = ["<SELF_MANAGED_COUCHBASE_CLUSTER>"]
default-bucket = "travel-sample"
username = "<SELF_MANAGED_ADMIN>"
password = "<SELF_MANAGED_ADMIN_PWD>"
tls-cert-path = "/<ABSOLUTE_PATH_TO_SELF_MANAGED_ROOT_CERT>"
data-timeout = "2500ms"
connect-timeout = "7500ms"
query-timeout = "75s"
 
[[clusters]]
identifier = "Capella-Cluster"
hostnames = ["<COUCHBASE_CAPELLA_ENDPOINT>"]
default-bucket = "travel-sample"
username = "<CAPELLA_DATABASE_USER>"
password = "<CAPELLA_DATABASE_USER_PWD>"
tls-cert-path = "/<ABSOLUTE_PATH_TO_COUCHBASE_CAPELLA_ROOT_CERT>"
data-timeout = "2500ms"
connect-timeout = "7500ms"
query-timeout = "75s"
```

儲存組態檔案之前，請使用下表來確保您已新增自己的來源和目標叢集資訊。

 


|  |  | 
| --- |--- |
| <SELF\$1MANAGED\$1COUCHBASE\$1CLUSTER> | 使用自我管理 Couchbase Server 叢集的 IP 地址。 | 
| <SELF\$1MANAGED\$1ADMIN> | 將管理員使用者用於自我管理的 Couchbase Server 叢集。 | 
| <ABSOLUTE\$1PATH\$1TO\$1SELF\$1MANAGED\$1ROOT\$1CERT> | 針對自我管理的 Couchbase Server 叢集，使用儲存根憑證檔案的絕對路徑。 | 
| <COUCHBASE\$1CAPELLA\$1ENDPOINT> | 使用 Couchbase Capella 叢集的連線端點。 | 
| <CAPELLA\$1DATABASE\$1USER> | 為您的 Couchbase Capella 叢集使用資料庫使用者。 | 
| <CAPELLA\$1DATABASE\$1USER\$1PWD> | 為您的 Couchbase Capella 叢集使用資料庫使用者密碼。 | 
| <ABSOLUTE\$1PATH\$1TO\$1COUCHBASE\$1CAPELLA\$1ROOT\$1CERT> | 為您的 Couchbase Capella 叢集使用儲存根憑證檔案的絕對路徑。 | 

# 從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2"></a>

*Neal Ardeljan 和 Afroz Khan，Amazon Web Services*

## 總結
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-summary"></a>

此模式會逐步引導您從執行 IBM WebSphere 應用程式伺服器 (WAS) 的內部部署 Red Hat Enterprise Linux (RHEL) 6.9 或更新版本系統遷移至在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行 Apache Tomcat 的 RHEL 8。 

模式可套用至下列來源和目標版本： 
+ WebSphere Application Server 7.x 到 Apache Tomcat 8 （使用 Java 7 或更新版本） 
+ WebSphere Application Server 8.x 到 Apache Tomcat 8 （使用 Java 7 或更新版本） 
+ WebSphere Application Server 8.5.5.x 到 Apache Tomcat 9 （使用 Java 8 或更新版本） 
+ WebSphere Application Server 8.5.5.x 到 Apache Tomcat 10 （使用 Java 8 或更新版本） 

## 先決條件和限制
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-prereqs"></a>

**先決條件******
+ 作用中的 AWS 帳戶 
+ 來源 Java 程式碼，假設如下：
  + 使用 Java 開發套件 (JDK) 版的 Java 7 或更新版本 
  + 使用 Spring 或 Apache Struts 架構 
  + 未使用 Enterprise Java Beans (EJB) 架構或任何其他無法立即提供給 Tomcat 的 WebSphere 伺服器功能
  + 主要使用 servlet 或 Java 伺服器頁面 (JSPs) 
  + 使用 Java Database Connectivity (JDBC) 連接器連接到資料庫  
+ 來源 IBM WebSphere Application Server 7.x 版或更新版本 
+ 目標 Apache Tomcat 8.5 版或更新版本  

## Architecture
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-architecture"></a>

******Source 技術堆疊**
+ 使用 Apache Struts Model-View-Controller (MVC) 架構建置的 Web 應用程式 
+ 在 IBM WebSphere Application Server 7.x 或 8.x 版上執行的 Web 應用程式
+ 使用輕量型目錄存取通訊協定 (LDAP) 連接器連線至 LDAP 目錄 (iPlanet/eTrust) 的 Web 應用程式 
+ 使用 IBM Tivoli Access Manager (TAM) 連線更新 TAM 使用者密碼的應用程式 （目前實作中，應用程式使用 PD.jar)

******內部部署資料庫**
+ Oracle Database 21c (21.0.0.0)
+ Oracle 資料庫 19c (19.0.0.0)
+ Oracle 資料庫 12c 版本 2 (12.2.0.1)
+ Oracle 資料庫 12c 版本 1 (12.1.0.2)

**目標技術堆疊**
+ 在 EC2 執行個體上的 RHEL 上執行的 Apache Tomcat 第 8 版 （或更新版本）
+ 適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS)

如需 Amazon RDS 支援的 Oracle 版本的詳細資訊，請參閱 [Amazon RDS for Oracle](https://aws.amazon.com/rds/oracle/) 網站。

**目標架構**

![\[從 IBM WebSphere 遷移到 Amazon EC2 上 Apache Tomcat 的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/96f91201-e0a6-4d3f-a94e-7bd68a59cc4e/images/11afe7c0-b400-423b-9dfe-02a915fe47ff.png)


## 工具
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-tools"></a>
+ 應用程式層：將 Java 應用程式重建為 WAR 檔案。
+ 資料庫層：Oracle 原生備份和還原。
+ 雅加達 EE 的 Apache Tomcat 遷移工具。此工具採用針對在 Apache Tomcat 9 上執行的 Java EE 8 撰寫的 Web 應用程式，並自動將其轉換為在實作雅加達 EE 9 的 Apache Tomcat 10 上執行。

## 史詩
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 完成應用程式探索、目前狀態足跡和效能基準。 |  | BA，遷移主管 | 
| 驗證來源和目標資料庫版本。 |  | DBA | 
| 識別目標伺服器 EC2 執行個體的硬體需求。 |  | DBA、SysAdmin | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA、SysAdmin | 
| 根據容量、儲存功能和網路功能，選擇適當的 EC2 執行個體類型。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA、SysAdmin | 
| 識別應用程式遷移策略和工具。 |  | DBA，遷移主管 | 
| 完成應用程式的遷移設計和遷移指南。 |  | 組建主管、遷移主管 | 
| 完成應用程式遷移 Runbook。 |  | 組建主管、切換主管、測試主管、遷移主管 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) |  | SysAdmin | 
| 建立安全群組。 |  | SysAdmin | 
| 設定和啟動 Amazon RDS for Oracle。 |  | DBA、SysAdmin | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立或取得端點的存取權，以擷取資料庫備份檔案。 |  | DBA | 
| 使用原生資料庫引擎或第三方工具來遷移資料庫物件和資料。 | 如需詳細資訊，請參閱*其他資訊*區段中的「遷移資料庫物件和資料」。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 記錄遷移的變更請求 (CR)。 |  | 切換潛在客戶 | 
| 取得遷移的 CR 核准。 |  | 切換潛在客戶 | 
| 遵循應用程式遷移執行手冊中的應用程式遷移策略。 | 如需詳細資訊，請參閱*其他資訊*區段中的「設定應用程式層」。 | DBA、遷移工程師、應用程式擁有者 | 
| 升級應用程式 （如有必要）。 |  | DBA、遷移工程師、應用程式擁有者 | 
| 完成功能、非功能、資料驗證、SLA 和效能測試。 |  | 測試主管、應用程式擁有者、應用程式使用者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 向應用程式擁有者或企業擁有者取得簽署。 |  | 切換潛在客戶 | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、遷移工程師、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA、遷移工程師、SysAdmin | 
| 檢閱並驗證專案文件。 |  | 遷移主管 | 
| 收集指標，例如遷移時間、手動與自動任務的百分比，以及節省成本。 |  | 遷移主管 | 
| 關閉專案並提供意見回饋。 |  | 遷移主管，應用程式擁有者 | 

## 相關資源
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-resources"></a>

**參考**
+ [Apache Tomcat 10.0 文件](https://tomcat.apache.org/tomcat-10.0-doc/index.html)
+ [Apache Tomcat 9.0 文件](https://tomcat.apache.org/tomcat-9.0-doc/index.html)
+ [Apache Tomcat 8.0 文件](https://tomcat.apache.org/tomcat-8.0-doc)
+ [Apache Tomcat 8.0 安裝指南](https://tomcat.apache.org/tomcat-8.0-doc/setup.html)
+ [Apache Tomcat JNDI 文件](https://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html)
+ [Amazon RDS for Oracle 網站](https://aws.amazon.com/rds/oracle/) 
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/) 
+ [Oracle 和 Amazon Web Services](https://aws.amazon.com/oracle/) 
+ [Amazon RDS 上的 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/) 

**教學課程和影片**
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/) 

## 其他資訊
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-additional"></a>

**遷移資料庫物件和資料**

例如，如果您使用的是原生 Oracle 備份/還原公用程式：

1. 建立資料庫備份檔案的 Amazon Simple Storage Service (Amazon S3) 備份 （選用）。

1. 將 Oracle 資料庫資料備份至網路共用資料夾。

1. 登入遷移預備伺服器以映射網路共用資料夾。

1. 將資料從網路共用資料夾複製到 S3 儲存貯體。

1. 請求 Oracle 的 Amazon RDS 異地同步備份部署。

1. 將內部部署資料庫備份還原至 Amazon RDS for Oracle。

**設定應用程式層**

1. 從 Apache Tomcat 網站安裝 Tomcat 8 （或 9/10)。

1. 將應用程式和共用程式庫封裝到 WAR 檔案中。

1. 在 Tomcat 中部署 WAR 檔案。

1. 監控 WebSphere `Linux cat`中任何遺失共用程式庫的啟動日誌。

1. 觀看`Linux cat`任何 WebSphere 特定部署描述項延伸項目的開始記錄。

1. 從 WebSphere 伺服器收集任何缺少的相依 Java 程式庫。

1. 使用 Tomcat 相容對等項目修改 WebSphere 特定部署描述項元素。

1. 使用相依的 Java 程式庫和更新的部署描述項重建 WAR 檔案。

1. 更新 LDAP 組態、資料庫組態和測試連線 （請參閱 Apache Tomcat 文件中的[Realm Configuration How-TO](https://tomcat.apache.org/tomcat-8.0-doc/realm-howto.html)and[JNDI Datasource HOW-TO](https://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html))。

1. 根據還原的 Amazon RDS for Oracle 資料庫測試已安裝的應用程式。

1. 從 EC2 執行個體建立 Linux 的 Amazon Machine Image (AMI)。

1. 使用 Application Load Balancer 和 Auto Scaling 群組啟動完成的架構。

1. 更新 URLs（使用 WebSEAL 連接） 以指向 Application Load Balancer。

1. 更新組態管理資料庫 (CMDB)。

# 使用 Auto Scaling 從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling"></a>

*Kevin Yung 和 Afroz Khan，Amazon Web Services*

## 總結
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling-summary"></a>

此模式提供在啟用 Amazon EC2 Auto Scaling 的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上，將 Java 應用程式從 IBM WebSphere Application Server 遷移至 Apache Tomcat 的指引。 Amazon EC2 Auto Scaling  

透過使用此模式，您可以實現：
+ 降低 IBM 授權成本
+ 使用異地同步備份部署的高可用性
+ 使用 Amazon EC2 Auto Scaling 改善應用程式彈性

## 先決條件和限制
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling-prerequisites-and-limitations"></a>

**先決條件**
+ Java 應用程式 (7.*x* 或 8.*x* 版） 應該在 LAMP 堆疊中開發。
+ 目標狀態是在 Linux 主機上託管 Java 應用程式。此模式已成功在 Red Hat Enterprise Linux (RHEL) 7 環境中實作。其他 Linux 發行版本可以遵循此模式，但應該參考 Apache Tomcat 發行版本的組態。
+ 您應該了解 Java 應用程式的相依性。
+ 您必須有權存取 Java 應用程式原始碼才能進行變更。

**限制和修改變更**
+ 您應該了解企業封存 (EAR) 元件，並確認所有程式庫都封裝在 Web 元件 WAR 檔案中。您需要設定 [Apache Maven WAR 外掛程式](https://maven.apache.org/plugins/maven-war-plugin/)並產生 WAR 檔案成品。
+ 使用 Apache Tomcat 8 時，servlet-api.jar 和應用程式套件內建 jar 檔案之間存在已知衝突。若要解決此問題，請從應用程式套件中刪除 servlet-api.jar。
+ 您必須設定位於 [Apache Tomcat 組態](https://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html) *classpath* 中的 WEB-INF/resources。根據預設，JAR 程式庫不會載入 目錄中。或者，您可以在 src/main/resources 下部署所有資源*。*
+ 檢查 Java 應用程式中的任何硬式編碼內容根目錄，並更新 [Apache Tomcat 的新內容根目錄。](https://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Defining_a_context)
+ 若要設定 JVM 執行期選項，您可以在 Apache Tomcat bin 資料夾中建立組態檔案 setenv.sh，例如 JAVA\$1OPTS、JAVA\$1HOME ****等。 
+ 驗證是在容器層級設定，並在 Apache Tomcat 組態中設定為領域。會為下列三個領域中的任何一個建立身分驗證： 
  + [JDBC Database Realm](https://tomcat.apache.org/tomcat-8.0-doc/config/realm.html#JDBC_Database_Realm_-_org.apache.catalina.realm.JDBCRealm) 會在 JDBC 驅動程式存取的關聯式資料庫中查詢使用者。
  + [DataSource Database Realm](https://tomcat.apache.org/tomcat-8.0-doc/config/realm.html#DataSource_Database_Realm_-_org.apache.catalina.realm.DataSourceRealm) 會在 JNDI 存取的資料庫中查詢使用者。
  + [JNDI Directory Realm](https://tomcat.apache.org/tomcat-8.0-doc/config/realm.html#JNDI_Directory_Realm_-_org.apache.catalina.realm.JNDIRealm) 會在由 JNDI 供應商存取的輕量型目錄存取通訊協定 (LDAP) 目錄中查詢使用者。查詢需要： 
    + LDAP 連線詳細資訊：使用者搜尋基礎、搜尋篩選條件、角色基礎、角色篩選條件 
    + 金鑰 JNDI Directory Realm：連線至 LDAP、驗證使用者，以及擷取使用者為成員的所有群組
+ 授權：如果容器具有檢查 web.xml 中授權限制的角色型授權，則必須定義 Web 資源，並與限制中定義的角色進行比較。如果 LDAP 沒有群組角色映射，您必須在 web.xml 中設定屬性 <security-role-ref>，以實現群組角色映射。若要查看組態文件的範例，請參閱 [Oracle 文件](https://docs.oracle.com/cd/E19226-01/820-7627/bncav/index.html)。 
+ 資料庫連線：使用 Amazon Relational Database Service (Amazon RDS) 端點 URL 和連線詳細資訊，在 Apache Tomcat 中建立資源定義。使用 JNDI 查詢更新應用程式碼以參考 DataSource。在 WebSphere 中定義的現有資料庫連線無法運作，因為它使用 WebSphere 的 JNDI 名稱。您可以使用 JNDI 名稱和 DataSource 類型定義，在 web.xml 中新增 <resource-ref> 項目。若要查看範例組態文件，請參閱 [Apache Tomcat 文件](https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#JDBC_Data_Sources)。
+ 記錄：根據預設，Apache Tomcat 會記錄到主控台或日誌檔案。您可以更新 *logging.properties 來啟用領域層級追蹤 *（請參閱 [Tomcat 中的記錄](https://tomcat.apache.org/tomcat-8.0-doc/logging.html))。如果您使用 Apache Log4j 將日誌附加至檔案，則必須下載 tomcat-juli 並將其新增至 *classpath*。
+ 工作階段管理：如果您為應用程式負載平衡和工作階段管理保留 IBM WebSEAL，則不需要變更。如果您使用 Application Load Balancer 或 AWS 上的 Network Load Balancer 取代 IBM WebSEAL 元件，則必須使用 Amazon ElastiCache 執行個體搭配 Memcached 叢集來設定工作階段管理，並將 Apache Tomcat 設定為使用[開放原始碼工作階段管理](https://github.com/magro/memcached-session-manager)。 
+ 如果您使用 IBM WebSEAL 轉送代理，您必須在 AWS 上設定新的 Network Load Balancer。使用 Network Load Balancer for WebSEAL 連接組態提供的 IPs。
+ SSL 組態：我們建議您使用 Secure Sockets Layer (SSL) end-to-end通訊。若要在 Apache Tomcat 中設定 SSL 伺服器組態，請遵循 [Apache Tomcat 文件](https://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html)中的指示。 

## Architecture
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling-architecture"></a>

**來源技術堆疊**
+ IBM WebSphere 應用程式伺服器

 

**目標技術堆疊**
+ 架構使用 [Elastic Load Balancing （第 2 版](https://docs.aws.amazon.com/elasticloadbalancing/))。如果您使用 IBM WebSEAL 來識別管理和負載平衡，您可以在 AWS 上選取要與 IBM WebSEAL 反向代理整合的 Network Load Balancer。
+ Java 應用程式會部署到 Apache Tomcat 應用程式伺服器，該伺服器在 Amazon EC2 Auto Scaling 群組中的 EC2 執行個體上執行。 [Amazon EC2 Auto Scaling ](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html) 您可以根據 Amazon CloudWatch 指標設定[擴展政策](https://docs.aws.amazon.com/autoscaling/ec2/userguide/scaling_plan.html)，例如 CPU 使用率。 
+ 如果您要淘汰使用 IBM WebSEAL 進行負載平衡，您可以使用 [Amazon ElastiCache for Memcached](https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/WhatIs.html) 進行工作階段管理。
+ 對於後端資料庫，您可以[為 Amazon RDS 部署高可用性 （多可用區）](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZ.html)，然後選取資料庫引擎類型。

 

**目標架構**

![\[AWS 雲端 architecture with VPC, two availability zones, load balancer, and database components.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/52b91dab-7b3b-4751-abe2-25e7c7cd8d89/images/25125023-9a81-452a-9ada-184e2416cc02.png)


## 工具
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling-tools"></a>
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [AWS 命令列界面 (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
+ Apache Tomcat (7.*x* 或 8.*x* 版）
+ RHEL 7 或 Centos 7
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/)
+ [Amazon ElastiCache for Memcached](https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/WhatIs.html) （選用）

## 史詩
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling-epics"></a>

### 設定 VPC
<a name="set-up-the-vpc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) |  |  | 
| 建立子網路。 |  |  | 
| 視需要建立路由表。 |  |  | 
| 建立網路存取控制清單 ACLs)。 |  |  | 
| 設定 AWS Direct Connect 或企業 VPN 連線。 |  |  | 

### 複寫應用程式
<a name="replatform-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 重構應用程式建置 Maven 組態以產生 WAR 成品。 |  |  | 
| 重構 Apache Tomcat 中的應用程式相依性資料來源。 |  |  | 
| 重構應用程式原始碼，以在 Apache Tomcat 中使用 JNDI 名稱。 |  |  | 
| 將 WAR 成品部署至 Apache Tomcat。 |  |  | 
| 完成應用程式驗證和測試。 |  |  | 

### 設定網路
<a name="configure-the-network"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定公司防火牆以允許連線至相依性服務。 |  |  | 
| 設定公司防火牆以允許最終使用者存取 AWS 上的 Elastic Load Balancing。 |  |  | 

### 建立應用程式基礎設施
<a name="create-the-application-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 EC2 執行個體上建立和部署應用程式。 |  |  | 
| 建立 Amazon ElastiCache for Memcached 叢集以進行工作階段管理。 |  |  | 
| 為後端資料庫建立 Amazon RDS Multi-AZ 執行個體。 |  |  | 
| 建立 SSL 憑證並將其匯入 AWS Certificate Manager (ACM)。 |  |  | 
| 在負載平衡器上安裝 SSL 憑證。 |  |  | 
| 安裝 Apache Tomcat 伺服器的 SSL 憑證。 |  |  | 
| 完成應用程式驗證和測試。 |  |  | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉現有的基礎設施。 |  |  | 
| 將資料庫從生產還原至 Amazon RDS。 |  |  | 
| 透過 DNS 變更來切斷應用程式。 |  |  | 

## 相關資源
<a name="migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling-related-resources"></a>

**參考**
+ [Apache Tomcat 7.0 文件](https://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html)
+ [Apache Tomcat 7.0 安裝指南](https://tomcat.apache.org/tomcat-7.0-doc/appdev/installation.html)
+ [Apache Tomcat JNDI 文件](https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html)
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/)
+ [Amazon ElastiCache for Memcached](https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/WhatIs.html)

**教學課程和影片**
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)

# 將 .NET 應用程式從 Microsoft Azure App Service 遷移至 AWS Elastic Beanstalk
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk"></a>

*Raghavender Madamshitti，Amazon Web Services*

## 總結
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-summary"></a>

此模式說明如何將 Microsoft Azure App Service 上託管的 .NET Web 應用程式遷移至 AWS Elastic Beanstalk。有兩種方式可將應用程式遷移至 Elastic Beanstalk：
+ 使用 AWS Toolkit for Visual Studio - 此 Microsoft Visual Studio IDE 的外掛程式提供最簡單且最直接的方式，將自訂 .NET 應用程式部署到 AWS。您可以使用此方法將 .NET 程式碼直接部署到 AWS，並直接從 Visual Studio 建立支援資源，例如 SQL Server 資料庫的 Amazon Relational Database Service (Amazon RDS)。
+ 上傳和部署至 Elastic Beanstalk - 每個 Azure App Service 都包含名為 Kudu 的背景服務，可用於擷取記憶體傾印和部署日誌、檢視組態參數，以及存取部署套件。您可以使用 Kudu 主控台存取 Azure App Service 內容、擷取部署套件，然後使用 Elastic Beanstalk 主控台中的上傳和部署選項，將套件上傳至 Elastic Beanstalk。

此模式說明第二種方法 （透過 Kudu 將您的應用程式上傳至 Elastic Beanstalk)。模式也使用下列 AWS 服務：AWS Elastic Beanstalk、Amazon Virtual Private Cloud (Amazon VPC)、Amazon CloudWatch、Amazon Elastic Compute Cloud (Amazon EC2) Auto Scaling、Amazon Simple Storage Service (Amazon S3) 和 Amazon Route 53。 

.NET Web 應用程式會部署到 AWS Elastic Beanstalk，AWS Elastic Beanstalk 會在 Amazon EC2 Auto Scaling 群組中執行。您可以根據 Amazon CloudWatch 指標設定擴展政策，例如 CPU 使用率。對於資料庫，您可以根據您的應用程式和業務需求，在多可用區域環境或 Amazon DynamoDB 中使用 Amazon RDS。

## 先決條件和限制
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 在 Azure App Service 中執行的 .NET Web 應用程式
+ 使用 Azure App Service Kudu 主控台的許可

**產品版本**
+ .NET Core (x64) 1.0.1、2.0.0 或更新版本，或 .NET Framework 4.x、3.5 （請參閱 [Windows Server 平台歷史記錄上的 .NET](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platform-history-dotnet.html))
+ 在 Windows Server 2012 或更新版本上執行的網際網路資訊服務 (IIS) 8.0 版或更新版本
+ .NET 2.0 或 4.0 執行期。

## Architecture
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-architecture"></a>

**來源技術堆疊**
+  使用 .NET Framework 3.5 或更新版本或 .NET Core 1.0.1、2.0.0 或更新版本開發，並在 Azure App Service (Web 應用程式或 API 應用程式） 上託管的應用程式

**目標技術堆疊**
+ 在 Amazon EC2 Auto Scaling 群組中執行的 AWS Elastic Beanstalk 

**遷移架構**

![\[Kudu 存取 Azure App Service 內容、取得部署套件、將其上傳至 Elastic Beanstalk。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/df606a2d-b0a8-4035-b377-0a760e7300c9/images/dd15f97b-9cf2-4bcc-af45-44df1c4ca4a5.png)


 

**部署工作流程**

![\[部署工作流程以建立應用程式、將其發佈至啟動環境，然後管理環境。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/df606a2d-b0a8-4035-b377-0a760e7300c9/images/accec77d-c753-4166-8f27-bd4932b3d884.png)


## 工具
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-tools"></a>

**工具**
+ .NET Core 或 .NET Framework
+ C\$1
+ IIS
+ Kudu 主控台

**AWS 服務和功能**
+ [AWS Elastic Beanstalk](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html) – Elastic Beanstalk 是一種easy-to-use用於部署和擴展 .NET Web 應用程式。Elastic Beanstalk 會自動管理容量佈建、負載平衡和自動擴展。
+ [Amazon EC2 Auto Scaling 群組](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroup.html) – Elastic Beanstalk 包含管理環境中 Amazon EC2 執行個體的 Auto Scaling 群組。在單一執行個體環境中，Auto Scaling 群組可確保隨時都有一個執行個體正在執行。在負載平衡的環境中，您可以使用要執行的執行個體範圍來設定群組，而 Amazon EC2 Auto Scaling 會根據負載視需要新增或移除執行個體。
+ [Elastic Load Balancing](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) – 當您在 AWS Elastic Beanstalk 中啟用負載平衡時，它會建立負載平衡器，在環境中的 EC2 執行個體之間分配流量。
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) – Elastic Beanstalk 會自動使用 Amazon CloudWatch 來提供應用程式和環境資源的相關資訊。Amazon CloudWatch 支援標準指標、自訂指標和警示。
+ [Amazon Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html) – Amazon Route 53 是高可用性且可擴展的雲端網域名稱系統 (DNS) Web 服務。您可以使用 Route 53 別名記錄，將自訂網域名稱映射至 AWS Elastic Beanstalk 環境。

## 史詩
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-epics"></a>

### 設定 VPC
<a name="set-up-a-vpc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定虛擬私有雲端 (VPC)。 | 在您的 AWS 帳戶中，使用必要資訊建立 VPC。 | 系統管理員 | 
| 建立子網路。 | 在 VPC 中建立兩個或多個子網路。 | 系統管理員 | 
| 建立路由表。 | 根據您的需求建立路由表。 | 系統管理員 | 

### 設定 Elastic Beanstalk
<a name="set-up-elastic-beanstalk"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 存取 Azure App Service Kudu 主控台。 | 導覽至 App Service 儀表板，然後選擇**進階工具** Go，透過 Azure 入口網站存取 Kudu****。或者，您可以修改 Azure App Service URL，如下所示：`https://<appservicename>.scm.azurewebsites.net`。 | 應用程式開發人員、系統管理員 | 
| 從 Kudu 下載部署套件。 | 選擇 **DebugConsole** 選項，導覽至 Windows PowerShell。這會開啟 Kudo 主控台。前往 `wwwroot` 資料夾並下載。這會將 Azure App Service 部署套件下載為 zip 檔案。如需範例，請參閱附件。 | 應用程式開發人員、系統管理員 | 
| 為 Elastic Beanstalk 建立套件。 | 解壓縮您從 Azure App Service 下載的部署套件。建立名為 的 JSON 檔案 `aws-windows-deployment-manifest.json`（只有 .NET Core 應用程式需要此檔案）。建立包含 `aws-windows-deployment-manifest.json`和 Azure App Service 部署套件檔案的 zip 檔案。如需範例，請參閱附件。 | 應用程式開發人員、系統管理員 | 
| 建立新的 Elastic Beanstalk 應用程式。 | 開啟 Elastic Beanstalk 主控台。選擇現有的應用程式或建立新的應用程式。 | 應用程式開發人員、系統管理員 | 
| 建立環境。 | 在 Elastic Beanstalk 主控台**動作**功能表中，選擇**建立環境**。選取 Web 伺服器環境和 .NET/IIS 平台。針對應用程式碼，選擇**上傳**。上傳您為 Elastic Beanstalk 準備的 zip 檔案，然後選擇**建立環境**。 | 應用程式開發人員、系統管理員 | 
| 設定 Amazon CloudWatch。 | 預設會啟用基本 CloudWatch 監控。如果您想要變更組態，請在 Elastic Beanstalk 精靈中選擇已發佈的應用程式，然後選擇**監控**。 | 系統管理員 | 
| 確認部署套件位於 Amazon S3 中。 | 建立應用程式環境後，您可以在 S3 儲存貯體中找到部署套件。 | 應用程式開發人員、系統管理員 | 
| 測試應用程式。 | 建立環境後，請使用 Elastic Beanstalk 主控台中提供的 URL 來測試應用程式。 | 系統管理員 | 

## 相關資源
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-resources"></a>
+ [AWS Elastic Beanstack 概念](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.html) (Elastic Beanstalk 文件）
+ [Elastic Beanstalk 上的 .NET 入門](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/dotnet-getstarted.html) (Elastic Beanstalk 文件）
+ [Kudu 主控台](https://github.com/projectkudu/kudu/wiki/Kudu-console) (GitHub)
+ [使用「Kudu」管理 Azure Web 應用程式 ](https://www.gslab.com/blogs/kudu-azure-web-app/)(GS Lab 文章）
+ [自訂 ASP.NET Core Elastic Beanstalk 部署 ](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/deployment-beanstalk-custom-netcore.html)(AWS Toolkit for Visual Studio 使用者指南）
+ [Elastic Load Balancing 文件](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html)
+ [AWS Elastic Beanstalk 支援的平台 ](https://docs.amazonaws.cn/en_us/elasticbeanstalk/latest/platforms/platforms-supported.html)(Elastic Beanstalk 文件）
+ [將 Web 應用程式部署至 AWS](https://www.c-sharpcorner.com/article/deploying-a-web-application-to-aws/) (C\$1 轉角文章）
+ [擴展 Auto Scaling 群組的大小](https://docs.aws.amazon.com/autoscaling/ec2/userguide/scaling_plan.html) (Amazon EC2 文件）
+ [Amazon RDS 的高可用性 （多可用區域）](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZ.html) (Amazon RDS 文件）

## 其他資訊
<a name="migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk-additional"></a>

**備註**
+ 如果您要將內部部署或 Azure SQL Server 資料庫遷移至 Amazon RDS，您也必須更新資料庫連線詳細資訊。 
+ 為了測試目的，會連接範例示範應用程式。

## 附件
<a name="attachments-df606a2d-b0a8-4035-b377-0a760e7300c9"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/df606a2d-b0a8-4035-b377-0a760e7300c9/attachments/attachment.zip)

# 在 Amazon ECS 上從 Oracle WebLogic 遷移至 Apache Tomcat (TomEE)
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs"></a>

*Anya Epishcheva 和 Harshad Gohil，Amazon Web Services*

## 總結
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs-summary"></a>

此模式討論透過 Amazon Elastic Container Service (Amazon ECS) 將執行 Oracle WebLogic 的現場部署 Oracle Solaris SPARC 系統遷移至執行 [Apache TomEE](http://tomee.apache.org/)（新增容器支援的 Apache Tomcat) 的 Docker 容器型安裝的步驟。

如需有關將與您從 Oracle WebLogic 遷移至 Tomcat 之應用程式相關聯的資料庫遷移的資訊，請參閱此目錄中的資料庫遷移模式。 

**最佳實務**

遷移 Java 和 Java Enterprise Edition (Java EE) Web 應用程式的步驟會有所不同，取決於應用程式所使用的容器特定資源數量。以 Spring 為基礎的應用程式通常更容易遷移，因為它們在部署容器上有少量的相依性。相反地，使用企業 JavaBeans (EJBs) 和受管容器資源的 Java EE 應用程式，例如執行緒集區、Java 身分驗證和授權服務 (JAAS) 和容器受管持久性 (CMP)，需要更多努力。 

為 Oracle Application Server 開發的應用程式經常使用 Oracle Identity Management 套件。遷移至開放原始碼應用程式伺服器的客戶經常選擇使用以 SAML 為基礎的聯合重新實作身分和存取管理。當從 Oracle Identity Management 套件遷移不是選項時，其他 會使用 Oracle HTTP Server Webgate。 

Java 和 Java EE Web 應用程式非常適合部署在以 Docker 為基礎的 AWS 服務上，例如 AWS Fargate 和 Amazon ECS。客戶經常選擇預先安裝最新版本的目標應用程式伺服器 （例如 TomEE) 和 Java 開發套件 (JDK) 的 Docker 映像。他們會在基礎 Docker 映像檔上安裝應用程式，將其發佈到 Amazon Elastic Container Registry (Amazon ECR) 登錄檔中，並使用它在 AWS Fargate 或 Amazon ECS 上可擴展地部署其應用程式。 

理想情況下，應用程式部署是彈性的；也就是說，應用程式執行個體的數量會根據流量或工作負載縮減或縮減。這表示應用程式執行個體需要上線或終止，才能根據需求調整容量。 

將 Java 應用程式移至 AWS 時，請考慮使其無狀態。這是 AWS Well-Architected Framework 的關鍵架構原則，將使用容器化啟用水平擴展。例如，大多數以 Java 為基礎的 Web 應用程式會在本機存放使用者工作階段資訊。為了避免應用程式執行個體因 Amazon Elastic Compute Cloud (Amazon EC2) 中的自動擴展或其他原因而終止，使用者工作階段資訊應全域儲存，以便 Web 應用程式使用者可以繼續無縫且透明地工作，而無需重新連線或重新登入 Web 應用程式。此方法有數種架構選項，包括 Amazon ElastiCache for Redis，或在全域資料庫中儲存工作階段狀態。TomEE 等應用程式伺服器具有外掛程式，可透過 Redis、資料庫和其他全域資料存放區啟用工作階段儲存和管理。

使用與 Amazon CloudWatch 和 AWS X-Ray 輕鬆整合的常見集中式記錄和偵錯工具。遷移提供改善應用程式生命週期功能的機會。例如，您可能想要自動化建置程序，以便使用持續整合和持續交付 (CI/CD) 管道輕鬆進行變更。這可能需要變更應用程式，以便在不停機的情況下進行部署。 

## 先決條件和限制
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs-prerequisites-and-limitations"></a>

**先決條件**
+ 作用中的 AWS 帳戶 
+ 來源 Java 程式碼和 JDK 
+ 使用 Oracle WebLogic 建置的來源應用程式
+ 定義身分和存取管理的解決方案 (SAML 或 Oracle Webgate)
+ 定義應用程式工作階段管理的解決方案 (like-for-like或搭配 Amazon ElastiCache 移動，或視需要使應用程式無狀態）
+ 了解團隊是否需要重構 J2EE-specific程式庫，以移轉至 Apache TomEE （請參閱 Apache 網站上的 [Java EE 7 實作狀態](http://tomee.apache.org/javaee7-status.html)) 
+ 根據您的安全需求強化 TomEE 映像
+ 預先安裝目標 TomEE 的容器映像 
+ 視需要同意並實作應用程式修復 （例如，記錄偵錯建置、身分驗證）

**產品版本**
+ Oracle WebLogic OC4J、9i、10g 
+ Tomcat 7 （使用 Java 1.6 或更新版本） 

## Architecture
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs-architecture"></a>

 **來源技術堆疊 **
+ 使用 Oracle WebLogic 建置的 Web 應用程式
+ 使用 Oracle Webgate 或 SAML 身分驗證的 Web 應用程式
+ 連接至 Oracle Database 10g 版及更新版本的 Web 應用程式 

**目標技術堆疊 **
+ 在 Amazon ECS 上執行的 TomEE(Apache Tomcat 與新增的容器支援） （另請參閱在 Amazon ECS 上[部署 Java Web 應用程式](https://aws.amazon.com/answers/web-applications/aws-web-app-deployment-java/)和 Java Microservices)[https://aws.amazon.com/blogs/compute/deploying-java-microservices-on-amazon-ec2-container-service/](https://aws.amazon.com/blogs/compute/deploying-java-microservices-on-amazon-ec2-container-service/) 
+ 適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS)；適用於 Amazon RDS 支援的 Oracle 版本，請參閱適用於 [Oracle 的 Amazon RDS](https://aws.amazon.com/rds/oracle/)** **

**目標架構**

![\[AWS 雲端 architecture diagram showing VPC, application subnets, and shared services account components.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d5e7b3fa-062f-4559-af56-aa6058f96755/images/762193cf-aa68-4195-b3c7-6541caee61c9.png)


 

## 工具
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs-tools"></a>

若要在 TomEE 上操作，Java 應用程式必須重建為 .war 檔案。在某些情況下，在 TomEE 上操作應用程式可能需要變更應用程式；您應該檢查以確保正確定義必要的組態選項和環境屬性。  

此外，應該正確定義 Java 命名和目錄界面 (JNDI) 查詢和 JavaServer 頁面 (JSP) 命名空間。請考慮檢查應用程式使用的檔案名稱，以避免命名與內建 T 程式庫的衝突。例如，solveence.xml 是 Apache OpenJPA 架構 （與 TomEE 中的 OpenEJB 綁定） 用於組態用途的檔案名稱。PUI 中的 persistence.xml 檔案包含 Spring 架構 Bean 宣告。  

TomEE 版本 7.0.3 和更新版本 (Tomcat 8.5.7 和更新版本） 會針對具有特殊字元的原始 （未編碼） URLs 傳回 HTTP 400 回應 （錯誤請求）。伺服器回應會顯示為最終使用者的空白頁面。TomEE 和 Tomcat 的早期版本允許在 URLs中使用某些未編碼的特殊字元；不過，它被視為不安全，如[CVE-2016-6816 網站](http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-6816)所述。若要解決 URL 編碼問題，直接透過 JavaScript 傳遞至瀏覽器URLs 必須使用 **encodeURI()** 方法編碼，而不是用作原始字串。

在 TomEE 中部署 .war 檔案後，**請監控是否有任何遺失的共用程式庫和 Oracle 特定延伸模組*，*以從 Tomcat 程式庫新增缺少的元件。 

 

**一般程序**
+ 在 TomEE 上設定應用程式。
+ 識別並重新設定從來源到目標格式的應用程式伺服器特定組態檔案和資源。
+ 識別並重新設定 JNDI 資源。
+ 將 EJB 命名空間和查閱調整為目標應用程式伺服器所需的格式 （如適用）。
+ 重新設定 JAAS 應用程式容器特定的安全角色和原則映射 （如適用）。
+ 將應用程式和共用程式庫封裝到 .war 檔案中。
+ 使用提供的 Docker 容器在 TomEE 中部署 .war 檔案。
+ 監控*啟動日誌*以識別任何遺失的共用程式庫和部署描述項延伸。如果找到任何 ，請返回第一個任務。
+ 根據還原的 Amazon RDS 資料庫測試已安裝的應用程式。
+ 遵循 [Deploy Docker Containers](https://aws.amazon.com/getting-started/tutorials/deploy-docker-containers/) 中的指示，以負載平衡器和 Amazon ECS 叢集啟動完整的架構。
+ 更新 URLs以指向負載平衡器。
+ 更新組態管理資料庫 (CMDB)。

## 史詩
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行應用程式探索 （目前狀態足跡和效能基準）。 |  | BA，遷移主管 | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
| 驗證來源和目標應用程式設計 （身分和工作階段管理）。 |  | DBA、遷移工程師、應用程式擁有者 | 
| 識別目標伺服器執行個體的硬體和儲存需求。 |  | DBA、SysAdmin | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA、SysAdmin | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA、SysAdmin | 
| 識別應用程式遷移策略和工具。 |  | DBA，遷移主管 | 
| 完成應用程式的遷移設計和遷移指南。 |  | 組建主管、遷移主管 | 
| 完成應用程式遷移 Runbook。 |  | 組建主管、切換主管、測試主管、遷移主管 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) |  | SysAdmin | 
| 建立安全群組。 |  | SysAdmin | 
| 設定和啟動 Amazon RDS 資料庫執行個體。 |  | DBA、SysAdmin | 
| 設定 Amazon ECS 部署。 |  | SysAdmin | 
| 將您的應用程式封裝為 Docker 映像。 |  | SysAdmin | 
| 將映像推送至 Amazon ECR 登錄檔 （或略過此步驟並將其推送至 Amazon ECS 叢集）。 |  | SysAdmin | 
| 設定應用程式和 Amazon ECS 服務選項的任務定義。 |  | SysAdmin | 
| 設定叢集、檢閱安全設定，以及設定 AWS Identity and Access Management (IAM) 角色。 |  | SysAdmin | 
| 啟動您的設定，並根據您的應用程式遷移 Runbook 執行測試。 |  | SysAdmin | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得您的安全保證團隊將生產資料移至 AWS 的許可。 |  | DBA、遷移工程師、應用程式擁有者 | 
| 建立並取得端點的存取權，以擷取資料庫備份檔案。 |  | DBA | 
| 使用原生資料庫引擎或第三方工具來遷移資料庫物件和資料。 |  | DBA | 
| 從應用程式遷移 Runbook 執行必要的測試，以確認資料遷移成功。 |  | DBA、遷移工程師、應用程式擁有者 | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立遷移的變更請求 (CR)。 |  | 切換潛在客戶 | 
| 取得遷移的 CR 核准。 |  | 切換潛在客戶 | 
| 遵循應用程式遷移 Runbook 中的應用程式遷移策略。 |  | DBA、遷移工程師、應用程式擁有者 | 
| 升級應用程式 （如果需要）。 |  | DBA、遷移工程師、應用程式擁有者 | 
| 完成功能、非功能、資料驗證、SLA 和效能測試。 |  | 測試主管、應用程式擁有者、應用程式使用者 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從應用程式或企業擁有者取得簽署。 |  | 切換潛在客戶 | 
| 執行資料表主題練習，逐步解說切換執行手冊的所有步驟。 |  | DBA、遷移工程師、應用程式擁有者 | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、遷移工程師、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | DBA、遷移工程師、SysAdmin | 
| 檢閱並驗證專案文件。 |  | 遷移主管 | 
| 收集遷移時間的指標、手動與工具的 %、節省成本等。 |  | 遷移主管 | 
| 關閉專案並提供意見回饋。 |  | 遷移主管，應用程式擁有者 | 

## 相關資源
<a name="migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs-related-resources"></a>

**參考**
+ [Apache Tomcat 7.0 文件](https://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html) 
+ [Apache Tomcat 7.0 安裝指南](https://tomcat.apache.org/tomcat-7.0-doc/appdev/installation.html) 
+ [Apache Tomcat JNDI 文件](https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html) 
+ [Apache TomEE 文件](http://tomee.apache.org/) 
+ [Amazon RDS for Oracle](https://aws.amazon.com/rds/oracle/) 
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/) 
+ [Oracle 和 AWS](https://aws.amazon.com/oracle/) 
+ [Oracle on Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/) 
+ [Amazon ECS 入門](https://aws.amazon.com/ecs/getting-started/)
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/) 

**教學課程和影片**
+ [在 Amazon RDS 上執行 Oracle 資料庫的最佳實務](https://www.youtube.com/watch?v=j2wqT0EPDbw) (re：Invent 2018 簡報） 

# 使用 AWS DMS 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for Oracle
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms"></a>

*Chethan Gangadharaiah 和 Brian motzer，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms-summary"></a>

此模式說明使用 AWS Database Migration Service (AWS DMS) 將 Amazon Elastic Compute Cloud (Amazon EC2) 上的 Oracle 資料庫遷移至 Amazon Relational Database Service (Amazon RDS) for Oracle 的步驟。模式也會使用 Oracle SQL Developer 或 SQL \$1Plus 連線到您的 Oracle 資料庫執行個體，並包含可自動化部分任務的 AWS CloudFormation 範本。

遷移至 Amazon RDS for Oracle 可讓您專注於業務和應用程式，同時 Amazon RDS 會處理資料庫管理任務，例如佈建資料庫、備份和復原、安全修補程式、版本升級和儲存體管理。

## 先決條件和限制
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms-prerequisites-and-limitations"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Amazon EC2 上 Oracle 資料庫的 Amazon Machine Image (AMI)

**產品版本**
+ AWS DMS 支援適用於 Enterprise、Standard、Standard One 和 Standard Two 版本的 Amazon RDS 執行個體資料庫的 Oracle 11g 版 (11.2.0.3.v1 版和更新版本）、12c 和 18c 版。如需支援版本的最新資訊，請參閱 [AWS 文件中的使用 Oracle 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Oracle.html)。（連接的 AWS CloudFormation 範本使用 Oracle 12c 版做為來源資料庫。)
+ Oracle SQL 開發人員 4.0.3

## Architecture
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms-architecture"></a>

**來源架構**
+ Amazon EC2 上的 Oracle 資料庫

**目標架構**
+ Amazon RDS for Oracle

**遷移架構**

![\[AWS 雲端 architecture showing Oracle database migration from EC2 to RDS across availability zones.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4db0c731-0897-4eb8-a06f-b648c3d94b2c/images/636c2a69-5a78-482d-ae81-55e9ec975ead.png)


## 工具
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms-tools"></a>
+ [AWS DMS](https://docs.aws.amazon.com/dms/index.html) – AWS Database Migration Service (AWS DMS) 可協助您快速安全地將資料庫遷移至 AWS。它同時支援同質和異質遷移。如需有關支援的 Oracle 資料庫版本和版本的資訊，請參閱 [AWS 文件中的使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)和[使用 Oracle 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Oracle.html)。
+ **Oracle SQL Developer 或 SQL \$1Plus** – 這些工具可讓您連線至 Amazon RDS for Oracle 資料庫執行個體。

## 史詩
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms-epics"></a>

### 設定您的目標資料庫
<a name="set-up-your-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS for Oracle 資料庫執行個體。 | 登入 AWS 管理主控台，開啟位於 https://console.aws.amazon.com/rds/ 的 Amazon RDS 主控台。透過選取 Oracle 資料庫的適當引擎、範本、資料庫憑證設定、執行個體類型、儲存體、異地同步備份設定、虛擬私有雲端 (VPC) 和組態、登入憑證和其他設定，來建立 Oracle 資料庫執行個體。如需說明，請檢視「相關資源」區段中的連結。或使用附件中的 AWS CloudFormation 範本 (Create\$1RDS.yaml) 來建立 Amazon RDS for Oracle 資料庫執行個體。 | 開發人員 | 
| 連線至 Amazon RDS 並將權限授予 Oracle 使用者。 | 修改安全群組以開啟要從本機電腦和 AWS DMS 複寫執行個體連線的適當連接埠。當您設定連線時，請確定已選取「可公開存取」選項，以便您可以從 VPC 外部連線至資料庫。透過 Oracle SQL Developer 或 SQL \$1Plus 連線至 Amazon RDS，方法是使用登入憑證、建立 AWS DMS 使用者，並提供必要的權限給 AWS DMS 使用者以修改資料庫。 | 開發人員 | 

### 設定來源 EC2 執行個體的安全群組
<a name="configure-the-security-group-of-the-source-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查 Oracle 資料庫是否已啟動並執行。 | 使用 Secure Shell (SSH) 連線至 EC2 執行個體，並使用 SQL \$1Plus 嘗試連線至 Oracle 資料庫。 | 開發人員 | 
| 修改安全群組。 | 修改 EC2 執行個體的安全群組以開啟適當的連接埠，以便您可以從本機電腦和 AWS DMS 複寫執行個體進行連線。 | 開發人員 | 

### 設定 AWS DMS
<a name="set-up-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 複寫執行個體。 | 在 AWS DMS 中，在與 Amazon RDS for Oracle 資料庫執行個體相同的 VPC 中建立複寫執行個體。指定複寫執行個體的名稱和描述、選擇執行個體類別和複寫引擎版本 （使用預設值）、選擇您在其中建立 Amazon RDS 資料庫執行個體的 VPC、視需要設定異地同步備份設定、配置儲存、指定可用區域，以及設定其他設定。或者，您可以使用附件中的 AWS CloudFormation 範本 (DMS.yaml) 來實作此步驟。 | DBA | 
| 連線至來源和目標資料庫端點。 | 指定端點識別符、引擎、伺服器、連接埠、登入憑證和額外的連線屬性，以建立來源和目標資料庫端點。對於來源伺服器，請使用託管 Oracle 資料庫之 EC2 執行個體的公有 DNS。對於目標伺服器，請使用 Amazon RDS for Oracle 的端點。執行測試以確認來源和目標連線是否正常運作。或者，您可以使用附件中的 AWS CloudFormation 範本 (DMS.yaml) 來實作此步驟。 | DBA | 
| 建立 AWS DMS 任務。 | 建立 AWS DMS 任務，將資料從來源端點遷移到目標端點，設定來源和目的地端點之間的複寫，或同時設定兩者。建立 AWS DMS 任務時，請指定複寫執行個體、來源端點、目標端點、遷移類型 （僅限資料、僅限複寫或兩者）、資料表映射和篩選條件。執行 AWS DMS 任務、監控任務、檢查資料表統計資料，以及檢查 Amazon CloudWatch 中的日誌。或者，您可以使用附件中的 AWS CloudFormation 範本 (DMS.yaml) 來實作此步驟。 | DBA | 

## 相關資源
<a name="migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms-related-resources"></a>
+ [建立 Amazon RDS 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateOracleInstance.html)
+ [連接至執行 Oracle 資料庫引擎的資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToOracleInstance.html)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [AWS DMS Step-by-Step演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)
+ [將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html)

## 附件
<a name="attachments-4db0c731-0897-4eb8-a06f-b648c3d94b2c"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/4db0c731-0897-4eb8-a06f-b648c3d94b2c/attachments/attachment.zip)

# 使用 Logstash 將內部部署 Oracle 資料庫遷移至 Amazon OpenSearch Service
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash"></a>

*Aditya Goteti，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-summary"></a>

此模式說明如何使用 Logstash 將資料從現場部署 Oracle 資料庫移至 Amazon OpenSearch Service。它包含架構考量，以及一些必要的技能集和建議。資料可以來自單一資料表，也可以來自需要執行全文搜尋的多個資料表。 

OpenSearch Service 可以在虛擬私有雲端 (VPC) 中設定，也可以使用 IP 型限制公開放置。此模式說明在 VPC 中設定 OpenSearch Service 的情況。Logstash 用於從 Oracle 資料庫收集資料、將其剖析為 JSON 格式，然後將資料饋送至 OpenSearch Service。 

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Java 8 (Logstash 6.4.3 必要）
+ 內部部署資料庫伺服器與 VPC 中的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體之間的連線，使用 AWS Virtual Private Network (AWS VPN) 建立
+ 從資料庫擷取要推送至 OpenSearch Service 所需資料的查詢
+ Oracle Java Database Connectivity (JDBC) 驅動程式

**限制**
+ Logstash 無法識別從資料庫硬刪除的記錄 

**產品版本**
+ Oracle 資料庫 12c
+ OpenSearch Service 6.3
+ Logstash 6.4.3

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫
+ 內部部署 AWS VPN

**目標技術堆疊**
+ VPC
+ EC2 執行個體
+ OpenSearch Service 
+ Logstash
+ NAT Gateway （用於 EC2 執行個體上的作業系統更新，以及安裝 Java 8、Logstash 和外掛程式）

**資料遷移架構**

![\[如何使用 Logstash 將資料從內部部署 Oracle 資料庫移至 Amazon OpenSearch Service。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/09f6d2de-de2f-4ed6-af93-34b71b75a263/images/df6a61fb-09fb-49d4-a7e8-b04e88c003df.png)


## 工具
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-tools"></a>
+ Logstash 6.4.3
+ JDBC 輸入外掛程式 ([下載和更多資訊](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html))
+ Logstash 輸出外掛程式 ([logstash-output-amazon\$1es](https://github.com/awslabs/logstash-output-amazon_es))
+ Oracle JDBC 驅動程式

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別來源資料的大小。 | 來源資料的大小是您用來判斷索引中要設定之碎片數量的參數之一。 | DBA，資料庫開發人員 | 
| 分析每個資料欄的資料類型和對應的資料。 | 在文件中找到先前看不到的欄位時，OpenSearch Service 會動態映射資料類型。如果有任何特定資料類型或格式 （例如日期欄位） 需要明確宣告，請在建立索引期間識別欄位並定義這些欄位的映射。 | 應用程式擁有者、開發人員、資料庫開發人員 | 
| 判斷是否有任何具有主索引鍵或唯一索引鍵的資料欄。 | 若要避免在更新或插入期間重複 Amazon OpenSearch Service 中的記錄，您需要在`amazon_es`外掛程式的輸出區段中設定 `document_id`設定 （例如， `document_id => "%{customer_id}"` `customer_id`是主索引鍵）。 | 應用程式擁有者、開發人員 | 
| 分析新增記錄的數量和頻率；檢查記錄的刪除頻率。 | 需要此任務才能了解來源資料的成長速率。如果資料密集讀取且插入很少見，您可以擁有單一索引。如果頻繁插入新記錄且未刪除，碎片大小可以輕鬆超過建議的 50 GB 大小上限。在這種情況下，您可以透過在 Logstash 和程式碼中設定索引模式來動態建立索引，您可以在其中使用別名來存取索引。 | 應用程式擁有者、開發人員 | 
| 決定需要多少個複本。 |  | 應用程式擁有者、開發人員 | 
| 決定要在索引上設定的碎片數量。 |  | 應用程式擁有者、開發人員 | 
| 識別專用主節點、資料節點和 EC2 執行個體的執行個體類型。 | 如需詳細資訊，請參閱[相關資源](#migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-resources)一節。 | 應用程式擁有者、開發人員 | 
| 判斷所需的專用主節點和資料節點數量。 | 如需詳細資訊，請參閱[相關資源](#migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-resources)一節。 |  | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 EC2 執行個體。 | 在連接 AWS VPN 的 VPC 中啟動 EC2 執行個體。 | Amazon VPC 建構、AWS VPN | 
| 在 EC2 執行個體上安裝 Logstash。 |  | 開發人員 | 
| 安裝 Logstash 外掛程式。 | 安裝必要的 Logstash 外掛程式 `jdbc-input`和 ` logstash-output-amazon_es`。 | 開發人員 | 
| 設定 Logstash。 | 建立 Logstash 金鑰存放區以存放敏感資訊，例如 AWS Secrets Manager 金鑰和資料庫登入資料，然後將參考放在 Logstash 組態檔案中。 | 開發人員 | 
| 設定無效字母佇列和持久性佇列。 | 根據預設，當 Logstash 遇到因為資料包含映射錯誤或其他問題而無法處理的事件時，Logstash 管道會停止或捨棄失敗的事件。為了避免在這種情況下遺失資料，您可以設定 Logstash 將失敗的事件寫入無效字母佇列，而不是捨棄它們。為了避免在異常終止期間遺失資料，Logstash 具有持久性佇列功能，可將訊息佇列存放在磁碟上。持久性佇列在 Logstash 中提供資料耐久性。 | 開發人員 | 
| 建立 Amazon OpenSearch Service 網域。 | 使用不需要使用 AWS Identity and Access Management (IAM) 憑證簽署請求的存取政策來建立 Amazon OpenSearch Service 網域。Amazon OpenSearch Service 網域必須在相同的 VPC 內建立。您也應該選取執行個體類型，並根據分析設定專用節點和主節點的數量。 | 開發人員 | 
| 設定所需的 Amazon OpenSearch Service 日誌。 | 如需詳細資訊，請參閱 [OpenSearch Service 文件](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/cloudwatch-alarms.html)。 |  | 
| 建立索引。 |  | 開發人員 | 
| 啟動 Logstash。 | 執行 Logstash 做為背景服務。Logstash 會執行設定的 SQL 查詢、提取資料、將其轉換為 JSON 格式，並將其饋送至 OpenSearch Service。對於初始載入，請勿在 Logstash 組態檔案中設定排程器。 | 開發人員 | 
| 檢查文件。 | 檢查索引上的文件數量，以及來源資料庫中是否存在所有文件。在初始載入期間，它們會新增至索引，並用來停止 Logstash。變更 Logstash 組態，根據用戶端需求新增以固定間隔執行的排程器，然後重新啟動 Logstash。Logstash 只會挑選上次執行後更新或新增的記錄，而上次執行時間戳記會存放在以 `last_run_metadata_path => "/usr/share/logstash/.logstash_jdbc_last_run"` Logstash 組態檔案中 屬性設定的檔案中。 | 開發人員 | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash-resources"></a>
+ [建議的 CloudWatch 警示](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/cloudwatch-alarms.html) 
+ [專用 Amazon OpenSearch Service 主節點](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-managedomains-dedicatedmasternodes.html) 
+ [調整 Amazon OpenSearch Service 網域的大小](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/sizing-domains.html) 
+ [Logstash 文件](https://www.elastic.co/guide/en/logstash/current/getting-started-with-logstash.html) 
+ [JDBC 輸入外掛程式](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html)
+ [Logstash 輸出外掛程式](https://github.com/awslabs/logstash-output-amazon_es)
+ [Amazon OpenSearch Service 網站](https://aws.amazon.com/elasticsearch-service/) 

# 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle"></a>

*Baji Shaik 和 Pavan Pusuluri，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-summary"></a>

此模式說明將內部部署 Oracle 資料庫遷移至 Amazon Relational Database Service (Amazon RDS) for Oracle 的步驟。作為遷移程序的一部分，您可以建立遷移計劃，並根據來源資料庫考慮有關目標資料庫基礎設施的重要因素。您可以根據您的業務需求和使用案例，選擇兩個遷移選項之一：
+ AWS Database Migration Service (AWS DMS) – 您可以使用 AWS DMS 快速且安全地將資料庫遷移至 AWS 雲端。您的來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降到最低。您可以使用 AWS DMS 來建立任務，在您透過稱為變更[資料擷取 (CDC) 的程序完成初始完全載入遷移後擷取持續變更](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Task.CDC.html)。
+ 原生 Oracle 工具 – 您可以使用原生 Oracle 工具來遷移資料庫，例如 Oracle、[Data Pump Export](https://docs.oracle.com/cd/E11882_01/server.112/e22490/dp_export.htm#SUTIL200) 和 [Data Pump Import](https://docs.oracle.com/cd/E11882_01/server.112/e22490/dp_import.htm#SUTIL300) with [Oracle GoldenGate](https://docs.oracle.com/goldengate/c1230/gg-winux/GGCON/introduction-oracle-goldengate.htm#GGCON-GUID-EF513E68-4237-4CB3-98B3-2E203A68CBD4) for CDC。您也可以使用原生 Oracle 工具，例如原始[匯出公用程式](https://docs.oracle.com/cd/E11882_01/server.112/e22490/original_export.htm#SUTIL3634)和原始[匯入公用程式](https://docs.oracle.com/cd/E11882_01/server.112/e22490/original_import.htm#SUTIL001)，以減少完整載入時間。

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署 Oracle 資料庫
+ Amazon RDS Oracle 資料庫 (DB) 執行個體

**限制**
+ 資料庫大小限制：64 TB

**產品版本**
+ Oracle 版本 11g （版本 11.2.0.3.v1 和更新版本） 以及最多 12.2 和 18c。如需支援版本的最新清單，請參閱 AWS 文件中的[Amazon RDS for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)。對於 AWS DMS 支援的 Oracle 版本，請參閱 [AWS DMS 文件中的使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫

**目標技術堆疊**
+ Amazon RDS for Oracle

**來源和目標架構**

下圖顯示如何使用 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle。

![\[使用 AWS DMS 將 Oracle 資料庫遷移至 Amazon RDS for Oracle 的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/25912997-0ac0-4303-9ce5-0621a7e12406/images/20f94a5c-1095-4182-b964-c379414c9a36.png)


該圖顯示以下工作流程：

1. 建立或使用現有的資料庫使用者，將必要的 [AWS DMS 許可](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Self-Managed)授予該使用者，開啟 [ARCHIVELOG 模式](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Self-Managed.Configuration.ArchiveLogMode)，然後設定[補充記錄](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Self-Managed.Configuration.SupplementalLogging)。

1. 設定內部部署和 AWS 網路之間的網際網路閘道。

1. 設定 AWS DMS 的[來源和目標端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)。

1. 設定 [AWS DMS 複寫任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.html)，將資料從來源資料庫遷移至目標資料庫。

1. 完成目標資料庫上的遷移後活動。

下圖顯示如何使用原生 Oracle 工具將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle。

![\[使用 Oracle 工具將 Oracle 資料庫遷移至 Amazon RDS for Oracle 的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/25912997-0ac0-4303-9ce5-0621a7e12406/images/af8e0e1a-d4c8-4d99-9780-3e093ad9a257.png)


該圖顯示以下工作流程：

1. 建立或使用現有的資料庫使用者，並使用 Oracle Export (`exp`) 和 Import (`imp`) 公用程式授予備份 Oracle 資料庫所需的許可。

1. 設定內部部署和 AWS 網路之間的網際網路閘道。

1. 在[堡](https://www.oracle.com/security/cloud-security/bastion/)壘主機上設定 Oracle 用戶端以取得備份資料庫。

1. 將備份資料庫上傳至 Amazon Simple Storage Service (Amazon S3) 儲存貯體。

1. 將資料庫備份從 Amazon S3 還原至 Amazon RDS for Oracle 資料庫。

1. 為 CDC 設定 Oracle GoldenGate。

1. 完成目標資料庫上的遷移後活動。

## 工具
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ 原生 Oracle 工具可協助您執行同質遷移。您可以使用 [Oracle Data Pump](https://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_overview.htm) 在來源和目標資料庫之間遷移資料。此模式使用 Oracle Data Pump 執行從來源資料庫到目標資料庫的完整載入。
+ [Oracle GoldenGate](https://docs.oracle.com/goldengate/c1230/gg-winux/GGCON/introduction-oracle-goldengate.htm#GGCON-GUID-EF513E68-4237-4CB3-98B3-2E203A68CBD4) 可協助您在兩個或多個資料庫之間執行邏輯複寫。此模式使用 GoldenGate，透過 Oracle Data Pump 在初始載入後複寫差異變更。

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立專案文件並記錄資料庫詳細資訊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA | 
| 識別儲存需求。 | 識別並記錄您的儲存需求，包括下列項目：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html)對於[一般用途 (gp2) SSD 磁碟區](https://aws.amazon.com/ebs/volume-types/)，每 1 GB 的儲存體可獲得三個 IOPS。透過計算來源資料庫上的讀取和寫入 IOPS 總數來分配儲存體。 | DBA、SysAdmin | 
| 根據運算需求選擇適當的執行個體類型。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | SysAdmin | 
| 識別網路存取安全需求。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA、SysAdmin | 
| 識別應用程式遷移策略。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA、SysAdmin、應用程式擁有者 | 
| 識別遷移風險。 | 評估資料庫並記錄遷移的特定風險和緩解措施。例如：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC。 | 為目標資料庫執行個體[建立新的 Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/gsg_create_vpc.html)。 | SysAdmin | 
| 建立安全群組。 | 在新的 VPC 中[建立安全群組](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/working-with-security-groups.html#creating-security-group)，以允許與資料庫執行個體的傳入連線。 | SysAdmin | 
| 建立 Amazon RDS for Oracle 資料庫執行個體。 | 使用新的 VPC 和安全群組[建立目標資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html)，然後啟動執行個體。 | SysAdmin | 

### 選項 1 - 使用原生 Oracle 或第三方工具來遷移資料
<a name="option-1---use-native-oracle-or-third-party-tools-to-migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備來源資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA、SysAdmin | 
| 準備目標資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA、SysAdmin | 

### 選項 2 - 使用 AWS DMS 遷移資料
<a name="option-2---use-aws-dms-to-migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA | 
| 遷移資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA | 

### 切換到目標資料庫
<a name="cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA、SysAdmin、應用程式擁有者 | 
| 實作您的轉返計劃。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html) | DBA、應用程式擁有者 | 

### 關閉遷移專案
<a name="close-out-the-migration-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除資源。 | 關閉或移除臨時 AWS 資源，例如 AWS DMS 複寫執行個體和 S3 儲存貯體。 | DBA、SysAdmin | 
| 檢閱專案文件。 | 檢閱遷移規劃文件和目標，然後確認您已完成所有必要的遷移步驟。 | DBA、SysAdmin、應用程式擁有者 | 
| 收集指標。 | 記錄金鑰遷移指標，包括完成遷移所需的時間、手動與工具型任務的百分比、節省成本和其他相關指標。 | DBA、SysAdmin、應用程式擁有者 | 
| 關閉專案。 | 關閉遷移專案並擷取工作的相關意見回饋。 | DBA、SysAdmin、應用程式擁有者 | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-resources"></a>

**參考**
+ [將 Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html) (AWS 規範指引）
+ [AWS Database Migration Service](https://aws.amazon.com/dms/) (AWS DMS 文件）
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/) (Amazon RDS 文件）

**教學課程和影片**
+ [AWS Database Migration Service 入門](https://aws.amazon.com/dms/getting-started/) (AWS DMS 文件）
+ [Amazon RDS 資源](https://aws.amazon.com/rds/getting-started/) (Amazon RDS 文件）
+ [AWS Database Migration Service (DMS)](https://www.youtube.com/watch?v=zb4GcjEdl8U) (YouTube)

# 使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump"></a>

*Mohan Annam 和 Brian motzer，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump-summary"></a>

此模式說明如何使用 Oracle Data Pump，將 Oracle 資料庫從內部部署資料中心遷移至 Amazon Relational Database Service (Amazon RDS) for Oracle 資料庫執行個體。 

模式涉及從來源資料庫建立資料傾印檔案、將檔案存放在 Amazon Simple Storage Service (Amazon S3) 儲存貯體中，然後將資料還原至 Amazon RDS for Oracle 資料庫執行個體。當您使用 AWS Database Migration Service (AWS DMS) 進行遷移時，此模式非常有用。

## 先決條件和限制
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 在 AWS Identity and Access Management (IAM) 和 Amazon S3 分段上傳中建立角色所需的許可
+ 從來源資料庫匯出資料所需的許可
+ 安裝[https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)並[設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) AWS Command Line Interface (AWS CLI)

**產品版本**
+ Oracle Data Pump 僅適用於 Oracle Database 10g 版本 1 (10.1) 和更新版本。

## Architecture
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫

**目標技術堆疊**
+ Amazon RDS for Oracle
+ SQL 用戶端 (Oracle SQL Developer)
+ S3 儲存貯體

**來源和目標架構**

![\[Amazon S3 分段使用 Oracle Data Pump 從內部部署 Oracle 資料庫上傳至 Amazon RDS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d8d6e00f-753e-4ecc-80e5-e60e279a699b/images/1bb6095a-0a95-4469-be0e-7b7bd59b35ae.png)


## 工具
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump-tools"></a>

**AWS 服務**
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。在此模式中，IAM 用於建立將資料從 Amazon S3 遷移至 Amazon RDS for Oracle 所需的角色和政策。
+ [Amazon Relational Database Service (Amazon RDS) for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 可協助您在 AWS 雲端中設定、操作和擴展 Oracle 關聯式資料庫。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**其他工具**
+ [Oracle Data Pump](https://docs.oracle.com/cd/B19306_01/server.102/b14215/dp_overview.htm) 可協助您以高速將資料和中繼資料從一個資料庫移至另一個資料庫。在此模式中，Oracle Data Pump 會用來將資料傾印 (.dmp) 檔案匯出至 Oracle 伺服器，並將其匯入 Amazon RDS for Oracle。如需詳細資訊，請參閱《[Amazon RDS 文件》中的在 Amazon RDS 上將資料匯入 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Procedural.Importing.html#Oracle.Procedural.Importing.DataPump.S3)。
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。它與現場部署 Oracle 資料庫和 Amazon RDS for Oracle 互動，以執行匯出和匯入資料所需的 SQL 命令。

## 史詩
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump-epics"></a>

### 建立 S3 儲存貯體
<a name="create-an-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立儲存貯體。 | 若要建立 S3 儲存貯體，請遵循 [AWS 文件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)中的指示。 | AWS 系統管理員 | 

### 建立 IAM 角色並指派政策
<a name="create-the-iam-role-and-assign-policies"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 IAM 許可。 | 若要設定許可，請遵循 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-s3-integration.html#oracle-s3-integration.preparing)中的指示。 | AWS 系統管理員 | 

### 建立目標 Amazon RDS for Oracle 資料庫執行個體，並關聯 Amazon S3 整合角色
<a name="create-the-target-amazon-rds-for-oracle-db-instance-and-associate-the-amazon-s3-integration-role"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立目標 Amazon RDS for Oracle 資料庫執行個體。 | 若要建立 Amazon RDS for Oracle 執行個體，請遵循 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.Oracle.html)中的指示。 | AWS 系統管理員 | 
| 將角色與資料庫執行個體建立關聯。 | 若要將角色與執行個體建立關聯，請遵循 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-s3-integration.html#oracle-s3-integration.preparing.instance)中的指示。 | DBA | 

### 在目標資料庫上建立資料庫使用者
<a name="create-the-database-user-on-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立使用者。 | 從 Oracle SQL Developer 或 SQL\$1Plus 連線至目標 Amazon RDS for Oracle 資料庫，並執行下列 SQL 命令來建立要匯入結構描述的使用者。<pre>create user SAMPLE_SCHEMA identified by <PASSWORD>;<br />grant create session, resource to <USER NAME>;<br />alter user <USER NAME> quota 100M on users;</pre> | DBA | 

### 從來源 Oracle 資料庫建立匯出檔案
<a name="create-the-export-file-from-the-source-oracle-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料傾印檔案。 | 若要在 `sample.dmp``DATA_PUMP_DIR`目錄中建立名為 的傾印檔案來匯出`SAMPLE_SCHEMA`使用者，請使用下列指令碼。<pre>DECLARE<br />    hdnl NUMBER;<br />BEGIN<br />    hdnl := dbms_datapump.open(operation => 'EXPORT', <br />                                job_mode => 'SCHEMA', <br />                                job_name => NULL);<br /><br />    dbms_datapump.add_file( handle => hdnl, <br />                            filename => 'sample.dmp', <br />                            directory => 'DATA_PUMP_DIR', <br />                            filetype => dbms_datapump.ku$_file_type_dump_file);<br /><br />    dbms_datapump.add_file(handle => hdnl, <br />                            filename => 'export.log', <br />                            directory => 'DATA_PUMP_DIR', <br />                            filetype => dbms_datapump.ku$_file_type_log_file);<br /><br />    dbms_datapump.metadata_filter(hdnl, 'SCHEMA_EXPR', 'IN (''SAMPLE_SCHEMA'')');  <br /><br />    dbms_datapump.start_job(hdnl);<br />END;<br />/</pre>檢閱本機`DATA_PUMP_DIR`目錄中`export.log`的檔案，以檢閱匯出詳細資訊。 | DBA | 

### 將傾印檔案上傳至 S3 儲存貯體
<a name="upload-the-dump-file-to-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將資料傾印檔案從來源上傳至 S3 儲存貯體。 | 使用 AWS CLI，執行下列命令。<pre>aws s3 cp sample.dmp s3://<bucket_created_epic_1>/</pre> | DBA | 

### 從 S3 儲存貯體下載匯出檔案至 RDS 執行個體
<a name="download-the-export-file-from-the-s3-bucket-to-the-rds-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將資料傾印檔案下載至 Amazon RDS | 若要將傾印檔案`sample.dmp`從 S3 儲存貯體複製到 Amazon RDS for Oracle 資料庫，請執行下列 SQL 命令。在此範例中，`sample.dmp`檔案會從 S3 儲存貯體下載`my-s3-integration1`到 Oracle 目錄 `DATA_PUMP_DIR`。請確定已將足夠的磁碟空間配置給 RDS 執行個體，以容納資料庫和匯出檔案。<pre>-- If you want to download all the files in the S3 bucket remove the p_s3_prefix line.<br /><br />SELECT rdsadmin.rdsadmin_s3_tasks.download_from_s3(<br />      p_bucket_name    =>  'my-s3-integration',    <br />      p_s3_prefix => 'sample.dmp',<br />      p_directory_name =>  'DATA_PUMP_DIR') <br />   AS TASK_ID FROM DUAL;</pre>先前的命令會輸出任務 ID。若要檢閱任務 ID 中的資料來檢閱下載狀態，請執行下列命令。<pre>SELECT text FROM table(rdsadmin.rds_file_util.read_text_file('BDUMP','dbtask-<task_id>.log'));<br /><br /></pre>若要查看 `DATA_PUMP_DIR`目錄中的檔案，請執行下列命令。<pre>SELECT filename,type,filesize/1024/1024 size_megs,to_char(mtime,'DD-MON-YY HH24:MI:SS') timestamp<br />FROM TABLE(rdsadmin.rds_file_util.listdir(p_directory => upper('DATA_PUMP_DIR'))) order by 4;</pre> | AWS 系統管理員 | 

### 將傾印檔案匯入目標資料庫
<a name="import-the-dump-file-into-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將結構描述和資料還原至 Amazon RDS。 | 若要將傾印檔案匯入`sample_schema`資料庫結構描述，請從 SQL Developer 或 SQL\$1Plus 執行下列 SQL 命令。<pre>DECLARE<br />hdnl NUMBER;<br />BEGIN<br /><br />hdnl := DBMS_DATAPUMP.OPEN( operation => 'IMPORT', job_mode => 'SCHEMA', job_name=>null);<br /><br />DBMS_DATAPUMP.ADD_FILE( handle => hdnl, filename => 'sample.dmp', directory => 'DATA_PUMP_DIR', filetype => dbms_datapump.ku$_file_type_dump_file);<br /><br />DBMS_DATAPUMP.ADD_FILE( handle    => hdnl, filename  => 'import.log', directory => 'DATA_PUMP_DIR', filetype  => dbms_datapump.ku$_file_type_log_file);<br /><br />DBMS_DATAPUMP.METADATA_FILTER(hdnl,'SCHEMA_EXPR','IN (''SAMPLE_SCHEMA'')');<br /><br />DBMS_DATAPUMP.START_JOB(hdnl);<br /><br />END;<br />/</pre>若要從匯入查看日誌檔案，請執行下列命令。<pre>SELECT text FROM table(rdsadmin.rds_file_util.read_text_file('DATA_PUMP_DIR','import.log'));</pre> | DBA | 

### 從 DATA\$1PUMP\$1DIR 目錄移除傾印檔案
<a name="remove-the-dump-file-from-the-data_pump_dir-directory"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 列出並清除匯出檔案。 | 列出並移除 `DATA_PUMP_DIR`目錄中的匯出檔案，執行下列命令。<pre>-- List the files<br />SELECT filename,type,filesize/1024/1024 size_megs,to_char(mtime,'DD-MON-YY HH24:MI:SS') timestamp FROM TABLE(rdsadmin.rds_file_util.listdir(p_directory => upper('DATA_PUMP_DIR'))) order by 4;</pre><pre>-- Remove the files<br />EXEC UTL_FILE.FREMOVE('DATA_PUMP_DIR','sample.dmp');<br />EXEC UTL_FILE.FREMOVE('DATA_PUMP_DIR','import.log');</pre> | AWS 系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump-resources"></a>
+ [Amazon S3 整合](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-s3-integration.html#oracle-s3-integration.preparing)
+ [建立資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateDBInstance.html)
+ [在 Amazon RDS 上將資料匯入 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Procedural.Importing.html#Oracle.Procedural.Importing.DataPump.S3)
+ [Amazon S3 文件](https://docs.aws.amazon.com/s3/index.html)
+ [IAM 文件](https://docs.aws.amazon.com/iam/index.html)
+ [Amazon RDS 文件](https://docs.aws.amazon.com/rds/index.html)
+ [Oracle Data Pump 文件](https://docs.oracle.com/en/database/oracle/oracle-database/19/sutil/oracle-data-pump-overview.html)
+ [Oracle SQL Developer](https://www.oracle.com/database/sqldeveloper/)

# 使用 pglogical 從 Amazon EC2 上的 PostgreSQL 遷移至 Amazon RDS for PostgreSQL Amazon EC2
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical"></a>

*Rajesh Madiwale，Amazon Web Services*

## 總結
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical-summary"></a>

此模式概述使用 PostgreSQL **pglogical** 延伸模組，將 PostgreSQL 資料庫 (9.5 版及更新版本） 從 Amazon Elastic Compute Cloud (Amazon EC2) 遷移至 Amazon Relational Database Service (Amazon RDS) for PostgreSQL 的步驟。Amazon RDS 現在支援 PostgreSQL 第 10 版的 pglogical 擴充功能。

## 先決條件和限制
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical-prereqs"></a>

**先決條件 **
+ 選擇正確的 Amazon RDS 執行個體類型。如需詳細資訊，請參閱[Amazon RDS 執行個體類型](https://aws.amazon.com/rds/instance-types/)。
+ 請確定 PostgreSQL 的來源和目標版本相同。  
+ 安裝[**pglogical** 延伸模組並與 PostgreSQL](https://github.com/2ndQuadrant/pglogical)on Amazon EC2 整合。

**產品版本**
+ Amazon RDS 上的 PostgreSQL 10 版和更新版本，具有 Amazon RDS 上支援的功能 （請參閱 AWS 文件中的 [Amazon RDS 上的 PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts))。此模式是透過在 Amazon RDS 上將 PostgreSQL 9.5 遷移至 PostgreSQL 10 版來測試，但也適用於 Amazon RDS 上的 PostgreSQL 更新版本。

## Architecture
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical-architecture"></a>

**資料遷移架構**

![\[Amazon RDS 上 PostgreSQL 的資料遷移架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/29af3931-48de-499f-9c4b-e10a98e4bba5/images/5f5b906f-dc1a-49a5-ae3f-3e10ae854784.png)


## 工具
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical-tools"></a>
+ [https://github.com/2ndQuadrant/pglogical](https://github.com/2ndQuadrant/pglogical) 延伸模組
+ PostgreSQL 原生公用程式：[https://www.postgresql.org/docs/9.5/app-pgdump.html](https://www.postgresql.org/docs/9.5/app-pgdump.html) 和 [https://www.postgresql.org/docs/9.6/app-pgrestore.html](https://www.postgresql.org/docs/9.6/app-pgrestore.html)

## 史詩
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical-epics"></a>

### 使用 pglogical 延伸模組遷移資料
<a name="migrate-data-by-using-the-pglogical-extension"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS PostgreSQL 資料庫執行個體。 | 在 Amazon RDS 中設定 PostgreSQL 資料庫執行個體。如需說明，請參閱 [Amazon RDS for PostgreSQL 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.PostgreSQL.html)。 | DBA | 
| 從來源 PostgreSQL 資料庫取得結構描述傾印，並將其還原至目標 PostgreSQL 資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical.html) | DBA | 
| 開啟邏輯解碼。 | 在 Amazon RDS 資料庫參數群組中，將`rds.logical_replication`靜態參數設定為 1。如需說明，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.FeatureSupport.LogicalDecoding)。 | DBA | 
| 在來源和目標資料庫上建立 pglogical 延伸。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical.html) | DBA | 
| 在來源 PostgreSQL 資料庫上建立發佈者。 | 若要建立發佈者，請執行：<pre>psql -d dbname -p 5432 <<EOF<br />SELECT pglogical.create_node( node_name := 'provider1', dsn := 'host=<ec2-endpoint> port=5432 dbname=source-dbname user=source-dbuser' );<br />EOF</pre> | DBA | 
| 建立複寫集、新增資料表和序列。 | 若要在來源 PostgreSQL 資料庫上建立複寫集，以及將資料表和序列新增至複寫集，請執行：<pre>psql -d dbname -p 5432 <<EOF<br />SELECT pglogical.replication_set_add_all_tables('default', '{public}'::text[],synchronize_data := true);<br />EOF</pre> | DBA | 
| 建立訂閱者。 | 若要在目標 PostgreSQL 資料庫上建立訂閱者，請執行：<pre>psql -h <rds-endpoint> -d target-dbname -U target-dbuser  <<EOF<br />SELECT pglogical.create_node(<br />    node_name := 'subscriber1',<br />    dsn := 'host=<rds-endpoint> port=5432 dbname=target-dbname password=postgres user=target-dbuser'<br />);<br />EOF</pre> | DBA | 
| 建立訂閱。 | 若要在目標 PostgreSQL 資料庫上建立訂閱，請執行：<pre>psql -h <rds-endpoint> -d target -U postgres  <<EOF<br />SELECT pglogical.create_subscription(<br /> subscription_name := 'subscription1',<br /> replication_sets := array['default'],<br />    provider_dsn := 'host=<ec2-endpoint> port=5432 dbname=<source-dbname> password=<password> user=source-dbuser'<br />);</pre> | DBA | 

### 驗證您的資料
<a name="validate-your-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查來源和目標資料庫。 | 檢查來源和目標資料庫，以確認資料已成功複寫。您可以從來源和目標資料表使用 `select count(1)` 執行基本驗證。 | DBA | 

## 相關資源
<a name="migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical-resources"></a>
+ [Amazon RDS](https://aws.amazon.com/rds/)
+ [Amazon RDS 上的 PostgreSQL 邏輯複寫 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.FeatureSupport.LogicalReplication)(Amazon RDS 文件）
+ [pglogical](https://github.com/2ndQuadrant/pglogical) (GitHub 儲存庫）
+ [pglogical 的限制](https://github.com/2ndQuadrant/pglogical#limitations-and-restrictions) (GitHub 儲存庫 README 檔案）
+ [使用邏輯複寫將 PostgreSQL 從內部部署或 Amazon EC2 遷移至 Amazon RDS ](https://aws.amazon.com/blogs/database/migrating-postgresql-from-on-premises-or-amazon-ec2-to-amazon-rds-using-logical-replication/)(AWS 資料庫部落格）

# 將內部部署 PostgreSQL 資料庫遷移至 Aurora PostgreSQL
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql"></a>

*Baji Shaik 和 Jitender Kumar，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-summary"></a>

Amazon Aurora PostgreSQL 相容版本結合了高階商業資料庫的效能和可用性，以及開放原始碼資料庫的簡單性和成本效益。Aurora 透過將儲存體擴展到相同 AWS 區域中的三個可用區域，提供這些優勢，並支援最多 15 個僅供讀取複本執行個體，以擴展讀取工作負載，並在單一區域中提供高可用性。透過使用 Aurora 全域資料庫，您可以在最多五個區域中複寫 PostgreSQL 資料庫，以便在發生區域故障時進行遠端讀取存取和災難復原。此模式說明將內部部署 PostgreSQL 來源資料庫遷移至 Aurora PostgreSQL 相容資料庫的步驟。模式包含兩個遷移選項：使用 AWS Data Migration Service (AWS DMS) 或使用原生 PostgreSQL 工具 （例如，[pg\$1dump](https://www.postgresql.org/docs/current/app-pgdump.html)、[pg\$1restore](https://www.postgresql.org/docs/current/app-pgrestore.html) 和[psql](https://www.postgresql.org/docs/current/app-psql.html)) 或第三方工具。 

此模式中描述的步驟也適用於 Amazon Relational Database Service (Amazon RDS) 和 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的目標 PostgreSQL 資料庫。 Amazon Relational Database Service 

## 先決條件和限制
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的 PostgreSQL 來源資料庫
+ [Aurora PostgreSQL 相容資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html)或 [Amazon RDS for PostgreSQL 資料庫執行個體](https://aws.amazon.com/getting-started/hands-on/create-connect-postgresql-db/)

**限制**
+ Amazon RDS for PostgreSQL 的資料庫大小限制為 64 TB，Aurora PostgreSQL 相容則為 128 TB。
+ 如果您使用的是 AWS DMS 遷移選項，請檢閱[使用 PostgreSQL 資料庫做為來源的 AWS DMS 限制](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html#CHAP_Source.PostgreSQL.Limitations)。

**產品版本**
+ 如需 Amazon RDS 中的 PostgreSQL 主要和次要版本支援，請參閱 [Amazon RDS 文件中的 Amazon RDS for PostgreSQL 更新](https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-versions.html)。
+ 如需 Aurora 中的 PostgreSQL 支援，請參閱 [Aurora 文件中的 Amazon Aurora PostgreSQL 更新](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/AuroraPostgreSQL.Updates.html)。
+ 如果您使用的是 AWS DMS 遷移選項，請參閱 AWS DMS 文件中的[支援的 PostgreSQL 版本](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)。

## Architecture
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-architecture"></a>

**來源技術堆疊**
+ 內部部署PostgreSQL 資料庫

**目標技術堆疊**
+ Aurora PostgreSQL 相容資料庫執行個體

**來源架構**

![\[內部部署 PostgreSQL 資料庫的來源架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/a8621ad3-781b-45a9-86a8-d0b0ec5c79ea.png)


**目標架構**

![\[Amazon Aurora 上 PostgreSQL 資料庫的目標架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/fc2ec0cb-7b9b-4cc0-b70c-40e47c2f4c45.png)


**資料遷移架構**

*使用 AWS DMS*

![\[使用 AWS DMS 將內部部署 PostgreSQL 資料庫遷移至 Aurora\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/5336adb4-e9eb-47d0-a5b5-d149261b1638.png)


*使用原生 PostgreSQL 工具*

![\[使用 pg_dump 和 pg_restore 將內部部署 PostgreSQL 資料庫遷移至 Aurora\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/3c6fb533-45ff-443e-bfb1-97e60cbdd583.png)


## 工具
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署組態的組合之間遷移。此服務支援不同的來源和目標資料庫。如需有關如何驗證支援與 AWS DMS 搭配使用之 PostgreSQL 來源和目標資料庫版本的資訊，請參閱[使用 PostgreSQL 資料庫做為 AWS DMS 來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。
+ 原生 PostgreSQL 工具包括 [pg\$1dump](https://www.postgresql.org/docs/current/app-pgdump.html)、[pg\$1restore](https://www.postgresql.org/docs/current/app-pgrestore.html) 和[psql](https://www.postgresql.org/docs/current/app-psql.html)。

## 史詩
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-epics"></a>

### 分析遷移
<a name="analyze-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本。 | 如果您使用的是 AWS DMS，請確定您使用的是[支援的 PostgreSQL 版本](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)。 | DBA | 
| 識別儲存類型和容量需求。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA，系統管理員 | 
| 選擇適當的執行個體類型、容量、儲存功能和網路功能。 | 判斷目標資料庫執行個體的運算需求。檢閱可能需要額外注意的已知效能問題。請考慮下列因素，以判斷適當的執行個體類型：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html)如需詳細資訊，請參閱 [Aurora 文件中的 Aurora 資料庫執行個體類別](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.DBInstanceClass.html)。 | DBA，系統管理員 | 
| 識別來源和目標資料庫的網路存取安全需求。 | 決定適當的安全群組，讓應用程式能夠與資料庫通訊。 | DBA，系統管理員 | 
| 識別應用程式遷移策略。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA、應用程式擁有者、系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC。 | 為目標資料庫執行個體建立新的虛擬私有雲端 (VPC)。 | 系統管理員 | 
| 建立安全群組。 | 在 VPC 內建立安全群組 （如上一個圖示中所決定），以允許資料庫執行個體的傳入連線。 | 系統管理員 | 
| 設定和啟動 Aurora 資料庫叢集。 | 使用新的 VPC 和安全群組建立目標資料庫執行個體，並啟動執行個體。 | 系統管理員 | 

### 遷移資料 ‒ 選項 1 （使用 AWS DMS)
<a name="migrate-data-option-1-using-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 完成預遷移步驟。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA | 
| 完成遷移步驟。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA | 
| 驗證資料。 | 為了確保您的資料從來源準確遷移到目標，請遵循 AWS DMS 文件中的[資料驗證步驟](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | DBA | 

### 遷移資料 ‒ 選項 2 （使用 pg\$1dump 和 pg\$1restore)
<a name="migrate-data-option-2-using-pg_dump-and-pg_restore"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備來源資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html)如需詳細資訊，請參閱 AWS DMS 文件中的 [pg\$1dump](https://www.postgresql.org/docs/current/app-pgdump.html) 文件和[逐步解說](https://docs.aws.amazon.com/dms/latest/sbs/chap-manageddatabases.postgresql-rds-postgresql-full-load-pd_dump.html)。 | DBA | 
| 準備目標資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html)如需詳細資訊，請參閱 AWS DMS 文件中的 [pg\$1restore](https://www.postgresql.org/docs/current/app-pgrestore.html) 文件和[逐步解說](https://docs.aws.amazon.com/dms/latest/sbs/chap-manageddatabases.postgresql-rds-postgresql-full-load-pd_dump.html)。 | DBA | 
| 驗證資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 | 實作您在第一個史詩中建立的應用程式遷移策略。 | DBA、應用程式擁有者、系統管理員 | 

### 切換到目標資料庫
<a name="cut-over-to-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA、應用程式擁有者、系統管理員 | 
| 如果您需要復原遷移。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | DBA、應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉資源。 | 關閉臨時 AWS 資源。 | DBA，系統管理員 | 
| 驗證文件。 | 檢閱並驗證專案文件。 | DBA、應用程式擁有者、系統管理員 | 
| 收集指標。 | 收集遷移時間、手動與工具成本節省百分比等指標。 | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案。 | 關閉專案並提供任何意見回饋。 | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-resources"></a>

**參考**
+ [AWS Data Migration Service](https://aws.amazon.com/dms/)
+ [VPCs和 Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_VPC.html)
+ [Amazon Aurora 定價](https://aws.amazon.com/rds/aurora/pricing/)
+ [使用 PostgreSQL 資料庫做為 AWS DMS 來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)
+ [如何建立 AWS DMS 複寫執行個體](https://aws.amazon.com/premiumsupport/knowledge-center/create-aws-dms-replication-instance/)
+ [如何使用 AWS DMS 建立來源和目標端點](https://aws.amazon.com/premiumsupport/knowledge-center/create-source-target-endpoints-aws-dms/)

**其他資源**
+ [AWS DMS 入門](https://aws.amazon.com/dms/getting-started/)
+ [資料遷移step-by-step演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)
+ [Amazon Aurora 資源](https://aws.amazon.com/rds/aurora/getting-started/)

# 將內部部署 Microsoft SQL Server 資料庫遷移至執行 Linux 的 Amazon EC2 上的 Microsoft SQL Server
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux"></a>

*Tirumala Dasari，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux-summary"></a>

此模式說明如何使用備份和還原公用程式，從在 Microsoft Windows 上執行的內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Elastic Compute Cloud (Amazon EC2) Linux 執行個體上的 Microsoft SQL Server。

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 搭配 Microsoft SQL Server 的 Amazon EC2 Linux AMI (Amazon Machine Image)
+ Linux EC2 執行個體上的現場部署 Windows 和 Microsoft SQL Server 之間的 AWS Direct Connect

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux-architecture"></a>

**來源技術堆疊**
+ 內部部署 Microsoft SQL Server 資料庫

**目標技術堆疊**
+ 具有 Microsoft SQL Server 資料庫的 Linux EC2 執行個體

**資料庫遷移架構**

![\[將內部部署 SQL Server 資料庫遷移至 Linux EC2 執行個體的架構圖。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f331ad15-2d41-4087-a6d1-60e3443e2acf/images/f50a779a-ce5d-44b1-8d37-dedd6400a12c.png)


## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux-tools"></a>
+ **WinSCP** - 此工具可讓 Windows 使用者輕鬆與 Linux 使用者共用檔案。
+ **Sqlcmd** - 此命令列公用程式可讓您將 T-SQL 陳述式或批次提交至 SQL Server 的本機和遠端執行個體。此公用程式對於批次處理或單元測試等重複性資料庫任務非常有用。

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux-epics"></a>

### 使用 SQL Server 準備 EC2 Linux 執行個體
<a name="prepare-the-ec2-linux-instance-with-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選取提供 Linux 作業系統並包含 Microsoft SQL Server 的 AMI。 |  | Sysadmin | 
| 設定 AMI 以建立 EC2 執行個體。 |  | Sysadmin | 
| 建立安全群組的傳入和傳出規則。 |  | Sysadmin | 
| 設定 Microsoft SQL Server 資料庫的 Linux EC2 執行個體。 |  | DBA | 
| 建立使用者並提供與來源資料庫中相同的許可。 |  | Appowner、DBA | 
| 在 Linux EC2 執行個體上安裝 SQL Server 工具和 sqlcmd 公用程式。 |  | DBA | 

### 備份資料庫並將備份檔案移至 Linux EC2 執行個體
<a name="back-up-the-database-and-move-backup-file-to-linux-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 備份現場部署 SQL Server 資料庫。 |  | DBA | 
| 在 Microsoft SQL Server 上安裝 WinSCP。 |  | DBA | 
| 將備份檔案移至執行 Microsoft SQL Server 的 Linux EC2 執行個體。 |  | DBA | 

### 在執行 SQL Server 的 Linux EC2 執行個體上還原資料庫
<a name="restore-the-database-on-linux-ec2-instance-running-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 sqlcmd 公用程式從資料庫備份檔案還原資料庫。 |  | DBA | 
| 驗證資料庫物件和資料。 |  | 開發人員、測試工程師 | 

### 從 Windows SQL Server 切換到 Linux EC2 執行個體上的 Windows SQL Server
<a name="cut-over-from-windows-sql-server-to-windows-sql-server-on-linux-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料庫物件和資料。 |  | 開發人員、測試工程師 | 
| 從內部部署 Microsoft SQL Server 資料庫切換到執行 Microsoft SQL Server 的 Linux EC2 執行個體。 |  | DBA | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux-resources"></a>
+ [如何在 Amazon Linux 和 Ubuntu AMIs 上設定 SQL Server 2017](https://aws.amazon.com/blogs/database/configuring-sql-server-2017-on-amazon-linux-2-and-ubuntu-amis/) 
+ [在 Linux 執行個體上安裝 SQL 工具](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-2017#RHEL) 
+ [從內部部署 Microsoft SQL Server 資料庫備份和還原至 Linux EC2 執行個體上的 Microsoft SQL Server](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-migrate-restore-database?view=sql-server-2017#create-a-backup-on-windows) 

# 使用連結的伺服器將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers"></a>

*Kevin Yung、Vitakash Adwani 和 Amazon Web Services Vishal Singh*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers-summary"></a>

連結的伺服器可讓 Microsoft SQL Server 在資料庫伺服器的其他執行個體上執行 SQL 陳述式。此模式說明如何將內部部署 Microsoft SQL Server 資料庫遷移至 Microsoft SQL Server 的 Amazon Relational Database Service (Amazon RDS)，以實現更低的成本和更高的可用性。目前，Amazon RDS for Microsoft SQL Server 不支援 Amazon Virtual Private Cloud (Amazon VPC) 網路以外的連線。 

您可以使用此模式來達成下列目標：
+ 將 Microsoft SQL Server 遷移至 Amazon RDS for Microsoft SQL Server，而不會中斷連結的伺服器功能。
+ 在不同的波段中排定和遷移連結的 Microsoft SQL Server 的優先順序。

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers-prerequisites-and-limitations"></a>

**先決條件**
+ 檢查 [Amazon RDS 上的 Microsoft SQL Server](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html) 是否支援您需要的功能。
+ 請確定您可以使用[Amazon RDS for Microsoft SQL Server 搭配預設定序或透過資料庫層級設定的定序](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.SQLServer.CommonDBATasks.Collation.html)。 

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers-architecture"></a>

**來源技術堆疊**
+ 內部部署資料庫 (Microsoft SQL Server)

 **目標技術堆疊**
+ Amazon RDS for SQL Server

**來源狀態架構**

![\[Diagram showing data replication between two data centers with primary and secondary SQL servers.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/95234758-cb8b-46e5-afd2-3d4aaf6ed668/images/776b453a-7fa0-43fd-b1ca-fb9e5cc21820.png)


 

 

 

 

 

 

 

 

 

 

 

 

**目標狀態架構**

在目標狀態下，您可以使用連結的伺服器，將 Microsoft SQL Server 遷移至 Amazon RDS for Microsoft SQL Server。此架構使用 Network Load Balancer 將流量從 Amazon RDS for Microsoft SQL Server 代理到執行 Microsoft SQL Server 的內部部署伺服器。下圖顯示 Network Load Balancer 的反向代理功能。

![\[AWS 雲端 architecture with RDS SQL Server instances in two availability zones and on-premises databases.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/95234758-cb8b-46e5-afd2-3d4aaf6ed668/images/6bdbdfbf-b048-4fbd-acef-0aeb826edb50.png)


 

## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers-tools"></a>
+ AWS CloudFormation
+ Network Load Balancer 
+ 位於多個可用區域的 Amazon RDS for SQL Server （多AZs區域）
+ AWS Database Migration Service (AWS DMS) 

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers-epics"></a>

### 建立登陸區域 VPC
<a name="create-a-landing-zone-vpc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 CIDR 配置。 |  | AWS SysAdmin | 
| 建立 Virtual Private Cloud (VPC) |  | AWS SysAdmin | 
| 建立 VPC 子網路。 |  | AWS SysAdmin | 
| 建立子網路存取控制清單 ACLs)。 |  | AWS SysAdmin | 
| 建立子網路路由表。 |  | AWS SysAdmin | 
| 建立與 AWS Direct Connect 或 AWS Virtual Private Network (VPN) 的連線。 |  | AWS SysAdmin | 

### 將資料庫遷移至 Amazon RDS
<a name="migrate-the-database-to-amazon-rds"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS for Microsoft SQL Server 資料庫執行個體。 |  | AWS SysAdmin | 
| 建立 AWS DMS 複寫執行個體。 |  | AWS SysAdmin | 
| 在 AWS DMS 中建立來源和目標資料庫端點。 |  | AWS SysAdmin | 
| 建立遷移任務，並在完全載入後將連續複寫設定為 ON。 |  | AWS SysAdmin | 
| 請求防火牆變更，以允許 Amazon RDS for Microsoft SQL Server 存取內部部署 SQL Server 資料庫。 |  | AWS SysAdmin | 
| 建立 Network Load Balancer。 |  | AWS SysAdmin | 
| 建立目標群組，以資料中心中的資料庫伺服器為目標 | 我們建議您在目標設定中使用主機名稱來整合資料中心 (DC) 容錯移轉事件。 | AWS SysAdmin | 
| 針對連結的伺服器設定執行 SQL 陳述式。 | 針對 Amazon RDS for Microsoft SQL Server 資料庫執行個體，使用 Microsoft SQL 管理工具執行 SQL 陳述式來新增連結的伺服器。在 SQL 陳述式中，將 @datasrc 設定為使用 Network Load Balancer 主機名稱。針對 Amazon RDS for Microsoft SQL Server 資料庫執行個體，使用 Microsoft SQL 管理工具新增連結的伺服器登入憑證。 | AWS SysAdmin | 
| 測試和驗證 SQL Server 函數。 |  | AWS SysAdmin | 
| 建立切換。 |  | AWS SysAdmin | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers-related-resources"></a>
+ [Amazon RDS 上 Microsoft SQL Server 的常見管理任務](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General)
+ [Microsoft SQL Server 的定序和字元集](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.SQLServer.CommonDBATasks.Collation.html) 
+ [Network Load Balancer 文件](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html) 
+ [使用 Amazon RDS for Microsoft SQL Server 實作連結的伺服器 （部落格文章）](https://aws.amazon.com/blogs/database/implement-linked-servers-with-amazon-rds-for-microsoft-sql-server/)

# 使用原生備份和還原方法，將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods"></a>

*Tirumala Dasari、David Queiroz 和 Amazon Web Services Vishal Singh*

## 總結
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods-summary"></a>

此模式說明如何將內部部署 Microsoft SQL Server 資料庫遷移至 SQL Server 資料庫執行個體的 Amazon Relational Database Service (Amazon RDS) （同質遷移）。遷移程序是以原生 SQL Server 備份和還原方法為基礎。它使用 SQL Server Management Studio (SSMS) 來建立資料庫備份檔案，並使用 Amazon Simple Storage Service (Amazon S3) 儲存貯體來存放備份檔案，然後再將其還原至 Amazon RDS for SQL Server。

## 先決條件和限制
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 存取 S3 儲存貯體和 Amazon RDS for SQL Server 資料庫執行個體的 AWS Identity and Access Management (IAM) 角色政策。

**限制**
+ 此模式中描述的程序只會遷移資料庫。SQL 登入或資料庫使用者，包括任何 SQL Server Agent 任務，都不會遷移，因為它們需要額外的步驟。

**產品版本**
+ SQL Server 2012-2017。如需支援版本和功能的最新清單，請參閱 AWS 文件中的 [Amazon RDS 上的 Microsoft SQL Server](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.FeatureSupport)。

## Architecture
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods-architecture"></a>

**來源技術堆疊**
+ 內部部署 Microsoft SQL Server 資料庫

**目標技術堆疊**
+ Amazon RDS for SQL Server 資料庫執行個體

**資料遷移****架構**

![\[將內部部署 SQL Server 資料庫遷移至 Amazon RDS for SQL Server 資料庫執行個體的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/c2dcd6ab-deb1-4d5e-b3c5-3bf48c02ca4e/images/29f90473-6dd4-4574-bfbd-5c6a0481c40e.png)


## 工具
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods-tools"></a>
+ Microsoft SQL Server Management Studio (SSMS) 是用於管理 SQL Server 基礎設施的整合環境。它提供使用者介面和一組工具，其中包含與 SQL Server 互動的豐富指令碼編輯器。

## 史詩
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods-epics"></a>

### 建立 Amazon RDS for SQL Server 資料庫執行個體
<a name="create-an-amazon-rds-for-sql-server-db-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選取 SQL Server 做為 Amazon RDS for SQL Server 中的資料庫引擎。 |  | DBA | 
| 選擇 SQL Server Express Edition。 |  | DBA | 
| 指定資料庫詳細資訊。 | 如需建立資料庫執行個體的詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html)。 | DBA、應用程式擁有者 | 

### 從內部部署 SQL Server 資料庫建立備份檔案
<a name="create-a-backup-file-from-the-on-premises-sql-server-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 透過 SSMS 連線至內部部署 SQL Server 資料庫。 |  | DBA | 
| 建立資料庫的備份。 | 如需說明，請參閱 [SSMS 文件](https://learn.microsoft.com/en-us/sql/ssms/sql-server-management-studio-ssms)。 | DBA、應用程式擁有者 | 

### 將備份檔案上傳至 Amazon S3
<a name="upload-the-backup-file-to-amazon-s3"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon S3 中建立儲存貯體。 | 如需詳細資訊，請參閱 [Amazon S3 說明文件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)。 | DBA | 
| 將備份檔案上傳至 S3 儲存貯體。 | 如需詳細資訊，請參閱 [Amazon S3 說明文件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html)。 | SysOps 管理員 | 

### 在 Amazon RDS for SQL Server 中還原資料庫
<a name="restore-the-database-in-amazon-rds-for-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將選項群組新增至 Amazon RDS。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods.html)如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html)。 | SysOps 管理員 | 
| 還原資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods.html) | DBA | 

### 驗證目標資料庫
<a name="validate-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證物件和資料。 | 驗證來源資料庫與 Amazon RDS for SQL Server 之間的物件和資料。此任務只會遷移資料庫。不會遷移登入和任務。 | 應用程式擁有者、DBA | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 重新導向應用程式流量。 | 驗證後，將應用程式流量重新導向至 Amazon RDS for SQL Server 資料庫執行個體。 | 應用程式擁有者、DBA | 

## 相關資源
<a name="migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods-resources"></a>
+ [Amazon S3 文件](https://docs.aws.amazon.com/s3/) 
+ [Amazon RDS for SQL Server 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html) 
+ [Microsoft SQL Server 資料庫引擎的選項](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.SQLServer.Options.html) 

# 使用 AWS DMS 和 AWS SCT 將 Microsoft SQL Server 資料庫遷移至 Aurora MySQL
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct"></a>

*Mark Szalkiewicz 和 Pavan Pusuluri，Amazon Web Services*

## 總結
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct-summary"></a>

此模式說明如何將內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 Microsoft SQL Server 資料庫遷移至 Amazon Aurora MySQL。模式使用 AWS Database Migration Service (AWS DMS) 和 AWS Schema Conversion Tool (AWS SCT) 進行資料遷移和結構描述轉換。

## 先決條件和限制
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct-prerequisites-and-limitations"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心或 EC2 執行個體上的 Microsoft SQL Server 來源資料庫 
+ AWS SCT 連接器的 Java Database Connectivity (JDBC) 驅動程式，安裝在本機電腦或安裝 AWS SCT 的 EC2 執行個體上 

 

**限制**
+ 資料庫大小限制：64 TB

**產品版本**
+ 適用於 Enterprise、Standard、Workgroup 和 Developer 版本的 Microsoft SQL Server 2008、2008R2、2012、2014、2016 和 2017。AWS DMS 不支援 Web 和 Express 版本。如需支援版本的最新清單，請參閱[使用 Microsoft SQL Server 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。如需 AWS SCT 支援的 Microsoft SQL Server 版本相關資訊，請參閱 [AWS SCT 文件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。
+ MySQL 5.5、5.6 和 5.7 版。如需支援版本的最新清單，請參閱[使用 MySQL 相容資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)。

## Architecture
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct-architecture"></a>

**來源技術堆疊**

下列其中一項： 
+ 內部部署 Microsoft SQL Server 資料庫
+ EC2 執行個體上的 Microsoft SQL Server 資料庫

**目標技術堆疊**
+ Aurora MySQL

**資料遷移架構**
+ 從 AWS 雲端中執行的 Microsoft SQL Server 資料庫 

![\[AWS 雲端 architecture showing VPC with private subnet containing SQL Server and Aurora MySQL databases.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e2de4507-82a8-4bd6-b25b-1e830b197b9f/images/c675ada4-e92c-4ddb-b49f-69668f532504.png)

+ 從內部部署資料中心執行的 Microsoft SQL Server 資料庫

![\[AWS 雲端 architecture diagram showing on-premises to cloud migration using AWS SCT, DMS, and Aurora MySQL.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e2de4507-82a8-4bd6-b25b-1e830b197b9f/images/b6ce0199-fc56-4bf2-a8cc-67de161e3cf0.png)


## 工具
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct-tools"></a>
+ **AWS DMS** - [AWS Data Migration Service](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html) (AWS DMS) 可協助您在廣泛使用的商業和開放原始碼資料庫之間遷移資料，包括 Oracle、SQL Server、MySQL 和 PostgreSQL。您可以使用 AWS DMS 將資料遷移至 AWS 雲端，可在現場部署執行個體 (透過 AWS 雲端設定) 或在雲端和現場部署設定之間進行。
+ **AWS SCT** - [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) (AWS SCT) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，讓異質資料庫遷移變得更容易。

## 史詩
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct-epics"></a>

### 準備遷移
<a name="prepare-for-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
| 為來源和目標資料庫建立傳出安全群組。 |  | SysAdmin | 
| 視需要建立和設定 AWS SCT 的 EC2 執行個體。 |  | DBA | 
| 下載最新版本的 AWS SCT 和相關聯的驅動程式。 |  | DBA | 
| 在來源資料庫中新增和驗證先決條件使用者和授權。 |  | DBA | 
| 為工作負載建立 AWS SCT 專案，並連線至來源資料庫。 |  | DBA | 
| 產生評估報告並評估可行性。 |  | DBA | 

### 準備目標資料庫
<a name="prepare-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Amazon Aurora 做為資料庫引擎，建立目標 Amazon RDS 資料庫執行個體。 |  | DBA | 
| 從來源擷取使用者、角色和授予的清單。 |  | DBA | 
| 將現有的資料庫使用者映射至新的資料庫使用者。 |  | 應用程式擁有者 | 
| 在目標資料庫中建立使用者。 |  | DBA | 
| 將上一個步驟的角色套用至目標資料庫。 |  | DBA | 
| 檢閱來源資料庫中的資料庫選項、參數、網路檔案和資料庫連結，然後評估其對目標資料庫的適用性。 |  | DBA | 
| 將任何相關設定套用至目標。 |  | DBA | 

### 傳輸物件
<a name="transfer-objects"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定目標資料庫的 AWS SCT 連線。 |  | DBA | 
| 使用 AWS SCT 轉換結構描述。 | AWS SCT 會自動將來源資料庫結構描述和大多數自訂程式碼轉換為與目標資料庫相容的格式。工具無法自動轉換的任何程式碼都會清楚標示，讓您可以自行轉換。 | DBA | 
| 檢閱產生的 SQL 報告，並儲存任何錯誤和警告。 |  | DBA | 
| 將自動化結構描述變更套用至目標，或將其儲存為 .sql 檔案。 |  | DBA | 
| 驗證 AWS SCT 是否已在目標上建立物件。 |  | DBA | 
| 手動重寫、拒絕或重新設計任何無法自動轉換的項目。 |  | DBA | 
| 套用產生的角色和使用者授權，並檢閱任何例外狀況。 |  | DBA | 

### 遷移資料
<a name="migrate-the-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定遷移方法。 |  | DBA | 
| 從 AWS DMS 主控台建立複寫執行個體。 | 如需使用 AWS DMS 的詳細資訊，請參閱「相關資源」一節中的連結。 | DBA | 
| 建立來源和目標端點。 |  | DBA | 
| 建立複寫任務。 |  | DBA | 
| 啟動複寫任務並監控日誌。 |  | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS SCT 來分析和轉換應用程式程式碼中的 SQL 項目。 | 當您將資料庫結構描述從一個引擎轉換到另一個引擎，您也需更新應用程式中的 SQL 程式碼，以便與新的資料庫引擎互動，取代舊引擎。您可以檢視、分析、編輯和儲存轉換後的 SQL 程式碼。如需使用 AWS SCT 的詳細資訊，請參閱「相關資源」一節中的連結。 | 應用程式擁有者 | 
| 在 AWS 上建立新的應用程式伺服器。 |  | 應用程式擁有者 | 
| 將應用程式碼遷移至新的伺服器。 |  | 應用程式擁有者 | 
| 設定目標資料庫和驅動程式的應用程式伺服器。 |  | 應用程式擁有者 | 
| 修正應用程式中來源資料庫引擎特有的任何程式碼。 |  | 應用程式擁有者 | 
| 最佳化目標引擎的應用程式碼。 |  | 應用程式擁有者 | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將任何新使用者、授權和程式碼變更套用至目標。 |  | DBA | 
| 鎖定應用程式是否有任何變更。 |  | 應用程式擁有者 | 
| 驗證所有變更是否已傳播到目標資料庫。 |  | DBA | 
| 將新的應用程式伺服器指向目標資料庫。 |  | 應用程式擁有者 | 
| 重新檢查所有項目。 |  | 應用程式擁有者 | 
| 上線。 |  | 應用程式擁有者 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源 (AWS DMS 複寫執行個體和用於 AWS SCT 的 EC2 執行個體）。 |  | DBA、應用程式擁有者 | 
| 更新內部團隊的 AWS DMS 程序意見回饋。 |  | DBA、應用程式擁有者 | 
| 修訂 AWS DMS 程序並視需要改善範本。 |  | DBA、應用程式擁有者 | 
| 檢閱並驗證專案文件。 |  | DBA、應用程式擁有者 | 
| 收集遷移時間、手動與工具成本節省百分比等指標。 |  | DBA、應用程式擁有者 | 
| 關閉專案並提供任何意見回饋。 |  | DBA、應用程式擁有者 | 

## 相關資源
<a name="migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct-related-resources"></a>

**參考**
+ [AWS DMS 使用者指南](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [AWS SCT 使用者指南](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)  
+ [Amazon Aurora 定價](https://aws.amazon.com/rds/aurora/pricing/) 

**教學課程和影片**
+ [AWS Database Migration Service 入門](https://aws.amazon.com/dms/getting-started/)
+ [AWS Schema Conversion Tool入門](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [Amazon RDS 資源](https://aws.amazon.com/rds/getting-started/)
+ [AWS DMS Step-by-Step演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html) 

# 使用原生工具將內部部署 MariaDB 資料庫遷移至 Amazon RDS for MariaDB
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools"></a>

*Shyam Sunder Rakhecha，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools-summary"></a>

此模式提供使用原生工具將內部部署 MariaDB 資料庫遷移至 MariaDB 的 Amazon Relational Database Service (Amazon RDS) 的指引。如果您已安裝 MySQL 工具，則可以使用 **mysql** 和 **mysqldump**。如果您已安裝 MariaDB 工具，則可以使用 **mariadb** 和 **mariadb-dump**。MySQL 和 MariaDB 工具具有相同的原始伺服器，但在 MariaDB 10.6 版和更新版本中存在細微差異。

## 先決條件和限制
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的 MariaDB 來源資料庫

**限制**
+ 資料庫大小限制：64 TB

**產品版本**
+ MariaDB 10.0-10.6 版 （如需支援版本的最新清單，請參閱 AWS 文件中的 [Amazon RDS 上的MariaDB](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MariaDB.html#MariaDB.Concepts.VersionMgmt))

## Architecture
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools-architecture"></a>

**來源技術堆疊**
+ 內部部署資料中心中的 MariaDB 資料庫

**目標技術堆疊**
+ Amazon RDS for MariaDB 資料庫執行個體

**目標架構**

![\[具有不同可用區域中主要和待命 RDS 資料庫執行個體的架構圖。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7be644e0-da42-4515-87b7-04da7a054adb/images/eca8eb55-579a-42e2-96ce-9b14b097b4c9.png)


**資料遷移架構**

![\[將內部部署 MariaDB 資料庫遷移至 Amazon RDS 的架構圖\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7be644e0-da42-4515-87b7-04da7a054adb/images/daba40e2-a2b1-44f8-8e69-31458206a823.png)


## 工具
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools-tools"></a>
+ 原生 MySQL 工具：**mysql** 和 **mysqldump**
+ 原生 MariaDB 工具：**mariadb** 和 **mariadb-dump**

## 史詩
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源和目標資料庫版本和引擎。 |  | DBA | 
| 識別目標伺服器執行個體的硬體需求。 |  | DBA，系統管理員 | 
| 識別儲存需求 （儲存類型和容量）。 |  | DBA，系統管理員 | 
| 根據容量、儲存功能和網路功能選擇適當的執行個體類型。 |  | DBA，系統管理員 | 
| 識別來源和目標資料庫的網路存取安全需求。 |  | DBA，系統管理員 | 
| 識別應用程式遷移策略。 |  | DBA、應用程式擁有者、系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) |  | 系統管理員 | 
| 建立安全群組。 |  | 系統管理員 | 
| 設定並啟動執行 MariaDB 的 Amazon RDS 資料庫執行個體。 |  | 系統管理員 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生工具來遷移資料庫物件和資料。 | 在來源資料庫中，使用 **mysqldump ****ormariadb-dump** 建立包含資料庫物件和資料的輸出檔案。在目標資料庫中，使用 **mysql **或 **mariadb **還原資料。 | DBA | 
| 驗證資料。 | 檢查來源和目標資料庫，以確認資料遷移成功。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循應用程式遷移策略。 |  | DBA、應用程式擁有者、系統管理員 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將應用程式用戶端切換到新的基礎設施。 |  | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 |  | 系統管理員 | 
| 檢閱並驗證專案文件。 |  | DBA、應用程式擁有者、系統管理員 | 
| 收集遷移時間、工具提供的成本節省等指標。 |  | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案並提供意見回饋。 |  | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools-resources"></a>

**Amazon RDS 參考**
+ [Amazon RDS for MariaDB](https://aws.amazon.com/rds/mariadb/)
+ [Amazon Virtual Private Cloud VPCs和 Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.html)
+ [Amazon RDS 異地同步備份部署](https://aws.amazon.com/rds/details/multi-az/)
+ [Amazon RDS 定價](https://aws.amazon.com/rds/pricing/)

**MySQL 和 MariaDB 參考**
+ [mariadb-dump/mysqldump](https://mariadb.com/kb/en/mariadb-dumpmysqldump/) 
+ [mysql 命令列用戶端](https://mariadb.com/kb/en/mysql-command-line-client/) 

**教學課程和影片**
+ [Amazon RDS 入門](https://aws.amazon.com/rds/getting-started/)

# 將內部部署 MySQL 資料庫遷移至 Aurora MySQL
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql"></a>

*Igor Obradovic，Amazon Web Services*

## 總結
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql-summary"></a>

此模式說明如何將內部部署 MySQL 來源資料庫遷移至 Amazon Aurora MySQL 相容版本。它描述了兩種遷移選項：使用 AWS Database Migration Service (AWS DMS) 或使用 **mysqldbcopy** 和**mysqldump** 等原生 MySQL 工具。

## 先決條件和限制
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 內部部署資料中心中的來源 MySQL 資料庫

**限制**
+ 資料庫大小限制：128 TB

**產品版本**
+ MySQL 8.0 版 (Aurora MySQL 第 3 版） 可在標準支援下使用。
+ MySQL 5.7 版 (Aurora MySQL 2 版） 可在擴充支援下使用，需額外付費。

如需支援版本的最新清單，請參閱 AWS 文件中的 [Amazon Aurora 版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraMySQLReleaseNotes/AuroraMySQL.release-calendars.html)。如果您使用的是 AWS DMS，另請參閱[使用 MySQL 相容資料庫做為 所支援 for MySQL 版本的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html) AWS DMS。 MySQL 

## Architecture
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql-architecture"></a>

**來源技術堆疊**
+ 內部部署 MySQL 資料庫

**目標技術堆疊**
+ Amazon Aurora MySQL-Compatible Edition 

**目標架構**

Aurora 資料存放在叢集磁碟區中，這是使用固態硬碟 (SSDs的單一虛擬磁碟區。叢集磁碟區包含跨單一 AWS 區域的三個可用區域的資料複本。由於資料會自動跨可用區域複寫，因此非常耐用，且資料遺失的可能性較低。

Aurora 會自動將您的資料庫磁碟區分割為分散在許多磁碟的 10 GB 區段。資料庫磁碟區的每個 10 GB 區塊都會以六種方式跨三個可用區域複寫。下圖說明叢集磁碟區、寫入器資料庫執行個體和 Aurora 資料庫叢集中讀取器資料庫執行個體之間的關係，以及運算容量和儲存體的分離。如需此架構的詳細資訊，請參閱 [Aurora 文件](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.Overview.html)和[常見問答集](https://aws.amazon.com/rds/aurora/faqs/#product-faqs)。

![\[Aurora MySQL 資料庫執行個體和 AWS 上的共用儲存磁碟區。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/22729803-e4ff-45a2-ab5b-8ba2445e5e21/images/0d7d8ebd-e0f2-4bcf-b296-8bdfb2f12b64.png)


**資料遷移架構**

*使用 AWS DMS：*

下圖說明使用 將內部部署 MySQL 資料庫遷移至 中與 Aurora MySQL 相容的叢集 AWS 雲端 AWS DMS。

![\[使用 AWS DMS 將內部部署 MySQL 資料庫遷移至 Aurora MySQL。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/22729803-e4ff-45a2-ab5b-8ba2445e5e21/images/e5d72ebd-d157-45d7-8844-d1011f1646c0.png)


*使用原生 MySQL 工具：*

下圖說明使用 **mysqldbcopy** 和**mysqldump** 等原生 MySQL 工具 AWS 雲端，將內部部署 MySQL 資料庫遷移至 中的 Aurora MySQL 相容叢集。

![\[使用 mysqldbcopy 和 mysqldump 將內部部署 MySQL 資料庫遷移至 Aurora MySQL。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/22729803-e4ff-45a2-ab5b-8ba2445e5e21/images/26258752-24f6-4241-a49f-59c15e946314.png)


 

## 工具
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 支援數個來源和目標資料庫引擎。如需 支援的 MySQL 來源和目標資料庫的相關資訊 AWS DMS，請參閱[將 MySQL 相容資料庫遷移至 AWS](https://docs.aws.amazon.com/dms/latest/sbs/CHAP_MySQL.html)。我們建議您使用最新版本的 AWS DMS ，以獲得最全面的版本和功能支援。
+ [mysqldbcopy](https://manpages.ubuntu.com/manpages/focal/man1/mysqldbcopy.1.html) 是一種 MySQL 公用程式，可在單一伺服器上或在伺服器之間複製 MySQL 資料庫。
+ [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) 是一種 MySQL 公用程式，可從 MySQL 資料庫建立傾印檔案，以供備份或遷移之用。

## 史詩
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證版本和引擎。 | 驗證來源和目標資料庫的資料庫版本和引擎。 | DBA | 
| 識別硬體需求。 | 識別目標伺服器執行個體的硬體需求。 | DBA，系統管理員 | 
| 識別儲存需求。 | 識別儲存需求 （儲存類型和容量）。 | DBA，系統管理員 | 
| 選擇執行個體類型。 | 根據您的運算、儲存和網路需求，選擇適當的執行個體類型。 | DBA，系統管理員 | 
| 判斷網路存取安全需求。 | 識別來源和目標資料庫的網路存取安全需求。 | DBA，系統管理員 | 
| 決定策略。 | 識別應用程式遷移策略。 | DBA、應用程式擁有者、系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Virtual Private Cloud (VPC) | 如需說明，請參閱《Amazon Virtual Private Cloud (Amazon [VPC) 文件》中的建立](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html) VPC。 | 系統管理員 | 
| 建立安全群組。 | 如需說明，請參閱 Amazon [VPC 文件中的為您的 VPC 建立安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/creating-security-groups.html)。 | 系統管理員 | 
| 在 中設定和啟動 Aurora MySQL 相容資料庫叢集 AWS 帳戶。 | 如需說明，請參閱 [Aurora 文件中的建立 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html)。 | 系統管理員 | 

### 遷移資料 - 選項 1
<a name="migrate-data---option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生 MySQL 工具或第三方工具來遷移資料庫物件和資料。 | 如需說明，請參閱 MySQL 工具的文件，例如 [mysqldbcopy](https://manpages.ubuntu.com/manpages/focal/man1/mysqldbcopy.1.html) 和 [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)。 | DBA | 

### 遷移資料 - 選項 2
<a name="migrate-data---option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 遷移資料 AWS DMS。 | 如需說明，請參閱 AWS DMS 文件中的[使用 MySQL 相容資料庫做為來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.MySQL.html)和[使用 MySQL 相容資料庫做為目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遵循 策略。 | 遵循應用程式遷移策略。 | DBA、應用程式擁有者、系統管理員 | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 切換應用程式用戶端。 | 切換應用程式用戶端以連線至新的 Aurora 叢集端點。 | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉資源。 | 關閉臨時 AWS 資源。 | DBA，系統管理員 | 
| 檢閱文件。 | 檢閱並驗證專案文件。 | DBA、應用程式擁有者、系統管理員 | 
| 收集指標。 | 收集遷移時間、手動步驟與工具用量的百分比、節省成本等指標。 | DBA、應用程式擁有者、系統管理員 | 
| 完成遷移專案。 | 關閉專案並提供意見回饋。 | 應用程式擁有者、DBA、系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-mysql-database-to-aurora-mysql-resources"></a>

**參考**
+ [將資料遷移至 Amazon Aurora MySQL 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Migrating.html)
+ [AWS DMS website](https://aws.amazon.com/dms/)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)
+ [Amazon Aurora 定價](https://aws.amazon.com/rds/aurora/pricing/)
+ [建立並連線至 Aurora MySQL 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.Aurora.html)
+ [Amazon VPC 和 Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.html)
+ [Amazon Aurora 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html)

**教學課程和影片**
+ [入門 AWS DMS](https://aws.amazon.com/dms/getting-started/)
+ [Amazon Aurora 入門](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.html)

# 使用 Percona XtraBackup、Amazon EFS 和 Amazon S3 將內部部署 MySQL 資料庫遷移至 Aurora MySQL
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3"></a>

*Rohan Jamadagni、Udayasimha Theepireddy 和 Sajith menon，Amazon Web Services*

## 總結
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-summary"></a>

此模式說明如何使用 Percona XtraBackup，有效率地將大型內部部署 MySQL 資料庫遷移至 Amazon Aurora MySQL。Percona XtraBackup 是 MySQL 型伺服器的開放原始碼、非封鎖備份公用程式。模式顯示如何使用 Amazon Elastic File System (Amazon EFS) 減少將備份上傳至 Amazon Simple Storage Service (Amazon S3) 的時間，並將備份還原至 Amazon Aurora MySQL。模式也提供如何進行增量 Percona 備份的詳細資訊，以將要套用至目標 Aurora MySQL 資料庫的二進位日誌數目降至最低。 

## 先決條件和限制
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 建立 AWS Identity and Access Management (IAM) 角色和政策的許可
+ 內部部署 MySQL 資料庫與 AWS 虛擬私有雲端 (VPC) 之間的網路連線

**限制**
+ 來源伺服器必須是 Linux 系統，可以安裝網路檔案系統 (NFS) 用戶端 (nfs-utils/nfs-common)。
+ 用於上傳備份檔案的 S3 儲存貯體僅支援伺服器端加密 (SSE-S3/SSE-KMS)。
+ Amazon S3 會將備份檔案的大小限制為 5 TB。如果您的備份檔案超過 5 TB，您可以將其分割成多個較小的檔案。
+ 上傳至 S3 儲存貯體的來源檔案數目不能超過一百萬個檔案。
+ 模式僅支援 Percona XtraBackup 完整備份和增量備份。它不支援使用 `--tables`、`--tables-exclude`、`--tables-file``--databases`、`--databases-exclude`、 或 的部分備份`--databases-file`。
+ Aurora 不會從來源 MySQL 資料庫還原使用者、函數、預存程序或時區資訊。

**產品版本**
+ 來源資料庫必須是 MySQL 5.5、5.6 或 5.7 版。
+ 對於 MySQL 5.7，您必須使用 Percona XtraBackup 2.4。
+ 對於 MySQL 5.6 和 5.6，您必須使用 Percona XtraBackup 2.3 或 2.4。

## Architecture
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-architecture"></a>

**來源技術堆疊**
+ Linux 作業系統
+ MySQL 伺服器
+ Percona XtraBackup

**目標技術堆疊**
+ Amazon Aurora
+ Amazon S3
+ Amazon EFS

**目標架構**

![\[使用 Percona XtraBackup 將大型 MySQL 資料庫遷移至 Amazon Aurora MySQL 的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bf327776-bafd-484d-9ae2-a6f5c8af6edd/images/7a410539-1511-4106-90e2-8c0c8e95f92b.png)


## 工具
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-tools"></a>

*AWS 服務*
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraMySQL.html) 是全受管關聯式資料庫引擎，可讓您輕鬆且符合成本效益地設定、操作和擴展 MySQL 部署。Aurora MySQL 是 MySQL 的下拉式選單。
+ [Amazon Elastic File System (Amazon EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) 可協助您在 AWS 雲端中建立和設定共用檔案系統。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**其他工具**
+ [Percona XtraBackup](https://www.percona.com/doc/percona-xtrabackup/2.4/index.html) 是一種開放原始碼公用程式，可執行 MySQL 資料庫的串流、壓縮和增量備份，而不會中斷或封鎖資料庫。

## 史詩
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-epics"></a>

### 建立 Amazon EFS 檔案系統
<a name="create-an-amazon-efs-file-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立安全群組以與 Amazon EFS 掛載目標建立關聯。 | 在 VPC 中建立安全群組，該安全群組使用透過 AWS Transit Gateway 連接至現場部署資料庫的 VPN 連接進行設定。如需此和其他案例所述命令和步驟的詳細資訊，請參閱此模式結尾的「相關資源」一節中的連結。 | AWS DevOps/資料庫管理員 | 
| 編輯安全群組規則。 | 新增傳入規則，使用類型 NFS、連接埠 2049 和現場部署資料庫伺服器的 IP 範圍做為來源。根據預設，傳出規則允許所有流量離開。如果不是這種情況 ，請新增傳出規則以開啟 NFS 連接埠的連線。新增另外兩個傳入規則：連接埠 2049 （來源：相同安全群組的安全群組 ID) 和連接埠 22 （來源：IP 範圍，您將從中連線至 EC2 執行個體）。 | AWS DevOps/資料庫管理員 | 
| 建立檔案系統。 | 在掛載目標中，使用您在上一個案例中建立的 VPC 和安全群組。根據內部部署資料庫的 I/O 需求，選擇輸送量模式和效能。或者，啟用靜態加密。 | AWS DevOps/資料庫管理員 | 

### 掛載檔案系統
<a name="mount-the-file-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立要與 EC2 執行個體建立關聯的 IAM 執行個體描述檔角色。 | 建立具有在 Amazon S3 中上傳和存取物件許可的 IAM 角色。選擇將備份儲存為政策資源的 S3 儲存貯體。 | AWS DevOps | 
| 建立 EC2 執行個體。 | 啟動以 Linux 為基礎的 EC2 執行個體，並連接您在上一個步驟中建立的 IAM 執行個體描述檔角色，以及您先前建立的安全群組。 | AWS DevOps | 
| 安裝 NFS 用戶端。 | 在內部部署資料庫伺服器和 EC2 執行個體上安裝 NFS 用戶端。如需安裝說明，請參閱「其他資訊」一節。 | DevOps | 
| 掛載 Amazon EFS 檔案系統。 | 在內部部署和 EC2 執行個體上掛載 Amazon EFS 檔案系統。在每個伺服器上，建立用於存放備份的目錄，並使用掛載目標端點掛載檔案系統。如需範例，請參閱「其他資訊」一節。 | DevOps | 

### 進行 MySQL 來源資料庫的備份
<a name="make-a-backup-of-the-mysql-source-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 Percona XtraBackup。 | 在內部部署資料庫伺服器上安裝 Percona XtraBackup 2.3 或 2.4 （取決於 MySQL 資料庫的版本）。如需安裝連結，請參閱「相關資源」一節。 | 資料庫管理員 | 
| 計算來源資料庫中的結構描述和資料表。 | 收集並記下來源 MySQL 資料庫中的結構描述和物件數量。遷移後，您將使用這些計數來驗證 Aurora MySQL 資料庫。 | 資料庫管理員 | 
| （選用） 記下來源資料庫的最新二進位日誌序列。 | 如果您想要在來源資料庫和 Aurora MySQL 之間建立二進位日誌複寫，以將停機時間降至最低，請執行此步驟。必須啟用 log-bin，且 server\$1id 必須是唯一的。請記下來源資料庫中目前的二進位日誌序列，就在啟動備份之前。如果您打算僅使用完整備份，請在完整備份之前執行此步驟。如果您打算在完整備份之後進行增量備份，請在 Aurora MySQL 資料庫執行個體上還原的最終增量備份之前執行此步驟。 | 資料庫管理員 | 
| 啟動來源 MySQL 資料庫的完整備份。 | 使用 Percona XtraBackup 完整備份 MySQL 來源資料庫。如需完整和增量備份的範例命令，請參閱「其他資訊」一節。 | 資料庫管理員 | 
| （選用） 使用 Percona XtraBackup 進行增量備份。 | 增量備份可用來減少您需要套用的二進位日誌數量，以便將來源資料庫與 Aurora MySQL 同步。大型和交易密集型資料庫可能會在備份期間產生大量二進位日誌。透過取得增量備份並將其儲存在共用的 Amazon EFS 檔案系統上，您可以大幅縮短備份和上傳資料庫的時間。如需詳細資訊，請參閱「其他資訊」一節。繼續進行增量備份，直到您準備好開始遷移至 Aurora。 | 資料庫管理員 | 
| 準備備份。 | 在此步驟中，交易日誌會套用至備份期間進行中交易的備份。繼續將交易日誌 （僅限 --apply-log-only) 套用至每個增量備份，以合併備份，但上次備份除外。如需範例，請參閱「其他資訊」一節。在此步驟之後，完整的合併備份將以 \$1/<efs\$1mount\$1name>/fullbackup 顯示。 | 資料庫管理員 | 
| 壓縮並分割最終合併的備份。 | 在您準備最終的合併備份之後，請使用 tar、zip 和 split 命令來建立較小的備份壓縮檔案。如需範例，請參閱「其他資訊」一節。 | 資料庫管理員 | 

### 將備份還原至 Aurora MySQL 資料庫叢集
<a name="restore-the-backup-to-an-aurora-mysql-db-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將備份上傳至 Amazon S3。 | 存放備份檔案的 Amazon EFS 檔案系統會同時掛載在現場部署資料庫和 EC2 執行個體上，因此備份檔案隨時可供 EC2 執行個體使用。使用 Secure Shell (SSH) 連線至 EC2 執行個體，並將壓縮的備份檔案上傳至新的或現有的 S3 儲存貯體；例如：aws s3 sync \$1/<efs\$1mount\$1name>/fullbackup s3：//<bucket\$1name>/fullbackup。如需其他詳細資訊，請參閱「相關資源」一節中的連結。 | AWS DevOps | 
| 為 Aurora 建立服務角色以存取 Amazon S3。 | 使用信任 "rds.amazonaws.com" 和政策建立 IAM 角色，讓 Aurora 存取存放備份檔案的 S3 儲存貯體。所需的許可為 ListBucket、GetObject 和 GetObjectVersion。 | AWS DevOps | 
| 建立 Aurora 的聯網組態。 | 建立具有至少兩個可用區域的叢集資料庫子網路群組，以及允許傳出連線至來源資料庫的子網路路由表組態。建立安全群組，允許對外連線至現場部署資料庫，並允許管理員連線至 Aurora 資料庫叢集。如需詳細資訊，請參閱「相關資源」一節中的連結。 | AWS DevOps/資料庫管理員 | 
| 將備份還原至 Aurora MySQL 資料庫叢集。 | 從您上傳至 Amazon S3 的備份還原資料。指定來源資料庫的 MySQL 版本、提供上傳備份檔案的 S3 儲存貯體名稱和資料夾路徑字首 （例如「其他資訊」區段中的範例為「完整備份」)，並提供您建立的 IAM 角色，以授權 Aurora 存取 Amazon S3。 | AWS DevOps/資料庫管理員 | 
| 驗證 Aurora MySQL 資料庫。 | 根據從來源資料庫取得的計數，驗證還原的 Aurora 資料庫叢集中的結構描述和物件計數。 | 資料庫管理員 | 
| 設定 binlog 複寫。 | 在進行還原至 Aurora 資料庫叢集的最後一個備份之前，請使用您先前記下的二進位日誌序列。在來源資料庫上建立複寫使用者，並遵循「其他資訊」一節中的指示提供適當的權限、在 Aurora 上啟用複寫，並確認複寫是同步的。 | AWS DevOps/資料庫管理員 | 

## 相關資源
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-resources"></a>

**建立 Amazon EFS 檔案系統**
+ [建立安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#CreatingSecurityGroups) (Amazon VPC 文件）
+ [傳輸閘道 VPN 連接](https://docs.aws.amazon.com/vpc/latest/tgw/tgw-vpn-attachments.html) (Amazon VPC 文件）
+ [使用 AWS Transit Gateway 擴展 VPN 輸送量](https://aws.amazon.com/blogs/networking-and-content-delivery/scaling-vpn-throughput-using-aws-transit-gateway/) （網路與內容交付部落格）
+ [建立 Amazon EFS 檔案系統](https://docs.aws.amazon.com/efs/latest/ug/efs-onpremises.html#wt5-step1-efs) (Amazon EFS 文件）
+ [建立掛載目標](https://docs.aws.amazon.com/efs/latest/ug/accessing-fs.html) (Amazon EFS 文件）
+ [加密靜態資料 ](https://docs.aws.amazon.com/efs/latest/ug/encryption-at-rest.html)(Amazon EFS 文件）

**掛載檔案系統**
+ [Amazon EC2 的 IAM 角色](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) (Amazon EC2 文件)
+ [啟動 Amazon EC2 Linux 執行個體 ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html#ec2-launch-instance)(Amazon EC2 文件）
+ [安裝 NFS 用戶端 ](https://docs.aws.amazon.com/efs/latest/ug/efs-onpremises.html#wt5-step4-install-nfs)(Amazon EFS 文件）
+ [在內部部署用戶端上掛載 Amazon EFS 檔案系統 ](https://docs.aws.amazon.com/efs/latest/ug/efs-onpremises.html#wt5-step3-connect)(Amazon EFS 文件）
+ [掛載 EFS 檔案系統](https://docs.aws.amazon.com/efs/latest/ug/mounting-fs.html) (Amazon EFS 文件）

**進行 MySQL 來源資料庫的備份**
+ [安裝 Percona XtraBackup 2.3](https://www.percona.com/doc/percona-xtrabackup/2.3/installation.html) (Percona XtraBackup 文件）
+ [安裝 Percona XtraBackup 2.4](https://www.percona.com/doc/percona-xtrabackup/2.4/installation.html) (Percona XtraBackup 文件） 
+ [設定複寫主組態 ](https://dev.mysql.com/doc/refman/5.7/en/replication-howto-masterbaseconfig.html)(MySQL 文件）
+ [將資料從外部 MySQL 資料庫遷移至 Aurora MySQL 資料庫叢集 ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Migrating.ExtMySQL.html)(Aurora 文件）
+ [增量備份](https://www.percona.com/doc/percona-xtrabackup/2.4/backup_scenarios/incremental_backup.html) (Percona XtraBackup 文件）

**將備份還原至 Amazon Aurora MySQL**
+ [建立儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#create-bucket-intro)體 (Amazon S3 文件）
+ [使用 SSH 連線至 Linux 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html) (Amazon Ec2 文件）
+ [設定 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) (AWS CLI 文件）
+ [sync 命令](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html) (AWS CLI 命令參考）
+ [建立 IAM 政策以存取 Amazon S3 資源](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.Authorizing.IAM.S3CreatePolicy.html) (Aurora 文件）
+ [資料庫叢集先決條件 ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html#Aurora.CreateInstance.Prerequisites)(Aurora 文件）
+ [使用資料庫子網路群組 ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html#USER_VPC.Subnets)(Aurora 文件）
+ [為私有資料庫執行個體建立 VPC 安全群組](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_Tutorials.WebServerDB.CreateVPC.html#CHAP_Tutorials.WebServerDB.CreateVPC.SecurityGroupDB) (Aurora 文件）
+ [從 S3 儲存貯體還原 Aurora MySQL 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Migrating.ExtMySQL.html#AuroraMySQL.Migrating.ExtMySQL.S3.Restore) (Aurora 文件）
+ [使用 MySQL 或其他 Aurora 資料庫叢集設定複寫 ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Replication.MySQL.html#AuroraMySQL.Replication.MySQL.SettingUp)(Aurora 文件）
+ [mysql.rds\$1set\$1external\$1master 程序](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql_rds_set_external_master.html) (Amazon RDS SQL 上的 MySQL 參考）
+ [mysql.rds\$1start\$1replication 程序](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql_rds_start_replication.html) (Amazon RDS SQL 上的 MySQL 參考）

**其他參考**
+ [將資料從外部 MySQL 資料庫遷移至 Aurora MySQL 資料庫叢集 ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Migrating.ExtMySQL.html)(Aurora 文件）
+ [MySQL 伺服器下載 ](https://downloads.mysql.com/archives/community/)(Oracle 網站）

**教學課程和影片**
+  [使用 Amazon S3 將 MySQL 資料遷移至 Aurora MySQL 資料庫叢集 ](https://aws.amazon.com/premiumsupport/knowledge-center/migrate-mysql-aurora-innobackup/)(AWS 知識中心）
+  [Amazon EFS 設定和掛載](https://www.youtube.com/watch?v=NR8rVsSn_dY) （影片）

## 其他資訊
<a name="migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3-additional"></a>

**安裝 NFS 用戶端**
+ 如果您使用的是 Red Hat 或類似的 Linux 作業系統，請使用 命令： 

```
$ sudo yum -y install nfs-utils
```
+ 如果您使用的是 Ubuntu 或類似的 Linux 作業系統，請使用 命令： 

```
$ sudo apt-get -y install nfs-common
```

如需詳細資訊，請參閱 Amazon EFS 文件中的[逐步解說](https://docs.aws.amazon.com/efs/latest/ug/efs-onpremises.html#wt5-step4-install-nfs)。

**掛載 Amazon EFS 檔案系統**

使用 命令：

```
mkdir ~/<efs_mount_name>
$ sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport mount-target-IP:/ ~/<efs_mount_name>
```

如需詳細資訊，請參閱 Amazon EFS 文件中的[逐步解說](https://docs.aws.amazon.com/efs/latest/ug/efs-onpremises.html#wt5-step3-connect)和掛載 EFS 檔案系統。 [ EFS ](https://docs.aws.amazon.com/efs/latest/ug/mounting-fs.html) 

**進行 MySQL 來源資料庫的備份**

*完整備份*

使用類似下列的命令，它會進行備份、壓縮，並將其分割成每個 1 GB 的較小區塊：

```
xtrabackup --backup --user=dbuser --password=<password> --binlog-info=AUTO --stream=tar --target-dir=~/<efs_mount_name>/fullbackup | gzip - | split -d --bytes=1024MB - ~/<efs_mount_name>/fullbackup/backup.tar.gz &
```

如果您打算在完整備份之後進行後續增量備份，請勿壓縮和分割備份。請改用類似以下的命令：

```
xtrabackup --backup --user=dbuser --password=<password> --target-dir=~/<efs_mount_name>/fullbackup/
```

*增量備份*

使用 `--incremental-basedir` 參數的完整備份路徑；例如：

```
xtrabackup --backup --user=dbuser --password=<password> --target-dir=~/<efs_mount_name>/incremental/backupdate --incremental-basedir=~/<efs_mount_name>/fullbackup
```

其中 *basedir* 是完整備份和 xtrabackup\$1checkpoints 檔案的路徑。

如需進行備份的詳細資訊，請參閱 [Aurora 文件中的將資料從外部 MySQL 資料庫遷移至 Amazon Aurora MySQL 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Migrating.ExtMySQL.html)。

**準備備份**

若要準備完整備份：

```
xtrabackup --prepare --apply-log-only --target-dir=~/<efs_mount_name>/fullbackup
```

若要準備增量備份：

```
xtrabackup --prepare --apply-log-only --target-dir=~/<efs_mount_name>/fullbackup --incremental-dir=~/<efs_mount_name>/incremental/06062020
```

若要準備最終備份：

```
xtrabackup --prepare --target-dir=~/<efs_mount_name>/fullbackup --incremental-dir=~/<efs_mount_name>/incremental/06072020
```

如需詳細資訊，請參閱 Percona XtraBackup 文件中的[增量備份](https://www.percona.com/doc/percona-xtrabackup/2.4/backup_scenarios/incremental_backup.html)。

**壓縮和分割合併的備份**

若要壓縮位於 \$1/<efs\$1mount\$1name>/fullbackup 的合併備份：

```
tar -zcvf <backupfilename.tar.gz> ~/<efs_mount_name>/fullbackup
```

若要分割備份：

```
split -d -b1024M --verbose  <backupfilename.tar.gz> <backupfilename.tar.gz>
```

**設定 binlog 複寫**

若要在來源資料庫上建立複寫使用者並提供適當的權限：

```
CREATE USER 'repl_user'@'' IDENTIFIED BY ''; GRANT REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'repl_user'@'';
```

若要透過連線至 Aurora 資料庫叢集在 Aurora 上啟用複寫，請在資料庫叢集參數群組中啟用二進位日誌。Set `binlog_format = mixed`（偏好混合模式）。此變更需要您重新啟動執行個體才能套用更新。

```
CALL mysql.rds_set_external_master ('sourcedbinstanceIP', sourcedbport, 'repl_user', '', 'binlog_file_name', binlog_file_position, 0); CALL mysql.rds_start_replication;
```

若要確認複寫是同步的：

```
SHOW Slave Status \G;
```

**主欄位後面的秒**數會顯示 Aurora 與內部部署資料庫的距離。

# 使用 AWS App2Container 將內部部署 Java 應用程式遷移至 AWS
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container"></a>

*Dhananjay Karanjkar，Amazon Web Services*

## 總結
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container-summary"></a>

AWS App2Container (A2C) 是一種命令列工具，可協助將虛擬機器中執行的現有應用程式轉換為容器，而不需要任何程式碼變更。A2C 會探索在伺服器上執行的應用程式、識別相依性，並產生相關成品，以便無縫部署至 Amazon Elastic Container Service (Amazon ECS) 和 Amazon Elastic Kubernetes Service (Amazon EKS)。

此模式提供透過工作者機器使用 App2Container 將部署在應用程式伺服器上的內部部署 Java 應用程式遠端遷移至 AWS Fargate 或 Amazon EKS 的步驟。 

工作者機器可用於下列使用案例：
+ 執行 Java 應用程式的應用程式伺服器上不允許或無法使用 Docker 安裝。
+ 您必須管理部署在不同實體或虛擬伺服器上的多個應用程式的遷移。

此模式使用 AWS CodeCommit AWS CodePipeline、 和 AWS CodeBuild。

## 先決條件和限制
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container-prereqs"></a>

**先決條件**
+ 在 Linux 伺服器上執行 Java 應用程式的應用程式伺服器
+ 具有 Linux 作業系統的工作者機器
+ 具有至少 20 GB 可用磁碟空間的工作者機器

**限制**
+ 並非所有應用程式都受到支援。如需詳細資訊，請參閱 [Linux 支援的應用程式](https://docs.aws.amazon.com/app2container/latest/UserGuide/supported-applications.html)。

## Architecture
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container-architecture"></a>

**來源技術堆疊**
+ 在 Linux 伺服器上執行的 Java 應用程式

**目標技術堆疊**
+ AWS CodeBuild
+ AWS CodeCommit
+ AWS CodeDeploy
+ AWS CodePipeline
+ Amazon Elastic Container Registry
+ AWS Fargate

**目標架構**

![\[AWS 上內部部署 Java 應用程式的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/61ed65a0-fab2-4fc8-8531-18bfd56a25b3/images/602cde7b-ab0c-46a5-8c37-afe304adf061.png)


 

## 工具
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container-tools"></a>

**工具**
+ [AWS App2Container](https://docs.aws.amazon.com/app2container/latest/UserGuide/what-is-a2c.html) – AWS App2Container (A2C) 是一種命令列工具，可協助您提升和轉移在內部部署資料中心或虛擬機器中執行的應用程式，使其在由 Amazon ECS 或 Amazon EKS 管理的容器中執行。
+ [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html) – AWS CodeBuild 是雲端中全受管的建置服務。CodeBuild 可編譯原始碼、執行單元測試，並產生可立即部署的成品。
+ [AWS CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html) – AWS CodeCommit 是由 Amazon Web Services 託管的版本控制服務，可用來在雲端中私下存放和管理資產 （例如文件、原始程式碼和二進位檔案）。
+ [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html) – AWS CodePipeline 是一種持續交付服務，可用來建立模型、視覺化和自動化發行軟體所需的步驟。
+ [Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) – Amazon Elastic Container Service (Amazon ECS) 是一種高度可擴展的快速容器管理服務，用於執行、停止和管理叢集上的容器。
+ [Amazon ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html) – Amazon Elastic Container Registry (Amazon ECR) 是一種 AWS 受管容器映像登錄服務，安全、可擴展且可靠。
+ [Amazon EKS](https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html) – Amazon Elastic Kubernetes Service (Amazon EKS) 是一項受管服務，可讓您在 AWS 上執行 Kubernetes，而無需安裝、操作和維護您自己的 Kubernetes 控制平面或節點。
+ [AWS Fargate](https://docs.aws.amazon.com/AmazonECS/latest/userguide/what-is-fargate.html) – AWS Fargate 是一種技術，您可以與 Amazon ECS 搭配使用來執行容器，而無需管理 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體的伺服器或叢集。使用 Fargate，就不再需要佈建、設定或擴展虛擬機器的叢集來執行容器。

## 史詩
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container-epics"></a>

### 設定登入資料
<a name="set-up-credentials"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立秘密以存取應用程式伺服器。 | 若要從工作者機器遠端存取應用程式伺服器，請在 AWS Secrets Manager 中建立秘密。對於您的秘密，您可以使用 SSH 私有金鑰或憑證和 SSH 私有金鑰。如需詳細資訊，請參閱[管理 AWS App2Container 的秘密](https://docs.aws.amazon.com/app2container/latest/UserGuide/manage-secrets.html)。 | DevOps、開發人員 | 

### 設定工作者機器
<a name="set-up-the-worker-machine"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 tar 檔案。 | 執行 `sudo yum install -y tar`。 | DevOps、開發人員 | 
| 安裝 AWS CLI。 | 若要安裝 Amazon Command Line Interface (AWS CLI)，請執行 `curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"`。 解壓縮 `awscliv2.zip`。執行 `sudo ./aws/install`。 | DevOps、開發人員 | 
| 安裝 App2Container。 | 執行下列命令：`curl -o AWSApp2Container-installer-linux.tar.gz https://app2container-release-us-east-1.s3.us-east-1.amazonaws.com/latest/linux/AWSApp2Container-installer-linux.tar.gz``sudo tar xvf AWSApp2Container-installer-linux.tar.gz``sudo ./install.sh` | DevOps、開發人員 | 
| 設定設定檔。 | 若要設定 AWS 預設設定檔，請執行 `sudo aws configure`。若要設定名為 AWS 的預設設定檔，請執行 `sudo aws configure --profile <profile name>`。 | DevOps、開發人員 | 
| 安裝 Docker. | 執行下列命令。`sudo yum install -y docker``sudo systemctl enable docker & sudo systemctl restart docker` |  | 
| 初始化 App2Container。 | 若要初始化 App2Container，您需要以下資訊：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-on-premises-java-applications-to-aws-using-aws-app2container.html)執行 `sudo app2container init`。 | DevOps、開發人員 | 

### 設定工作者機器
<a name="configure-the-worker-machine"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將工作者機器設定為遠端連線，並在應用程式伺服器上執行 App2Container 命令。 | 若要設定工作者機器，需要下列資訊：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-on-premises-java-applications-to-aws-using-aws-app2container.html)執行 `sudo app2container remote configure`。 | DevOps、開發人員 | 

### 在工作者機器上探索、分析和擷取應用程式
<a name="discover-analyze-and-extract-applications-on-the-worker-machine"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 探索內部部署 Java 應用程式。 | 若要遠端探索應用程式伺服器上執行的所有應用程式，請執行下列命令。`sudo app2container remote inventory --target <FQDN/IP of App server>`此命令會在 中產生已部署應用程式的清單`inventory.json`。 | DevOps 開發人員 DevOps | 
| 分析探索到的應用程式。 | 若要使用庫存階段中取得的應用程式 ID 遠端分析每個應用程式，請執行下列命令。`sudo app2container remote analyze --application-id <java-app-id> --target <FQDN/IP of App Server>`這會在工作區位置產生`analysis.json`檔案。產生此檔案後，您可以根據您的需求修改容器化參數。 | DevOps 開發人員 DevOps | 
| 擷取已分析的應用程式。 | 若要為分析的應用程式產生應用程式封存，請遠端執行下列命令，這會在工作區位置產生 tar 套件。`sudo app2container remote extract --application-id <application id> --target <FQDN/IP of App Server>`擷取的成品可以在本機工作者機器上產生。 | DevOps 開發人員 DevOps | 

### 在工作者機器上容器化擷取的成品
<a name="containerize-the-extracted-artifacts-on-the-worker-machine"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 容器化擷取的成品。 | 執行下列命令，將上一個步驟中擷取的成品容器化。`sudo app2container containerize --input-archive <tar bundle location on worker machine>` | DevOps 開發人員 DevOps | 
| 完成目標。 | 若要完成目標，請開啟 `deployment.json`在`containerize`命令執行時建立的 。若要指定 AWS Fargate 做為目標，請將 `createEcsArtifacts`設定為 `true`。若要將 Amazon EKS 設定為目標，請將 `createEksArtifacts` 設為 true。 | DevOps 開發人員 DevOps | 

### 產生和佈建 AWS 成品
<a name="generate-and-provision-aws-artifacts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在工作者機器上產生 AWS 部署成品。 | 若要產生部署成品，請執行下列命令。`sudo app2container generate app-deployment --application-id <application id>`這會在工作區中產生 `ecs-master.yml` AWS CloudFormation 範本。 | DevOps | 
| 佈建成品。 | 若要進一步佈建產生的成品，請執行下列命令來部署 AWS CloudFormation 範本。`aws cloudformation deploy --template-file <path to ecs-master.yml> --capabilities CAPABILITY_NAMED_IAM --stack-name <application id>–ECS` | DevOps | 
| 產生管道。 | 根據您的需求修改在上一個故事中建立`pipeline.json`的 。然後執行 `generate pipeline`命令來產生管道部署成品。 | DevOps | 

## 相關資源
<a name="migrate-on-premises-java-applications-to-aws-using-aws-app2container-resources"></a>
+ [什麼是 App2Container？](https://docs.aws.amazon.com/app2container/latest/UserGuide/what-is-a2c.html)
+ [AWS App2Container 部落格文章](https://aws.amazon.com/blogs/aws/aws-app2container-a-new-containerizing-tool-for-java-and-asp-net-applications/)
+ [AWS CLI 組態基本概念](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html)
+ [Amazon ECS 的 Docker 基本概念](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html)
+ [Docker 命令](https://docs.docker.com/engine/reference/commandline/cli/)

# 在 AWS 大型遷移中遷移共用檔案系統
<a name="migrate-shared-file-systems-in-an-aws-large-migration"></a>

*Amit Rudraraju、Sam Apa、Bheemeswararao Balla、Wally Lu 和 Sanjeev Prakasam、Amazon Web Services*

## 總結
<a name="migrate-shared-file-systems-in-an-aws-large-migration-summary"></a>

遷移 300 個以上的伺服器會被視為*大型遷移*。大型遷移的目的是將工作負載從現有的現場部署資料中心遷移到 AWS 雲端，這些專案通常專注於應用程式和資料庫工作負載。不過，共用檔案系統需要集中注意力和單獨的遷移計畫。此模式說明共用檔案系統的遷移程序，並提供在大型遷移專案中成功遷移它們的最佳實務。

*共用檔案系統* (SFS) 也稱為*網路*或*叢集*檔案系統，是掛載到多個伺服器的檔案共用。共用檔案系統可透過網路檔案系統 (NFS)、通用網際網路檔案系統 (CIFS) 或伺服器訊息區塊 (SMB) 等通訊協定存取。

這些系統不會使用標準遷移工具進行遷移，例如， AWS Application Migration Service 因為它們既不專用於要遷移的主機，也不表示為區塊型設備。雖然大多數主機相依性都是透明遷移的，但相依檔案系統的協調和管理必須分別處理。

您會在下列階段遷移共用檔案系統：探索、規劃、準備、切換和驗證。使用此模式和連接的手冊，您可以將共用檔案系統遷移至 AWS 儲存服務，例如 Amazon Elastic File System (Amazon EFS)、Amazon FSx for NetApp ONTAP 或 Amazon FSx for Windows File Server。若要傳輸檔案系統，您可以使用 AWS DataSync 或第三方工具，例如 NetApp SnapMirror。

**注意**  
此模式是有關[大型遷移到 AWS 雲端](https://aws.amazon.com/prescriptive-guidance/large-migrations/) AWS 的規範性指引系列的一部分。此模式包含將 SFSs 整合到伺服器的波浪計劃的最佳實務和指示。如果您要在大型遷移專案之外遷移一或多個共用檔案系統，請參閱 [Amazon EFS](https://docs.aws.amazon.com/efs/latest/ug/trnsfr-data-using-datasync.html)、[Amazon FSx for Windows File Server](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/migrate-to-fsx.html) 和 [Amazon FSx for NetApp ONTAP](https://docs.aws.amazon.com/fsx/latest/ONTAPGuide/migrating-fsx-ontap.html) AWS 文件中的資料傳輸說明。

## 先決條件和限制
<a name="migrate-shared-file-systems-in-an-aws-large-migration-prereqs"></a>

**先決條件**

先決條件可能會根據您的來源和目標共用檔案系統和您的使用案例而有所不同。以下是最常見的：
+ 作用中 AWS 帳戶。
+ 您已完成大型遷移專案的應用程式產品組合探索，並開始開發波動計畫。如需詳細資訊，請參閱[AWS 大型遷移的產品組合手冊](https://docs.aws.amazon.com/prescriptive-guidance/latest/large-migration-portfolio-playbook/welcome.html)。
+ 虛擬私有雲端 (VPCs) 和安全群組，允許內部部署資料中心與您的 AWS 環境之間的輸入和輸出流量。如需詳細資訊，請參閱[網路對 Amazon VPC 連線選項](https://docs.aws.amazon.com/whitepapers/latest/aws-vpc-connectivity-options/network-to-amazon-vpc-connectivity-options.html)和[AWS DataSync 網路需求](https://docs.aws.amazon.com/datasync/latest/userguide/datasync-network.html)。
+ 建立 AWS CloudFormation 堆疊的許可或建立 Amazon EFS 或 Amazon FSx 資源的許可。如需詳細資訊，請參閱 [CloudFormation 文件](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html)、[Amazon EFS 文件](https://docs.aws.amazon.com/efs/latest/ug/security-iam.html)或 [Amazon FSx 文件](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/security-iam.html)。
+ 如果您使用 AWS DataSync 執行遷移，則需要下列許可：
  +  AWS DataSync 將日誌傳送至 Amazon CloudWatch Logs 日誌群組的許可。如需詳細資訊，請參閱[允許 DataSync 將日誌上傳至 CloudWatch 日誌群組](https://docs.aws.amazon.com/datasync/latest/userguide/monitor-datasync.html#cloudwatchlogs)。
  + 存取 CloudWatch Logs 日誌群組的許可。如需詳細資訊，請參閱[管理 CloudWatch Logs 資源存取許可的概觀](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/iam-access-control-overview-cwl.html)。
  + 在 DataSync 中建立客服人員和任務的許可。如需詳細資訊，請參閱[使用 所需的 IAM 許可 AWS DataSync](https://docs.aws.amazon.com/datasync/latest/userguide/permissions-requirements.html)。

**限制**
+ 此模式旨在將 SFSs 遷移為大型遷移專案的一部分。它包含將 SFSs 併入您遷移應用程式的波浪計劃的最佳實務和說明。如果您要在大型遷移專案之外遷移一或多個共用檔案系統，請參閱 [Amazon EFS](https://docs.aws.amazon.com/efs/latest/ug/trnsfr-data-using-datasync.html)、[Amazon FSx for Windows File Server](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/migrate-to-fsx.html) 和 [Amazon FSx for NetApp ONTAP](https://docs.aws.amazon.com/fsx/latest/ONTAPGuide/migrating-fsx-ontap.html) AWS 文件中的資料傳輸說明。
+ 此模式是以常用的架構、服務和遷移模式為基礎。不過，大型遷移專案和策略可能因組織而異。您可能需要根據您的需求自訂此解決方案或提供的手冊。

## Architecture
<a name="migrate-shared-file-systems-in-an-aws-large-migration-architecture"></a>

**來源技術堆疊**

下列一個或多個：
+ Linux (NFS) 檔案伺服器
+ Windows (SMB) 檔案伺服器
+ NetApp 儲存陣列
+ Dell EMC Isilon 儲存陣列

**目標技術堆疊**

下列一個或多個：
+ Amazon Elastic File System
+ Amazon FSx for NetApp ONTAP
+ Amazon FSx for Windows File Server

**目標架構**

![\[使用 AWS DataSync 將內部部署共用檔案系統遷移至 AWS 的架構圖。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a30cf791-7a8a-4f71-8927-bc61f3b332f2/images/13232433-7d33-44c8-8998-b720f33f67b3.png)


圖表顯示下列程序：

1. 您可以使用 AWS Direct Connect 或 AWS 服務 等 AWS 雲端 ，在現場部署資料中心與 之間建立連線 AWS Site-to-Site VPN。

1. 您可以在內部部署資料中心安裝 DataSync 代理程式。

1. 根據您的波動計畫，您可以使用 DataSync 將來源共用檔案系統的資料複寫至目標 AWS 檔案共用。

**遷移階段**

下圖顯示在大型遷移專案中遷移 SFS 的階段和高階步驟。

![\[探索、規劃、準備、切換和驗證將共用檔案系統遷移至 AWS 的階段。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a30cf791-7a8a-4f71-8927-bc61f3b332f2/images/f1e0c94d-0eea-46a8-bdec-3297b34c1d43.png)


此模式的 [Epics](#migrate-shared-file-systems-in-an-aws-large-migration-epics) 區段包含有關如何完成遷移和使用連接工作手冊的詳細說明。以下是此分階段方法中步驟的高階概觀。


| 
| 
| 階段 | 步驟 | 
| --- |--- |
| 探索 | 1. 使用探索工具，您可以收集共用檔案系統的資料，包括伺服器、掛載點和 IP 地址。2. 使用組態管理資料庫 (CMDB) 或遷移工具，您可以收集伺服器的詳細資訊，包括遷移波動、環境、應用程式擁有者、IT 服務管理 (ITSM) 服務名稱、組織單位和應用程式 ID 的相關資訊。 | 
| 計畫 | 3. 使用 SFSs和伺服器所收集的資訊，建立 SFS 波動計畫。4. 使用建置工作表中的資訊，為每個 SFS 選擇目標 AWS 服務 和遷移工具。 | 
| 準備 | 5. 在 Amazon EFS、Amazon FSx for NetApp ONTAP 或 Amazon FSx for Windows File Server 中設定目標基礎設施。6. 設定資料傳輸服務，例如 DataSync，然後啟動初始資料同步。當初始同步完成時，您可以設定重複發生的同步以排程執行，7. 使用目標檔案共享的相關資訊更新 SFS 波動計畫，例如 IP 地址或路徑。 | 
| 剪下 | 8. 停止主動存取來源 SFS 的應用程式。9. 在資料傳輸服務中，執行最終資料同步。10. 同步完成時，請檢閱 CloudWatch Logs 中的日誌資料，以驗證是否完全成功。 | 
| 驗證 | 11. 在伺服器上，將掛載點變更為新的 SFS 路徑。12. 重新啟動並驗證應用程式。 | 

## 工具
<a name="migrate-shared-file-systems-in-an-aws-large-migration-tools"></a>

**AWS 服務**
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 可協助您集中所有系統、應用程式的日誌， AWS 服務 以便您可以監控日誌並將其安全地存檔。
+ [AWS DataSync](https://docs.aws.amazon.com/datasync/latest/userguide/what-is-datasync.html) 是一種線上資料傳輸和探索服務，可協助您在 AWS 儲存服務之間來回移動檔案或物件資料。
+ [Amazon Elastic File System (Amazon EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) 協助您在 AWS 雲端中建立和設定共用檔案系統。
+ [Amazon FSx](https://docs.aws.amazon.com/fsx/?id=docs_gateway) 提供檔案系統，可支援業界標準的連線通訊協定，並提供高可用性和跨系統複寫 AWS 區域。

**其他工具**
+ [SnapMirror](https://library.netapp.com/ecmdocs/ECMP1196991/html/GUID-BA1081BE-B2BB-4C6E-8A82-FB0F87AC514E.html) 是一種 NetApp 資料複寫工具，可將資料分別從指定的來源磁碟區或[樹狀目錄](https://library.netapp.com/ecmdocs/ECMP1154894/html/GUID-8F084F85-2AB8-4622-B4F3-2D9E68559292.html)複寫到目標磁碟區或樹狀目錄。您可以使用此工具將 NetApp 來源檔案系統遷移至 Amazon FSx for NetApp ONTAP。
+ [Robocopy](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy) 短於*強式檔案複製*，是 Windows 的命令列目錄和命令。您可以使用此工具將 Windows 來源檔案系統遷移至 Amazon FSx for Windows File Server。

## 最佳實務
<a name="migrate-shared-file-systems-in-an-aws-large-migration-best-practices"></a>

**波規劃方法**

為您的大型遷移專案規劃波浪時，請考慮延遲和應用程式效能。當 SFS 和相依應用程式在不同位置操作時，例如一個在雲端，另一個在內部部署資料中心，這可能會增加延遲並影響應用程式效能。以下是建立波動計畫時的可用選項：

1. **在同一波內遷移 SFS 和所有相依伺服器** – 此方法可防止效能問題，並將重做降至最低，例如多次重新設定掛載點。當應用程式和 SFS 之間需要非常低的延遲時，建議使用此選項。不過，波動規劃很複雜，目標是從相依性分組中移除變數，而不是新增到它們。此外，如果許多伺服器存取相同的 SFS，則不建議使用此方法，因為它會使波動過大。

1. **在遷移最後一個相依伺服器之後遷移 SFS **– 例如，如果多個伺服器存取 SFS，且這些伺服器排程在波 4、6 和 7 中遷移，請排程 SFS 在波 7 中遷移。

   這種方法通常是大型遷移最符合邏輯的方法，建議用於對延遲敏感的應用程式。它可降低與資料傳輸相關的成本。它也可以將 SFS 和更高層級 （例如生產） 應用程式之間的延遲期間降至最低，因為在開發和 QA 應用程式之後，更高層級的應用程式通常會排程為最後遷移。

   不過，這種方法仍然需要探索、規劃和敏捷性。您可能需要在較早的波動中遷移 SFS。確認應用程式可以在第一個相依波與包含 SFS 的波之間的時間內承受額外的延遲。與應用程式擁有者進行探索工作階段，並將應用程式遷移至對延遲最敏感的應用程式。如果在遷移相依應用程式後發現效能問題，請準備好盡快進行樞紐，以盡快遷移 SFS。

1. **在大型遷移專案結束時遷移 SFS **– 如果延遲不是一個因素，例如當 SFS 中的資料不常存取或不對應用程式效能至關重要時，建議使用此方法。此方法可簡化遷移，並簡化切換任務。

您可以根據應用程式的延遲敏感度來混合這些方法。例如，您可以使用方法 1 或 2 遷移對延遲敏感SFSs，然後使用方法 3 遷移其餘SFSs。

**選擇 AWS 檔案系統服務**

AWS 為檔案儲存提供數種雲端服務。每個 都為效能、擴展、可存取性、整合、合規和成本最佳化提供不同的優點和限制。有一些邏輯預設選項。例如，如果您目前的現場部署檔案系統正在操作 Windows Server，則 Amazon FSx for Windows File Server 是預設選項。或者，如果內部部署檔案系統正在操作 NetApp ONTAP，則 Amazon FSx for NetApp ONTAP 是預設選項。不過，您可以根據您的應用程式需求或實現其他雲端操作優勢，選擇目標服務。如需詳細資訊，請參閱[為您的部署選擇正確的 AWS 檔案儲存服務](https://d1.awsstatic.com/events/Summits/awsnycsummit/Choosing_the_right_AWS_file_storage_service_for_your_deployment_STG302.pdf)AWS (Summit presentation)。

**選擇遷移工具**

Amazon EFS 和 Amazon FSx 支援使用 AWS DataSync 將共用檔案系統遷移至 AWS 雲端。如需支援的儲存系統和服務、優點和使用案例的詳細資訊，請參閱[什麼是 AWS DataSync](https://docs.aws.amazon.com/datasync/latest/userguide/what-is-datasync.html) 。如需使用 DataSync 傳輸檔案的程序概觀，請參閱[AWS DataSync 傳輸的運作方式](https://docs.aws.amazon.com/datasync/latest/userguide/how-datasync-transfer-works.html)。

也有數種可用的第三方工具，包括下列項目：
+ 如果您選擇 Amazon FSx for NetApp ONTAP，您可以使用 NetApp SnapMirror 將檔案從內部部署資料中心遷移至雲端。SnapMirror 使用區塊層級複寫，可以比 DataSync 更快，並減少資料傳輸程序的持續時間。如需詳細資訊，請參閱[使用 NetApp SnapMirror 遷移至 FSx for ONTAP](https://docs.aws.amazon.com/fsx/latest/ONTAPGuide/migrating-fsx-ontap-snapmirror.html)。
+ 如果您選擇 Amazon FSx for Windows File Server，您可以使用 Robocopy 將檔案遷移至雲端。如需詳細資訊，請參閱[使用 Robocopy 將現有檔案遷移至 FSx for Windows File Server](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/migrate-files-to-fsx.html)。

## 史詩
<a name="migrate-shared-file-systems-in-an-aws-large-migration-epics"></a>

### 探索
<a name="discover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備 SFS 探索工作手冊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師，遷移負責人 | 
| 收集來源 SFS 的相關資訊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師，遷移負責人 | 
| 收集伺服器的相關資訊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師，遷移負責人 | 

### 計畫
<a name="plan"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建置 SFS 波動計畫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 組建領導、Cutover 領導、遷移工程師、遷移領導 | 
| 選擇目標 AWS 服務 和遷移工具。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師，遷移負責人 | 

### 準備
<a name="prepare"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定目標檔案系統。 | 根據您的波動計畫中記錄的詳細資訊，在目標、 AWS 帳戶 VPC 和子網路中設定目標檔案系統。如需說明，請參閱下列 AWS 文件：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師、遷移負責人、AWS 管理員 | 
| 設定遷移工具和傳輸資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | AWS 管理員、雲端管理員、遷移工程師、遷移主管 | 
| 更新波動計畫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師，遷移負責人 | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止應用程式。 | 如果應用程式或用戶端正在來源 SFS 中主動執行讀取和寫入操作，請在執行最終資料同步之前停止它們。如需說明，請參閱應用程式文件或停止讀取和寫入活動的內部程序。例如，請參閱[啟動或停止 Web 伺服器 (IIS 8)](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/jj635851(v=ws.11)) (Microsoft 文件） 或使用 [systemctl 管理系統服務](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/managing-systemd_configuring-basic-system-settings#managing-system-services-with-systemctl_managing-systemd) (Red Hat 文件）。 | 應用程式擁有者、應用程式開發人員 | 
| 執行最終資料傳輸。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | 遷移工程師，遷移負責人 | 
| 驗證資料傳輸。 | 如果您使用的是 AWS DataSync，請執行下列動作來驗證已成功完成的最終資料傳輸：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html)如果您使用第三方工具，請參閱所選遷移工具文件中的資料傳輸驗證說明。 | 遷移工程師，遷移負責人 | 

### 驗證
<a name="validate"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 重新掛載檔案系統並驗證應用程式函數和效能。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-shared-file-systems-in-an-aws-large-migration.html) | AWS 系統管理員、應用程式擁有者 | 

## 疑難排解
<a name="migrate-shared-file-systems-in-an-aws-large-migration-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Microsoft Excel 中的儲存格值不會更新。 | 拖曳填充控點，複製範例資料列中的公式。如需詳細資訊，請參閱 [Windows ](https://support.microsoft.com/en-us/office/fill-a-formula-down-into-adjacent-cells-041edfe2-05bc-40e6-b933-ef48c3f308c6)或 [Mac](https://support.microsoft.com/en-au/office/copy-a-formula-by-dragging-the-fill-handle-in-excel-for-mac-dd928259-622b-473f-9a33-83aa1a63e218) 的說明 (Microsoft Support 網站）。 | 

## 相關資源
<a name="migrate-shared-file-systems-in-an-aws-large-migration-resources"></a>

**AWS 文件**
+ [AWS DataSync 文件](https://docs.aws.amazon.com/datasync/latest/userguide/what-is-datasync.html)
+ [Amazon EFS 文件](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html)
+ [Amazon FSx 文件](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/index.html)
+ [大型遷移至 AWS 雲端](https://aws.amazon.com/prescriptive-guidance/large-migrations/)
  + [AWS 大型遷移指南](https://docs.aws.amazon.com/prescriptive-guidance/latest/large-migration-guide/welcome.html)
  + [AWS 大型遷移的產品組合手冊](https://docs.aws.amazon.com/prescriptive-guidance/latest/large-migration-portfolio-playbook/welcome.html)

**疑難排解**
+ [故障診斷 AWS DataSync 問題](https://docs.aws.amazon.com/datasync/latest/userguide/troubleshooting-datasync.html)
+ [Amazon EFS 故障診斷](https://docs.aws.amazon.com/efs/latest/ug/troubleshooting.html)
+ [Amazon FSx for Windows File Server 故障診斷](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/troubleshooting.html)
+ [對 Amazon FSx for NetApp ONTAP 進行故障診斷](https://docs.aws.amazon.com/fsx/latest/ONTAPGuide/troubleshooting.html)

## 附件
<a name="attachments-a30cf791-7a8a-4f71-8927-bc61f3b332f2"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/a30cf791-7a8a-4f71-8927-bc61f3b332f2/attachments/attachment.zip)

# 使用 Oracle GoldenGate 平面檔案轉接器，將 Oracle 資料庫遷移至 Amazon RDS for Oracle
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters"></a>

*Dhairya Jindani 和 Baji Shaik，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-summary"></a>

Oracle GoldenGate 是異質資料庫和 IT 環境的即時資料擷取和複寫服務。不過，此服務目前不支援 Amazon Relational Database Service (Amazon RDS) for Oracle。如需支援的資料庫清單，請參閱 [Oracle GoldenGate for Heterogeneous Databases](https://docs.oracle.com/goldengate/c1230/gg-winux/GGHDB/12.3-what-is-oracle-goldengate-heterogeneous-databases.htm#GGHDB-GUID-08EAC588-F76C-4E37-BEBA-0DC57B98CA46) (Oracle 文件）。此模式說明如何使用 Oracle GoldenGate 和 Oracle GoldenGate 平面檔案轉接器從來源 Oracle 資料庫產生平面檔案，該資料庫可以是內部部署或在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上。然後，您可以將這些一般檔案匯入 Amazon RDS for Oracle 資料庫執行個體。

在此模式中，您可以使用 Oracle GoldenGate 從來源 Oracle 資料庫擷取追蹤檔案。資料幫浦會將追蹤檔案複製到整合伺服器，即 Amazon EC2 執行個體。在整合伺服器上，Oracle GoldenGate 會使用平面檔案轉接器，根據線索檔案的傳輸資料擷取產生一系列循序平面檔案。Oracle GoldenGate 會將資料格式化為分隔符號分隔值或長度分隔值。然後，您可以使用 Oracle SQL\$1Loader 將一般檔案匯入目標 Amazon RDS for Oracle 資料庫執行個體。

**目標對象**

此模式適用於具有 Oracle GoldenGate 基礎建置區塊經驗和知識的人員。如需詳細資訊，請參閱 [Oracle GoldenGate 架構概觀 ](https://docs.oracle.com/goldengate/1212/gg-winux/GWUAD/wu_about_gg.htm#GWUAD115)(Oracle 文件）。

## 先決條件和限制
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ Oracle GoldenGate 授權。
+ Oracle GoldenGate 轉接器的個別授權。
+ 來源 Oracle 資料庫，可在內部部署或在 Amazon EC2 執行個體上執行。
+ 用作整合伺服器的 Amazon EC2 Linux 執行個體。如需詳細資訊，請參閱[開始使用 Amazon EC2 Linux 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html) (Amazon EC2 文件）。
+ 目標 Amazon RDS for Oracle 資料庫執行個體。如需詳細資訊，請參閱[建立 Oracle 資料庫執行個體 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.Oracle.html)(Amazon RDS 文件）。

**產品版本**
+ Oracle Database Enterprise Edition 10g、11g、12c 或更新版本
+ Oracle GoldenGate 12.2.0.1.1 版或更新版本

## Architecture
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-architecture"></a>

**來源技術堆疊**

Oracle 資料庫 （內部部署或 Amazon EC2 執行個體）

**目標技術堆疊**

Amazon RDS for Oracle

**來源和目標架構**

![\[使用 Oracle GoldenGate 轉接器將 Oracle 資料庫遷移至 Amazon RDS for Oracle。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f34961f7-aa9a-41cb-b1ea-522e36ef2f67/images/21ef5177-e669-4591-aced-28d2f22decf2.png)


1. Oracle GoldenGate 從來源資料庫日誌中擷取追蹤。

1. 資料幫浦會擷取線索，並將其遷移至整合伺服器。

1. Oracle GoldenGate 平面檔案轉接器會讀取線索、來源定義和擷取參數。

1. 您結束擷取，這會產生控制檔案和一般資料檔案。

1. 您可以將一般資料檔案遷移至 中的 Amazon RDS for Oracle 資料庫執行個體 AWS 雲端。

## 工具
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) for Oracle 可協助您在 中設定、操作和擴展 Oracle 關聯式資料庫 AWS 雲端。

**其他服務**
+ [Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GWUAD/wu_about_gg.htm#GWUAD110) 是一種服務，可協助您將資料從一個資料庫複寫、篩選和轉換到另一個異質資料庫或另一個目標拓撲，例如一般檔案。
+ [Oracle GoldenGate 應用程式轉接器](https://docs.oracle.com/goldengate/gg121211/gg-adapter/GADAD/flatfile_config.htm#GADAD424)可讓 Oracle GoldenGate 從來源資料庫的追蹤檔案中擷取的交易資料產生一系列序列平面檔案和控制檔案。這些轉接器廣泛用於資料倉儲應用程式和專屬或舊版應用程式中的擷取、轉換和載入 (ETL) 操作。Oracle GoldenGate 會執行此擷取，並在異質資料庫、平台和作業系統之間近乎即時地套用。轉接器支援不同的輸出檔案格式，例如 CSV 或 Apache Parquet。您可以載入這些產生的檔案，以便將資料載入不同的異質資料庫。

## 史詩
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-epics"></a>

### 在來源資料庫伺服器上設定 Oracle GoldenGate
<a name="set-up-oracle-goldengate-on-the-source-database-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 Oracle GoldenGate。 | 在來源資料庫伺服器上，下載 Oracle GoldenGate 12.2.0.1.1 版或更新版本。如需說明，請參閱[下載 Oracle GoldenGate ](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/install.htm#GIORA164)(Oracle 文件）。 | DBA | 
| 安裝 Oracle GoldenGate。 | 如需說明，請參閱[安裝 Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/install.htm#GIORA162) (Oracle 文件）。 | DBA | 
| 設定 Oracle GoldenGate。 | 如需說明，請參閱[準備 Database for Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/setup.htm#GIORA357) (Oracle 文件）。 | DBA | 

### 在整合伺服器上設定 Oracle GoldenGate
<a name="set-up-oracle-goldengate-on-the-integration-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 Oracle GoldenGate。 | 在整合伺服器上，下載 Oracle GoldenGate 12.2.0.1.1 版或更新版本。如需說明，請參閱[下載 Oracle GoldenGate ](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/install.htm#GIORA164)(Oracle 文件）。 | DBA | 
| 安裝 Oracle GoldenGate。 | 建立目錄、設定管理員程序，以及為異質環境建立 `defgen` 檔案。如需說明，請參閱[安裝 Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/install.htm#GIORA162) (Oracle 文件）。 | DBA | 

### 變更 Oracle GoldenGate 資料擷取組態
<a name="change-the-oracle-goldengate-data-capture-configuration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備 Oracle GoldenGate 轉接器。 | 在整合伺服器上，設定 Oracle GoldenGate 轉接器軟體。請執行下列操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters.html) | DBA | 
| 設定資料幫浦。 | 在來源伺服器上，設定資料幫浦，將追蹤檔案從來源伺服器傳輸到整合伺服器。建立資料幫浦參數檔案和線索檔案目錄。如需說明，請參閱[設定平面檔案轉接器 ](https://docs.oracle.com/goldengate/gg12201/gg-adapter/GADAD/GUID-DF13488D-E0E9-497C-8AFF-70B839DE4843.htm#GADAD424)(Oracle 文件）。 | DBA | 

### 產生和遷移一般檔案
<a name="generate-and-migrate-the-flat-files"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 產生一般檔案。 | 建立擷取檔案和控制檔案，然後在整合伺服器上啟動擷取程序。這會擷取資料庫變更，並將來源資料庫寫入一般檔案。如需說明，請參閱[使用平面檔案轉接器 ](https://docs.oracle.com/goldengate/gg12201/gg-adapter/GADAD/GUID-D30CC70D-B90F-4209-BEB5-9BA53EA869EF.htm#GADAD432)(Oracle 文件）。 | DBA | 
| 將一般檔案載入目標資料庫。 | 將一般檔案載入目標 Amazon RDS for Oracle 資料庫執行個體。如需詳細資訊，請參閱[使用 Oracle SQL\$1Loader 匯入](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Procedural.Importing.SQLLoader.html) (Amazon RDS 文件）。 | DBA | 

## 疑難排解
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Oracle GoldenGate 平面檔案轉接器會產生錯誤。 | 如需轉接器錯誤的描述，請參閱[尋找錯誤訊息](https://docs.oracle.com/goldengate/gg12201/gg-adapter/GADAD/GUID-D30CC70D-B90F-4209-BEB5-9BA53EA869EF.htm#GADAD437) (Oracle 文件）。如需故障診斷說明，請參閱[故障診斷平面檔案轉接器 ](https://docs.oracle.com/goldengate/gg12201/gg-adapter/GADAD/GUID-CB3D9B2C-49CC-408A-8C00-06E0C7923DD6.htm#GADAD552)(Oracle 文件）。 | 

## 相關資源
<a name="migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters-resources"></a>
+ [安裝 Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/install.htm#GIORA162) (Oracle 文件）
+ [設定 Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/setup.htm#GIORA357) (Oracle 文件）
+ [了解 Oracle GoldenGate 轉接器 ](https://docs.oracle.com/goldengate/gg12201/gg-adapter/GADAD/GUID-F9105B02-9836-4F98-99F8-6E9C46D42764.htm#GADAD101)(Oracle 文件）
+ [設定平面檔案轉接器 ](https://docs.oracle.com/goldengate/gg12201/gg-adapter/GADAD/GUID-DF13488D-E0E9-497C-8AFF-70B839DE4843.htm#GADAD424)(Oracle 文件）

# 變更 Python 和 Perl 應用程式，以支援從 Microsoft SQL Server 到 Amazon Aurora PostgreSQL 相容版本的資料庫遷移
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition"></a>

*Dwarika Patra 和 Deepesh Jayaprakash，Amazon Web Services*

## 總結
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-summary"></a>

此模式說明將資料庫從 Microsoft SQL Server 遷移至 Amazon Aurora PostgreSQL 相容版本時可能需要的應用程式儲存庫變更。模式假設這些應用程式是以 Python 為基礎或以 Perl 為基礎，並提供這些指令碼語言的個別指示。

將 SQL Server 資料庫遷移至 Aurora PostgreSQL 相容包含結構描述轉換、資料庫物件轉換、資料遷移和資料載入。由於 PostgreSQL 和 SQL Server 之間的差異 （與資料類型、連線物件、語法和邏輯相關），最困難的遷移任務涉及對程式碼基礎進行必要的變更，以便能夠正確搭配 PostgreSQL 使用。

對於 Python 型應用程式，連線物件和類別會分散在整個系統中。此外，Python 程式碼庫可能會使用多個程式庫來連線至資料庫。如果資料庫連線界面變更，執行應用程式內嵌查詢的物件也需要變更。

對於 Perl 型應用程式，變更涉及連線物件、資料庫連線驅動程式、靜態和動態內嵌 SQL 陳述式，以及應用程式如何處理複雜的動態 DML 查詢和結果集。

遷移應用程式時，您也可以考慮 AWS 上可能的增強功能，例如將 FTP 伺服器取代為 Amazon Simple Storage Service (Amazon S3) 存取。

應用程式遷移程序涉及下列挑戰：
+ 連線物件。如果連線物件分散在具有多個程式庫和函數呼叫的程式碼中，您可能需要找到一種一般方法來變更它們以支援 PostgreSQL。
+ 在記錄擷取或更新期間處理錯誤或例外狀況。如果您在傳回變數、結果集或資料影格的資料庫上有條件式建立、讀取、更新和刪除 (CRUD) 操作，任何錯誤或例外狀況都可能導致具有層疊效果的應用程式錯誤。這些應該透過適當的驗證和儲存點仔細處理。其中一個儲存點是在`BEGIN...EXCEPTION...END`區塊內呼叫大型內嵌 SQL 查詢或資料庫物件。
+ 控制交易及其驗證。這些包括手動和自動遞交和轉返。適用於 Perl 的 PostgreSQL 驅動程式需要您一律明確設定自動遞交屬性。
+ 處理動態 SQL 查詢。這需要深入了解查詢邏輯和反覆測試，以確保查詢如預期般運作。
+ 效能。您應該確保程式碼變更不會導致應用程式效能降低。

此模式會詳細說明轉換程序。

## 先決條件和限制
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-prereqs"></a>

**先決條件**
+ Python 和 Perl 語法的工作知識。
+ SQL Server 和 PostgreSQL 中的基本技能。
+ 了解您現有的應用程式架構。
+ 存取您的應用程式碼、SQL Server 資料庫和 PostgreSQL 資料庫。
+ 使用用於開發、測試和驗證應用程式變更的登入資料來存取 Windows 或 Linux （或其他 Unix) 開發環境。
+ 對於 Python 型應用程式，您的應用程式可能需要的標準 Python 程式庫，例如 **Pandas** 來處理資料影格，以及 **psycopg2** 或 **SQLAlchemy** 用於資料庫連線。
+ 對於 Perl 型應用程式，需要具有相依程式庫或模組的 Perl 套件。Comprehensive Perl Archive Network (CPAN) 模組可支援大多數應用程式需求。
+ 所有必要的相依自訂程式庫或模組。 
+ 用於 SQL Server 讀取存取和 Aurora 讀取/寫入存取的資料庫登入資料。
+ PostgreSQL 使用 服務和使用者來驗證和偵錯應用程式變更。
+ 在應用程式遷移期間存取開發工具，例如 Visual Studio Code、Sublime Text 或 **pgAdmin**。

**限制**
+ 有些 Python 或 Perl 版本、模組、程式庫和套件與雲端環境不相容。
+ 某些用於 SQL Server 的第三方程式庫和架構無法取代，以支援 PostgreSQL 遷移。 
+ 效能變化可能需要變更您的應用程式、內嵌 Transact-SQL (T-SQL) 查詢、資料庫函數和預存程序。
+ PostgreSQL 支援資料表名稱、資料欄名稱和其他資料庫物件的小寫名稱。 
+ 有些資料類型，例如 UUID 資料欄，只會以小寫儲存。Python 和 Perl 應用程式必須處理此類案例差異。 
+ 角色編碼差異必須使用 PostgreSQL 資料庫中對應文字資料欄的正確資料類型來處理。                               

**產品版本**
+ Python 3.6 或更新版本 （使用支援您作業系統的版本）
+ Perl 5.8.3 或更新版本 （使用支援您作業系統的 版本）
+ Aurora PostgreSQL 相容版本 4.2 或更新版本 （請參閱[詳細資訊](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Updates.20180305.html#AuroraPostgreSQL.Updates.20180305.42))

## Architecture
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-architecture"></a>

**來源技術堆疊**
+ 指令碼 （應用程式程式設計） 語言：Python 2.7 或更新版本，或 Perl 5.8 
+ 資料庫：Microsoft SQL Server 第 13 版
+ 作業系統：Red Hat Enterprise Linux (RHEL) 7 

**目標技術堆疊**
+ 指令碼 （應用程式程式設計） 語言：Python 3.6 或更新版本，或 Perl 5.8 或更新版本 
+ 資料庫：Aurora PostgreSQL 相容 4.2
+ 作業系統：RHEL 7 

**遷移架構**

![\[使用 SQL Server 將 Perl 或 Python 應用程式遷移至 Aurora PostgreSQL 相容\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/b64de64a-bd55-4db7-ba7b-0a2557862af1/images/b8fab3e2-ded5-4f58-86bf-3f645252e9fc.png)


## 工具
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-tools"></a>

**AWS 服務和工具**
+ [Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是全受管、PostgreSQL 相容且符合 ACID 規範的關聯式資料庫引擎，結合了高階商業資料庫的速度和可靠性，以及開放原始碼資料庫的成本效益。Aurora PostgreSQL 是 PostgreSQL 的下拉式選單，可讓您更輕鬆且更具成本效益地設定、操作和擴展新的和現有的 PostgreSQL 部署。
+ [AWS Command Line Interface (AWS CLI) ](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)是一種開放原始碼工具，可讓您在命令列 Shell 中使用命令與 AWS 服務互動。

**其他工具**
+ [Python](https://www.python.org/) 和 PostgresSQL 資料庫連線程式庫，例如 [psycopg2](https://pypi.org/project/psycopg2/) 和 [SQLAlchemy](https://www.sqlalchemy.org/)
+ [Perl](https://www.perl.org/) 及其 [DBI 模組](https://metacpan.org/pod/DBD::Pg)
+ [PostgreSQL 互動式終端機](https://www.postgresql.org/docs/13/app-psql.html) (psql)

## 史詩
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-epics"></a>

### 將您的應用程式儲存庫遷移至 PostgreSQL – 高階步驟
<a name="migrate-your-application-repository-to-postgresql-ndash-high-level-steps"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 請依照這些程式碼轉換步驟，將您的應用程式遷移至 PostgreSQL。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html)下列語意提供適用於 Python 和 Perl 應用程式的一些轉換任務的詳細說明。 | 應用程式開發人員 | 
| 針對遷移的每個步驟使用檢查清單。 | 將以下內容新增至應用程式遷移每個步驟的檢查清單，包括最後一個步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html) | 應用程式開發人員 | 

### 分析和更新您的應用程式 – Python 程式碼基底
<a name="analyze-and-update-your-application-ndash-python-code-base"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 分析您現有的 Python 程式碼庫。 | 您的分析應包含下列項目，以促進應用程式遷移程序：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html) | 應用程式開發人員 | 
| 轉換資料庫連線以支援 PostgreSQL。 | 大多數 Python 應用程式使用 **pyodbc** 程式庫來連接 SQL Server 資料庫，如下所示。<pre>import pyodbc<br />....<br />try:<br />    conn_string = "Driver=ODBC Driver 17 for SQL<br />    Server;UID={};PWD={};Server={};Database={}".format (conn_user, conn_password,<br />    conn_server, conn_database)<br />    conn = pyodbc.connect(conn_string)<br />    cur = conn.cursor()<br />    result = cur.execute(query_string)<br />    for row in result:<br />    print (row)<br />except Exception as e:<br />    print(str(e))</pre>轉換資料庫連線以支援 PostgreSQL，如下所示。<pre>import pyodbc<br />import psycopg2<br />....<br />try:<br />    conn_string = ‘postgresql+psycopg2://’+<br />    conn_user+’:’+conn_password+’@’+conn_server+’/’+conn_database<br />    conn = pyodbc.connect(conn_string, connect_args={‘options’:’-csearch_path=dbo’})<br />    cur = conn.cursor()<br />    result = cur.execute(query_string)<br />    for row in result:<br />    print (row)<br />except Exception as e:<br />    print(str(e))</pre> | 應用程式開發人員 | 
| 將內嵌 SQL 查詢變更為 PostgreSQL。 | 將您的內嵌 SQL 查詢轉換為 PostgreSQL 相容格式。例如，下列 SQL Server 查詢會從資料表擷取字串。<pre>dtype = "type1"<br />stm = ‘"SELECT TOP 1 searchcode FROM TypesTable (NOLOCK)<br />WHERE code="’ + "’" + str(dtype) + "’"<br /># For Microsoft SQL Server Database Connection<br />engine = create_engine(‘mssql+pyodbc:///?odbc_connect=%s’ % urllib.parse.quote_plus(conn_string), connect_args={‘connect_timeout’:login_timeout})<br />conn = engine_connect()<br />rs = conn.execute(stm)<br />for row in rs:<br />    print(row)</pre>轉換後，與 PostgreSQL 相容的內嵌 SQL 查詢如下所示。<pre>dtype = "type1"<br />stm = ‘"SELECT searchcode FROM TypesTable<br />WHERE code="’ + "’" + str(dtype) + "’ LIMIT 1"<br /># For PostgreSQL Database Connection<br />engine = create_engine(‘postgres+psycopg2://%s’ %conn_string, connect_args={‘connect_timeout’:login_timeout})<br />conn = engine.connect()<br />rs = conn.execute(stm)<br />for row in rs:<br />    print(row)</pre> | 應用程式開發人員 | 
| 處理動態 SQL 查詢。 | 動態 SQL 可以存在於一個指令碼或多個 Python 指令碼中。先前範例示範如何使用 Python 的字串取代函數插入變數來建構動態 SQL 查詢。替代方法是在適用的情況下，使用變數附加查詢字串。 在下列範例中，查詢字串會根據函數傳回的值，以即時方式建構。<pre>query = ‘"SELECT id from equity e join issues i on e.permId=i.permId where e.id’"<br />query += get_id_filter(ids) + " e.id is NOT NULL</pre>這些類型的動態查詢在應用程式遷移期間非常常見。請依照下列步驟處理動態查詢：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html) | 應用程式開發人員 | 
| 處理結果集、變數和資料影格。 | 對於 Microsoft SQL Server，您可以使用 Python 方法，例如 `fetchall()``fetchone()`或 從資料庫擷取結果集。您也可以使用 `fetchmany(size)`並指定要從結果集傳回的記錄數目。若要這樣做，您可以使用 **pyodbc** 連線物件，如下列範例所示。**pyodbc (Microsoft SQL Server)**<pre>import pyodbc <br />server = 'tcp:myserver.database.windows.net' <br />database = 'exampledb' <br />username = 'exampleusername' <br />password = 'examplepassword' <br />conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)<br />cursor = conn.cursor()<br />cursor.execute("SELECT * FROM ITEMS") <br />row = cursor.fetchone() <br />while row: <br />    print(row[0])<br />    row = cursor.fetchone()</pre>在 Aurora 中，若要執行類似任務，例如連線至 PostgreSQL 和擷取結果集，您可以使用 **psycopg2** 或 **SQLAlchemy**。這些 Python 程式庫提供連線模組和游標物件，以周遊 PostgreSQL 資料庫記錄，如下列範例所示。**psycopg2 (Aurora PostgreSQL 相容）**<pre>import psycopg2<br />query = "SELECT * FROM ITEMS;"<br />//Initialize variables<br />host=dbname=user=password=port=sslmode=connect_timeout=""<br />connstring = "host='{host}' dbname='{dbname}' user='{user}' \<br />password='{password}'port='{port}'".format(host=host,dbname=dbname,\<br />user=user,password=password,port=port) <br />conn = psycopg2.connect(connstring)<br />cursor = conn.cursor()<br />cursor.execute(query)<br />column_names = [column[0] for column in cursor.description]<br />print("Column Names: ", column_names)<br />print("Column values: "<br />for row in cursor:<br />    print("itemid :", row[0])<br />    print("itemdescrption :", row[1])<br />    print("itemprice :", row[3]))</pre>**SQLAlchemy (Aurora PostgreSQL 相容）**<pre>from sqlalchemy import create_engine<br />from pandas import DataFrame<br />conn_string = 'postgresql://core:database@localhost:5432/exampledatabase'<br />engine = create_engine(conn_string)<br />conn = engine.connect()<br />dataid = 1001<br />result = conn.execute("SELECT * FROM ITEMS")<br />df = DataFrame(result.fetchall())<br />df.columns = result.keys()<br />df = pd.DataFrame()<br />engine.connect()<br />df = pd.read_sql_query(sql_query, engine, coerce_float=False)<br />print("df=", df)</pre> | 應用程式開發人員 | 
| 在遷移期間和之後測試您的應用程式。 | 測試遷移的 Python 應用程式是持續進行的程序。由於遷移包含連線物件變更 (**psycopg2** 或 **SQLAlchemy**)、錯誤處理、新功能 （資料框架）、內嵌 SQL 變更、大量複製功能 (`bcp`而非 `COPY`) 和類似變更，因此必須在應用程式遷移期間和之後仔細測試。檢查：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html) | 應用程式開發人員 | 

### 分析和更新您的應用程式 – Perl 程式碼庫
<a name="analyze-and-update-your-application-ndash-perl-code-base"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 分析現有的 Perl 程式碼基底。 | 您的分析應包含下列項目，以促進應用程式遷移程序。您應該識別：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html) | 應用程式開發人員 | 
| 轉換 Perl 應用程式和 DBI 模組的連線，以支援 PostgreSQL。 | Perl 型應用程式通常會使用 Perl DBI 模組，這是 Perl 程式設計語言的標準資料庫存取模組。您可以使用相同的 DBI 模組搭配 SQL Server 和 PostgreSQL 的不同驅動程式。如需必要 Perl 模組、安裝和其他說明的詳細資訊，請參閱 [DBD：：Pg 文件](https://metacpan.org/pod/DBD::Pg)。下列範例會連線至位於 的 Aurora PostgreSQL 相容`exampletest-aurorapg-database.cluster-sampleclusture.us-east.-rds.amazonaws.com`。<pre>#!/usr/bin/perl<br />use DBI;<br />use strict;<br />my $driver = "Pg";<br />my $hostname = "exampletest-aurorapg-database-sampleclusture.us-east.rds.amazonaws.com"<br />my $dsn = "DBI:$driver: dbname = $hostname;host = 127.0.0.1;port = 5432";<br />my $username = "postgres";<br />my $password = "pass123";<br />$dbh = DBI->connect("dbi:Pg:dbname=$hostname;host=$host;port=$port;options=$options",<br />      $username,<br />      $password,<br />      {AutoCommit => 0, RaiseError => 1, PrintError => 0}<br />      );</pre> | 應用程式開發人員 | 
| 將內嵌 SQL 查詢變更為 PostgreSQL。 | 您的應用程式可能有具有 `SELECT`、`UPDATE`、 `DELETE`和類似陳述式的內嵌 SQL 查詢，其中包含 PostgreSQL 不支援的查詢子句。例如，PostgreSQL `NOLOCK` 不支援查詢關鍵字，例如 `TOP`和 。下列範例示範如何處理 `TOP`、 `NOLOCK`和布林值變數。在 SQL Server 中：<pre>$sqlStr = $sqlStr<br />. "WHERE a.student_id in (SELECT TOP $numofRecords c_student_id   \<br />FROM active_student_record b WITH (NOLOCK) \<br />INNER JOIN student_contributor c WITH (NOLOCK) on c.contributor_id = b.c_st)</pre>對於 PostgreSQL，請轉換為：<pre>$sqlStr = $sqlStr<br />. "WHERE a.student_id in (SELECT TOP $numofRecords c_student_id  \<br />FROM active_student_record b INNER JOIN student_contributor c  \<br />on c.contributor_id = b.c_student_contr_id WHERE b_current_1 is true \<br />LIMIT $numofRecords)"</pre> | 應用程式開發人員 | 
| 處理動態 SQL 查詢和 Perl 變數。 | 動態 SQL 查詢是在應用程式執行時間建置的 SQL 陳述式。這些查詢會在應用程式執行時動態建構，視特定條件而定，因此在執行時間之前，不會知道查詢的全文。例如，財務分析應用程式每天分析前 10 個共享，這些共享每天都會變更。SQL 資料表是根據最佳執行者建立的，在執行時間之前不會知道這些值。假設此範例的內嵌 SQL 查詢會傳遞至包裝函式，以取得變數中設定的結果，然後變數會使用條件來判斷資料表是否存在：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html)以下是變數處理的範例，後面接著此使用案例的 SQL Server 和 PostgreSQL 查詢。<pre>my $tableexists = db_read( arg 1, $sql_qry, undef, 'writer');<br />my $table_already_exists = $tableexists->[0]{table_exists};<br />if ($table_already_exists){<br /># do some thing<br />}<br />else {<br /># do something else<br />}</pre>SQL Server：<pre>my $sql_qry = "SELECT OBJECT_ID('$backendTable', 'U') table_exists", undef, 'writer')";</pre>PostgreSQL：<pre>my $sql_qry = "SELECT TO_REGCLASS('$backendTable', 'U') table_exists", undef, 'writer')";</pre>下列範例使用內嵌 SQL 中的 ****Perl 變數，該變數會搭配 執行`SELECT`陳述式`JOIN`，以擷取資料表的主索引鍵和索引鍵資料欄的位置。SQL Server：<pre>my $sql_qry = "SELECT column_name', character_maxi mum_length \<br />FROM INFORMATION_SCHEMA.COLUMNS \<br />WHERE TABLE_SCHEMA='$example_schemaInfo' \<br />AND TABLE_NAME='$example_table' \<br />AND DATA_TYPE IN ('varchar','nvarchar');";</pre>PostgreSQL：<pre>my $sql_qry = "SELECT c1.column_name, c1.ordinal_position \<br />FROM information_schema.key_column_usage AS c LEFT \<br />JOIN information_schema.table_constraints AS t1 \<br />ON t1.constraint_name = c1.constraint_name \<br />WHERE t1.table_name = $example_schemaInfo'.'$example_table’ \<br />AND t1.constraint_type = 'PRIMARY KEY' ;";</pre> | 應用程式開發人員 | 

### 對 Perl 型或 Python 型應用程式進行其他變更，以支援 PostgreSQL
<a name="make-additional-changes-to-your-perl-based-or-python-based-application-to-support-postgresql"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將其他 SQL Server 建構轉換為 PostgreSQL。 | 下列變更適用於所有應用程式，無論程式設計語言為何。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.html) | 應用程式開發人員 | 

### 改善效能
<a name="improve-performance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 利用 AWS 服務來增強效能。 | 當您遷移至 AWS 雲端時，您可以精簡應用程式和資料庫設計，以利用 AWS 服務。例如，如果連接至 Aurora PostgreSQL 相容資料庫伺服器的 Python 應用程式查詢花費的時間比原始 Microsoft SQL Server 查詢更長，您可以考慮直接從 Aurora 伺服器建立歷史資料的摘要至 Amazon Simple Storage Service (Amazon S3) 儲存貯體，並使用 Amazon Athena 型 SQL 查詢來產生使用者儀表板的報告和分析資料查詢。 | 應用程式開發人員、雲端架構師 | 

## 相關資源
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-resources"></a>
+ [Perl](https://www.perl.org/)
+ [Perl DBI 模組](https://metacpan.org/pod/DBI)
+ [Python](https://www.python.org/)
+ [psycopg2](https://pypi.org/project/psycopg2/)
+ [SQLAlchemy](https://www.sqlalchemy.org/)
+ [大量複製 - PostgreSQL](https://www.postgresql.org/docs/9.2/sql-copy.html)
+ [大量複製 - Microsoft SQL Server](https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15)
+ [PostgreSQL](https://www.postgresql.org/)
+ [使用 Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)

## 其他資訊
<a name="change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition-additional"></a>

Microsoft SQL Server 和 Aurora PostgreSQL 相容都是 ANSI SQL 投訴。不過，當您將 Python 或 Perl 應用程式從 SQL Server 遷移至 PostgreSQL 時，仍應注意語法、資料欄資料類型、原生資料庫特定函數、大量插入和區分大小寫方面的任何不相容。

以下各節提供有關可能的不一致的詳細資訊。

**資料類型比較**

從 SQL Server 到 PostgreSQL 的資料類型變更，可能會導致應用程式操作所產生資料的顯著差異。如需資料類型的比較，請參閱 [Sqlines 網站上的](https://www.sqlines.com/sql-server-to-postgresql) 資料表。

**原生或內建 SQL 函數**

某些函數的行為在 SQL Server 和 PostgreSQL 資料庫之間有所不同。下表提供比較。


| 
| 
| Microsoft SQL Server | Description | PostgreSQL | 
| --- |--- |--- |
| `CAST`  | 將一個值從某個資料類型轉換至另一個類型。 | PostgreSQL `type :: operator` | 
| `GETDATE()` | 以 `YYYY-MM-DD hh:mm:ss.mmm` 格式傳回目前的資料庫系統日期和時間。 | `CLOCK_TIMESTAMP` | 
| `DATEADD` | 將時間/日期間隔新增至日期。 | `INTERVAL` 表達式 | 
| `CONVERT` | 將值轉換為特定資料格式。 | `TO_CHAR` | 
| `DATEDIFF` | 傳回兩個日期之間的差異。 | `DATE_PART` | 
| `TOP` | 限制`SELECT`結果集中的資料列數。 | `LIMIT/FETCH` | 

** 匿名區塊**

結構化 SQL 查詢會組織成數個區段，例如宣告、可執行檔和例外狀況處理。下表比較簡單匿名區塊的 Microsoft SQL Server 和 PostgreSQL 版本。對於複雜的匿名區塊，我們建議您在應用程式中呼叫自訂資料庫函數。


| 
| 
| Microsoft SQL Server | PostgreSQL | 
| --- |--- |
| <pre>my $sql_qry1=<br />my $sql_qry2 =<br />my $sqlqry = "BEGIN TRAN<br />$sql_qry1 $sql_qry2<br />if @\@error !=0 ROLLBACK<br />TRAN<br />else COMIT TRAN";</pre> | <pre>my $sql_qry1=<br />my $sql_qry2 =<br />my $sql_qry = " DO \$\$<br />BEGIN<br />$header_sql $content_sql<br />END<br />\$\$";</pre> | 

 

**其他差異**
+ **大量插入資料列：**相當於 Microsoft SQL Server bcp 公用程式的 PostgreSQL 是 [COPY](https://www.postgresql.org/docs/9.2/sql-copy.html)。 [https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15](https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15)
+ **區分大小寫：**PostgreSQL 中的資料欄名稱區分大小寫，因此您必須將 SQL Server 資料欄名稱轉換為小寫或大寫。當您擷取或比較資料，或在結果集或變數中放置資料欄名稱時，這會成為一個因素。下列範例會識別值可能以大寫或小寫儲存的資料欄。

```
my $sql_qry = "SELECT $record_id FROM $exampleTable WHERE LOWER($record_name) = \'failed transaction\'"; 
```
+ **Concatenation：**SQL Server 使用 `+`做為字串串連的運算子，而 PostgreSQL 則使用 `||`。
+ **驗證：**您應該先測試和驗證內嵌 SQL 查詢和函數，再將其用於 PostgreSQL 的應用程式碼。
+ **ORM 程式庫包含 ：**您也可以尋找將現有的資料庫連線程式庫包含或取代為 Python ORM 程式庫，例如 [SQLAlchemy](https://www.sqlalchemy.org/) 和 [PynomoDB](https://pynamodb.readthedocs.io/en/latest/quickstart.html)。這有助於使用物件導向範式，從資料庫輕鬆查詢和操作資料。

# 依工作負載的遷移模式
<a name="migration-migration-patterns-by-workload-pattern-list"></a>

**Topics**
+ [IBM](migration-migration-patterns-by-workload-ibm-pattern-list.md)
+ [Microsoft](migration-migration-patterns-by-workload-microsoft-pattern-list.md)
+ [N/A](migration-migration-patterns-by-workload-notapplicable-pattern-list.md)
+ [開放原始碼](migration-migration-patterns-by-workload-open-source-pattern-list.md)
+ [Oracle](migration-migration-patterns-by-workload-oracle-pattern-list.md)
+ [SAP](migration-migration-patterns-by-workload-sap-pattern-list.md)

# IBM
<a name="migration-migration-patterns-by-workload-ibm-pattern-list"></a>

**Topics**
+ [使用 AWS DMS 將 Db2 資料庫從 Amazon EC2 遷移至 Aurora MySQL 相容](migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.md)
+ [使用日誌運送將 LUW 的 Db2 遷移至 Amazon EC2，以減少中斷時間](migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time.md)
+ [將 LUW 的 Db2 遷移至具有高可用性災難復原的 Amazon EC2](migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery.md)
+ [使用 AWS DMS 和 AWS SCT 從 Amazon EC2 上的 IBM Db2 遷移至 Aurora PostgreSQL 相容 Amazon EC2](migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.md)
+ [從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat](migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2.md)

# Microsoft
<a name="migration-migration-patterns-by-workload-microsoft-pattern-list"></a>

**Topics**
+ [加速探索 Microsoft 工作負載並將其遷移至 AWS](accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.md)
+ [變更 Python 和 Perl 應用程式，以支援從 Microsoft SQL Server 到 Amazon Aurora PostgreSQL 相容版本的資料庫遷移](change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.md)
+ [使用 Microsoft Excel 和 Python 為 AWS DMS 任務建立 AWS CloudFormation 範本](create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫匯出至 Amazon S3](export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms.md)
+ [從 SQL Server 遷移至 PostgreSQL 時，實作 PII 資料的 SHA1 雜湊](implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.md)
+ [將 EC2 Windows 執行個體擷取並遷移至 AWS Managed Services 帳戶](ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.md)
+ [將訊息佇列從 Microsoft Azure Service Bus 遷移至 Amazon SQS](migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫從 Amazon EC2 遷移至 Amazon DocumentDB](migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms.md)
+ [使用 AWS DMS 和 AWS SCT 將 Microsoft SQL Server 資料庫遷移至 Aurora MySQL](migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct.md)
+ [將 .NET 應用程式從 Microsoft Azure App Service 遷移至 AWS Elastic Beanstalk](migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server.md)
+ [使用連結的伺服器將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers.md)
+ [使用原生備份和還原方法，將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods.md)
+ [使用 AWS DMS 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms.md)
+ [使用 AWS SCT 資料擷取代理程式將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至執行 Linux 的 Amazon EC2 上的 Microsoft SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux.md)
+ [使用 Rclone 將資料從 Microsoft Azure Blob 遷移至 Amazon S3](migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone.md)
+ [使用 appcmd.exe 將 IIS 託管應用程式遷移至 Amazon EC2](migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.md)
+ [使用 Application Migration Service 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.md)
+ [使用 ACM 將 Windows SSL 憑證遷移至 Application Load Balancer](migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.md)
+ [在 AWS 雲端中重新託管內部部署工作負載：遷移檢查清單](rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist.md)
+ [解決將 Microsoft SQL Server 遷移至 AWS 雲端後的連線錯誤](resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud.md)
+ [使用 Amazon FSx 設定 SQL Server Always On FCI 的異地同步備份基礎設施](set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.md)

# N/A
<a name="migration-migration-patterns-by-workload-notapplicable-pattern-list"></a>

**Topics**
+ [在重新託管遷移至 期間建立防火牆請求的核准程序 AWS](create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws.md)

# 開放原始碼
<a name="migration-migration-patterns-by-workload-open-source-pattern-list"></a>

**Topics**
+ [在 Aurora PostgreSQL 相容中建立應用程式使用者和角色](create-application-users-and-roles-in-aurora-postgresql-compatible.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL AWS CLI CloudFormation](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.md)
+ [使用原生工具將內部部署 MariaDB 資料庫遷移至 Amazon RDS for MariaDB](migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools.md)
+ [將內部部署 MySQL 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql.md)
+ [將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-an-on-premises-mysql-database-to-aurora-mysql.md)
+ [將內部部署 PostgreSQL 資料庫遷移至 Aurora PostgreSQL](migrate-an-on-premises-postgresql-database-to-aurora-postgresql.md)
+ [將 Couchbase Server 資料庫遷移至 Amazon EC2](migrate-couchbase-server-ec2.md)
+ [使用 Auto Scaling 從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat](migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling.md)
+ [使用 pglogical 從 Amazon EC2 上的 PostgreSQL 遷移至 Amazon RDS for PostgreSQL Amazon EC2](migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical.md)
+ [使用 AWS App2Container 將內部部署 Java 應用程式遷移至 AWS](migrate-on-premises-java-applications-to-aws-using-aws-app2container.md)
+ [使用 Percona XtraBackup、Amazon EFS 和 Amazon S3 將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3.md)
+ [將 Oracle 外部資料表遷移至 Amazon Aurora PostgreSQL 相容](migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible.md)
+ [重新啟動 RHEL 來源伺服器後，在不停用 SELinux 的情況下自動重新啟動 AWS 複寫代理程式](restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server.md)
+ [使用 pg\$1transport 在兩個 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫](transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.md)

# Oracle
<a name="migration-migration-patterns-by-workload-oracle-pattern-list"></a>

**Topics**
+ [將 Oracle 的 VARCHAR2(1) 資料類型轉換為 Amazon Aurora PostgreSQL 的布林資料類型](convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.md)
+ [使用 PostgreSQL 相容 Aurora 全域資料庫模擬 Oracle DR](emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database.md)
+ [使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.md)
+ [在 Aurora PostgreSQL 相容中使用檔案編碼將 BLOB 檔案載入 TEXT](load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.md)
+ [使用 AWS DMS，以 SSL 模式將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.md)
+ [將 Amazon RDS for Oracle 資料庫遷移至另一個資料庫 AWS 帳戶 ， AWS 區域 並使用 AWS DMS 進行持續複寫](migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon EC2](migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.md)
+ [使用 Logstash 將內部部署 Oracle 資料庫遷移至 Amazon OpenSearch Service](migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash.md)
+ [使用 AWS DMS 和 AWS SCT 將內部部署 Oracle 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump.md)
+ [使用 Oracle 旁觀者和 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon EC2 上的 Oracle](migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for MariaDB](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms.md)
+ [使用 Oracle GoldenGate 平面檔案轉接器，將 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Amazon Redshift](migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct.md)
+ [使用 Oracle Data Pump 和 AWS DMS 將 Oracle JD Edwards EnterpriseOne 資料庫遷移至 AWS](migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.md)
+ [使用 AWS DMS 將 Oracle 分割的資料表遷移至 PostgreSQL](migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms.md)
+ [使用 AWS DMS 將 Oracle PeopleSoft 資料庫遷移至 AWS](migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.md)
+ [將資料從現場部署 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql.md)
+ [從 Amazon RDS for Oracle 遷移至 Amazon RDS for MySQL](migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql.md)
+ [使用具體化視觀表和 AWS DMS，從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms.md)
+ [使用 Oracle GoldenGate 從 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.md)
+ [使用 AWS DMS 和 AWS SCT 從 Oracle on Amazon EC2 遷移至 Amazon RDS for MySQL](migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [在 Amazon ECS 上從 Oracle WebLogic 遷移至 Apache Tomcat (TomEE)](migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs.md)
+ [將函數型索引從 Oracle 遷移至 PostgreSQL](migrate-function-based-indexes-from-oracle-to-postgresql.md)
+ [將舊版應用程式從 Oracle Pro\$1C 遷移至 ECPG](migrate-legacy-applications-from-oracle-pro-c-to-ecpg.md)
+ [將 Oracle CLOB 值遷移至 AWS 上的 PostgreSQL 中的個別資料列](migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws.md)
+ [將 Oracle 資料庫錯誤代碼遷移至與 Amazon Aurora PostgreSQL 相容的資料庫](migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database.md)
+ [使用延伸模組將 Oracle 原生函數遷移至 PostgreSQL](migrate-oracle-native-functions-to-postgresql-using-extensions.md)
+ [將 Oracle PeopleSoft 遷移至 Amazon RDS Custom](migrate-oracle-peoplesoft-to-amazon-rds-custom.md)
+ [將 Oracle ROWID 功能遷移至 AWS 上的 PostgreSQL](migrate-oracle-rowid-functionality-to-postgresql-on-aws.md)
+ [將 Oracle SERIALLY\$1REUSABLE pragma 套件遷移至 PostgreSQL](migrate-oracle-serially-reusable-pragma-packages-into-postgresql.md)
+ [將虛擬產生的資料欄從 Oracle 遷移至 PostgreSQL](migrate-virtual-generated-columns-from-oracle-to-postgresql.md)
+ [在 Aurora PostgreSQL 相容上設定 Oracle UTL\$1FILE 功能](set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible.md)
+ [從 Oracle 遷移到 Amazon Aurora PostgreSQL 後驗證資料庫物件](validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql.md)

# SAP
<a name="migration-migration-patterns-by-workload-sap-pattern-list"></a>

**Topics**
+ [使用 AWS DMS 從 SAP ASE 遷移至 Amazon RDS for SQL Server](migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon EC2 上的 SAP ASE 遷移至與 Amazon Aurora PostgreSQL 相容](migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms.md)

# 更多模式
<a name="migration-more-patterns-pattern-list"></a>

**Topics**
+ [安裝 以 AWS 服務 從 IBM z/OS 存取 AWS CLI](access-aws-services-from-ibm-z-os-by-installing-aws-cli.md)
+ [評估將 SQL Server 資料庫遷移至 AWS 上的 MongoDB Atlas 的查詢效能](assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws.md)
+ [使用 DR Orchestrator Framework 自動化跨區域容錯移轉和容錯回復](automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.md)
+ [使用 AWS Lambda 和 任務排程器，在 Amazon EC2 上的 SQL Server Express 中自動化資料庫任務](automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.md)
+ [在 AWS 雲端中建置進階大型主機檔案檢視器](build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.md)
+ [透過私有網路連線至 Application Migration Service 資料和控制平面](connect-to-application-migration-service-data-and-control-planes-over-a-private-network.md)
+ [容器化已由 Blu Age 現代化的大型主機工作負載](containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.md)
+ [將 JSON Oracle 查詢轉換為 PostgreSQL 資料庫 SQL](convert-json-oracle-queries-into-postgresql-database-sql.md)
+ [將 Teradata NORMALIZE 暫時功能轉換為 Amazon Redshift SQL](convert-the-teradata-normalize-temporal-feature-to-amazon-redshift-sql.md)
+ [將 Teradata RESET WHEN 功能轉換為 Amazon Redshift SQL](convert-the-teradata-reset-when-feature-to-amazon-redshift-sql.md)
+ [使用 跨帳戶複製 Amazon DynamoDB 資料表 AWS Backup](copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.md)
+ [使用私有靜態 IPs 在 Amazon EC2 上部署 Cassandra 叢集，以避免重新平衡](deploy-a-cassandra-cluster-on-amazon-ec2-with-private-static-ips-to-avoid-rebalancing.md)
+ [使用 AWS CDK 搭配 TypeScript 部署多堆疊應用程式](deploy-multiple-stack-applications-using-aws-cdk-with-typescript.md)
+ [使用 Terraform 在 Amazon EC2 和 Amazon FSx 上部署 SQL Server 容錯移轉叢集執行個體](deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.md)
+ [在 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 中模擬 Oracle PL/SQL 關聯陣列](emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql.md)
+ [使用 AWR 報告估計 Oracle 資料庫的 Amazon RDS 引擎大小](estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.md)
+ [在 Quick Sight 中使用 AWS Mainframe Modernization 和 Amazon Q 產生資料洞見](generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.md)
+ [在 Aurora PostgreSQL 中處理動態 SQL 陳述式中的匿名區塊](handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql.md)
+ [遷移至 Amazon ECR 儲存庫時，自動識別重複的容器映像](identify-duplicate-container-images-automatically-when-migrating-to-ecr-repository.md)
+ [使用 FSx for Windows File Server 在 Amazon EC2 上設定 Microsoft SQL Server 容錯移轉叢集](microsoft-sql-failover-cluster-on-amazon-ec2.md)
+ [使用 AWS Glue 將 Apache Cassandra 工作負載遷移至 Amazon Keyspaces](migrate-apache-cassandra-workloads-to-amazon-keyspaces-by-using-aws-glue.md)
+ [將您的容器工作負載從 Azure Red Hat OpenShift (ARO) 遷移至 Red Hat OpenShift Service on AWS (ROSA)](migrate-container-workloads-from-aro-to-rosa.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for Oracle](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.md)
+ [使用 遷移 Microsoft SQL Server Always On 可用性群組 AWS Application Migration Service](migrate-microsoft-sql-server-always-on-group-using-mgn.md)
+ [將具有超過 100 個引數的 Oracle 函數和程序遷移至 PostgreSQL](migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql.md)
+ [使用具有相同主機名稱的 SAP HSR 將 SAP HANA 遷移至 AWS](migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname.md)
+ [使用分散式可用性群組將 SQL Server 遷移至 AWS](migrate-sql-server-to-aws-using-distributed-availability-groups.md)
+ [使用 和 Terraform 現代化 AWS Transform 和部署大型主機應用程式](modernize-mainframe-app-transform-terraform.md)
+ [使用 Micro Focus Enterprise Server 和 LRS VPSX/MFI 將 AWS 上的大型主機線上列印工作負載現代化](modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.md)
+ [AWS 使用 Rocket Enterprise Server 和 LRS PageCenterX 在 上現代化大型主機輸出管理](modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.md)
+ [當您從 F5 遷移到 AWS 上的 Application Load Balancer 時修改 HTTP 標頭](modify-http-headers-when-you-migrate-from-f5-to-an-application-load-balancer-on-aws.md)
+ [使用應用程式復原控制器管理 EMR 叢集的多可用區域容錯移轉](multi-az-failover-spark-emr-clusters-arc.md)
+ [分析從 Oracle 到 PostgreSQL 的部分資料庫遷移的物件相依性](multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql.md)
+ [使用 Terraform 設定資料庫遷移的 CI/CD 管道](set-up-ci-cd-pipeline-for-db-migration-with-terraform.md)
+ [使用 AWS Elastic Disaster Recovery 為 Oracle JD Edwards EnterpriseOne 設定災難復原](set-up-disaster-recovery-for-oracle-jd-edwards-enterpriseone-with-aws-elastic-disaster-recovery.md)
+ [使用 AWS Private CA 和 AWS RAM 簡化私有憑證管理](simplify-private-certificate-management-by-using-aws-private-ca-and-aws-ram.md)
+ [以 CSV 檔案將大規模 Db2 z/OS 資料傳輸至 Amazon S3](transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.md)
+ [使用 AWS Transform 自訂將 Easytrieve 轉換為現代語言](transform-easytrieve-modern-languages.md)

# 現代化
<a name="modernization-pattern-list"></a>

**Topics**
+ [使用 DynamoDB TTL 自動將項目封存至 Amazon S3](automatically-archive-items-to-amazon-s3-using-dynamodb-ttl.md)
+ [在 Amazon OpenSearch Service 中建置多租戶無伺服器架構](build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.md)
+ [使用 AWS CDK 搭配 TypeScript 部署多堆疊應用程式](deploy-multiple-stack-applications-using-aws-cdk-with-typescript.md)
+ [使用 AWS SAM 自動化巢狀應用程式的部署](automate-deployment-of-nested-applications-using-aws-sam.md)
+ [使用 AWS Lambda 字符販賣機實作 Amazon S3 的 SaaS 租用戶隔離](implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine.md)
+ [使用 AWS Step Functions 實作無伺服器 saga 模式](implement-the-serverless-saga-pattern-by-using-aws-step-functions.md)
+ [使用 AWS CDK 設定 Amazon ECS Anywhere 來管理內部部署容器應用程式](manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk.md)
+ [在 AWS 上現代化 ASP.NET Web Forms 應用程式](modernize-asp-net-web-forms-applications-on-aws.md)
+ [使用 C\$1 和 AWS CDK 在孤立模型的 SaaS 架構中加入租用戶](tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.md)
+ [使用 CQRS 和事件來源將整體分解為微服務](decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.md)
+ [更多模式](modernization-more-patterns-pattern-list.md)

# 使用 DynamoDB TTL 自動將項目封存至 Amazon S3
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl"></a>

*Tabby Ward，Amazon Web Services*

## 總結
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-summary"></a>

此模式提供從 Amazon DynamoDB 資料表移除舊資料並將其封存至 Amazon Web Services (AWS) 上 Amazon Simple Storage Service (Amazon S3) 儲存貯體的步驟，而不必管理伺服器機群。 

此模式使用 Amazon DynamoDB 存留時間 (TTL) 自動刪除舊項目，並使用 Amazon DynamoDB 串流擷取 TTL 過期項目。然後，它會將 DynamoDB Streams 連線至 AWS Lambda，其會執行程式碼，而無需佈建或管理任何伺服器。 

將新項目新增至 DynamoDB 串流時，會啟動 Lambda 函數，並將資料寫入 Amazon Data Firehose 交付串流。Firehose 提供簡單、全受管的解決方案，將資料作為封存載入 Amazon S3。

DynamoDB 通常用於存放時間序列資料，例如網頁點擊串流資料或來自感應器和連線裝置的物聯網 (IoT) 資料。許多客戶不想要刪除較不常存取的項目，而是想要將其封存以供稽核之用。TTL 會根據時間戳記屬性自動刪除項目，簡化此封存。 

TTL 刪除的項目可以在 DynamoDB Streams 中識別，該串流會擷取項目層級修改的時間順序，並將序列存放在日誌中長達 24 小時。此資料可供 Lambda 函數使用，並封存在 Amazon S3 儲存貯體中，以降低儲存成本。為了進一步降低成本，可以建立 [Amazon S3 生命週期規則](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html)，以自動將資料 （建立後立即） 轉換為成本最低的[儲存類別](https://aws.amazon.com/s3/storage-classes/)。

## 先決條件和限制
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ [在 macOS、Linux 或 Windows 上安裝和設定 AWS Command Line Interface (AWS CLI) 1.7 或更新版本。](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html) macOS
+ [Python 3.7 ](https://www.python.org/downloads/release/python-370/)或更新版本。
+ [Boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)，已安裝並設定。如果尚未安裝 Boto3，請執行 `python -m pip install boto3`命令來安裝它。

## Architecture
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-architecture"></a>

**技術堆疊**
+ Amazon DynamoDB
+ Amazon DynamoDB Streams
+ Amazon Data Firehose
+ AWS Lambda
+ Amazon S3

![\[從 DynamoDB 到 S3 儲存貯體的四步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9dbc833f-cf3c-4574-8f09-d0b81134fe41/images/50d9da65-5398-4a99-bc8f-58afc80e9d7b.png)


1. TTL 會刪除項目。

1. DynamoDB 串流觸發程序會叫用 Lambda 串流處理器函數。

1. Lambda 函數會以批次格式將記錄放入 Firehose 交付串流中。

1. 資料記錄會封存在 S3 儲存貯體中。

## 工具
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-tools"></a>
+ [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) – AWS Command Line Interface (AWS CLI) 是管理 AWS 服務的統一工具。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) – Amazon DynamoDB 是一種鍵值和文件資料庫，可在任何規模下提供單一位數毫秒的效能。
+ [Amazon DynamoDB 存留時間 (TTL)](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/howitworks-ttl.html) – Amazon DynamoDB TTL 可協助您定義每個項目的時間戳記，以判斷何時不再需要項目。
+ [Amazon DynamoDB Streams](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Types_Amazon_DynamoDB_Streams.html) – Amazon DynamoDB Streams 會擷取任何 DynamoDB 資料表中項目層級修改的時間順序，並將此資訊存放在日誌中長達 24 小時。
+ [Amazon Data Firehose](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html) – Amazon Data Firehose 是將串流資料可靠載入資料湖、資料存放區和分析服務的最簡單方法。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) – AWS Lambda 執行程式碼，無需佈建或管理伺服器。您只需為使用的運算時間支付費用。
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是一種物件儲存服務，可提供業界領先的可擴展性、資料可用性、安全性和效能。

**Code**

此模式的程式碼可在 GitHub Archive [項目中使用 DynamoDB TTL 儲存庫傳送至 S3](https://github.com/aws-samples/automatically-archive-items-to-s3-using-dynamodb-ttl)。

## 史詩
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-epics"></a>

### 設定 DynamoDB 資料表、TTL 和 DynamoDB 串流
<a name="set-up-a-dynamodb-table-ttl-and-a-dynamodb-stream"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 DynamoDB 資料表。 | 使用 AWS CLI 在 DynamoDB 中建立名為 的資料表`Reservation`。選擇隨機讀取容量單位 (RCU) 和寫入容量單位 (WCU)，並為您的資料表提供兩個屬性： `ReservationID`和 `ReservationDate`。 <pre>aws dynamodb create-table \<br />--table-name Reservation \<br />--attribute-definitions AttributeName=ReservationID,AttributeType=S AttributeName=ReservationDate,AttributeType=N \<br />--key-schema AttributeName=ReservationID,KeyType=HASH AttributeName=ReservationDate,KeyType=RANGE \<br />--provisioned-throughput ReadCapacityUnits=100,WriteCapacityUnits=100 </pre>`ReservationDate` 是用來開啟 TTL 的 epoch 時間戳記。 | 雲端架構師、應用程式開發人員 | 
| 開啟 DynamoDB TTL。 | 使用 AWS CLI 為 `ReservationDate` 屬性開啟 DynamoDB TTL。<pre>aws dynamodb update-time-to-live \<br />--table-name Reservation\<br />  --time-to-live-specification Enabled=true,AttributeName=ReservationDate</pre> | 雲端架構師、應用程式開發人員 | 
| 開啟 DynamoDB 串流。 | 使用 AWS CLI，透過使用串流類型來開啟`Reservation`資料表的 DynamoDB `NEW_AND_OLD_IMAGES` 串流。 <pre>aws dynamodb update-table \<br />--table-name Reservation \<br />  --stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES</pre>此串流將包含新項目、更新項目、已刪除項目和 TTL 刪除項目的記錄。TTL 刪除的項目記錄包含額外的中繼資料屬性，以區分它們與手動刪除的項目。TTL 刪除`userIdentity`的 欄位表示 DynamoDB 服務已執行刪除動作。 在此模式中，只會封存 TTL 刪除的項目，但您只能封存 `eventName`為 `REMOVE`且`userIdentity`包含`principalId`等於 的記錄`dynamodb.amazonaws.com`。 | 雲端架構師、應用程式開發人員 | 

### 建立和設定 S3 儲存貯體
<a name="create-and-configure-an-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 使用 AWS CLI 在您的 AWS 區域中建立目的地 S3 儲存貯體，`us-east-1`將 取代為您的區域，並將 amzn-s3-demo-destination-bucket 取代為您的儲存貯體名稱。 <pre>aws s3api create-bucket \<br />--bucket amzn-s3-demo-destination-bucket \<br />--region us-east-1</pre>請確定 S3 儲存貯體的名稱是全域唯一的，因為命名空間是由所有 AWS 帳戶共用。 | 雲端架構師、應用程式開發人員 | 
| 建立 S3 儲存貯體的 30 天生命週期政策。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-archive-items-to-amazon-s3-using-dynamodb-ttl.html) | 雲端架構師、應用程式開發人員 | 

### 建立 Firehose 交付串流
<a name="create-a-akf-delivery-stream"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立和設定 Firehose 交付串流。 | 從 GitHub 儲存庫下載和編輯`CreateFireHoseToS3.py`程式碼範例。 此程式碼是以 Python 撰寫，並說明如何建立 Firehose 交付串流和 AWS Identity and Access Management (IAM) 角色。IAM 角色會有政策，可供 Firehose 用來寫入目的地 S3 儲存貯體。若要執行指令碼，請使用下列命令和命令列引數。引數 1 = `<Your_S3_bucket_ARN>`，這是您先前建立之儲存貯體的 Amazon Resource Name (ARN)引數 2 = 您的 Firehose 名稱 （此試驗正在使用`firehose_to_s3_stream`。)引數 3 = 您的 IAM 角色名稱 （此試驗使用 `firehose_to_s3`。)<pre>python CreateFireHoseToS3.py <Your_S3_Bucket_ARN> firehose_to_s3_stream firehose_to_s3</pre>如果指定的 IAM 角色不存在，指令碼會建立具有信任關係政策的擔任角色，以及授予足夠 Amazon S3 許可的政策。如需這些政策的範例，請參閱*其他資訊*一節。 | 雲端架構師、應用程式開發人員 | 
| 驗證 Firehose 交付串流。 | 使用 AWS CLI 來驗證已成功建立交付串流，以描述 Firehose 交付串流。<pre>aws firehose describe-delivery-stream --delivery-stream-name firehose_to_s3_stream </pre> | 雲端架構師、應用程式開發人員 | 

### 建立 Lambda 函數來處理 Firehose 交付串流
<a name="create-a-lambda-function-to-process-the-akf-delivery-stream"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Lambda 函數的信任政策。 | 使用下列資訊建立信任政策檔案。<pre> {<br />     "Version": "2012-10-17",		 	 	 <br />     "Statement": [<br />      {<br />          "Effect": "Allow",<br />          "Principal": {<br />              "Service": "lambda.amazonaws.com"<br />           },<br />           "Action": "sts:AssumeRole"<br />      }<br />    ]<br />  } </pre>這可讓您的函數存取 AWS 資源。 | 雲端架構師、應用程式開發人員 | 
| 建立 Lambda 函數的執行角色。 | 若要建立執行角色，請執行下列程式碼。<pre>aws iam create-role --role-name lambda-ex --assume-role-policy-document file://TrustPolicy.json</pre> | 雲端架構師、應用程式開發人員 | 
| 將許可新增至角色。 | 若要將許可新增至角色，請使用 `attach-policy-to-role`命令。<pre>aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole<br />aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole<br />aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/AmazonKinesisFirehoseFullAccess<br />aws iam attach-role-policy --role-name lambda-ex --policy-arn arn:aws:iam::aws:policy/IAMFullAccess </pre> | 雲端架構師、應用程式開發人員 | 
| 建立 Lambda 函式。 | 執行下列命令，從程式碼儲存庫壓縮 `LambdaStreamProcessor.py` 檔案。<pre>zip function.zip LambdaStreamProcessor.py</pre>當您建立 Lambda 函數時，您將需要 Lambda 執行角色 ARN。若要取得 ARN，請執行下列程式碼。<pre>aws iam get-role \<br />--role-name lambda-ex </pre>若要建立 Lambda 函數，請執行下列程式碼。<pre># Review the environment variables and replace them with your values.<br /><br />aws lambda create-function --function-name LambdaStreamProcessor \<br />--zip-file fileb://function.zip --handler LambdaStreamProcessor.handler --runtime python3.8 \<br />--role {Your Lamda Execution Role ARN}\<br />  --environment Variables="{firehose_name=firehose_to_s3_stream,bucket_arn = <Your_S3_bucket_ARN>,iam_role_name = firehose_to_s3, batch_size=400}"</pre> | 雲端架構師、應用程式開發人員 | 
| 設定 Lambda 函數觸發。 | 使用 AWS CLI 來設定觸發 (DynamoDB Streams)，這會叫用 Lambda 函數。400 的批次大小是為了避免在 Lambda 並行問題中執行。<pre>aws lambda create-event-source-mapping --function-name LambdaStreamProcessor \<br />--batch-size 400 --starting-position LATEST \<br />--event-source-arn <Your Latest Stream ARN From DynamoDB Console></pre> | 雲端架構師、應用程式開發人員 | 

### 測試功能
<a name="test-the-functionality"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將具有過期時間戳記的項目新增至保留資料表。 | 若要測試功能，請將具有過期 epoch 時間戳記的項目新增至`Reservation`資料表。TTL 會根據時間戳記自動刪除項目。 Lambda 函數會在 DynamoDB Stream 活動上啟動，並篩選事件以識別`REMOVE`活動或刪除的項目。然後，它會以批次格式將記錄放入 Firehose 交付串流。Firehose 交付串流會使用 `firehosetos3example/year=current year/month=current month/ day=current day/hour=current hour/`字首將項目傳輸到目的地 S3 儲存貯體。若要最佳化資料擷取，請使用 `Prefix`和 設定 Amazon S3`ErrorOutputPrefix`，詳細資訊請參閱*其他資訊*一節。 | 雲端架構師  | 

### 清除資源
<a name="clean-up-the-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 刪除所有資源。 | 刪除所有資源，以確保不會針對您未使用的任何服務向您收費。  | 雲端架構師、應用程式開發人員 | 

## 相關資源
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-resources"></a>
+ [管理儲存生命週期](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-lifecycle.html)
+ [Amazon S3 儲存類別](https://aws.amazon.com/s3/storage-classes/)
+ [適用於 Python 的 AWS 開發套件 (Boto3) 文件](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)

## 其他資訊
<a name="automatically-archive-items-to-amazon-s3-using-dynamodb-ttl-additional"></a>

**建立和設定 Firehose 交付串流 – 政策範例**

*Firehose 信任關係政策範例文件*

```
firehose_assume_role = {
        'Version': '2012-10-17',
        'Statement': [
            {
                'Sid': '',
                'Effect': 'Allow',
                'Principal': {
                    'Service': 'firehose.amazonaws.com'
                },
                'Action': 'sts:AssumeRole'
            }
        ]
    }
```

*S3 許可政策範例*

```
s3_access = {
        "Version": "2012-10-17",		 	 	 
        "Statement": [
            {
                "Sid": "",
                "Effect": "Allow",
                "Action": [
                    "s3:AbortMultipartUpload",
                    "s3:GetBucketLocation",
                    "s3:GetObject",
                    "s3:ListBucket",
                    "s3:ListBucketMultipartUploads",
                    "s3:PutObject"
                ],
                "Resource": [
                    "{your s3_bucket ARN}/*",
                    "{Your s3 bucket ARN}"
                ]
            }
        ]
    }
```

**測試功能 – Amazon S3 組態**

Amazon S3 組態具有下列特性`Prefix`，且`ErrorOutputPrefix`選擇此組態來最佳化資料擷取。 

*prefix*

```
firehosetos3example/year=! {timestamp: yyyy}/month=! {timestamp:MM}/day=! {timestamp:dd}/hour=!{timestamp:HH}/
```

Firehose 首先會在 S3 儲存貯體`firehosetos3example`下直接建立名為 的基本資料夾。然後，它會使用 Java [DateTimeFormatter](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html) 格式評估表達式 `!{timestamp:yyyy}`、`!{timestamp:dd}`、 `!{timestamp:MM}`和 `!{timestamp:HH}` 到年、月、日和小時。

例如，Unix epoch 時間中 1604683577 的大致到達時間戳記會評估為 `year=2020`、`day=06`、 `month=11`和 `hour=05`。因此，Amazon S3 中交付資料記錄的位置會評估為 `firehosetos3example/year=2020/month=11/day=06/hour=05/`。

*ErrorOutputPrefix*

```
firehosetos3erroroutputbase/!{firehose:random-string}/!{firehose:error-output-type}/!{timestamp:yyyy/MM/dd}/
```

`ErrorOutputPrefix` 會產生`firehosetos3erroroutputbase`直接在 S3 儲存貯體下呼叫的基本資料夾。表達式會`!{firehose:random-string}`評估為 11 個字元的隨機字串，例如 `ztWxkdg3Thg`。交付失敗記錄的 Amazon S3 物件位置可以評估為 `firehosetos3erroroutputbase/ztWxkdg3Thg/processing-failed/2020/11/06/`。

# 在 Amazon OpenSearch Service 中建置多租戶無伺服器架構
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service"></a>

*Tabby Ward 和 Nisha Gambhir，Amazon Web Services*

## 總結
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-summary"></a>

Amazon OpenSearch Service 是一種受管服務，可讓您輕鬆部署、操作和擴展 Elasticsearch，這是熱門的開放原始碼搜尋和分析引擎。OpenSearch Service 提供任意文字搜尋，以及近乎即時的串流資料擷取和儀表板，例如日誌和指標。

軟體即服務 (SaaS) 供應商經常使用 OpenSearch Service 來處理各種使用案例，例如以可擴展且安全的方式獲得客戶洞見，同時降低複雜性和停機時間。

在多租戶環境中使用 OpenSearch Service 引入了一系列的考量，會影響 SaaS 解決方案的分割、隔離、部署和管理。SaaS 提供者必須考慮如何使用不斷轉移的工作負載，有效地擴展其 Elasticsearch 叢集。他們還需要考慮分層和嘈雜的鄰國條件如何影響其分割模型。

此模式會檢閱用於使用 Elasticsearch 建構來表示和隔離租戶資料的模型。此外，模式著重於簡單的無伺服器參考架構作為範例，以示範在多租戶環境中使用 OpenSearch Service 進行索引和搜尋。它會實作集區資料分割模型，在所有租用戶之間共用相同的索引，同時維持租用戶的資料隔離。此模式使用下列 AWS 服務：Amazon API Gateway AWS Lambda、Amazon Simple Storage Service (Amazon S3) 和 OpenSearch Service。

如需集區模型和其他資料分割模型的詳細資訊，請參閱[其他資訊](#build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-additional)一節。

## 先決條件和限制
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ [AWS Command Line Interface (AWS CLI) 2.x 版](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)，在 macOS、Linux 或 Windows 上安裝和設定
+ [Python 3.9 版](https://www.python.org/downloads/release/python-3921/)
+ [pip3](https://pip.pypa.io/en/stable/) – Python 原始程式碼以要部署在 Lambda 函數中的 .zip 檔案提供。如果您想要在本機使用或自訂程式碼，請依照下列步驟開發和重新編譯原始程式碼：

  1. 在與 Python 指令碼相同的目錄中執行下列命令來產生`requirements.txt`檔案： `pip3 freeze > requirements.txt`

  1. 安裝相依性： `pip3 install -r requirements.txt`

**限制**
+ 此程式碼在 Python 中執行，目前不支援其他程式設計語言。 
+ 範例應用程式不包含 AWS 跨區域或災難復原 (DR) 支援。 
+ 此模式僅供示範之用。它不適用於生產環境。

## Architecture
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-architecture"></a>

下圖說明此模式的高階架構。架構包含下列項目：
+ Lambda 索引和查詢內容 
+ OpenSearch Service 執行搜尋 
+ API Gateway 提供與 使用者的 API 互動
+ Amazon S3 儲存原始 （非索引） 資料
+ Amazon CloudWatch 監控日誌
+ AWS Identity and Access Management (IAM) 以建立租戶角色和政策

![\[高階多租戶無伺服器架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/1a8501e7-0776-4aca-aed3-28e3ada1d15d.png)


**自動化和擴展**

為了簡化， 模式會使用 AWS CLI 來佈建基礎設施和部署範例程式碼。您可以建立 CloudFormation 範本或 AWS Cloud Development Kit (AWS CDK) 指令碼來自動化模式。

## 工具
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-tools"></a>

**AWS 服務**
+ [AWS CLI](https://aws.amazon.com/cli/) 是統一的工具，可讓您在命令列 Shell 中使用命令來管理 AWS 服務 和 資源。
+ [Lambda](https://aws.amazon.com/lambda/) 是一種運算服務，可讓您執行程式碼，而無需佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。
+ [API Gateway](https://aws.amazon.com/api-gateway/) 是 ， AWS 服務 用於建立、發佈、維護、監控和保護任何規模的 REST、HTTP 和 WebSocket APIs。
+ [Amazon S3](https://aws.amazon.com/s3/) 是一種物件儲存服務，可讓您隨時從 Web 上的任何位置存放和擷取任意數量的資訊。
+ [OpenSearch Service](https://aws.amazon.com/opensearch-service/) 是一項全受管服務，可讓您以經濟實惠的方式大規模部署、保護和執行 Elasticsearch。

**Code**

附件提供此模式的範例檔案。其中包含：
+ `index_lambda_package.zip` – 使用集區模型為 OpenSearch Service 中的資料編製索引的 Lambda 函數。
+ `search_lambda_package.zip` – 在 OpenSearch Service 中搜尋資料的 Lambda 函數。
+ `Tenant-1-data` – Tenant-1 的原始 （非索引） 資料範例。
+ `Tenant-2-data` – Tenant-2 的原始 （非索引） 資料範例。

**重要**  
此模式中的故事包括針對 Unix、Linux 和 macOS 格式化的 AWS CLI 命令範例。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

**注意**  
在 AWS CLI 命令中，將角括號 (<>) 內的所有值取代為正確的值。

## 史詩
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-epics"></a>

### 建立和設定 S3 儲存貯體
<a name="create-and-configure-an-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 在 中建立 S3 儲存貯體 AWS 區域。此儲存貯體會保留範例應用程式的非索引租用戶資料。請確定 S3 儲存貯體的名稱是全域唯一的，因為命名空間是由所有 共用 AWS 帳戶。若要建立 S3 儲存貯體，您可以使用 AWS CLI [create-bucket](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/create-bucket.html) 命令，如下所示：<pre>aws s3api create-bucket \<br />  --bucket <tenantrawdata> \<br />  --region <your-AWS-Region></pre>其中 `tenantrawdata`是 S3 儲存貯體名稱。（您可以使用遵循儲存[貯體命名準則](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html)的任何唯一名稱。) | 雲端架構師、雲端管理員 | 

### 建立和設定 Elasticsearch 叢集
<a name="create-and-configure-an-elasticsearch-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 OpenSearch Service 網域 | 執行 AWS CLI [create-elasticsearch-domain](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/es/create-elasticsearch-domain.html) 命令來建立 OpenSearch Service 網域：<pre>aws es create-elasticsearch-domain \<br />  --domain-name vpc-cli-example \<br />  --elasticsearch-version 7.10 \<br />  --elasticsearch-cluster-config InstanceType=t3.medium.elasticsearch,InstanceCount=1 \<br />  --ebs-options EBSEnabled=true,VolumeType=gp2,VolumeSize=10 \<br />  --domain-endpoint-options "{\"EnforceHTTPS\": true}" \<br />  --encryption-at-rest-options "{\"Enabled\": true}" \<br />  --node-to-node-encryption-options "{\"Enabled\": true}" \<br />  --advanced-security-options "{\"Enabled\": true, \"InternalUserDatabaseEnabled\": true, \<br />    \"MasterUserOptions\": {\"MasterUserName\": \"KibanaUser\", \<br />    \"MasterUserPassword\": \"NewKibanaPassword@123\"}}" \<br />  --vpc-options "{\"SubnetIds\": [\"<subnet-id>\"], \"SecurityGroupIds\": [\"<sg-id>\"]}" \<br />  --access-policies "{\"Version\": \"2012-10-17\", \"Statement\": [ { \"Effect\": \"Allow\", \ <br />    \"Principal\": {\"AWS\": \"*\" }, \"Action\":\"es:*\", \<br />    \"Resource\": \"arn:aws:es:<region>:<account-id>:domain\/vpc-cli-example\/*\" } ] }"</pre>執行個體計數設定為 1，因為網域用於測試目的。您需要使用 `advanced-security-options` 參數啟用精細存取控制，因為在建立網域之後無法變更詳細資訊。 此命令會建立主要使用者名稱 (`KibanaUser`) 和密碼，您可以用來登入 Kibana 主控台。由於網域是虛擬私有雲端 (VPC) 的一部分，因此您必須指定要使用的存取政策，以確保可以連接 Elasticsearch 執行個體。如需詳細資訊，請參閱 AWS 文件中的在 [VPC 內啟動 Amazon OpenSearch Service 網域](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html)。 | 雲端架構師、雲端管理員 | 
| 設定堡壘主機。 | 將 Amazon Elastic Compute Cloud (Amazon EC2) Windows 執行個體設定為堡壘主機，以存取 Kibana 主控台。Elasticsearch 安全群組必須允許來自 Amazon EC2 安全群組的流量。如需說明，請參閱部落格文章[使用堡壘伺服器控制 EC2 執行個體的網路存取](https://aws.amazon.com/blogs/security/controlling-network-access-to-ec2-instances-using-a-bastion-server/)。當堡壘主機已設定，且您有與執行個體相關聯的安全群組可用時，請使用 AWS CLI [authorize-security-group-ingress](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/authorize-security-group-ingress.html) 命令將許可新增至 Elasticsearch 安全群組，以允許來自 Amazon EC2 （堡壘主機） 安全群組的連接埠 443。<pre>aws ec2 authorize-security-group-ingress \<br />  --group-id <SecurityGroupIdfElasticSearch> \ <br />  --protocol tcp \<br />  --port 443 \<br />  --source-group <SecurityGroupIdfBashionHostEC2></pre> | 雲端架構師、雲端管理員 | 

### 建立和設定 Lambda 索引函數
<a name="create-and-configure-the-lam-index-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Lambda 執行角色。 | 執行 AWS CLI [createe-role](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-role.html) 命令，以授予 Lambda 索引函數對 AWS 服務 和 資源的存取權：<pre>aws iam create-role \<br />  --role-name index-lambda-role \<br />  --assume-role-policy-document file://lambda_assume_role.json</pre>其中 `lambda_assume_role.json`是將`AssumeRole`許可授予 Lambda 函數的 JSON 文件，如下所示：<pre>{<br />     "Version": "2012-10-17",		 	 	 <br />     "Statement": [<br />         {<br />             "Effect": "Allow",<br />             "Principal": {<br />                 "Service": "lambda.amazonaws.com"<br />               },<br />             "Action": "sts:AssumeRole"<br />         }<br />     ]<br /> }</pre> | 雲端架構師、雲端管理員 | 
| 將受管政策連接至 Lambda 角色。 | 執行 AWS CLI [attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html) 命令，將受管政策連接到上一個步驟中建立的角色。這兩個政策提供角色建立彈性網路界面和將日誌寫入 CloudWatch Logs 的許可。<pre>aws iam attach-role-policy \<br />  --role-name index-lambda-role \<br />  --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole<br /><br />aws iam attach-role-policy \<br />  --role-name index-lambda-role \<br />  --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole </pre> | 雲端架構師、雲端管理員 | 
| 建立政策以授予 Lambda 索引函數讀取 S3 物件的許可。 | 對 執行 the AWS CLI [create-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html) 命令，授予 Lambda 索引函數讀取 S3 儲存貯體中物件的`s3:GetObject`許可：<pre>aws iam create-policy \<br />  --policy-name s3-permission-policy \<br />  --policy-document file://s3-policy.json</pre>檔案`s3-policy.json`是如下所示的 JSON 文件，授予`s3:GetObject`許可以允許對 S3 物件的讀取存取。如果您在建立 S3 儲存貯體時使用不同的名稱，請在 `Resource `區段中提供正確的儲存貯體名稱：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />           "Effect": "Allow",<br />           "Action": "s3:GetObject",<br />           "Resource": "arn:aws:s3:::<tenantrawdata>/*"<br />        }<br />    ]<br />}</pre> | 雲端架構師、雲端管理員 | 
| 將 Amazon S3 許可政策連接至 Lambda 執行角色。 | 執行 AWS CLI [attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html) 命令，將您在上一個步驟中建立的 Amazon S3 許可政策連接至 Lambda 執行角色：<pre>aws iam attach-role-policy \<br />  --role-name index-lambda-role \<br />  --policy-arn <PolicyARN></pre>其中 `PolicyARN`是 Amazon S3 許可政策的 Amazon Resource Name (ARN)。您可以從上一個命令的輸出取得此值。 | 雲端架構師、雲端管理員 | 
| 建立 Lambda 索引函數。 | 執行 AWS CLI [createe-function](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-function.html) 命令來建立 Lambda 索引函數，這會存取 OpenSearch Service：<pre>aws lambda create-function \<br />  --function-name index-lambda-function \<br />  --zip-file fileb://index_lambda_package.zip \<br />  --handler lambda_index.lambda_handler \<br />  --runtime python3.9 \<br />  --role "arn:aws:iam::account-id:role/index-lambda-role" \<br />  --timeout 30 \<br />  --vpc-config "{\"SubnetIds\": [\"<subnet-id1\>", \"<subnet-id2>\"], \<br />    \"SecurityGroupIds\": [\"<sg-1>\"]}"</pre> | 雲端架構師、雲端管理員 | 
| 允許 Amazon S3 呼叫 Lambda 索引函數。 | 執行 AWS CLI [add-permission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/add-permission.html) 命令，給予 Amazon S3 呼叫 Lambda 索引函數的許可：<pre>aws lambda add-permission \<br />  --function-name index-lambda-function \<br />  --statement-id s3-permissions \<br />  --action lambda:InvokeFunction \<br />  --principal s3.amazonaws.com \<br />  --source-arn "arn:aws:s3:::<tenantrawdata>" \<br />  --source-account "<account-id>" </pre> | 雲端架構師、雲端管理員 | 
| 為 Amazon S3 事件新增 Lambda 觸發條件。 | 執行 AWS CLI [put-bucket-notification-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/put-bucket-notification-configuration.html) 命令，以在偵測到 Amazon S3 `ObjectCreated`事件時傳送通知至 Lambda 索引函數。索引函數會在物件上傳到 S3 儲存貯體時執行。 <pre>aws s3api put-bucket-notification-configuration \<br />  --bucket <tenantrawdata> \<br />  --notification-configuration file://s3-trigger.json</pre>檔案`s3-trigger.json`是目前資料夾中的 JSON 文件，會在 Amazon S3 `ObjectCreated`事件發生時將資源政策新增至 Lambda 函數。 | 雲端架構師、雲端管理員 | 

### 建立和設定 Lambda 搜尋函數
<a name="create-and-configure-the-lam-search-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Lambda 執行角色。 | 執行 AWS CLI [createe-role](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-role.html) 命令，以授予 Lambda 搜尋函數對 AWS 服務 和 資源的存取權：<pre>aws iam create-role \<br />  --role-name search-lambda-role \<br />  --assume-role-policy-document file://lambda_assume_role.json</pre>其中 `lambda_assume_role.json` 是目前資料夾中的 JSON 文件，授予 Lambda 函數`AssumeRole`許可，如下所示：<pre>{<br />     "Version": "2012-10-17",		 	 	 <br />     "Statement": [<br />         {<br />             "Effect": "Allow",<br />             "Principal": {<br />                 "Service": "lambda.amazonaws.com"<br />               },<br />             "Action": "sts:AssumeRole"<br />         }<br />     ]<br /> }</pre> | 雲端架構師、雲端管理員 | 
| 將受管政策連接至 Lambda 角色。 | 執行 AWS CLI [attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html) 命令，將受管政策連接至上一個步驟中建立的角色。這兩個政策提供角色建立彈性網路界面和將日誌寫入 CloudWatch Logs 的許可。<pre>aws iam attach-role-policy \<br />  --role-name search-lambda-role \<br />  --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole<br /><br />aws iam attach-role-policy \<br />  --role-name search-lambda-role \<br />  --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole </pre> | 雲端架構師、雲端管理員 | 
| 建立 Lambda 搜尋函數。 | 執行 AWS CLI [createe-function](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-function.html) 命令來建立 Lambda 搜尋函數，這會存取 OpenSearch Service：<pre>aws lambda create-function \<br />  --function-name search-lambda-function \<br />  --zip-file fileb://search_lambda_package.zip \<br />  --handler lambda_search.lambda_handler \<br />  --runtime python3.9 \<br />  --role "arn:aws:iam::account-id:role/search-lambda-role" \<br />  --timeout 30 \<br />  --vpc-config "{\"SubnetIds\": [\"<subnet-id1\>", \"<subnet-id2>\"], \<br />    \"SecurityGroupIds\": [\"<sg-1>\"]}"</pre> | 雲端架構師、雲端管理員 | 

### 建立和設定租戶角色
<a name="create-and-configure-tenant-roles"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立租戶 IAM 角色。 | 執行 the AWS CLI [create-role](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-role.html) 命令來建立兩個租用戶角色，用於測試搜尋功能：<pre>aws iam create-role \<br />  --role-name Tenant-1-role \<br />  --assume-role-policy-document file://assume-role-policy.json</pre><pre>aws iam create-role \<br />  --role-name Tenant-2-role \<br />  --assume-role-policy-document file://assume-role-policy.json</pre>檔案`assume-role-policy.json`是目前資料夾中的 JSON 文件，可將`AssumeRole`許可授予 Lambda 執行角色：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Principal": {<br />                 "AWS": "<Lambda execution role for index function>",<br />                 "AWS": "<Lambda execution role for search function>"<br />             },<br />            "Action": "sts:AssumeRole"<br />        }<br />    ]<br />}</pre> | 雲端架構師、雲端管理員 | 
| 建立租戶 IAM 政策。 | 執行 AWS CLI [createe-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html) 命令來建立租用戶政策，以授予對 Elasticsearch 操作的存取權：<pre>aws iam create-policy \<br />  --policy-name tenant-policy \<br />  --policy-document file://policy.json</pre>檔案`policy.json`是目前資料夾中的 JSON 文件，可授予 Elasticsearch 的許可：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Action": [<br />                "es:ESHttpDelete",<br />                "es:ESHttpGet",<br />                "es:ESHttpHead",<br />                "es:ESHttpPost",<br />                "es:ESHttpPut",<br />                "es:ESHttpPatch"<br />            ],<br />            "Resource": [<br />                "<ARN of Elasticsearch domain created earlier>"<br />            ]<br />        }<br />    ]<br />}</pre> | 雲端架構師、雲端管理員 | 
| 將租戶 IAM 政策連接至租戶角色。 | 執行 AWS CLI [attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html) 命令，將租用戶 IAM 政策連接至您在先前步驟中建立的兩個租用戶角色：<pre>aws iam attach-role-policy \<br />  --policy-arn arn:aws:iam::account-id:policy/tenant-policy \<br />  --role-name Tenant-1-role<br /><br />aws iam attach-role-policy \<br />  --policy-arn arn:aws:iam::account-id:policy/tenant-policy \<br />  --role-name Tenant-2-role</pre>政策 ARN 來自上一個步驟的輸出。 | 雲端架構師、雲端管理員 | 
| 建立 IAM 政策，授予 Lambda 擔任角色的許可。 | 執行 the AWS CLI [create-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html) 命令，為 Lambda 建立政策以擔任租戶角色：<pre>aws iam create-policy \<br />  --policy-name assume-tenant-role-policy \<br />  --policy-document file://lambda_policy.json</pre>檔案`lambda_policy.json`是目前資料夾中的 JSON 文件，授予 許可`AssumeRole`：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />       {<br />            "Effect": "Allow",<br />            "Action":  "sts:AssumeRole",<br />            "Resource": "<ARN of tenant role created earlier>"<br />       }<br />    ]<br />}</pre>對於 `Resource`，您可以使用萬用字元來避免為每個租用戶建立新的政策。 | 雲端架構師、雲端管理員 | 
| 建立 IAM 政策，授予 Lambda 索引角色存取 Amazon S3 的許可。 | 執行 AWS CLI [createe-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html) 命令，授予 Lambda 索引角色存取 S3 儲存貯體中物件的許可：<pre>aws iam create-policy \<br />  --policy-name s3-permission-policy \<br />  --policy-document file://s3_lambda_policy.json</pre>檔案`s3_lambda_policy.json`是目前資料夾中的下列 JSON 政策文件：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Action": "s3:GetObject",<br />            "Resource": "arn:aws:s3:::tenantrawdata/*"<br />        }<br />    ]<br />}</pre> | 雲端架構師、雲端管理員 | 
| 將政策連接至 Lambda 執行角色。 | 執行 AWS CLI [attach-role-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/attach-role-policy.html) 命令，將上一個步驟中建立的政策連接至您先前建立的 Lambda 索引和搜尋執行角色：<pre>aws iam attach-role-policy \<br />  --policy-arn arn:aws:iam::account-id:policy/assume-tenant-role-policy \<br />  --role-name index-lambda-role<br /><br />aws iam attach-role-policy \<br />  --policy-arn arn:aws:iam::account-id:policy/assume-tenant-role-policy \<br />  --role-name search-lambda-role<br /><br />aws iam attach-role-policy \<br />  --policy-arn arn:aws:iam::account-id:policy/s3-permission-policy \<br />  --role-name index-lambda-role</pre>政策 ARN 來自上一個步驟的輸出。 | 雲端架構師、雲端管理員 | 

### 建立和設定搜尋 API
<a name="create-and-configure-a-search-api"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 API Gateway 中建立 REST API。 | 執行 AWS CLI [create-rest-api](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/apigateway/create-rest-api.html) 命令來建立 REST API 資源：<pre>aws apigateway create-rest-api \<br />  --name Test-Api \<br />  --endpoint-configuration "{ \"types\": [\"REGIONAL\"] }"</pre>對於端點組態類型，您可以指定 `EDGE`，而不是`REGIONAL`使用節點，而不是特定節點 AWS 區域。請注意命令輸出中 `id` 欄位的值。這是您將在後續命令中使用的 API ID。 | 雲端架構師、雲端管理員 | 
| 建立搜尋 API 的資源。 | 搜尋 API 資源會以資源名稱 啟動 Lambda 搜尋函數`search`。（您不需要為 Lambda 索引函數建立 API，因為它會在物件上傳至 S3 儲存貯體時自動執行。)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.html) | 雲端架構師、雲端管理員 | 
| 建立搜尋 API 的 GET 方法。 | 執行 AWS CLI [put-method](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/apigateway/put-method.html) 命令來建立搜尋 API `GET `的方法：<pre>aws apigateway put-method \<br />  --rest-api-id <API-ID> \<br />  --resource-id <ID from the previous command output> \<br />  --http-method GET \<br />  --authorization-type "NONE" \<br />  --no-api-key-required</pre>針對 `resource-id`，指定來自 `create-resource`命令輸出的 ID。 | 雲端架構師、雲端管理員 | 
| 建立搜尋 API 的方法回應。 | 執行 AWS CLI [put-method-response](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/apigateway/put-method-response.html) 命令，為搜尋 API 新增方法回應：<pre>aws apigateway put-method-response \<br />  --rest-api-id <API-ID> \<br />  --resource-id  <ID from the create-resource command output> \<br />  --http-method GET \<br />  --status-code 200 \<br />  --response-models "{\"application/json\": \"Empty\"}"</pre>針對 `resource-id`，指定先前`create-resource`命令輸出的 ID。 | 雲端架構師、雲端管理員 | 
| 設定搜尋 API 的代理 Lambda 整合。 | 執行 AWS CLI [put-integration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/apigateway/put-integration.html) 命令來設定與 Lambda 搜尋函數的整合：<pre>aws apigateway put-integration \<br />  --rest-api-id <API-ID> \<br />  --resource-id  <ID from the create-resource command output> \<br />  --http-method GET \<br />  --type AWS_PROXY \<br />  --integration-http-method GET \<br />  --uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/arn:aws:lambda:<region>:<account-id>:function:<function-name>/invocations</pre>針對 `resource-id`，指定先前`create-resource`命令的 ID。 | 雲端架構師、雲端管理員 | 
| 授予 API Gateway 呼叫 Lambda 搜尋函數的許可。 | 執行 AWS CLI [add-permission](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/add-permission.html) 命令，給予 API Gateway 使用搜尋函數的許可：<pre>aws lambda add-permission \<br />  --function-name <function-name> \<br />  --statement-id apigateway-get \<br />  --action lambda:InvokeFunction \<br />  --principal apigateway.amazonaws.com \<br />  --source-arn "arn:aws:execute-api:<region>:<account-id>:api-id/*/GET/search</pre>如果您使用不同的 API 資源名稱而非 ，請變更`source-arn`路徑`search`。 | 雲端架構師、雲端管理員 | 
| 部署搜尋 API。 | 執行 the AWS CLI [create-deployment](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/apigateway/create-deployment.html) 命令來建立名為 的階段資源`dev`：<pre>aws apigateway create-deployment \<br />  --rest-api-id <API-ID> \<br />  --stage-name dev</pre>如果您更新 API，您可以使用相同的 AWS CLI 命令將其重新部署到相同的階段。 | 雲端架構師、雲端管理員 | 

### 建立和設定 Kibana 角色
<a name="create-and-configure-kibana-roles"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 登入 Kibana 主控台。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.html) | 雲端架構師、雲端管理員 | 
| 建立和設定 Kibana 角色。 | 若要提供資料隔離並確保一個租用戶無法擷取另一個租用戶的資料，您需要使用文件安全，這允許租用戶僅存取包含其租用戶 ID 的文件。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.html) | 雲端架構師、雲端管理員 | 
| 將使用者映射至角色。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.html)我們建議您在租戶加入時自動建立租戶和 Kibana 角色。 | 雲端架構師、雲端管理員 | 
| 建立租用戶資料索引。 | 在導覽窗格的**管理**下，選擇**開發工具**，然後執行下列命令。此命令會建立`tenant-data`索引來定義 `TenantId` 屬性的映射。<pre>PUT /tenant-data<br />{<br />  "mappings": {<br />    "properties": {<br />      "TenantId": { "type": "keyword"}<br />    }<br />  }<br />}</pre> | 雲端架構師、雲端管理員 | 

### 為 Amazon S3 和 建立 VPC 端點 AWS STS
<a name="create-vpc-endpoints-for-s3-and-sts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 Amazon S3 建立 VPC 端點。 | 執行 AWS CLI [create-vpc-endpoint](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/create-vpc-endpoint.html) 命令，為 Amazon S3 建立 VPC 端點。端點可讓 VPC 中的 Lambda 索引函數存取 Amazon S3。<pre>aws ec2 create-vpc-endpoint \<br />  --vpc-id <VPC-ID> \<br />  --service-name com.amazonaws.us-east-1.s3 \<br />  --route-table-ids <route-table-ID></pre>針對 `vpc-id`，指定您用於 Lambda 索引函數的 VPC。對於 `service-name`，請使用 Amazon S3 端點的正確 URL。針對 `route-table-ids`，指定與 VPC 端點相關聯的路由表。 | 雲端架構師、雲端管理員 | 
| 為 建立 VPC 端點 AWS STS。 | 執行 AWS CLI [create-vpc-endpoint](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/create-vpc-endpoint.html) 命令來建立 AWS Security Token Service () 的 VPC 端點AWS STS。端點可讓 VPC 中的 Lambda 索引和搜尋函數存取 AWS STS。函數在擔任 IAM 角色 AWS STS 時使用。<pre>aws ec2 create-vpc-endpoint \<br />  --vpc-id <VPC-ID> \<br />  --vpc-endpoint-type Interface \<br />  --service-name com.amazonaws.us-east-1.sts \<br />  --subnet-id <subnet-ID> \<br />  --security-group-id <security-group-ID></pre>針對 `vpc-id`，指定您用於 Lambda 索引和搜尋函數的 VPC。針對 `subnet-id`，提供應建立此端點的子網路。針對 `security-group-id`，指定要與此端點建立關聯的安全群組。（它可以與 Lambda 使用的安全群組相同。) | 雲端架構師、雲端管理員 | 

### 測試多租戶和資料隔離
<a name="test-multi-tenancy-and-data-isolation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新索引和搜尋函數的 Python 檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.html)您可以從 OpenSearch Service 主控台的**概觀**索引標籤取得 Elasticsearch 端點。 OpenSearch 其格式為 `<AWS-Region>.es.amazonaws.com`。 | 雲端架構師、應用程式開發人員 | 
| 更新 Lambda 程式碼。 | 使用 AWS CLI [update-function-code](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html) 命令，使用您對 Python 檔案所做的變更來更新 Lambda 程式碼：<pre>aws lambda update-function-code \<br />  --function-name index-lambda-function \<br />  --zip-file fileb://index_lambda_package.zip<br /><br />aws lambda update-function-code \<br />  --function-name search-lambda-function \<br />  --zip-file fileb://search_lambda_package.zip</pre> | 雲端架構師、應用程式開發人員 | 
| 將原始資料上傳至 S3 儲存貯體。 | 使用 the AWS CLI [cp](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/cp.html) 命令將Tenant-1 和Tenant-2 物件的資料上傳至儲存`tenantrawdata`貯體 （指定您為此目的建立的 S3 儲存貯體名稱）：<pre>aws s3 cp tenant-1-data s3://tenantrawdata<br />aws s3 cp tenant-2-data s3://tenantrawdata</pre>S3 儲存貯體設定為在上傳資料時執行 Lambda 索引函數，以便在 Elasticsearch 中編製文件索引。 | 雲端架構師、雲端管理員 | 
| 從 Kibana 主控台搜尋資料。 | 在 Kibana 主控台上執行下列查詢：<pre>GET tenant-data/_search</pre>此查詢會顯示在 Elasticsearch 中編製索引的所有文件。在此情況下，您應該會看到兩個單獨的Tenant-1 和Tenant-2 文件。 | 雲端架構師、雲端管理員 | 
| 從 API Gateway 測試搜尋 API。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service.html)如需畫面圖例，請參閱[其他資訊](#build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-additional)一節。 | 雲端架構師、應用程式開發人員 | 
| 清除資源。 | 清除您建立的所有資源，以防止您的 帳戶產生額外費用。 | AWS DevOps、雲端架構師、雲端管理員 | 

## 相關資源
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-resources"></a>
+ [適用於 Python (Boto) 的 AWS SDK](https://aws.amazon.com/sdk-for-python/)
+ [AWS Lambda 文件](https://docs.aws.amazon.com/lambda/)
+ [API Gateway 文件](https://docs.aws.amazon.com/apigateway/)
+ [Amazon S3 文件](https://docs.aws.amazon.com/s3/)
+ [Amazon OpenSearch Service 文件](https://docs.aws.amazon.com/elasticsearch-service/)
  + [Amazon OpenSearch Service 中的精細存取控制](https://docs.amazonaws.cn/en_us/elasticsearch-service/latest/developerguide/fgac.html)
  + [使用 Amazon OpenSearch Service 建立搜尋應用程式](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/search-example.html)
  + [在 VPC 中啟動 Amazon OpenSearch Service 網域](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html)

## 其他資訊
<a name="build-a-multi-tenant-serverless-architecture-in-amazon-opensearch-service-additional"></a>

**資料分割模型**

多租戶系統中使用三種常見的資料分割模型：孤立、集區和混合。您選擇的模型取決於您環境的合規、雜訊鄰近、操作和隔離需求。

*Silo 模型*

在孤島模型中，每個租用戶的資料會存放在不同的儲存區域中，其中不會混合租用戶資料。您可以使用兩種方法來使用 OpenSearch Service 實作孤立模型：每個租用戶的網域和每個租用戶的索引。
+ **每個租用戶的網域** – 您可以為每個租用戶使用單獨的 OpenSearch Service 網域 （與 Elasticsearch 叢集同義）。將每個租用戶放在自己的網域中，可提供與在獨立建構中擁有資料相關聯的所有優點。不過，這種方法帶來了管理和敏捷性的挑戰。其分散式性質使彙整和評估租戶的運作狀態和活動更加困難。這是一個昂貴的選項，要求每個 OpenSearch Service 網域至少擁有三個主節點和兩個資料節點供生產工作負載使用。

![\[多租用戶無伺服器架構的每個租用戶孤島模型的網域。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/c2195f82-e5ed-40bb-b76a-3b0210bf1254.png)


 
+ **每個租用戶的索引** – 您可以將租用戶資料放在 OpenSearch Service 叢集中的個別索引中。透過此方法，您可以在建立和命名索引時使用租用戶識別符，方法是在索引名稱前面加上租用戶識別符。每個租用戶的索引方法可協助您實現孤立目標，而無需為每個租用戶引入完全獨立的叢集。不過，如果索引數量增加，您可能會遇到記憶體壓力，因為這種方法需要更多的碎片，主節點必須處理更多的配置和重新平衡。

![\[多租用戶無伺服器架構的每個租用戶孤島模型索引。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/354a9463-25bb-422b-84de-d4875a7c8ea2.png)


 

**孤立模型中的隔離** – 在孤立模型中，您可以使用 IAM 政策來隔離存放每個租戶資料的網域或索引。這些政策可防止一個租用戶存取另一個租用戶的資料。若要實作孤立隔離模型，您可以建立以資源為基礎的政策，以控制對租戶資源的存取。這通常是網域存取政策，指定委託人可以在網域的子資源上執行的動作，包括 Elasticsearch 索引和 APIs。透過 IAM 身分型政策，您可以在 OpenSearch Service 中的網域、索引或 APIs上指定*允許**或拒絕*的動作。IAM 政策的 `Action`元素說明政策允許或拒絕的特定動作，而 `Principal `元素指定受影響的帳戶、使用者或角色。

下列範例政策僅授予Tenant-1 對`tenant-1`網域上子資源的完整存取權 （如 所指定`es:*`)。`Resource`元素`/*`中的結尾表示此政策適用於網域的子資源，而非網域本身。當此政策生效時，租用戶不得在現有網域上建立新的網域或修改設定。

```
{
   "Version": "2012-10-17",		 	 	 
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": {
            "AWS": "arn:aws:iam::<aws-account-id>:user/Tenant-1"
         },
         "Action": "es:*",
         "Resource": "arn:aws:es:<Region>:<account-id>:domain/tenant-1/*"
      }
   ]
}
```

若要實作每個索引孤島模型的租用戶，您需要修改此範例政策，透過指定索引名稱，進一步將Tenant-1 限制為指定的索引或索引。下列範例政策會將Tenant-1 限制為`tenant-index-1`索引。 

```
{
   "Version": "2012-10-17",		 	 	 
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": {
            "AWS": "arn:aws:iam::123456789012:user/Tenant-1"
         },
         "Action": "es:*",
         "Resource": "arn:aws:es:<Region>:<account-id>:domain/test-domain/tenant-index-1/*"
      }
   ]
}
```

*集區模型*

在集區模型中，所有租用戶資料都會存放在相同網域內的索引中。租用戶識別符包含在資料 （文件） 中，並用作分割區索引鍵，因此您可以判斷哪些資料屬於哪個租用戶。此模型可減少管理開銷。操作和管理集區索引比管理多個索引更簡單且更有效率。不過，由於租戶資料在相同索引中混合，您會失去孤立模型提供的自然租戶隔離。這種方法也可能會因為雜訊鄰近效果而降低效能。

![\[多租戶無伺服器架構的集區模型。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/c2c3bb0f-6ccd-47a7-ab67-e7f3f8c7f289.png)


 

**集區模型中的租戶隔離** – 一般而言，在集區模型中實作租戶隔離具有挑戰性。與孤立模型搭配使用的 IAM 機制不允許您根據存放在文件中的租用戶 ID 來描述隔離。

另一種方法是使用 Open Distro for Elasticsearch 提供的[精細存取控制 ](https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html)(FGAC) 支援。FGAC 可讓您在索引、文件或欄位層級控制許可。在每個請求中，FGAC 會評估使用者登入資料，並對使用者進行身分驗證或拒絕存取。如果 FGAC 驗證使用者，它會擷取對應至該使用者的所有角色，並使用完整的許可集來判斷如何處理請求。 

若要在集區模型中實現所需的隔離，您可以使用[文件層級安全性](https://opendistro.github.io/for-elasticsearch-docs/docs/security/access-control/document-level-security/)，這可讓您將角色限制為索引中的文件子集。下列範例角色會將查詢限制為Tenant-1。透過將此角色套用至Tenant-1，您可以實現必要的隔離。 

```
{
   "bool": {
     "must": {
       "match": {
         "tenantId": "Tenant-1"
       }
     }
   }
 }
```

*混合模型*

混合模型在相同環境中使用孤立和集區模型的組合，為每個租用戶層 （例如免費、標準和高級層） 提供獨特的體驗。每個層遵循與集區模型中使用的相同安全性描述檔。

 

![\[多租戶無伺服器架構的混合模型。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/e7def98a-38ef-435a-9881-7e95ae4d4940.png)


**混合模型中的租用戶隔離** – 在混合模型中，您遵循與集區模型相同的安全性設定檔，其中在文件層級使用 FGAC 安全模型提供租用戶隔離。雖然此策略可簡化叢集管理並提供敏捷性，但它會使架構的其他層面變得複雜。例如，您的程式碼需要額外的複雜性，才能判斷哪個模型與每個租用戶相關聯。您也必須確保單一租用戶查詢不會讓整個網域飽和，並降低其他租用戶的體驗。 

**在 API Gateway 中測試**

*Tenant-1 查詢的測試時段*

![\[Tenant-1 查詢的測試時段。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/a6757d3f-977a-4ecc-90cb-83ab7f1c3588.png)


*Tenant-2 查詢的測試時段*

 

![\[Tenant-2 查詢的測試時段。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/750196bb-03f6-4b6e-92cd-eb7141602547/images/31bfd656-33ca-4750-b6e6-da4d703c2071.png)


## 附件
<a name="attachments-750196bb-03f6-4b6e-92cd-eb7141602547"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/750196bb-03f6-4b6e-92cd-eb7141602547/attachments/attachment.zip)

# 使用 AWS CDK 搭配 TypeScript 部署多堆疊應用程式
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript"></a>

*Rahul Sharad Gaikwad 醫生，Amazon Web Services*

## 總結
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-summary"></a>

此模式提供step-by-step方法。 TypeScript 例如， 模式會部署無伺服器即時分析應用程式。

模式會建置和部署巢狀堆疊應用程式。父 AWS CloudFormation 堆疊會呼叫子堆疊或巢狀堆疊。 每個子堆疊都會建置和部署 CloudFormation 堆疊中定義的 AWS 資源。AWS CDK Toolkit 是命令列界面 (CLI) 命令 `cdk`，是 CloudFormation 堆疊的主要界面。

## 先決條件和限制
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 現有的虛擬私有雲端 (VPC) 和子網路
+ 安裝並設定 AWS CDK Toolkit
+ 具有管理員許可和一組存取金鑰的使用者。
+ Node.js
+ AWS 命令列界面 (AWS CLI)

**限制**
+ 由於 AWS CDK 使用 AWS CloudFormation，AWS CDK 應用程式受限於 CloudFormation 服務配額。如需詳細資訊，請參閱 [AWS CloudFormation 配額](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)。

**產品版本**

此模式已使用下列工具和版本建置和測試。
+ AWS CDK Toolkit 1.83.0
+ Node.js 14.13.0
+ npm 7.0.14

模式應適用於任何版本的 AWS CDK 或 npm。請注意，Node.js 13.0.0 到 13.6.0 版與 AWS CDK 不相容。

## Architecture
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-architecture"></a>

**目標技術堆疊**
+ AWS Amplify 主控台
+ Amazon API Gateway
+ AWS CDK
+ Amazon CloudFront
+ Amazon Cognito
+ Amazon DynamoDB
+ Amazon Data Firehose
+ Amazon Kinesis Data Streams
+ AWS Lambda
+ Amazon Simple Storage Service (Amazon S3)

**目標架構**

下圖顯示使用 AWS CDK 搭配 TypeScript 的多堆疊應用程式部署。

![\[VPC 中的堆疊架構，具有父堆疊和兩個包含資源的子堆疊。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0ac29a11-1362-4084-92ed-6b85205763ca/images/8f92e86a-aa3d-4f8a-9b11-b92c52a7226c.png)


 

下圖顯示範例無伺服器即時應用程式的架構。

![\[區域中的應用程式架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0ac29a11-1362-4084-92ed-6b85205763ca/images/2df00faf-f871-4aec-9655-19ba2eb14cf8.png)


 

## 工具
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-tools"></a>

**工具**
+ [AWS Amplify 主控台](https://docs.aws.amazon.com/amplify/latest/userguide/welcome.html)是 AWS 中完全堆疊 Web 和行動應用程式部署的控制中心。Amplify 主控台託管提供以 git 為基礎的工作流程，用於託管具有持續部署的完整堆疊無伺服器 Web 應用程式。Admin UI 是前端 Web 和行動開發人員的視覺化界面，可在 AWS 主控台外部建立和管理應用程式後端。
+ [Amazon API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) 是一種 AWS 服務，可用於建立、發佈、維護、監控和保護任何規模的 REST、HTTP 和 WebSocket APIs。
+ [AWS 雲端開發套件 (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) 是一種軟體開發架構，可協助您在程式碼中定義和佈建 AWS 雲端基礎設施。
+ [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) 是命令列雲端開發套件，可協助您與 AWS CDK 應用程式互動。CLI `cdk` 命令是與您的 AWS CDK 應用程式互動的主要工具。它會執行您的應用程式、查詢您定義的應用程式模型，以及產生和部署由 AWS CDK 產生的 AWS CloudFormation 範本。
+ [Amazon CloudFront](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html) 是一種 Web 服務，可加速靜態和動態 Web 內容的分佈，例如 .html、.css、.js 和映像檔案。CloudFront 透過稱為節點的全球資料中心網路提供內容，以降低延遲並改善效能。
+ [Amazon Cognito](https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html) 為您的 Web 和行動應用程式提供身分驗證、授權和使用者管理。您的使用者可以直接或透過第三方登入。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能和無縫的可擴展性。
+ [Amazon Data Firehose](https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html) 是一項全受管服務，可將即時[串流資料](https://aws.amazon.com/streaming-data/)交付至目的地，例如 Amazon S3、Amazon Redshift、Amazon OpenSearch Service、Splunk，以及受支援的第三方服務供應商擁有的任何自訂 HTTP 端點或 HTTP 端點。
+ [Amazon Kinesis Data Streams](https://docs.aws.amazon.com/streams/latest/dev/introduction.html) 是一項服務，可即時收集和處理大型資料記錄串流。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，支援執行程式碼，無需佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。只需為使用的運算時間支付費用，一旦未執行程式碼，就會停止計費。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**Code**

此模式的程式碼已連接。

## 史詩
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-epics"></a>

### 安裝 AWS CDK Toolkit
<a name="install-aws-cdk-toolkit"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS CDK Toolkit。 | 若要全域安裝 AWS CDK Toolkit，請執行下列命令。`npm install -g aws-cdk` | DevOps | 
| 驗證版本。 | 若要驗證 AWS CDK Toolkit 版本，請執行下列命令。 `cdk --version` | DevOps | 

### 設定 AWS 登入資料
<a name="set-up-aws-credentials"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定登入資料。 | 若要設定登入資料，請執行 `aws configure`命令並依照提示操作。<pre>$aws configure<br />AWS Access Key ID [None]: <br />AWS Secret Access Key [None]: your_secret_access_key<br />Default region name [None]:<br />Default output format [None]:</pre> | DevOps | 

### 下載專案程式碼
<a name="download-the-project-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載連接的專案程式碼。 | 如需 目錄和檔案結構的詳細資訊，請參閱*其他資訊*一節。 | DevOps | 

### 引導 AWS CDK 環境
<a name="bootstrap-the-aws-cdk-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 引導環境。 | 若要將 AWS CloudFormation 範本部署到您要使用的帳戶和 AWS 區域，請執行下列命令。`cdk bootstrap <account>/<Region>`如需詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)。 | DevOps | 

### 建置和部署專案
<a name="build-and-deploy-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建置專案。 | 若要建置專案程式碼，請執行 `npm run build`命令。 | DevOps | 
| 部署專案。 | 若要部署專案程式碼，請執行 `cdk deploy`命令。 |  | 

### 驗證輸出
<a name="verify-outputs"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證堆疊建立。 | 在 AWS 管理主控台上，選擇 **CloudFormation**。在專案的堆疊中，確認已建立父堆疊和兩個子堆疊。 | DevOps | 

### 測試應用程式。
<a name="test-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將資料傳送至 Kinesis Data Streams。 | 設定您的 AWS 帳戶，使用 Amazon Kinesis Data Generator (KDG) 將資料傳送至 Kinesis Data Streams。如需詳細資訊，請參閱 [Amazon Kinesis Data Generator](https://awslabs.github.io/amazon-kinesis-data-generator/web/help.html)。 | DevOps | 
| 建立 Amazon Cognito 使用者。 | 若要建立 Amazon Cognito 使用者，請從 [Kinesis Data Generator 說明頁面上](https://awslabs.github.io/amazon-kinesis-data-generator/web/help.html)*的建立 Amazon Cognito 使用者*區段下載 cognito-setup.json CloudFormation 範本。啟動範本，然後輸入您的 Amazon Cognito **使用者名稱和密碼******。**Outputs** 索引標籤會列出 Kinesis Data Generator URL。 | DevOps | 
| 登入 Kinesis Data Generator | 若要登入 KDG，請使用您提供的 Amazon Cognito 登入資料和 Kinesis Data Generator URL。 | DevOps | 
| 測試應用程式。 | 在 KDG 的記錄**範本****範本 1 **中，從*其他資訊*區段貼上測試碼，然後選擇**傳送資料**。 | DevOps | 
| 測試 API Gateway。 | 擷取資料之後，請使用 `GET`方法來擷取資料，以測試 API Gateway。 | DevOps | 

## 相關資源
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-resources"></a>

**參考**
+ [AWS 雲端開發套件](https://aws.amazon.com/cdk/)
+ [GitHub 上的 AWS CDK](https://github.com/aws/aws-cdk)
+ [使用巢狀堆疊](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html)
+ [AWS 範例 - 無伺服器即時分析](https://github.com/aws-samples/serverless-realtime-analytics)

## 其他資訊
<a name="deploy-multiple-stack-applications-using-aws-cdk-with-typescript-additional"></a>

**目錄和檔案詳細資訊**

此模式會設定下列三個堆疊。
+ `parent-cdk-stack.ts` – 此堆疊做為父堆疊，並呼叫兩個子應用程式做為巢狀堆疊。 
+ `real-time-analytics-poc-stack.ts` – 此巢狀堆疊包含基礎設施和應用程式程式碼。
+ `real-time-analytics-web-stack.ts` – 此巢狀堆疊僅包含靜態 Web 應用程式程式碼。

*重要檔案及其功能*
+ `bin/real-time-analytics-poc.ts` – AWS CDK 應用程式的進入點。它會載入 下定義的所有堆疊`lib/`。
+ `lib/real-time-analytics-poc-stack.ts` – AWS CDK 應用程式堆疊的定義 (`real-time-analytics-poc`)。
+ `lib/real-time-analytics-web-stack.ts` – AWS CDK 應用程式堆疊的定義 (`real-time-analytics-web-stack`)。
+ `lib/parent-cdk-stack.ts` – AWS CDK 應用程式堆疊的定義 (`parent-cdk`)。
+ `package.json` – npm 模組資訊清單，其中包含應用程式名稱、版本和相依性。
+ `package-lock.json` – 由 npm 維護。
+ `cdk.json` – 用於執行應用程式的 工具組。
+ `tsconfig.json` – 專案的 TypeScript 組態。
+ `.gitignore` – Git 應從來源控制中排除的檔案清單。
+ `node_modules` – 由 npm 維護；包括專案的相依性。

父堆疊中的下一節程式碼會將子應用程式稱為巢狀 AWS CDK 堆疊。

```
import * as cdk from '@aws-cdk/core';
import { Construct, Stack, StackProps } from '@aws-cdk/core';
import { RealTimeAnalyticsPocStack } from './real-time-analytics-poc-stack';
import { RealTimeAnalyticsWebStack } from './real-time-analytics-web-stack';


export class CdkParentStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);


    new RealTimeAnalyticsPocStack(this, 'RealTimeAnalyticsPocStack');
    new RealTimeAnalyticsWebStack(this, 'RealTimeAnalyticsWebStack');
  }
}
```

**用於測試的程式碼**

```
session={{date.now('YYYYMMDD')}}|sequence={{date.now('x')}}|reception={{date.now('x')}}|instrument={{random.number(9)}}|l={{random.number(20)}}|price_0={{random.number({"min":10000, "max":30000})}}|price_1={{random.number({"min":10000, "max":30000})}}|price_2={{random.number({"min":10000, "max":30000})}}|price_3={{random.number({"min":10000, "max":30000})}}|price_4={{random.number({"min":10000, "max":30000})}}|price_5={{random.number({"min":10000, "max":30000})}}|price_6={{random.number({"min":10000, "max":30000})}}|price_7={{random.number({"min":10000, "max":30000})}}|price_8={{random.number({"min":10000, "max":30000})}}|
```

**測試 API Gateway**

在 API Gateway 主控台上，使用 `GET`方法測試 API Gateway。

![\[在 OPTIONS 下選擇具有 GET 的 API Gateway 主控台。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0ac29a11-1362-4084-92ed-6b85205763ca/images/452e5b8f-6d61-401d-8484-e5a436cb6f1b.png)


 

## 附件
<a name="attachments-0ac29a11-1362-4084-92ed-6b85205763ca"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/0ac29a11-1362-4084-92ed-6b85205763ca/attachments/attachment.zip)

# 使用 AWS SAM 自動化巢狀應用程式的部署
<a name="automate-deployment-of-nested-applications-using-aws-sam"></a>

*Rahul Sharad Gaikwad 醫生、Ishwar Chauthaiwale、Dmitry Gulin 和 Tabby Ward，Amazon Web Services*

## 總結
<a name="automate-deployment-of-nested-applications-using-aws-sam-summary"></a>

在 Amazon Web Services (AWS) 上，AWS Serverless Application Model (AWS SAM) 是一種開放原始碼架構，提供速記語法來表達函數、APIs、資料庫和事件來源映射。只要為每個資源幾行，您就可以定義所需的應用程式，並使用 YAML 建立模型。在部署期間，SAM 會將 SAM 語法轉換並擴展為 AWS CloudFormation 語法，您可以用來更快速地建置無伺服器應用程式。

AWS SAM 可簡化 AWS 平台上無伺服器應用程式的開發、部署和管理。它提供標準化架構、更快速的部署、本機測試功能、資源管理、與 開發工具的無縫整合，以及支援社群。這些功能使其成為有效建置無伺服器應用程式的寶貴工具。

此模式使用 AWS SAM 範本來自動化巢狀應用程式的部署。巢狀應用程式是另一個應用程式中的應用程式。父應用程式會呼叫其子應用程式。這些是無伺服器架構鬆散耦合的元件。 

使用巢狀應用程式，您可以重複使用獨立撰寫和維護但使用 AWS SAM 和 Serverless Application Repository 組成的服務或元件，快速建置高度複雜的無伺服器架構。巢狀應用程式可協助您建置功能更強大的應用程式，避免重複的工作，並確保團隊和組織的一致性和最佳實務。為了示範巢狀應用程式， 模式會部署[範例 AWS 無伺服器購物車應用程式](https://github.com/aws-samples/aws-sam-nested-stack-sample)。

## 先決條件和限制
<a name="automate-deployment-of-nested-applications-using-aws-sam-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 現有的虛擬私有雲端 (VPC) 和子網路
+ 整合的開發環境，例如 Visual Studio Code （如需詳細資訊，請參閱[在 AWS 上建置的工具](https://aws.amazon.com/getting-started/tools-sdks/#IDE_and_IDE_Toolkits))
+ 如果尚未安裝 Python wheel 程式庫，請使用 pip 安裝 wheel 安裝

**限制**
+ 可在無伺服器應用程式中巢狀化的應用程式數量上限為 200。
+ 巢狀應用程式的參數數目上限可以有 60 個。

**產品版本**
+ 此解決方案建置在 AWS SAM 命令列界面 (AWS SAM CLI) 1.21.1 版上，但此架構應與更新的 AWS SAM CLI 版本搭配使用。

## Architecture
<a name="automate-deployment-of-nested-applications-using-aws-sam-architecture"></a>

**目標技術堆疊**
+ Amazon API Gateway
+ AWS SAM
+ Amazon Cognito
+ Amazon DynamoDB
+ AWS Lambda
+ Amazon Simple Queue Service (Amazon SQS) 佇列

**目標架構**

下圖顯示使用者如何透過呼叫 APIs 向購物服務提出請求。使用者的請求，包括所有必要的資訊，會傳送至 Amazon API Gateway 和 Amazon Cognito 授權方，該授權方會執行 APIs 的身分驗證和授權機制。

在 DynamoDB 中新增、刪除或更新項目時，會將事件放入 DynamoDB Streams，進而啟動 Lambda 函數。為了避免在同步工作流程中立即刪除舊項目，訊息會放入 SQS 佇列，這會啟動工作者函數來刪除訊息。

![\[從 API Gateway 到 Lambda 函數到 DynamoDB 和產品服務的 POST 和 PUT 操作。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/218adecc-b5b8-4193-9012-b5d584e2e128/images/5b454bae-5fd4-405d-a37d-6bafc3fcf889.png)


在此解決方案設定中，AWS SAM CLI 做為 AWS CloudFormation 堆疊的界面。AWS SAM 範本會自動部署巢狀應用程式。父 SAM 範本會呼叫子範本，而父 CloudFormation 堆疊會部署子堆疊。每個子堆疊都會建置 AWS SAM CloudFormation 範本中定義的 AWS 資源。

![\[使用 AWS SAM CLI 搭配父系和三個子系 CloudFormation 堆疊的四步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/218adecc-b5b8-4193-9012-b5d584e2e128/images/5828026e-72ad-4a3f-a5f2-bffac0f13e42.png)


1. 建置和部署堆疊。

1. Auth CloudFormation 堆疊包含 Amazon Cognito。

1. 產品 CloudFormation 堆疊包含 Lambda 函數和 Amazon API Gateway

1. 購物 CloudFormation 堆疊包含 Lambda 函數、Amazon API Gateway、SQS 佇列和 Amazon DynamoDB 資料庫。

## 工具
<a name="automate-deployment-of-nested-applications-using-aws-sam-tools"></a>

**工具**
+ [Amazon API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) 可協助您建立、發佈、維護、監控和保護任何規模的 REST、HTTP 和 WebSocket APIs。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速且一致地佈建資源，以及在 AWS 帳戶和區域的整個生命週期中管理這些資源。
+ [Amazon Cognito](https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html) 為 Web 和行動應用程式提供身分驗證、授權和使用者管理。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，可協助您執行程式碼，而無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [AWS Serverless Application Model (AWS SAM)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) 是一種開放原始碼架構，可協助您在 AWS 雲端中建置無伺服器應用程式。
+ [Amazon Simple Queue Service (Amazon SQS)](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) 提供安全、耐用且可用的託管佇列，可協助您整合和分離分散式軟體系統和元件。

**Code**

此模式的程式碼可在 GitHub [AWS SAM 巢狀堆疊範例](https://github.com/aws-samples/aws-sam-nested-stack-sample)儲存庫中使用。

## 史詩
<a name="automate-deployment-of-nested-applications-using-aws-sam-epics"></a>

### 安裝 AWS SAM CLI
<a name="install-aws-sam-cli"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS SAM CLI。 | 若要安裝 AWS SAM CLI，請參閱 [AWS SAM 文件](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)中的說明。 | DevOps 工程師 | 
| 設定 AWS 登入資料。 | 若要設定 AWS 登入資料，讓 AWS SAM CLI 可以代表您呼叫 AWS 服務，請執行 `aws configure`命令並依照提示操作。<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]:<br />Default output format [None]:</pre>如需設定登入資料的詳細資訊，請參閱[身分驗證和存取登入資料](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-authentication.html)。 | DevOps 工程師 | 

### 初始化 AWS SAM 專案
<a name="initialize-the-aws-sam-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 AWS SAM 程式碼儲存庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-deployment-of-nested-applications-using-aws-sam.html) | DevOps 工程師 | 
| 部署 範本以初始化專案。 | 若要初始化專案，請執行 `SAM init`命令。當系統提示您選擇範本來源時，請選擇 `Custom Template Location`。 | DevOps 工程師 | 

### 編譯和建置 SAM 範本程式碼
<a name="compile-and-build-the-sam-template-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱 AWS SAM 應用程式範本。 | 檢閱巢狀應用程式的範本。此範例使用以下巢狀應用程式範本：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-deployment-of-nested-applications-using-aws-sam.html) | DevOps 工程師 | 
| 檢閱父範本。 | 檢閱將調用巢狀應用程式範本的範本。在此範例中，父範本為 `template.yml`。所有個別的應用程式都會巢狀在單一父範本 中`template.yml`。 | DevOps 工程師 | 
| 編譯並建置 AWS SAM 範本程式碼。 | 使用 AWS SAM CLI，執行下列命令。<pre>sam build</pre> | DevOps 工程師 | 

### 部署 AWS SAM 範本
<a name="deploy-the-aws-sam-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署應用程式。 | 若要啟動建立巢狀應用程式 CloudFormation 堆疊並在 AWS 環境中部署程式碼的 SAM 範本程式碼，請執行下列命令。<pre>sam deploy --guided --stack-name shopping-cart-nested-stack --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND</pre>命令將提示幾個問題。使用 回答所有問題`y`。 | DevOps 工程師 | 

### 驗證部署
<a name="verify-the-deployment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證堆疊。 | 若要檢閱 AWS CloudFormation 範本中定義的 AWS CloudFormation 堆疊和 AWS 資源，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-deployment-of-nested-applications-using-aws-sam.html) | DevOps 工程師 | 

## 相關資源
<a name="automate-deployment-of-nested-applications-using-aws-sam-resources"></a>

**參考**
+ [AWS Serverless 應用程式模型 (AWS SAM)](https://aws.amazon.com/serverless/sam/#:~:text=The%20AWS%20Serverless%20Application%20Model,and%20model%20it%20using%20YAML.)
+ [GitHub 上的 AWS SAM](https://github.com/aws/serverless-application-model)
+ [無伺服器購物車微服務](https://github.com/aws-samples/aws-serverless-shopping-cart) (AWS 範例應用程式）

**教學課程和影片**
+ [建置無伺服器應用程式](https://youtu.be/Hv3YrP8G4ag)
+ [AWS Online Tech Talks：使用 AWS SAM 進行無伺服器應用程式建置和部署](https://youtu.be/1NU7vyJw9LU)

## 其他資訊
<a name="automate-deployment-of-nested-applications-using-aws-sam-additional"></a>

所有程式碼都就緒後，範例會有下列目錄結構：
+ [sam\$1stacks](https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html) – 此資料夾包含 `shared.py` layer。layer 是檔案封存，其中包含程式庫、自訂執行時間或其他相依性。透過 layer，您可以在函數中使用程式庫，而無需將其包含在部署套件中。
+ *product-mock-service* – 此資料夾包含所有產品相關的 Lambda 函數和檔案。
+ *shopping-cart-service* – 此資料夾包含所有與購物相關的 Lambda 函數和檔案。

# 使用 AWS Lambda 字符販賣機實作 Amazon S3 的 SaaS 租用戶隔離
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine"></a>

*Tabby Ward、Thomas Davis 和 Sravan Periyathambi，Amazon Web Services*

## 總結
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-summary"></a>

多租戶 SaaS 應用程式必須實作系統，以確保維持租戶隔離。當您將租戶資料存放在相同的 AWS 資源時，例如當多個租戶將資料存放在相同的 Amazon Simple Storage Service (Amazon S3) 儲存貯體時，您必須確保跨租戶存取不會發生。字符販賣機 (TVMs) 是提供租戶資料隔離的一種方式。這些機器提供一種機制來取得權杖，同時抽象化這些權杖產生方式的複雜性。開發人員可以使用 TVM，而無需詳細了解其如何產生字符。

此模式使用 實作 TVM AWS Lambda。TVM 會產生權杖，其中包含臨時安全權杖服務 (STS) 憑證，以限制對 S3 儲存貯體中單一 SaaS 租用戶資料的存取。

TVMs和此模式提供的程式碼通常用於衍生自 JSON Web Token (JWTs) 的宣告，以將 AWS 資源請求與租用戶範圍 AWS Identity and Access Management (IAM) 政策建立關聯。您可以使用此模式中的程式碼做為實作 SaaS 應用程式的基礎，該應用程式會根據 JWT 權杖中提供的宣告產生範圍廣泛的暫時 STS 憑證。

## 先決條件和限制
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ AWS Command Line Interface (AWS CLI) [1.19.0 版或更新版本](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html)，在 macOS、Linux 或 Windows 上安裝和設定。或者，您可以使用 AWS CLI [2.1 版或更新版本。](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)

**限制**
+ 此程式碼在 Java 中執行，目前不支援其他程式設計語言。 
+ 範例應用程式不包含 AWS 跨區域或災難復原 (DR) 支援。 
+ 此模式示範適用於 SaaS 應用程式的 Lambda TVM 如何提供範圍租用戶存取。此模式不適用於生產環境，如果在特定應用程式或使用案例中沒有額外的安全測試。

## Architecture
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-architecture"></a>

**目標技術堆疊**
+ AWS Lambda
+ Amazon S3
+ IAM
+ AWS Security Token Service (AWS STS)

**目標架構**

![\[產生權杖以取得臨時 STS 登入資料，以存取 S3 儲存貯體中的資料。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/97a34c8e-d04e-40b6-acbf-1baa176d22a9/images/14d0508a-703b-4229-85e6-c5094de7fe01.png)


 

## 工具
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-tools"></a>

**AWS 服務**
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您 AWS 服務 透過命令列 shell 中的命令與 互動。
+ [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 Security Token Service (AWS STS)](https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html) 可協助您為使用者請求暫時、有限權限的登入資料。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**Code**

此模式的原始碼可做為附件使用，並包含下列檔案：
+ `s3UploadSample.jar` 提供 Lambda 函數的原始碼，可將 JSON 文件上傳至 S3 儲存貯體。
+ `tvm-layer.zip` 提供可重複使用的 Java 程式庫，可為 Lambda 函數提供權杖 (STS 臨時登入資料），以存取 S3 儲存貯體並上傳 JSON 文件。
+ `token-vending-machine-sample-app.zip` 提供用來建立這些成品和編譯指示的原始碼。

若要使用這些檔案，請遵循下一節中的指示。

## 史詩
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-epics"></a>

### 判斷變數值
<a name="determine-variable-values"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 判斷變數值。 | 此模式的實作包含數個必須一致使用的變數名稱。決定應該用於每個變數的值，並在後續步驟中請求時提供該值。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine.html) | 雲端管理員 | 

### 建立 S3 儲存貯體
<a name="create-an-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為範例應用程式建立 S3 儲存貯體。 | 使用下列 AWS CLI 命令來建立 S3 儲存貯體。在程式碼片段中提供 `<sample-app-bucket-name>`****值：<pre>aws s3api create-bucket --bucket <sample-app-bucket-name></pre>Lambda 範例應用程式會將 JSON 檔案上傳至此儲存貯體。 | 雲端管理員 | 

### 建立 IAM TVM 角色和政策
<a name="create-the-iam-tvm-role-and-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 TVM 角色。 | 使用下列其中一個 AWS CLI 命令來建立 IAM 角色。在 命令中提供 `<sample-tvm-role-name>`****值。對於 macOSor Linux shell：<pre>aws iam create-role \<br />--role-name <sample-tvm-role-name> \<br />--assume-role-policy-document '{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Action": [<br />                "sts:AssumeRole"<br />            ],<br />            "Principal": {<br />                "Service": [<br />                    "lambda.amazonaws.com"<br />                ]<br />            },<br />            "Condition": {<br />                "StringEquals": {<br />                    "aws:SourceAccount": "<AWS Account ID>"<br />                }<br />            }<br />        }<br />    ]<br />}'</pre>對於 Windows 命令列：<pre>aws iam create-role ^<br />--role-name <sample-tvm-role-name> ^<br />--assume-role-policy-document "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\", \"Action\": [\"sts:AssumeRole\"], \"Principal\": {\"Service\": [\"lambda.amazonaws.com\"]}, \"Condition\": {\"StringEquals\": {\"aws:SourceAccount\": \"<AWS Account ID>\"}}}]}"</pre>Lambda 範例應用程式會在叫用應用程式時擔任此角色。使用範圍政策擔任應用程式角色的功能為程式碼提供更廣泛存取 S3 儲存貯體的許可。 | 雲端管理員 | 
| 建立內嵌 TVM 角色政策。 | 使用下列其中一個 AWS CLI 命令來建立 IAM 政策。在命令中提供 `<sample-tvm-role-name>`****`<AWS Account ID>`、 和 `<sample-app-role-name>`值。對於 macOS 或 Linux shell：<pre>aws iam put-role-policy \<br />--role-name <sample-tvm-role-name> \<br />--policy-name assume-app-role \<br />--policy-document '{<br />    "Version": "2012-10-17",		 	 	  <br />    "Statement": [<br />        {<br />            "Effect": "Allow", <br />            "Action": "sts:AssumeRole", <br />            "Resource": "arn:aws:iam::<AWS Account ID>:role/<sample-app-role-name>"<br />        }<br />    ]}'</pre>對於 Windows 命令列：<pre>aws iam put-role-policy ^<br />--role-name <sample-tvm-role-name> ^<br />--policy-name assume-app-role ^<br />--policy-document "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\", \"Action\": \"sts:AssumeRole\", \"Resource\": \"arn:aws:iam::<AWS Account ID>:role/<sample-app-role-name>\"}]}"</pre>此政策會連接到 TVM 角色。它為程式碼提供擔任應用程式角色的能力，其具有更廣泛存取 S3 儲存貯體的許可。 | 雲端管理員 | 
| 連接 受管 Lambda 政策。 | 使用下列 AWS CLI 命令來連接`AWSLambdaBasicExecutionRole` IAM 政策。在 命令中提供 `<sample-tvm-role-name>`值：<pre>aws iam attach-role-policy \<br />--role-name <sample-tvm-role-name> \<br />--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole</pre>對於 Windows 命令列：<pre>aws iam attach-role-policy ^<br />--role-name <sample-tvm-role-name> ^<br />--policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole</pre>此受管政策會連接至 TVM 角色，以允許 Lambda 將日誌傳送至 Amazon CloudWatch。 | 雲端管理員 | 

### 建立 IAM 應用程式角色和政策
<a name="create-the-iam-application-role-and-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立應用程式角色。 | 使用下列其中一個 AWS CLI 命令來建立 IAM 角色。在 命令中提供 `<AWS Account ID>`、 `<sample-app-role-name>`和 `<sample-tvm-role-name>`值。對於 macOS 或 Linux shell：<pre>aws iam create-role \<br />--role-name <sample-app-role-name> \<br />--assume-role-policy-document '{<br />    "Version": "2012-10-17",		 	 	  <br />    "Statement": [<br />        {<br />            "Effect": <br />            "Allow",<br />            "Principal": {<br />                "AWS": "arn:aws:iam::<AWS Account ID>:role/<sample-tvm-role-name>"<br />            },<br />            "Action": "sts:AssumeRole"<br />        }<br />    ]}'</pre>對於 Windows 命令列：<pre>aws iam create-role ^<br />--role-name <sample-app-role-name> ^<br />--assume-role-policy-document "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\",\"Principal\": {\"AWS\": \"arn:aws:iam::<AWS Account ID>:role/<sample-tvm-role-name>\"},\"Action\": \"sts:AssumeRole\"}]}"</pre>Lambda 範例應用程式會使用範圍政策擔任此角色，以取得 S3 儲存貯體的租戶型存取權。 | 雲端管理員 | 
| 建立內嵌應用程式角色政策。 | 使用下列其中一個 AWS CLI mmands 來建立 IAM 政策。在 命令中提供 `<sample-app-role-name>`和 `<sample-app-bucket-name>`****值。對於 macOS 或 Linux shell：<pre>aws iam put-role-policy \<br />--role-name <sample-app-role-name> \<br />--policy-name s3-bucket-access \<br />--policy-document '{<br />    "Version": "2012-10-17",		 	 	  <br />    "Statement": [<br />        {<br />            "Effect": "Allow", <br />            "Action": [<br />                "s3:PutObject", <br />                "s3:GetObject", <br />                "s3:DeleteObject"<br />            ], <br />            "Resource": "arn:aws:s3:::<sample-app-bucket-name>/*"<br />        }, <br />        {<br />            "Effect": "Allow", <br />            "Action": ["s3:ListBucket"], <br />            "Resource": "arn:aws:s3:::<sample-app-bucket-name>"<br />        }<br />    ]}'</pre>對於 Windows 命令列：<pre>aws iam put-role-policy ^<br />--role-name <sample-app-role-name> ^<br />--policy-name s3-bucket-access ^<br />--policy-document "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\", \"Action\": [\"s3:PutObject\", \"s3:GetObject\", \"s3:DeleteObject\"], \"Resource\": \"arn:aws:s3:::<sample-app-bucket-name>/*\"}, {\"Effect\": \"Allow\", \"Action\": [\"s3:ListBucket\"], \"Resource\": \"arn:aws:s3:::<sample-app-bucket-name>\"}]}"</pre>此政策會連接至應用程式角色。它提供對 S3 儲存貯體中物件的廣泛存取。當範例應用程式擔任角色時，這些許可的範圍會限定為具有 TVM 動態產生政策的特定租用戶。 | 雲端管理員 | 

### 使用 TVM 建立 Lambda 範例應用程式
<a name="create-the-lam-sample-application-with-tvm"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載編譯的來源檔案。 | 下載 `s3UploadSample.jar`和 `tvm-layer.zip`****檔案，其中包含為附件。中提供了用於建立這些成品和編譯函數的原始程式碼`token-vending-machine-sample-app.zip`。 | 雲端管理員 | 
| 建立 Lambda 層。 | 使用下列 AWS CLI 命令來建立 Lambda 層，讓 Lambda 可存取 TVM。 如果您不是從下載的位置執行此命令` tvm-layer.zip`，請在 `--zip-file`參數`tvm-layer.zip`中提供正確的路徑。 <pre>aws lambda publish-layer-version \<br />--layer-name sample-token-vending-machine \<br />--compatible-runtimes java11 \<br />--zip-file fileb://tvm-layer.zip</pre>對於 Windows 命令列：<pre>aws lambda publish-layer-version ^<br />--layer-name sample-token-vending-machine ^<br />--compatible-runtimes java11 ^<br />--zip-file fileb://tvm-layer.zip</pre>此命令會建立包含可重複使用 TVM 程式庫的 Lambda 層。 | 雲端管理員、應用程式開發人員 | 
| 建立 Lambda 函數。 | 使用下列 AWS CLI 命令來建立 Lambda 函數。在命令中提供 `<sample-app-function-name>`、`<AWS Account ID>`、`<sample-app-bucket-name>`、、 `<AWS Region>` `<sample-tvm-role-name>`和 `<sample-app-role-name>`值。 如果您不是從下載 的位置執行此命令`s3UploadSample.jar`，請在 `--zip-file`參數`s3UploadSample.jar`中提供正確的路徑。 <pre>aws lambda create-function \<br />--function-name <sample-app-function-name>  \<br />--timeout 30 \<br />--memory-size 256 \<br />--runtime java11 \<br />--role arn:aws:iam::<AWS Account ID>:role/<sample-tvm-role-name> \<br />--handler com.amazon.aws.s3UploadSample.App \<br />--zip-file fileb://s3UploadSample.jar \<br />--layers arn:aws:lambda:<AWS Region>:<AWS Account ID>:layer:sample-token-vending-machine:1 \<br />--environment "Variables={S3_BUCKET=<sample-app-bucket-name>,<br />ROLE=arn:aws:iam::<AWS Account ID>:role/<sample-app-role-name>}"</pre>對於 Windows 命令列：<pre>aws lambda create-function ^<br />--function-name <sample-app-function-name>  ^<br />--timeout 30 ^<br />--memory-size 256 ^<br />--runtime java11 ^<br />--role arn:aws:iam::<AWS Account ID>:role/<sample-tvm-role-name> ^<br />--handler com.amazon.aws.s3UploadSample.App ^<br />--zip-file fileb://s3UploadSample.jar ^<br />--layers arn:aws:lambda:<AWS Region>:<AWS Account ID>:layer:sample-token-vending-machine:1 ^<br />--environment "Variables={S3_BUCKET=<sample-app-bucket-name>,ROLE=arn:aws:iam::<AWS Account ID>:role/<sample-app-role-name>}"</pre>此命令會建立連接範例應用程式程式碼和 TVM layer 的 Lambda 函數。它也會設定兩個環境變數： `S3_BUCKET`和 `ROLE`。範例應用程式使用這些變數來決定要擔任的角色，以及要上傳 JSON 文件的 S3 儲存貯體。 | 雲端管理員、應用程式開發人員 | 

### 測試範例應用程式和 TVM
<a name="test-the-sample-application-and-tvm"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 叫用 Lambda 範例應用程式。 | 使用下列其中一個 AWS CLI 命令，以其預期的承載啟動 Lambda 範例應用程式。在 命令中提供 `<sample-app-function-name>`和 `<sample-tenant-name>`值。對於 macOS 和 Linux shell：<pre>aws lambda invoke \<br />--function <sample-app-function-name> \<br />--invocation-type RequestResponse \<br />--payload '{"tenant": "<sample-tenant-name>"}' \<br />--cli-binary-format raw-in-base64-out response.json</pre>對於 Windows 命令列：<pre>aws lambda invoke ^<br />--function <sample-app-function-name> ^<br />--invocation-type RequestResponse ^<br />--payload "{\"tenant\": \"<sample-tenant-name>\"}" ^<br />--cli-binary-format raw-in-base64-out response.json</pre>此命令會呼叫 Lambda 函數，並在`response.json`文件中傳回結果。在許多以 Unix 為基礎的系統上，您可以將 `response.json` 變更為 `/dev/stdout`，直接將結果輸出到您的 shell，而無需建立另一個檔案。 變更此 Lambda 函數後續調用中的`<sample-tenant-name>`值會變更 JSON 文件的位置，以及字符提供的許可。 | 雲端管理員、應用程式開發人員 | 
| 檢視 S3 儲存貯體以查看建立的物件。 | 瀏覽至您先前建立的 S3 儲存貯體 (`<sample-app-bucket-name>`)。此儲存貯體包含值為 的 S3 物件字首`<sample-tenant-name>`。在此字首下，您會找到名為 且具有 UUID 的 JSON 文件。多次叫用範例應用程式會新增更多 JSON 文件。 | 雲端管理員 | 
| 在 CloudWatch Logs 中檢視範例應用程式的日誌。 | 檢視與 CloudWatch Logs `<sample-app-function-name>`中名為 的 Lambda 函數相關聯的日誌。如需說明，請參閱 [Lambda 文件中的將 Lambda 函數日誌傳送至 CloudWatch Logs](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html)。您可以在這些日誌中檢視 TVM 產生的租戶範圍政策。此租用戶範圍政策將範例應用程式的許可授予 Amazon S3 **PutObject**、**GetObject**、**DeleteObject** 和 **ListBucket** APIs，但僅適用於與 相關聯的物件字首`<sample-tenant-name>`。在範例應用程式的後續調用中，如果您變更 `<sample-tenant-name>`，TVM 會更新範圍政策，以對應調用承載中提供的租用戶。此動態產生的政策顯示如何在 SaaS 應用程式中使用 TVM 維護租戶範圍存取。 TVM 功能是在 Lambda 層中提供，因此可以連接到應用程式使用的其他 Lambda 函數，而不必複寫程式碼。如需動態產生政策的圖例，請參閱[其他資訊](#implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-additional)一節。 | 雲端管理員 | 

## 相關資源
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-resources"></a>
+ [使用動態產生的 IAM 政策隔離租用戶](https://aws.amazon.com/blogs/apn/isolating-saas-tenants-with-dynamically-generated-iam-policies/) （部落格文章）
+ [在 SaaS 環境中套用動態產生的隔離政策 ](https://aws.amazon.com/blogs/apn/applying-dynamically-generated-isolation-policies-in-saas-environments/)（部落格文章）
+ [上的 SaaS AWS](https://aws.amazon.com/saas/)

## 其他資訊
<a name="implement-saas-tenant-isolation-for-amazon-s3-by-using-an-aws-lambda-token-vending-machine-additional"></a>

以下日誌顯示此模式中 TVM 程式碼產生的動態產生政策。在此螢幕擷取畫面中， `<sample-app-bucket-name>`是`DOC-EXAMPLE-BUCKET` ，而 `<sample-tenant-name>`是 `test-tenant-1`。此範圍政策傳回的 STS 登入資料無法在 S3 儲存貯體中的物件上執行任何動作，但與物件金鑰字首 相關聯的物件除外`test-tenant-1`。

![\[日誌顯示由 TVM 程式碼產生的動態產生政策。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/97a34c8e-d04e-40b6-acbf-1baa176d22a9/images/d4776ebe-fb8f-41ac-b8c5-b4f97a821c8c.png)


## 附件
<a name="attachments-97a34c8e-d04e-40b6-acbf-1baa176d22a9"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/97a34c8e-d04e-40b6-acbf-1baa176d22a9/attachments/attachment.zip)

# 使用 AWS Step Functions 實作無伺服器 saga 模式
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions"></a>

*Tabby Ward、Joe Kern 和 Rohan Mehta，Amazon Web Services*

## 摘要
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-summary"></a>

在微服務架構中，主要目標是建置解耦的獨立元件，以提升應用程式的敏捷性、彈性和更快的上市時間。由於解耦，每個微服務元件都有自己的資料持久性層。在分散式架構中，商業交易可以跨越多個微服務。由於這些微服務無法使用單一原子性、一致性、隔離性、耐久性 (ACID) 交易，因此您可能會最終產生部分交易。在此情況下，需要一些控制邏輯才能復原已處理的交易。分散式 saga 模式通常用於此目的。 

saga 模式是一種故障管理模式，可協助在分散式應用程式中建立一致性，並協調多個微服務之間的交易，以維持資料一致性。當您使用 saga 模式時，每個執行交易的服務都會發佈事件，觸發後續服務在鏈結中執行下一個交易。這會持續到鏈結中的最後一個交易完成為止。如果商業交易失敗，saga 會協調一系列補償交易，復原先前交易所做的變更。

此模式示範如何使用 AWS Step Functions、AWS Lambda 和 Amazon DynamoDB 等無伺服器技術，自動設定和部署範例應用程式 （處理行程保留）。範例應用程式也會使用 Amazon API Gateway 和 Amazon Simple Notification Service (Amazon SNS) 來實作 saga 執行協調器。模式可以使用基礎設施即程式碼 (IaC) 架構進行部署，例如 AWS Cloud Development Kit (AWS CDK)、AWS Serverless Application Model (AWS SAM) 或 Terraform。

## 先決條件和限制
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 建立 AWS CloudFormation 堆疊的許可。如需詳細資訊，請參閱 CloudFormation 文件中的[控制存取](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html)。
+ 使用 AWS 帳戶設定您選擇的 IaC 架構 (AWS CDK、AWS SAM 或 Terraform)，以便您可以使用架構 CLI 部署應用程式。
+ NodeJS，用於建置應用程式並在本機執行。
+ 您選擇的程式碼編輯器 （例如 Visual Studio Code、Sublime 或 Atom)。

**產品版本**
+ [NodeJS 第 14 版](https://nodejs.org/en/download/)
+ [AWS CDK 2.37.1 版](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_install)
+ [AWS SAM 1.71.0 版](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
+ [Terraform 1.3.7 版](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)

**限制**

事件來源是在微服務架構中實作 saga 協同運作模式的一種自然方式，其中所有元件都鬆散耦合，彼此沒有直接知識。如果您的交易涉及少量步驟 （三到五個），則 Saga 模式可能非常適合。不過，複雜度會隨著微服務數量和步驟數量而增加。 

當您使用此設計時，測試和偵錯可能會變得困難，因為您必須執行所有服務才能模擬交易模式。

## Architecture
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-architecture"></a>

**目標架構 **

提議的架構使用 AWS Step Functions 建置類似模式來預訂航班、預訂租車，以及處理假期的付款。

下列工作流程圖說明行程保留系統的典型流程。工作流程包含預留航空旅程 ("ReserveFlight")、預留車輛 ("ReserveCarRental")、處理付款 ("ProcessPayment")、確認航班保留 ("ConfirmFlight")，以及確認租車 ("ConfirmCarRental")，隨後在這些步驟完成時會收到成功通知。不過，如果系統在執行任何這些交易時遇到任何錯誤，就會開始向後失敗。例如，付款處理 ("ProcessPayment") 的錯誤會觸發退款 ("RefundPayment")，然後觸發租車和航班 ("CancelRentalReservation" 和 "CancelFlightReservation") 的取消，以失敗訊息結束整個交易。

此模式會針對圖表中反白顯示的每個任務部署個別的 Lambda 函數，以及三個用於航班、租車和付款的 DynamoDB 資料表。每個 Lambda 函數都會建立、更新或刪除個別 DynamoDB 資料表中的資料列，視交易是否確認或復原而定。模式使用 Amazon SNS 傳送文字 (SMS) 訊息給訂閱者，通知他們交易失敗或成功。 

![\[根據 saga 模式的旅遊保留系統工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/fec0789c-d9b1-4d80-b179-dd9a7ecbec07/images/daad3e8e-6e6b-41c2-95c1-ca79d53ead64.png)


 

**自動化和擴展**

您可以使用其中一個 IaC 架構來建立此架構的組態。將下列其中一個連結用於您偏好的 IaC。
+ [使用 AWS CDK 部署](https://serverlessland.com/workflows/saga-pattern-cdk)
+ [使用 AWS SAM 部署](https://serverlessland.com/workflows/saga-pattern-sam)
+ [使用 Terraform 部署](https://serverlessland.com/workflows/saga-pattern-tf)

## 工具
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-tools"></a>

**AWS 服務**
+ [AWS Step Functions](https://aws.amazon.com/step-functions/) 是一種無伺服器協同運作服務，可讓您結合 AWS Lambda 函數和其他 AWS 服務來建置業務關鍵應用程式。透過 Step Functions 圖形主控台，您會將應用程式的工作流程視為一系列的事件驅動步驟。
+ [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能和無縫的可擴展性。您可以使用 DynamoDB 建立資料庫資料表，藉此存放和擷取任意數量的資料，並為任何層級的請求流量提供服務。
+ [AWS Lambda](https://aws.amazon.com/lambda/) 是一種運算服務，可讓您執行程式碼，而無需佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。
+ [Amazon API Gateway](https://aws.amazon.com/api-gateway/) 是一種 AWS 服務，可用於建立、發佈、維護、監控和保護任何規模的 REST、HTTP 和 WebSocket APIs。
+ [Amazon Simple Notification Service (Amazon SNS)](https://aws.amazon.com/sns/) 是一種受管服務，可將訊息從發佈者交付給訂閱者。
+ [AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk/) 是一種軟體開發架構，可透過使用 TypeScript、JavaScript、Python、Java 和 C\$1/ 等熟悉的程式設計語言來定義您的雲端應用程式資源。淨額。
+ [AWS Serverless Application Model (AWS SAM)](https://aws.amazon.com/serverless/sam/) 是用於建置無伺服器應用程式的開放原始碼架構。它提供速記語法來表達函數、APIs、資料庫和事件來源映射。

**Code**

您可以在以下連結中找到示範 saga 模式的範例應用程式的程式碼，包括 IaC 範本 (AWS CDK、AWS SAM 或 Terraform)、Lambda 函數和 DynamoDB 資料表。請遵循第一個 epic 中的指示來安裝這些項目。
+ [使用 AWS CDK 部署](https://serverlessland.com/workflows/saga-pattern-cdk)
+ [使用 AWS SAM 部署](https://serverlessland.com/workflows/saga-pattern-sam)
+ [使用 Terraform 部署](https://serverlessland.com/workflows/saga-pattern-tf)

## 史詩
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-epics"></a>

### 安裝套件、編譯和建置
<a name="install-packages-compile-and-build"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 NPM 套件。 | 建立新的目錄、導覽至終端機中的該目錄，並從此模式稍早的*程式碼*區段複製您選擇的 GitHub 儲存庫。在具有 `package.json` 檔案的根資料夾中，執行下列命令來下載並安裝所有 Node Package Manager (NPM) 套件：<pre>npm install</pre> | 開發人員、雲端架構師 | 
| 編譯指令碼。 | 在根資料夾中，執行下列命令，指示 TypeScript 轉換器建立所有必要的 JavaScript 檔案：<pre>npm run build</pre> | 開發人員、雲端架構師 | 
| 留意變更並重新編譯。 | 在根資料夾中，在不同的終端機視窗中執行下列命令，以 監看程式碼變更，並在偵測到變更時編譯程式碼：<pre>npm run watch</pre> | 開發人員、雲端架構師 | 
| 執行單位測試 （僅限 AWS CDK)。 | 如果您使用的是 AWS CDK，請在根資料夾中執行下列命令來執行 Jest 單位測試：<pre>npm run test</pre> | 開發人員、雲端架構師 | 

### 將資源部署到目標 AWS 帳戶
<a name="deploy-resources-to-the-target-aws-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將示範堆疊部署至 AWS。 | 應用程式與 AWS 區域無關。如果您使用設定檔，則必須在 [AWS Command Line Interface (AWS CLI) 設定檔](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)中或透過 [AWS CLI 環境變數明確宣告區域。](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html)在根資料夾中，執行下列命令來建立部署組件，並將其部署到預設的 AWS 帳戶和區域。AWS CDK：<pre>cdk bootstrap<br />cdk deploy</pre>AWS SAM：<pre>sam build<br />sam deploy --guided</pre>Terraform：<pre>terraform init<br />terraform apply</pre>此步驟可能需要幾分鐘的時間才能完成。此命令使用為 AWS CLI 設定的預設登入資料。請注意，在部署完成後，主控台上顯示的 API Gateway URL。您需要此資訊來測試 saga 執行流程。 | 開發人員、雲端架構師 | 
| 比較已部署的堆疊與目前狀態。 | 在根資料夾中，執行下列命令，在變更原始碼之後，將部署的堆疊與目前狀態 進行比較：AWS CDK：<pre>cdk diff</pre>AWS SAM：<pre>sam deploy</pre>Terraform：<pre>terraform plan</pre> | 開發人員、雲端架構師 | 

### 測試執行流程
<a name="test-the-execution-flow"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試 saga 執行流程。 | 當您部署堆疊時，導覽至您在先前步驟中記下的 API Gateway URL。此 URL 會觸發狀態機器啟動。如需如何透過傳遞不同的 URL 參數來操作狀態機器流程的詳細資訊，請參閱[其他資訊](#implement-the-serverless-saga-pattern-by-using-aws-step-functions-additional)一節。若要 檢視結果，請登入 AWS 管理主控台，然後導覽至 Step Functions 主控台。在這裡，您可以看到 saga 狀態機器的每個步驟。您也可以檢視 DynamoDB 資料表，以查看插入、更新或刪除的記錄。如果您經常重新整理畫面，您可以觀看交易狀態從 變更為 `pending` `confirmed`。 您可以訂閱 SNS 主題，方法是使用手機號碼更新 `stateMachine.ts` 檔案中的程式碼，以便在成功或失敗的保留時接收簡訊。如需詳細資訊，請參閱[其他資訊](#implement-the-serverless-saga-pattern-by-using-aws-step-functions-additional)區段中的 *Amazon SNS*。 | 開發人員、雲端架構師 | 

### 清除
<a name="clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除資源。 | 若要清除為此應用程式部署的資源，您可以使用下列其中一個命令。AWS CDK：<pre>cdk destroy</pre>AWS SAM：<pre>sam delete</pre>Terraform：<pre>terraform destroy</pre> | 應用程式開發人員、雲端架構師 | 

## 相關資源
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-resources"></a>

**技術論文**
+ [在 AWS 上實作微服務](https://docs.aws.amazon.com/pdfs/whitepapers/latest/microservices-on-aws/microservices-on-aws.pdf)
+ [無伺服器應用程式鏡頭](https://docs.aws.amazon.com/wellarchitected/latest/serverless-applications-lens/welcome.html)

**AWS 服務文件**
+ [AWS CDK 入門](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)
+ [AWS SAM 入門](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started.html)
+ [AWS Step Functions](https://docs.aws.amazon.com/step-functions/)
+ [Amazon DynamoDB](https://docs.aws.amazon.com/dynamodb/)
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/)
+ [Amazon API Gateway](https://docs.aws.amazon.com/apigateway/)
+ [Amazon SNS](https://docs.aws.amazon.com/sns/)

**教學課程**
+ [無伺服器運算實作研討會](https://aws.amazon.com/serverless-workshops/)

## 其他資訊
<a name="implement-the-serverless-saga-pattern-by-using-aws-step-functions-additional"></a>

**Code**

為了測試目的，此模式會部署 API Gateway 和測試 Lambda 函數，以觸發 Step Functions 狀態機器。使用 Step Functions，您可以透過傳遞`run_type`參數來模擬 "ReserveFlight"、"ReserveCarRental"、"ProcessPayment"、"ConfirmFlight" 和 "ConfirmCarRental."

`saga` Lambda 函數 (`sagaLambda.ts`) 會從 API Gateway URL 中的查詢參數取得輸入，建立下列 JSON 物件，並將其傳遞給 Step Functions 執行：

```
let input = {
"trip_id": tripID, //  value taken from query parameter, default is AWS request ID
"depart_city": "Detroit",
"depart_time": "2021-07-07T06:00:00.000Z",
"arrive_city": "Frankfurt",
"arrive_time": "2021-07-09T08:00:00.000Z",
"rental": "BMW",
"rental_from": "2021-07-09T00:00:00.000Z",
"rental_to": "2021-07-17T00:00:00.000Z",
"run_type": runType // value taken from query parameter, default is "success"
};
```

您可以傳遞下列 URL 參數來實驗 Step Functions 狀態機器的不同流程：
+ **成功執行** ─ https：//\$1api 閘道 url\$1
+ **預留航班失敗** - https：//\$1api 閘道 url\$1？**runType=failFlightsReservation**
+ **確認航班失敗** - https：//\$1api 閘道 url\$1？**runType=failFlightsConfirmation**
+ **預留租車失敗** - https：//\$1api 閘道 url\$1？**runType=failCarRentalReservation**
+ **確認租車失敗** - https：//\$1api 閘道 url\$1？**runType=failCarRentalConfirmation**
+ **處理付款失敗** - https：//\$1api 閘道 url\$1？**runType=failPayment**
+ **傳遞行程 ID** - https：//\$1api 閘道 url\$1？**tripID=**\$1預設情況下，行程 ID 將是 AWS 請求 ID\$1

**IaC 範本**

連結的儲存庫包含 IaC 範本，可用來建立整個範例行程保留應用程式。
+ [使用 AWS CDK 部署](https://serverlessland.com/workflows/saga-pattern-cdk)
+ [使用 AWS SAM 部署](https://serverlessland.com/workflows/saga-pattern-sam)
+ [使用 Terraform 部署](https://serverlessland.com/workflows/saga-pattern-tf)

**DynamoDB 資料表**

以下是航班、租車和付款資料表的資料模型。

```
Flight Data Model:
 var params = {
      TableName: process.env.TABLE_NAME,
      Item: {
        'pk' : {S: event.trip_id},
        'sk' : {S: flightReservationID},
        'trip_id' : {S: event.trip_id},
        'id': {S: flightReservationID},
        'depart_city' : {S: event.depart_city},
        'depart_time': {S: event.depart_time},
        'arrive_city': {S: event.arrive_city},
        'arrive_time': {S: event.arrive_time},
        'transaction_status': {S: 'pending'}
      }
    };

Car Rental Data Model:
var params = {
      TableName: process.env.TABLE_NAME,
      Item: {
        'pk' : {S: event.trip_id},
        'sk' : {S: carRentalReservationID},
        'trip_id' : {S: event.trip_id},
        'id': {S: carRentalReservationID},
        'rental': {S: event.rental},
        'rental_from': {S: event.rental_from},
        'rental_to': {S: event.rental_to},
        'transaction_status': {S: 'pending'}
      }
    };

Payment Data Model:
var params = {
      TableName: process.env.TABLE_NAME,
      Item: {
        'pk' : {S: event.trip_id},
        'sk' : {S: paymentID},
        'trip_id' : {S: event.trip_id},
        'id': {S: paymentID},
        'amount': {S: "750.00"}, // hard coded for simplicity as implementing any monetary transaction functionality is beyond the scope of this pattern
        'currency': {S: "USD"},
        'transaction_status': {S: "confirmed"}
      }
    };
```

**Lambda 函數**

將建立下列函數，以支援 Step Functions 中的狀態機器流程和執行：
+ **預留航班**：使用 `transaction_status`的 將記錄插入 DynamoDB 航班資料表`pending`，以預訂航班。
+ **確認航班**：更新 DynamoDB 航班資料表中的記錄，將 `transaction_status`設定為 `confirmed`，以確認航班。
+ **取消航班保留**：從 DynamoDB 航班資料表刪除記錄，以取消待定航班。
+ **預留租車**：使用 `transaction_status`的 將記錄插入 DynamoDB CarRentals 資料表`pending`，以預訂租車。
+ **確認租車**：更新 DynamoDB CarRentals 資料表中的記錄，將 `transaction_status`設定為 `confirmed`，以確認租車。
+ **取消租車保留：**從 DynamoDB CarRentals 資料表刪除記錄，以取消待定的租車。
+ **處理付款**：將記錄插入 DynamoDB 付款資料表以進行付款。
+ **取消付款**：從 DynamoDB 付款資料表中刪除付款的記錄。

**Amazon SNS**

範例應用程式會建立下列主題和訂閱來傳送簡訊，並通知客戶保留成功或失敗。如果您想要在測試範例應用程式時接收文字訊息，請在狀態機器定義檔案中使用有效的電話號碼更新簡訊訂閱。

AWS CDK 程式碼片段 （在下列程式碼的第二行中新增電話號碼）：

```
const topic = new  sns.Topic(this, 'Topic');
topic.addSubscription(new subscriptions.SmsSubscription('+11111111111'));
const snsNotificationFailure = new tasks.SnsPublish(this ,'SendingSMSFailure', {
topic:topic,
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
message: sfn.TaskInput.fromText('Your Travel Reservation Failed'),
});
 
const snsNotificationSuccess = new tasks.SnsPublish(this ,'SendingSMSSuccess', {
topic:topic,
integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
message: sfn.TaskInput.fromText('Your Travel Reservation is Successful'),
});
```

AWS SAM 程式碼片段 （將`+1111111111`字串取代為您的有效電話號碼）：

```
  StateMachineTopic11111111111:
    Type: 'AWS::SNS::Subscription'
    Properties:
      Protocol: sms
      TopicArn:
        Ref: StateMachineTopic
      Endpoint: '+11111111111'
    Metadata:
      'aws:sam:path': SamServerlessSagaStack/StateMachine/Topic/+11111111111/Resource
```

Terraform 程式碼片段 （將`+111111111`字串取代為您的有效電話號碼）：

```
resource "aws_sns_topic_subscription" "sms-target" {
  topic_arn = aws_sns_topic.topic.arn
  protocol  = "sms"
  endpoint  = "+11111111111"
}
```

**成功的保留**

以下流程說明「ReserveFlight」、「ReserveCarRental」和「ProcessPayment」後接「ConfirmFlight」和「ConfirmCarRental." 客戶會透過傳送給 SNS 主題訂閱者的簡訊收到成功預訂的通知。

![\[Step Functions 使用 saga 模式成功實作保留的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/fec0789c-d9b1-4d80-b179-dd9a7ecbec07/images/f58c894e-7721-4bc7-8f7d-29f23faa5dc1.png)


**失敗的保留**

此流程是 saga 模式失敗的範例。如果預訂航班和租車後，「ProcessPayment」失敗，步驟會依相反順序取消。 會釋出保留，並透過傳送給 SNS 主題訂閱者的簡訊通知客戶失敗。

![\[Step Functions 使用 saga 模式實作的失敗保留範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/fec0789c-d9b1-4d80-b179-dd9a7ecbec07/images/7c64d326-be27-42c3-b03f-d677efedb9a7.png)


# 使用 AWS CDK 設定 Amazon ECS Anywhere 來管理內部部署容器應用程式
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk"></a>

*Rahul Sharad Gaikwad 醫生，Amazon Web Services*

## 總結
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk-summary"></a>

[Amazon ECS Anywhere](https://aws.amazon.com/ecs/anywhere/) 是 Amazon Elastic Container Service (Amazon ECS) 的延伸。您可以使用 ECS Anywhere 在內部部署或客戶受管環境中部署原生 Amazon ECS 任務。此功能有助於降低成本，並減少複雜的本機容器協同運作和操作。您可以使用 ECS Anywhere 在內部部署和雲端環境中部署和執行容器應用程式。它消除了您的團隊學習多個網域和技能集，或自行管理複雜軟體的需求。

此模式示範使用 [AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk/) 堆疊設定 ECS Anywhere 的步驟。

## 先決條件和限制
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 安裝並設定 AWS Command Line Interface (AWS CLI)。（請參閱 [AWS CLI 文件中的安裝、更新和解除安裝](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) AWS CLI。) 
+ AWS CDK Toolkit，已安裝並設定。（請參閱 [AWS CDK 文件](https://docs.aws.amazon.com/cdk/v2/guide/cli.html)中的 AWS CDK Toolkit，並依照指示在全球安裝第 2 版。)
+ 節點套件管理員 (npm)，已安裝並設定 TypeScript 中的 AWS CDK。（請參閱 [npm 文件中的下載和安裝 Node.js 和](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) npm。)

**限制**
+ 如需限制和考量，請參閱 [Amazon ECS Anywhere)](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-anywhere.html#ecs-anywhere-considerations)。

**產品版本**
+ AWS CDK Toolkit 第 2 版
+ npm 7.20.3 版或更新版本
+ Node.js 16.6.1 版或更新版本

## Architecture
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk-architecture"></a>

**目標技術堆疊**
+ AWS CloudFormation
+ AWS CDK
+ Amazon ECS Anywhere
+ AWS Identity and Access Management (IAM)

**目標架構**

下圖說明使用 AWS CDK 搭配 TypeScript 的 ECS Anywhere 設定的高階系統架構，如此模式所實作。

1. 當您部署 AWS CDK 堆疊時，它會在 AWS 上建立 CloudFormation 堆疊。

1. CloudFormation 堆疊會佈建 Amazon ECS 叢集和相關的 AWS 資源。

1. 若要向 Amazon ECS 叢集註冊外部執行個體，您必須在虛擬機器 (VM) 上安裝 AWS Systems Manager Agent (SSM Agent)，並將 VM 註冊為 AWS Systems Manager 受管執行個體。 

1. 您還必須在 VM 上安裝 Amazon ECS 容器代理程式和 Docker，以將其註冊為 Amazon ECS 叢集的外部執行個體。

1. 使用 Amazon ECS 叢集註冊和設定外部執行個體時，它可以在您的 VM 上執行多個容器，其已註冊為外部執行個體。

![\[ECS Anywhere 設定搭配 TypeScript 使用 AWS CDK。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/3ed63c00-40e7-4831-bb9d-63049c3490aa/images/ff7dc774-830d-4b9f-8262-7314afe7a033.png)


 

**自動化和擴展**

此模式隨附的 [GitHub 儲存庫](https://github.com/aws-samples/amazon-ecs-anywhere-cdk-samples/)會使用 AWS CDK 做為基礎設施做為程式碼 (IaC) 工具，來建立此架構的組態。AWS CDK 可協助您協調資源並設定 ECS Anywhere。

## 工具
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk-tools"></a>
+ [AWS 雲端開發套件 (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) 是一種軟體開發架構，可協助您在程式碼中定義和佈建 AWS 雲端基礎設施。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。

**Code**

此模式的原始碼可在 GitHub 上的 [Amazon ECS Anywhere CDK 範例](https://github.com/aws-samples/amazon-ecs-anywhere-cdk-samples)儲存庫中取得。若要複製和使用儲存庫，請遵循下一節中的指示。

## 史詩
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk-epics"></a>

### 驗證 AWS CDK 組態
<a name="verify-aws-cdk-configuration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證 AWS CDK 版本。 | 執行下列命令來驗證 AWS CDK Toolkit 的版本：<pre>cdk --version</pre>此模式需要 AWS CDK 第 2 版。如果您有舊版的 AWS CDK，請遵循 [AWS CDK 文件](https://docs.aws.amazon.com/cdk/v2/guide/cli.html)中的指示進行更新。 | DevOps 工程師 | 
| 設定 AWS 登入資料。 | 若要設定登入資料，請執行 `aws configure`命令並遵循提示：<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]: <your-Region-name><br />Default output format [None]:</pre> | DevOps 工程師 | 

### 引導 AWS CDK 環境
<a name="bootstrap-the-aws-cdk-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 AWS CDK 程式碼儲存庫。 | 使用 命令複製此模式的 GitHub 程式碼儲存庫：<pre>git clone https://github.com/aws-samples/amazon-ecs-anywhere-cdk-samples.git</pre> | DevOps 工程師 | 
| 引導環境。 | 若要將 AWS CloudFormation 範本部署到您要使用的帳戶和 AWS 區域，請執行下列命令：<pre>cdk bootstrap <account-number>/<Region></pre>如需詳細資訊，請參閱 AWS CDK 文件中的[啟動](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)。 | DevOps 工程師 | 

### 建置和部署專案
<a name="build-and-deploy-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝套件相依性並編譯 TypeScript 檔案。 | 安裝套件相依性，並執行下列命令編譯 TypeScript 檔案：<pre>$cd amazon-ecs-anywhere-cdk-samples<br />$npm install<br />$npm fund </pre>這些命令會從範例儲存庫安裝所有套件。 如果您收到有關遺失套件的任何錯誤，請使用下列其中一個命令：<pre>$npm ci   </pre>—或—<pre>$npm install -g @aws-cdk/<package_name></pre>如需詳細資訊，請參閱 [npm 文件中的 npm ci](https://docs.npmjs.com/cli/v7/commands/npm-ci) 和 [npm 安裝](https://docs.npmjs.com/cli/v7/commands/npm-install)。 | DevOps 工程師 | 
| 建置專案。 | 若要建置專案程式碼，請執行 命令：<pre>npm run build</pre>如需建置和部署專案的詳細資訊，請參閱 [AWS CDK 文件中的您的第一個 AWS CDK 應用程式](https://docs.aws.amazon.com/cdk/latest/guide/hello_world.html#:~:text=the%20third%20parameter.-,Synthesize%20an%20AWS%20CloudFormation%20template,-Synthesize%20an%20AWS)。 | DevOps 工程師 | 
| 部署專案。 | 若要部署專案程式碼，請執行 命令：<pre>cdk deploy</pre> | DevOps 工程師 | 
| 驗證堆疊建立和輸出。 | 開啟位於 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 的 AWS CloudFormation 主控台，****然後選擇`EcsAnywhereStack`堆疊。**Outputs** 索引標籤會顯示要在外部 VM 上執行的命令。 | DevOps 工程師 | 

### 設定內部部署機器
<a name="set-up-an-on-premises-machine"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Vagrant 設定您的 VM。 | 基於示範目的，您可以使用 [HashiCorp Vagrant](https://www.vagrantup.com/) 來建立 VM。Vagrant 是一種開放原始碼公用程式，用於建置和維護可攜式虛擬軟體開發環境。從放置 Vagrantfile 的根目錄執行`vagrant up`命令來建立 Vagrant VM。如需詳細資訊，請參閱 [Vagrant 文件](https://www.vagrantup.com/docs/cli/up)。 | DevOps 工程師 | 
| 將您的 VM 註冊為外部執行個體。 | 1. 使用`vagrant ssh` 命令登入 Vagrant VM。如需詳細資訊，請參閱 [Vagrant 文件](https://www.vagrantup.com/docs/cli/ssh)。2. 建立啟用代碼和 ID，供您用來向 AWS Systems Manager 註冊 VM，以及啟用外部執行個體。此命令的輸出包含`ActivationId` 和`ActivationCode` 值： <pre>aws ssm create-activation --iam-role EcsAnywhereInstanceRole | tee ssm-activation.json</pre>3. 匯出啟用 ID 和程式碼值：<pre>export ACTIVATION_ID=<activation-ID><br />export ACTIVATION_CODE=<activation-code></pre>4. 將安裝指令碼下載到您的現場部署伺服器或 VM：<pre>curl -o "ecs-anywhere-install.sh" "https://amazon-ecs-agent.s3.amazonaws.com/ecs-anywhere-install-latest.sh" && sudo chmod +x ecs-anywhere-install.sh</pre>5. 在內部部署伺服器或 VM 上執行安裝指令碼：<pre>sudo ./ecs-anywhere-install.sh \<br />    --cluster test-ecs-anywhere \<br />     --activation-id $ACTIVATION_ID \<br />     --activation-code $ACTIVATION_CODE \<br />    --region <Region></pre>如需設定和註冊 VM 的詳細資訊，請參閱 Amazon ECS 文件中的[將外部執行個體註冊至叢集](https://docs.amazonaws.cn/en_us/AmazonECS/latest/developerguide/ecs-anywhere-registration.html)。 | DevOps 工程師 | 
| 驗證 ECS Anywhere 和外部 VM 的狀態。 | 若要驗證您的虛擬盒是否已連線至 Amazon ECS 控制平面並執行，請使用下列命令：<pre>aws ssm describe-instance-information<br />aws ecs list-container-instances --cluster $CLUSTER_NAME</pre> | DevOps 工程師 | 

### 清除
<a name="clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除和刪除資源。 | 完成此模式之後，您應該移除您建立的資源，以避免產生任何進一步的費用。若要清除，請執行 命令：<pre>cdk destroy</pre> | DevOps 工程師 | 

## 相關資源
<a name="manage-on-premises-container-applications-by-setting-up-amazon-ecs-anywhere-with-the-aws-cdk-resources"></a>
+ [Amazon ECS Anywhere 文件](https://aws.amazon.com/ecs/anywhere/) 
+ [Amazon ECS Anywhere 示範](https://www.youtube.com/watch?v=-eud6yUXsJM)
+ [Amazon ECS Anywhere 研討會範例](https://github.com/aws-samples/aws-ecs-anywhere-workshop-samples)

# 在 AWS 上現代化 ASP.NET Web Forms 應用程式
<a name="modernize-asp-net-web-forms-applications-on-aws"></a>

*Vijai Anand Ramalingam 和 Sreelaxmi Pai，Amazon Web Services*

## 總結
<a name="modernize-asp-net-web-forms-applications-on-aws-summary"></a>

此模式說明透過將舊版 ASP.NET Web Forms 應用程式移植到 AWS 上的 ASP.NET Core 來現代化舊版 Web Forms 應用程式的步驟。

將 ASP.NET Web Forms 應用程式移植到 ASP.NET Core 可協助您利用 Linux 的效能、節省成本和強大的生態系統。不過，這可能會是大量的手動工作。在此模式中，舊版應用程式會使用分階段方法逐步現代化，然後在 AWS 雲端中容器化。

考慮購物車的舊版整體應用程式。假設它是建立為 ASP.NET Web Forms 應用程式，並由具有程式碼後面 (`aspx.cs`) 檔案的 .aspx 頁面組成。現代化程序包含下列步驟：

1. 使用適當的分解模式，將整體分解為微服務。如需詳細資訊，請參閱 AWS 方案指引網站上的將[整體分解為微服務](https://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-decomposing-monoliths/)指南。

1. 將舊版 ASP.NET Web Forms (.NET Framework) 應用程式移植到 .NET 5 或更新版本中的 ASP.NET Core。在此模式中，您可以使用適用於 .NET 的移植助理來掃描 ASP.NET Web Forms 應用程式，並識別與 ASP.NET Core 的不相容。這可減少手動移植工作。

1. 使用 React 重新開發 Web Forms UI layer。此模式不包含 UI 重新開發。如需說明，請參閱 [React 文件中的建立新的 React 應用程式](https://reactjs.org/docs/create-a-new-react-app.html)。

1. 將 Web 表單程式碼落後檔案 （業務界面） 重新開發為 ASP.NET Core Web API。此模式使用 NDepend 報告來協助識別必要的檔案和相依性。

1. 使用適用於 .NET 的移植助理，將舊版應用程式中的共用/常見專案，例如商業邏輯和資料存取，升級至 .NET 5 或更新版本。 

1. 新增 AWS 服務以補充您的應用程式。例如，您可以使用 [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 來監控、存放和存取應用程式的日誌，以及使用 [AWS Systems Manager](https://aws.amazon.com/systems-manager/) 來存放應用程式設定。

1. 容器化現代化 ASP.NET Core 應用程式。此模式會建立以 Visual Studio 中的 Linux 為目標的 Docker 檔案，並使用 Docker 桌面在本機進行測試。此步驟假設您的舊版應用程式已在內部部署或 Amazon Elastic Compute Cloud (Amazon EC2) Windows 執行個體上執行。如需詳細資訊，請參閱模式 在 [Amazon EC2 Linux 執行個體上執行 ASP.NET Core Web API Docker 容器](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/run-an-asp-net-core-web-api-docker-container-on-an-amazon-ec2-linux-instance.html)。

1. 將現代化 ASP.NET 核心應用程式部署至 Amazon Elastic Container Service (Amazon ECS)。此模式不包含部署步驟。如需說明，請參閱 [Amazon ECS 研討會](https://ecsworkshop.com/)。

**注意**  
此模式不包含 UI 開發、資料庫現代化或容器部署步驟。

## 先決條件和限制
<a name="modernize-asp-net-web-forms-applications-on-aws-prereqs"></a>

**先決條件**
+ [Visual Studio](https://visualstudio.microsoft.com/downloads/) 或 [Visual Studio Code](https://code.visualstudio.com/download)，已下載並安裝。
+ 使用 AWS 管理主控台和 AWS Command Line Interface (AWS CLI) 第 2 版存取 AWS 帳戶。（請參閱[設定 AWS CLI 的說明](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)。)
+ AWS Toolkit for Visual Studio （請參閱[設定指示](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/setup.html))。
+ Docker Desktop，[已下載](https://www.docker.com/products/docker-desktop)並安裝。
+ .NET SDK，[已下載](https://download.visualstudio.microsoft.com/download/pr/4263dc3b-dc67-4f11-8d46-cc0ae86a232e/66782bbd04c53651f730b2e30a873f18/dotnet-sdk-5.0.203-win-x64.exe)並安裝。
+ NDepend 工具，[下載](https://www.ndepend.com/download)並安裝。若要安裝 Visual Studio 的 NDepend 延伸模組，請執行 `NDepend.VisualStudioExtension.Installer`([請參閱說明](https://www.ndepend.com/docs/getting-started-with-ndepend#Part1))。根據您的需求，您可以選擇 Visual Studio 2019 或 2022。 
+ 適用於 .NET 的移植助理，[已下載](https://aws.amazon.com/porting-assistant-dotnet/)並安裝。

## Architecture
<a name="modernize-asp-net-web-forms-applications-on-aws-architecture"></a>

**現代化購物車應用程式**

下圖說明舊版 ASP.NET 購物車應用程式的現代化程序。

![\[現代化傳統購物車應用程式\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36cda8e6-f2cb-4f1a-b37f-fa3045cc5ba1/images/4367e259-9bb3-4eb6-a54d-1c1e2dece7d4.png)


**目標架構**

下圖說明 AWS 上現代化購物車應用程式的架構。ASP.NET Core Web APIs會部署到 Amazon ECS 叢集。記錄和組態服務由 Amazon CloudWatch Logs 和 AWS Systems Manager 提供。

![\[AWS 上 ASP.NET Web Forms 應用程式的目標架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36cda8e6-f2cb-4f1a-b37f-fa3045cc5ba1/images/ed6d65ec-0dc9-43ab-ac07-1f172e089399.png)


## 工具
<a name="modernize-asp-net-web-forms-applications-on-aws-tools"></a>

**AWS 服務**
+ [Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) – Amazon Elastic Container Service (Amazon ECS) 是一種高度可擴展的快速容器管理服務，用於執行、停止和管理叢集上的容器。您可以在 AWS Fargate 管理的無伺服器基礎設施上執行任務和服務。或者，若要進一步控制您的基礎設施，您可以在您管理的 EC2 執行個體叢集上執行任務和服務。
+ [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) – Amazon CloudWatch Logs 會集中來自您使用之所有系統、應用程式和 AWS 服務的日誌。您可以檢視和監控日誌、搜尋特定錯誤代碼或模式、根據特定欄位篩選日誌，或安全地封存日誌以供未來分析。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) - AWS Systems Manager 是一種 AWS 服務，可用來檢視和控制 AWS 上的基礎設施。使用 Systems Manager 主控台，您可以檢視來自多個 AWS 服務的操作資料，並自動化 AWS 資源的操作任務。Systems Manager 會掃描受管執行個體，並在偵測到任何政策違規時回報 （或採取修正動作），以協助您維護安全性和合規性。

**工具**
+ [Visual Studio](https://visualstudio.microsoft.com/) 或 [Visual Studio 程式碼](https://code.visualstudio.com/) – 用於建置 .NET 應用程式、Web APIs和其他程式的工具。
+ [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) – Visual Studio 的延伸，可協助開發、偵錯和部署使用 AWS 服務的 .NET 應用程式。
+ [Docker Desktop](https://www.docker.com/products/docker-desktop) – 一種工具，可簡化建置和部署容器化應用程式。
+ [NDepend](https://www.ndepend.com/features/) – 監控 .NET 程式碼是否有相依性、品質問題和程式碼變更的分析器。
+ 適用於 [.NET 的移植助理](https://aws.amazon.com/porting-assistant-dotnet/) – 掃描 .NET 程式碼以識別與 .NET Core 不相容的分析工具，並估計遷移工作量。

## 史詩
<a name="modernize-asp-net-web-forms-applications-on-aws-epics"></a>

### 將舊版應用程式移植到 .NET 5 或更新版本
<a name="port-your-legacy-application-to-net-5-or-later-version"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 your.NET Framework 舊版應用程式升級至 .NET 5。 | 您可以使用適用於 .NET 的移植助理，將舊版 ASP.NET Web Forms 應用程式轉換為 .NET 5 或更新版本。遵循[適用於 .NET 的移植助理文件中](https://docs.aws.amazon.com/portingassistant/latest/userguide/porting-assistant-getting-started.html)的指示。 | 應用程式開發人員 | 
| 產生 NDepend 報告。 | 當您將 ASP.NET Web Forms 應用程式分解為微服務來現代化時，您可能不需要舊版應用程式中的所有 .cs 檔案。您可以使用 NDepend 來產生任何程式碼後面 (.cs) 檔案的報告，以取得所有來電者和來電者。此報告可協助您識別和僅使用微服務中的必要檔案。安裝 NDepend 後 [（請參閱先決條件](#modernize-asp-net-web-forms-applications-on-aws-prereqs)區段），請在 Visual Studio 中開啟舊版應用程式的解決方案 (.sln 檔案），並遵循下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)此程序會產生代碼後面檔案的報告，列出所有來電者和來電者。如需相依性圖表的詳細資訊，請參閱 [NDepend 文件](https://www.ndepend.com/docs/visual-studio-dependency-graph)。 | 應用程式開發人員 | 
| 建立新的 .NET 5 解決方案。 | 若要為現代化 ASP.NET Core Web APIs 建立新的 .NET 5 （或更新版本） 結構：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)如需建立專案和解決方案的詳細資訊，請參閱 [Visual Studio 文件](https://docs.microsoft.com/en-us/visualstudio/ide/creating-solutions-and-projects)。當您建置解決方案並驗證功能時，除了 NDepend 識別的檔案之外，您還可以識別要新增到解決方案的其他幾個檔案。 | 應用程式開發人員 | 

### 更新您的應用程式程式碼
<a name="update-your-application-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 ASP.NET Core 實作 Web APIs。 | 假設您在舊版單體購物車應用程式中識別的其中一個微服務是*產品*。您已在上一個史詩中為*產品*建立新的 ASP.NET Core Web API 專案。在此步驟中，您會識別和現代化與 *產品*相關的所有 Web 表單 (.aspx 頁面）。假設*產品*由四個 Web 表單組成，如先前[架構](#modernize-asp-net-web-forms-applications-on-aws-architecture)一節所示：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)您應該分析每個 Web 表單、識別傳送至資料庫以執行一些邏輯的所有請求，以及取得回應。您可以實作每個請求做為 Web API 端點。鑑於其 Web 表單，*產品*可以有下列可能端點：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)如前所述，您也可以重複使用升級至 .NET 5 的所有其他專案，包括商業邏輯、資料存取和共用/常見專案。 | 應用程式開發人員 | 
| 設定 Amazon CloudWatch Logs。 | 您可以使用 [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html) 來監控、存放和存取應用程式的日誌。您可以使用 AWS 開發套件將資料記錄到 Amazon CloudWatch Logs。您也可以使用 [NLog](https://www.nuget.org/packages/AWS.Logger.NLog/)、Log[Log4Net](https://www.nuget.org/packages/AWS.Logger.Log4net/) 和 [ASP.NET Core 記錄架構等熱門 .NET 記錄架構](https://www.nuget.org/packages/AWS.Logger.AspNetCore/)，將 .NET 應用程式與 CloudWatch Logs 整合。如需此步驟的詳細資訊，請參閱部落格文章 [Amazon CloudWatch Logs 和 .NET Logging Frameworks](https://aws.amazon.com/blogs/developer/amazon-cloudwatch-logs-and-net-logging-frameworks/)。 | 應用程式開發人員 | 
| 設定 AWS Systems Manager 參數存放區。 | 您可以使用 [AWS Systems Manager 參數存放區](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html)，將連線字串與應用程式的程式碼分開存放應用程式設定。NuGet [packageAmazon.Extensions.Configuration.SystemsManager](https://www.nuget.org/packages/Amazon.Extensions.Configuration.SystemsManager/) 可簡化您的應用程式如何將這些設定從 AWS Systems Manager 參數存放區載入 .NET Core 組態系統。 如需此步驟的詳細資訊，請參閱 [ AWS Systems Manager 的部落格文章 .NET Core 組態提供者](https://aws.amazon.com/blogs/developer/net-core-configuration-provider-for-aws-systems-manager/)。 | 應用程式開發人員 | 

### 新增身分驗證和授權
<a name="add-authentication-and-authorization"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用共用 Cookie 進行身分驗證。 | 將傳統整體應用程式現代化是一種反覆程序，需要整體及其現代化版本才能共存。您可以使用共用 Cookie 來實現兩個版本之間的無縫身分驗證。舊版 ASP.NET 應用程式會繼續驗證使用者登入資料並發出 Cookie，同時現代化 ASP.NET Core 應用程式會驗證 Cookie。 如需說明和範例程式碼，請參閱[範例 GitHub 專案](https://github.com/aws-samples/dotnet-share-auth-cookie-between-monolith-and-modernized-apps)。 | 應用程式開發人員 | 

### 在本機建置和執行容器
<a name="build-and-run-the-container-locally"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Visual Studio 建立 Docker 映像。 | 在此步驟中，您會使用 Visual Studio for .NET Core Web API 來建立 Docker 檔案。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html)Visual Studio 會為您的專案建立 Docker 檔案。如需 Docker 檔案範例，請參閱 Microsoft 網站上的[適用於 Docker 的 Visual Studio 容器工具](https://docs.microsoft.com/en-us/visualstudio/containers/overview)。 | 應用程式開發人員 | 
| 使用 Docker 桌面建置和執行容器。 | 現在您可以在 Docker 桌面中建置、建立和執行容器。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-asp-net-web-forms-applications-on-aws.html) | 應用程式開發人員 | 

## 相關資源
<a name="modernize-asp-net-web-forms-applications-on-aws-resources"></a>
+ [在 Amazon EC2 Linux 執行個體上執行 ASP.NET Core Web API Docker 容器](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/run-an-asp-net-core-web-api-docker-container-on-an-amazon-ec2-linux-instance.html) (AWS 方案指引）
+ [Amazon ECS 研討會](https://ecsworkshop.com/)
+ [使用 AWS CloudFormation (AWS CloudFormation 文件） 透過 CodeDeploy 執行 ECS 藍/綠部署](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html) AWS CloudFormation 
+ [NDepend 入門 ](https://www.ndepend.com/docs/getting-started-with-ndepend)(NDepend 文件）
+ [.NET 的移植助理](https://aws.amazon.com/porting-assistant-dotnet/)

## 其他資訊
<a name="modernize-asp-net-web-forms-applications-on-aws-additional"></a>

下表提供舊版購物車應用程式的範例專案，以及現代化 ASP.NET Core 應用程式中的同等專案。

**舊版解決方案：**


| 
| 
| Project name (專案名稱) | 專案範本 | 目標架構 | 
| --- |--- |--- |
| 業務界面  | 類別程式庫  | .NET Framework  | 
| BusinessLogic  | 類別程式庫  | .NET Framework  | 
| WebApplication  | ASP.NET Framework Web 應用程式  | .NET Framework  | 
| UnitTests  | NUnit 測試專案  | .NET Framework  | 
| 共用 -> 常見  | 類別程式庫  | .NET Framework  | 
| 共用 -> 架構  | 類別程式庫  | .NET Framework  | 

**新解決方案：**


| 
| 
| Project name (專案名稱) | 專案範本 | 目標架構 | 
| --- |--- |--- |
| BusinessLogic  | 類別程式庫  | .NET 5.0  | 
| <WebAPI>  | ASP.NET Core Web API  | .NET 5.0  | 
| <WebAPI>。UnitTests  | NUnit 3 測試專案  | .NET 5.0  | 
| 共用 -> 常見  | 類別程式庫  | .NET 5.0  | 
| 共用 -> 架構  | 類別程式庫  | .NET 5.0  | 

# 使用 C\$1 和 AWS CDK 在孤立模型的 SaaS 架構中加入租用戶
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk"></a>

*Tabby Ward、Susmitha Reddy Gankidi 和 Vijai Anand Ramalingam，Amazon Web Services*

## 總結
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-summary"></a>

軟體即服務 (SaaS) 應用程式可以使用各種不同的架構模型建置。*孤島模型*是指提供租戶專用資源的架構。

SaaS 應用程式依賴無摩擦模型，將新租戶引入其環境。這通常需要協調多個元件，才能成功佈建和設定建立新租用戶所需的所有元素。在 SaaS 架構中，此程序稱為租戶加入。應針對每個 SaaS 環境使用基礎設施做為加入程序中的程式碼，以完全自動化加入。

此模式會引導您完成在 Amazon Web Services (AWS) 上建立租用戶和佈建租用戶基本基礎設施的範例。模式使用 C\$1 和 AWS 雲端開發套件 (AWS CDK)。

由於此模式會建立帳單警示，因此建議您在美國東部 （維吉尼亞北部） 或 us-east-1 AWS 區域部署堆疊。如需詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html)。

## 先決條件和限制
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-prereqs"></a>

**先決條件******
+ 作用中的 [AWS 帳戶](https://aws.amazon.com/account/)。
+ 具有足夠 IAM 存取權的 AWS Identity and Access Management (IAM) 主體，可為此模式建立 AWS 資源。如需詳細資訊，請參閱 [IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)。
+ [安裝 Amazon Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) 並[設定 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) 以執行 AWS CDK 部署。
+ [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) 已下載並安裝，或 [Visual Studio Code](https://code.visualstudio.com/download) 已下載並安裝。
+ [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/setup.html) 設定。
+ [.NET Core 3.1 或更新版本](https://dotnet.microsoft.com/download/dotnet-core/3.1) (C\$1 AWS CDK 應用程式需要）
+ 已安裝 [Amazon.Lambda.Tools](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools)。

**限制******
+ AWS CDK 使用 [AWS CloudFormation](https://aws.amazon.com/cloudformation/)，因此 AWS CDK 應用程式受限於 CloudFormation 服務配額。如需詳細資訊，請參閱 [AWS CloudFormation 配額](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)。 
+ 租用戶 CloudFormation 堆疊是使用 CloudFormation 服務角色建立的，`infra-cloudformation-role`其動作上有萬用字元 (`sns`\$1 和 `sqs*`)，但資源鎖定為`tenant-cluster`字首。對於生產使用案例，請評估此設定，並僅提供對此服務角色的必要存取權。`InfrastructureProvision` Lambda 函數也會使用萬用字元 (`cloudformation*`) 來佈建 CloudFormation 堆疊，但資源會鎖定為`tenant-cluster`字首。
+ 此範例程式碼的 docker 組建使用 `--platform=linux/amd64` 來強制以映像`linux/amd64`為基礎。這是為了確保最終影像成品適用於 Lambda，依預設會使用 x86-64 架構。如果您需要變更目標 Lambda 架構，請務必同時變更 Dockerfile 和 AWS CDK 代碼。如需詳細資訊，請參閱部落格文章將 [ AWS Lambda 函數遷移至 Arm 型 AWS Graviton2 處理器](https://aws.amazon.com/blogs/compute/migrating-aws-lambda-functions-to-arm-based-aws-graviton2-processors/)。
+ 堆疊刪除程序不會清除堆疊產生的 CloudWatch Logs （日誌群組和日誌）。您必須透過 AWS 管理主控台 Amazon CloudWatch 主控台或透過 API 手動清除日誌。

此模式設定為範例。針對生產用途，請評估下列設定，並根據您的業務需求進行變更：
+ 此範例中的 [AWS Simple Storage Service (Amazon S3)](https://aws.amazon.com/s3/) 儲存貯體尚未啟用版本控制以簡化操作。視需要評估和更新設定。
+ 此範例設定 [Amazon API Gateway](https://aws.amazon.com/api-gateway/) REST API 端點，無需身分驗證、授權或限流即可簡化。對於生產用途，我們建議您將系統與商業安全基礎設施整合。評估此設定並視需要新增必要的安全設定。
+ 在此租戶基礎設施範例中，[Amazon Simple Notification Service (Amazon SNS)](https://aws.amazon.com/sns/) 和 [Amazon Simple Queue Service (Amazon SQS)](https://aws.amazon.com/sqs/) 只有最低設定。每個租用戶的 [AWS Key Management Service (AWS KMS)](https://aws.amazon.com/kms/) 會開啟帳戶中的 [Amazon CloudWatch](https://aws.amazon.com/cloudwatch/) 和 Amazon SNS 服務，以根據 [AWS KMS 金鑰政策](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-key-management.html#compatibility-with-aws-services)使用。設定只是範例預留位置。根據您的業務使用案例，視需要調整設定。
+ 整個設定包括但不限於 API 端點，以及使用 AWS CloudFormation 進行後端租用戶佈建和刪除，僅涵蓋基本的快樂路徑案例。根據您的業務需求，使用必要的重試邏輯、額外的錯誤處理邏輯和安全邏輯來評估和更新設定。
+ 範例程式碼使用up-to-date [cdk-nag](https://github.com/cdklabs/cdk-nag) 進行測試，以在撰寫本文時檢查政策。未來可能會強制執行新政策。這些新政策可能需要您根據建議手動修改堆疊，才能部署堆疊。檢閱現有的程式碼，以確保其符合您的業務需求。
+ 此程式碼倚賴 AWS CDK 產生隨機尾碼，而不是倚賴大多數建立資源的靜態指派實體名稱。此設定旨在確保這些資源是唯一的，並且不會與其他堆疊衝突。如需詳細資訊，請參閱 [AWS CDK 文件](https://docs.aws.amazon.com/cdk/v2/guide/resources.html#resources_physical_names)。根據您的業務需求進行調整。
+ 此範例程式碼會將 .NET Lambda 成品封裝至以 Docker 為基礎的映像，並使用 Lambda 提供的[容器映像執行時間](https://docs.aws.amazon.com/lambda/latest/dg/csharp-image.html)執行。容器映像執行時間對於標準傳輸和儲存機制 （容器登錄檔） 和更準確的本機測試環境 （透過容器映像） 具有優勢。您可以切換專案以使用 [Lambda 提供的 .NET 執行時間](https://docs.aws.amazon.com/lambda/latest/dg/lambda-csharp.html)，以減少 Docker 映像的建置時間，但接著您需要設定傳輸和儲存機制，並確保本機設定符合 Lambda 設定。調整程式碼以符合使用者的業務需求。

**產品版本**
+ AWS CDK 2.45.0 版或更新版本
+ Visual Studio 2022

## Architecture
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-architecture"></a>

**技術堆疊**
+ Amazon API Gateway
+ AWS CloudFormation
+ Amazon CloudWatch
+ Amazon DynamoDB
+ AWS Identity and Access Management (IAM)
+ AWS KMS
+ AWS Lambda
+ Amazon S3
+ Amazon SNS
+ Amazon SQS

**架構**

下圖顯示租戶堆疊建立流程。如需控制平面和租戶技術堆疊的詳細資訊，請參閱*其他資訊*一節。

![\[建立租用戶並為 AWS 上的租用戶佈建基本基礎設施的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5baef800-fe39-4eb8-b11d-2c23eb3175fc/images/0b579484-b87c-4acb-8c60-8c33c18370e3.png)


**租戶堆疊建立流程**

1. 使用者將具有 JSON 中新租用戶承載 （租用戶名稱、租用戶描述） 的 POST API 請求傳送至 Amazon API Gateway 託管的 REST API。API Gateway 會處理請求，並將其轉送至後端 Lambda 租戶加入函數。在此範例中，沒有授權或身分驗證。在生產設定中，此 API 應與 SaaS 基礎設施安全系統整合。

1. 租戶加入函數會驗證請求。然後，它會嘗試將租用戶記錄存放在 Amazon DynamoDB 租用戶加入資料表中，其中包含租用戶名稱、產生的租用戶通用唯一識別符 (UUID) 和租用戶描述。 

1. DynamoDB 儲存記錄後，DynamoDB 串流會啟動下游 Lambda 租用戶基礎設施函數。

1. 租戶基礎設施 Lambda 函數會根據收到的 DynamoDB 串流來運作。如果串流適用於 INSERT 事件，則函數會使用串流的 NewImage 區段 （最新更新記錄，租戶名稱欄位） 來叫用 CloudFormation，以使用存放在 S3 儲存貯體中的範本建立新的租戶基礎設施。CloudFormation 範本需要租用戶名稱參數。 

1. AWS CloudFormation 會根據 CloudFormation 範本和輸入參數建立租戶基礎設施。

1. 每個租戶基礎設施設定都有 CloudWatch 警示、帳單警示和警示事件。

1. 警示事件會變成 SNS 主題的訊息，由租戶的 AWS KMS 金鑰加密。

1. SNS 主題會將收到的警示訊息轉送至 SQS 佇列，該佇列由租戶的 AWS KMS 加密以進行加密金鑰。

其他系統可與 Amazon SQS 整合，以根據佇列中的訊息執行動作。在此範例中，若要保持程式碼通用，傳入的訊息會保留在佇列中，且需要手動刪除。

**租戶堆疊刪除流程**

1. 使用者將具有 JSON 中新租用戶承載 （租用戶名稱、租用戶描述） 的 DELETE API 請求傳送至 Amazon API Gateway 託管的 REST API，這會處理請求並轉送至租用戶加入函數。在此範例中，沒有授權或身分驗證。在生產設定中，此 API 將與 SaaS 基礎設施安全系統整合。

1. 租戶加入函數將驗證請求，然後嘗試從租戶加入資料表中刪除租戶記錄 （租戶名稱）。 

1. DynamoDB 成功刪除記錄後 （記錄存在於資料表中並刪除），DynamoDB 串流會啟動下游 Lambda 租用戶基礎設施函數。

1. 租戶基礎設施 Lambda 函數會根據收到的 DynamoDB 串流記錄運作。如果串流是用於 REMOVE 事件，則函數會使用記錄的 OldImage 區段 （記錄資訊和租用戶名稱欄位，在最新變更之前為刪除），根據該記錄資訊啟動現有堆疊的刪除。

1. AWS CloudFormation 會根據輸入刪除目標租用戶堆疊。

## 工具
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-tools"></a>

**AWS 服務**
+ [Amazon API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) 可協助您建立、發佈、維護、監控和保護任何規模的 REST、HTTP 和 WebSocket APIs。
+ [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/v2/guide/home.html) 是一種軟體開發架構，可協助您在程式碼中定義和佈建 AWS Cloud 基礎設施。
+ [AWS CDK Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/cli.html) 是命令列雲端開發套件，可協助您與 AWS Cloud Development Kit (AWS CDK) 應用程式互動。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您透過命令列 shell 中的命令與 AWS 服務互動。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速一致地佈建資源，以及在整個 AWS 帳戶和區域的生命週期進行管理。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Key Management Service (AWS KMS) ](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，可協助您執行程式碼，而不需要佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [Amazon Simple Notification Service (Amazon SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 可協助您協調和管理發佈者和用戶端之間的訊息交換，包括 Web 伺服器和電子郵件地址。
+ [Amazon Simple Queue Service (Amazon SQS)](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html) 提供安全、耐用且可用的託管佇列，可協助您整合和分離分散式軟體系統和元件。
+ [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) 是 Visual Studio 整合開發環境 (IDE) 的外掛程式。Toolkit for Visual Studio 支援開發、偵錯和部署使用 AWS 服務的 .NET 應用程式。

**其他工具**
+ [Visual Studio](https://docs.microsoft.com/en-us/visualstudio/ide/whats-new-visual-studio-2022?view=vs-2022) 是一種 IDE，其中包含編譯器、程式碼完成工具、圖形設計師和其他支援軟體開發的功能。

**Code**

此模式的程式碼位於 [ SaaS Architecture for Silo Model APG 範例儲存庫中的租戶加入](https://github.com/aws-samples/tenant-onboarding-in-saas-architecture-for-silo-model-apg-example)中。

## 史詩
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-epics"></a>

### 設定 AWS CDK
<a name="set-up-aws-cdk"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證 Node.js 安裝。 | 若要確認您的本機電腦上已安裝 Node.js，請執行下列命令。<pre>node --version</pre> | AWS 管理員、AWS DevOps | 
| 安裝 AWS CDK Toolkit。 | 若要在本機電腦上安裝 AWS CDK Toolkit，請執行下列命令。<pre>npm install -g aws-cdk</pre>如果未安裝 npm，您可以從 [Node.js 網站安裝。](https://nodejs.org/en/download/package-manager/) | AWS 管理員、AWS DevOps | 
| 驗證 AWS CDK Toolkit 版本。 | 若要確認您的電腦上已正確安裝 AWS CDK Toolkit 版本，請執行下列命令。 <pre>cdk --version</pre> | AWS 管理員、AWS DevOps | 

### 檢閱租戶加入控制平面的程式碼
<a name="review-the-code-for-the-tenant-onboarding-control-plane"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製儲存庫。 | 複製[儲存庫](https://github.com/aws-samples/tenant-onboarding-in-saas-architecture-for-silo-model-apg-example)，然後導覽至 `\tenant-onboarding-in-saas-architecture-for-silo-model-apg-example` 資料夾。在 Visual Studio 2022 中，開啟`\src\TenantOnboardingInfra.sln`解決方案。開啟 `TenantOnboardingInfraStack.cs` 檔案並檢閱程式碼。下列資源會建立為此堆疊的一部分：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html) | AWS 管理員、AWS DevOps | 
| 檢閱 CloudFormation 範本。 | 在 `\tenant-onboarding-in-saas-architecture-for-silo-model-apg-example\template`資料夾中，開啟 `infra.yaml`並檢閱 CloudFormation 範本。此範本將使用從租戶加入 DynamoDB 資料表擷取的租戶名稱進行補充。範本會佈建租戶特定的基礎設施。在此範例中，它會佈建 AWS KMS 金鑰、Amazon SNS、Amazon SQS 和 CloudWatch 警示。 | 應用程式開發人員、AWS DevOps | 
| 檢閱租戶加入函數。 | 開啟 `Function.cs`，並檢閱租戶加入函數的程式碼，該函數是使用 Visual Studio AWS Lambda 專案 (.NET Core- C\$1) 範本搭配 .NET 6 （容器映像） 藍圖所建立。開啟 `Dockerfile`，並檢閱程式碼。`Dockerfile` 是一個文字檔案，其中包含建置 Lambda 容器映像的說明。請注意，下列 NuGet 套件會新增為`TenantOnboardingFunction`專案的相依性：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html) | 應用程式開發人員、AWS DevOps | 
| 檢閱租戶 InfraProvisioning 函數。 | 導覽至 `\tenant-onboarding-in-saas-architecture-for-silo-model-apg-example\src\InfraProvisioningFunction`。開啟 `Function.cs`，並檢閱租用戶基礎設施佈建函數的程式碼，該函數是使用 Visual Studio AWS Lambda 專案 (.NET Core- C\$1) 範本搭配 .NET 6 （容器映像） 藍圖所建立。開啟 `Dockerfile`，並檢閱程式碼。請注意，下列 NuGet 套件會新增為`InfraProvisioningFunction`專案的相依性：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html) | 應用程式開發人員、AWS DevOps | 

### 部署 AWS 資源
<a name="deploy-the-aws-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建置解決方案。 | 若要建置解決方案，請執行下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html)在建置解決方案之前，請務必將`Amazon.CDK.Lib NuGet`套件更新至`\tenant-onboarding-in-saas-architecture-for-silo-model-apg-example\src\TenantOnboardingInfra`專案中的最新版本。 | 應用程式開發人員 | 
| 引導 AWS CDK 環境。 | 開啟 Windows 命令提示字元，並導覽至可使用 `cdk.json` 檔案的 AWS CDK 應用程式根資料夾 (`\tenant-onboarding-in-saas-architecture-for-silo-model-apg-example`)。執行下列命令進行引導。<pre>cdk bootstrap </pre>如果您已為登入資料建立 AWS 設定檔，請使用 命令搭配您的設定檔。<pre>cdk bootstrap --profile <profile name><br />  </pre> | AWS 管理員、AWS DevOps | 
| 列出 AWS CDK 堆疊。 | 若要列出要建立做為此專案一部分的所有堆疊，請執行下列命令。<pre>cdk ls<br />cdk ls --profile <profile name></pre>如果您已為登入資料建立 AWS 設定檔，請使用 命令搭配您的設定檔。<pre>cdk ls --profile <profile name></pre> | AWS 管理員、AWS DevOps | 
| 檢閱要建立的 AWS 資源。 | 若要檢閱將建立為此專案一部分的所有 AWS 資源，請執行下列命令。<pre>cdk diff</pre>如果您已為登入資料建立 AWS 設定檔，請使用 命令搭配您的設定檔。<pre>cdk diff --profile <profile name></pre> | AWS 管理員、AWS DevOps | 
| 使用 AWS CDK 部署所有 AWS 資源。 | 若要部署所有 AWS 資源，請執行下列命令。<pre>cdk deploy --all --require-approval never</pre>如果您已為登入資料建立 AWS 設定檔，請使用 命令搭配您的設定檔。<pre>cdk deploy --all --require-approval never --profile <profile name></pre>部署完成後，請從命令提示中的輸出區段複製 API URL，如下列範例所示。<pre>Outputs:<br />TenantOnboardingInfraStack.TenantOnboardingAPIEndpoint42E526D7 = https://j2qmp8ds21i1i.execute-api.us-west-2.amazonaws.com/prod/</pre> | AWS 管理員、AWS DevOps | 

### 驗證功能
<a name="verify-the-functionality"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立新的租用戶。 | 若要建立新的租用戶，請傳送下列 curl 請求。<pre>curl -X POST <TenantOnboardingAPIEndpoint* from CDK Output>tenant -d '{"Name":"Tenant123", "Description":"Stack for Tenant123"}'</pre>將預留位置變更為 AWS CDK `<TenantOnboardingAPIEndpoint* from CDK Output>`的實際值，如下列範例所示。<pre>curl -X POST https://j2qmp8ds21i1i.execute-api.us-west-2.amazonaws.com/prod/tenant -d '{"Name":"Tenant123", "Description":"test12"}'</pre>下列範例顯示輸出。<pre>{"message": "A new tenant added - 5/4/2022 7:11:30 AM"}</pre> | 應用程式開發人員、AWS 管理員、AWS DevOps | 
| 驗證 DynamoDB 中新建立的租戶詳細資訊。 | 若要在 DynamoDB 中驗證新建立的租戶詳細資訊，請執行下列步驟。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html) | 應用程式開發人員、AWS 管理員、AWS DevOps | 
| 驗證新租用戶的堆疊建立。 | 根據 CloudFormation 範本，確認新堆疊已成功使用新建立租用戶的基礎設施建立和佈建。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html) | 應用程式開發人員、AWS 管理員、AWS DevOps | 
| 刪除租戶堆疊。 | 若要刪除租戶堆疊，請傳送下列 curl 請求。<pre>curl -X DELETE <TenantOnboardingAPIEndpoint* from CDK Output>tenant/<Tenant Name from previous step></pre>將預留位置`<TenantOnboardingAPIEndpoint* from CDK Output>`變更為 AWS CDK 的實際值，並將 `<Tenant Name from previous step>`變更為上一個租用戶建立步驟的實際值，如下列範例所示。<pre>curl -X DELETE https://j2qmp8ds21i1i.execute-api.us-west-2.amazonaws.com/prod/tenant/Tenant123</pre>下列範例顯示輸出。<pre>{"message": "Tenant destroyed - 5/4/2022 7:14:48 AM"}</pre> | 應用程式開發人員、AWS DevOps、AWS 管理員 | 
| 驗證現有租用戶的堆疊刪除。 | 若要確認現有租用戶堆疊已刪除，請執行下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html) | 應用程式開發人員、AWS 管理員、AWS DevOps | 

### 清除
<a name="clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 銷毀環境。 | 在清除堆疊之前，請確定下列事項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk.html)測試完成後，AWS CDK 可以透過執行下列命令來銷毀所有堆疊和相關資源。<pre>cdk destroy --all;</pre>如果您已為登入資料建立 AWS 設定檔，請使用該設定檔。確認堆疊刪除提示以刪除堆疊。 | AWS 管理員、AWS DevOps | 
| 清除 Amazon CloudWatch Logs。 | 堆疊刪除程序不會清除堆疊產生的 CloudWatch Logs （日誌群組和日誌）。使用 CloudWatch 主控台或 API 手動清除 CloudWatch 資源。 | 應用程式開發人員、AWS DevOps、AWS 管理員 | 

## 相關資源
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-resources"></a>
+ [AWS CDK .NET 研討會](https://cdkworkshop.com/40-dotnet.html)
+ [在 C\$1 中使用 AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-csharp.html)
+ [CDK .NET 參考](https://docs.aws.amazon.com/cdk/api/v2/dotnet/api/index.html)

## 其他資訊
<a name="tenant-onboarding-in-saas-architecture-for-the-silo-model-using-c-and-aws-cdk-additional"></a>

**控制平面技術堆疊**

以 .NET 撰寫的 CDK 程式碼用於佈建控制平面基礎設施，其中包含下列資源：

1. **API Gateway**

   做為控制平面堆疊的 REST API 進入點。

1. **租用戶加入 Lambda 函數**

   此 Lambda 函數是由 API Gateway 使用 m 方法啟動。

   POST 方法 API 請求會導致 (`tenant name`、`tenant description`) 插入 DynamoDB `Tenant Onboarding`資料表。

   在此程式碼範例中，租用戶名稱也會用作租用戶堆疊名稱的一部分，以及該堆疊內資源的名稱。這是為了讓這些資源更容易識別。此租用戶名稱在整個設定中必須是唯一的，以避免衝突或錯誤。詳細的輸入驗證設定會在 [IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)文件和*限制*一節中說明。

   DynamoDB 資料表的持久性程序只有在未用於資料表中任何其他記錄時，才會成功。

   在這種情況下，租戶名稱是此表格的分割區索引鍵，因為只有分割區索引鍵可以用作`PutItem`條件表達式。

   如果先前從未記錄過租戶名稱，則記錄將成功儲存至資料表。

   不過，如果 資料表中的現有記錄已使用租用戶名稱，則操作將會失敗並啟動 DynamoDB `ConditionalCheckFailedException`例外狀況。例外狀況將用於傳回失敗訊息 (`HTTP BadRequest`)，指出租用戶名稱已存在。

   `DELETE` 方法 API 請求會從 `Tenant Onboardin`g 資料表中移除特定租用戶名稱的記錄。

   即使記錄不存在，此範例中的 DynamoDB 記錄刪除仍會成功。

   如果目標記錄存在且已刪除，則會建立 DynamoDB 串流記錄。否則，將不會建立任何下游記錄。

1. **啟用 Amazon DynamoDB Streams 的租戶加入 DynamoDB **

   這會記錄租戶中繼資料資訊，而任何記錄儲存或刪除都會將串流傳送至 `Tenant Infrastructure` Lambda 函數下游。 

1. **租戶基礎設施 Lambda 函數**

   此 Lambda 函數是由上一個步驟的 DynamoDB 串流記錄啟動。如果記錄是針對`INSERT`事件，它會叫用 AWS CloudFormation，以使用存放在 S3 儲存貯體中的 CloudFormation 範本建立新的租用戶基礎設施。如果記錄適用於 `REMOVE`，則會根據串流記錄的 `Tenant Name` 欄位啟動現有堆疊的刪除。

1. **S3 bucket (S3 儲存貯體)**

   這是用於存放 CloudFormation 範本。

1. **每個 Lambda 函數的 IAM 角色和 CloudFormation 的服務角色**

   每個 Lambda 函數都有其唯一的 IAM 角色，具有實現其任務[的最低權限許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)。例如，`Tenant On-boarding`Lambda 函數具有 DynamoDB 的讀取/寫入存取權，Lambda `Tenant Infrastructure` 函數只能讀取 DynamoDB 串流。

   為租戶堆疊佈建建立自訂 CloudFormation 服務角色。此服務角色包含 CloudFormation 堆疊佈建的其他許可 （例如 AWS KMS 金鑰）。這會在 Lambda 和 CloudFormation 之間分割角色，以避免單一角色 （基礎設施 Lambda 角色） 的所有許可。

   允許強大動作 （例如建立和刪除 CloudFormation 堆疊） 的許可會遭到鎖定，且僅允許在以 開頭的資源上`tenantcluster-`進行。例外狀況是 AWS KMS，因為其資源命名慣例。從 API 擷取的租用戶名稱將與其他驗證檢查`tenantcluster-`一起加上 （僅含破折號的英數字元，且限制為少於 30 個字元，以符合大多數 AWS 資源命名）。這可確保租戶名稱不會意外導致核心基礎設施堆疊或資源中斷。

**租戶技術堆疊**

CloudFormation 範本存放在 S3 儲存貯體中。範本會佈建租戶特定的 AWS KMS 金鑰、CloudWatch 警示、SNS 主題、SQS 佇列和 [SQS 政策](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-using-identity-based-policies.html)。

Amazon SNS 和 Amazon SQS 會將 AWS KMS 金鑰用於其訊息的資料加密。[AwsSolutions-SNS2 和 AwsSolutions-SQS2](https://github.com/cdklabs/cdk-nag/blob/main/RULES.md) 的安全實務建議您使用加密設定 Amazon SNS 和 Amazon SQS。不過，使用 AWS 受管金鑰時，CloudWatch 警示不適用於 Amazon SNS，因此在這種情況下，您必須使用客戶受管金鑰。如需詳細資訊，請參閱 [AWS 知識中心](https://aws.amazon.com/premiumsupport/knowledge-center/cloudwatch-receive-sns-for-alarm-trigger/)。

SQS 政策用於 Amazon SQS 佇列，以允許建立的 SNS 主題將訊息傳遞至佇列。如果沒有 SQS 政策，存取將被拒絕。如需詳細資訊，請參閱 [Amazon SNS 文件](https://docs.aws.amazon.com/sns/latest/dg/subscribe-sqs-queue-to-sns-topic.html#SendMessageToSQS.sqs.permissions)。

# 使用 CQRS 和事件來源將整體分解為微服務
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing"></a>

*Rodolfo Jr. Cerrada、Dmitry Gulin 和 Tabby Ward，Amazon Web Services*

## 總結
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-summary"></a>

此模式結合兩種模式，同時使用命令查詢責任分離 (CQRS) 模式和事件來源模式。CQRS 模式會區隔命令和查詢模型的責任。事件來源模式會利用非同步事件驅動的通訊來改善整體使用者體驗。

您可以使用 CQRS 和 Amazon Web Services (AWS) 服務獨立維護和擴展每個資料模型，同時將整體應用程式重構為微服務架構。然後，您可以使用事件來源模式，將資料從命令資料庫同步到查詢資料庫。

此模式使用包含解決方案 (\$1.sln) 檔案的範例程式碼，您可以使用最新版本的 Visual Studio 開啟該檔案。此範例包含獎勵 API 程式碼，示範 CQRS 和事件來源如何在 AWS 無伺服器和傳統或內部部署應用程式中運作。

若要進一步了解 CQRS 和事件來源，請參閱[其他資訊](#decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-additional)一節。

## 先決條件和限制
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Amazon CloudWatch
+ Amazon DynamoDB 資料表
+ Amazon DynamoDB Streams
+ AWS Identity and Access Management (IAM) 存取金鑰和私密金鑰；如需詳細資訊，請參閱*相關資源*區段中的影片
+ AWS Lambda
+ 熟悉 Visual Studio
+ 熟悉 AWS Toolkit for Visual Studio；如需詳細資訊，請參閱*相關資源*區段中的 *AWS Toolkit for Visual Studio 示範*影片

**產品版本**
+ [Visual Studio 2019 Community Edition](https://visualstudio.microsoft.com/downloads/)。
+ [AWS Toolkit for Visual Studio 2019](https://aws.amazon.com/visualstudio/)。
+ .NET Core 3.1。此元件是 Visual Studio 安裝中的選項。若要在安裝期間包含 .NET Core，請選取 **NET Core 跨平台開發**。

**限制**
+ 傳統內部部署應用程式 (ASP.NET Core Web API 和資料存取物件） 的範例程式碼不會隨附資料庫。不過，它隨附記憶體`CustomerData`內物件，可做為模擬資料庫。提供的程式碼足以讓您測試模式。

## Architecture
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-architecture"></a>

**來源技術堆疊**
+ ASP.NET Core Web API 專案
+ IIS Web 伺服器
+ 資料存取物件
+ CRUD 模型

**來源架構**

在來源架構中，CRUD 模型在一個應用程式中包含命令和查詢介面。如需範例程式碼，請參閱 `CustomerDAO.cs`（已連接）。

![\[應用程式、服務介面、客戶 CRUD 模型和資料庫之間的連線。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/1cd3a84c-12c7-4306-99aa-23f2c53d3cd3.png)


**目標技術堆疊**
+ Amazon DynamoDB
+ Amazon DynamoDB Streams
+ AWS Lambda
+ （選用） Amazon API Gateway
+ （選用） Amazon Simple Notification Service (Amazon SNS)

**目標架構**

在目標架構中，命令和查詢界面會分開。下圖中顯示的架構可以使用 API Gateway 和 Amazon SNS 擴充。如需詳細資訊，請參閱[其他資訊](#decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-additional)一節。

![\[與無伺服器 Customer Command 和 Customer Query 微服務連線的應用程式。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/1c665697-e3ac-4ef4-98d0-86c2cbf164c1.png)


1. 命令 Lambda 函數會在資料庫上執行寫入操作，例如建立、更新或刪除。

1. 查詢 Lambda 函數會在資料庫上執行讀取操作，例如取得或選取。

1. 此 Lambda 函數會處理來自 命令資料庫的 DynamoDB 串流，並更新查詢資料庫以進行變更。

## 工具
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-tools"></a>

**工具**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) – Amazon DynamoDB 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能和無縫的可擴展性。
+ [Amazon DynamoDB Streams](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html) – DynamoDB Streams 會擷取任何 DynamoDB 資料表中項目層級修改的時間順序序列。然後，它會將此資訊存放在日誌中長達 24 小時。靜態加密功能會加密 DynamoDB Streams 中的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) – AWS Lambda 是一種運算服務，支援執行程式碼，無需佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。只需為使用的運算時間支付費用，一旦未執行程式碼，就會停止計費。
+ [AWS 管理主控台](https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/learn-whats-new.html) – AWS 管理主控台是一種 Web 應用程式，包含用於管理 AWS 服務的廣泛服務主控台集合。
+ [Visual Studio 2019 Community Edition](https://visualstudio.microsoft.com/downloads/) – Visual Studio 2019 是整合式開發環境 (IDE)。開放原始碼參與者可免費使用 Community Edition。在此模式中，您將使用 Visual Studio 2019 Community Edition 來開啟、編譯和執行範例程式碼。僅供檢視，您可以使用任何文字編輯器或 [Visual Studio 程式碼](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/welcome.html)。
+ [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html) – AWS Toolkit for Visual Studio 是 Visual Studio IDE 的外掛程式。AWS Toolkit for Visual Studio 可讓您更輕鬆地開發、偵錯和部署使用 AWS 服務的 .NET 應用程式。

**Code**

已連接範例程式碼。如需部署範例程式碼的指示，請參閱 *Epics* 一節。

## 史詩
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-epics"></a>

### 開啟並建置解決方案
<a name="open-and-build-the-solution"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 開啟解決方案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員 | 
| 建置解決方案。 | 開啟解決方案的內容 （按一下滑鼠右鍵） 選單，然後選擇**建置解決方案**。這將建置和編譯解決方案中的所有專案。它應該可以成功編譯。Visual Studio Solution Explorer 應會顯示目錄結構。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員 | 

### 建置 DynamoDB 資料表
<a name="build-the-dynamodb-tables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 提供登入資料。 | 如果您還沒有存取金鑰，請參閱*相關資源*一節中的影片。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員、資料工程師、DBA | 
| 建置專案。 | 若要建置專案，請開啟 **AwS.APG.CQRSES.Build** 專案的內容 （按一下滑鼠右鍵） 選單，然後選擇**建置**。 | 應用程式開發人員、資料工程師、DBA | 
| 建置和填入資料表。 | 若要建置資料表並填入種子資料，請開啟 **AwS.APG.CQRSES.Build** 專案的內容 （按一下滑鼠右鍵） 選單，然後選擇**偵錯**、**啟動新執行個體**。 | 應用程式開發人員、資料工程師、DBA | 
| 驗證資料表建構和資料。 | 若要驗證，請導覽至 **AWS Explorer**，然後展開 **Amazon DynamoDB**。它應該會顯示資料表。開啟每個資料表以顯示範例資料。 | 應用程式開發人員、資料工程師、DBA | 

### 執行本機測試
<a name="run-local-tests"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建置 CQRS 專案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員、測試工程師 | 
| 建置事件來源專案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員、測試工程師 | 
| 執行測試。 | 若要執行所有測試，請選擇**檢視**、**測試總**管，然後選擇在**檢視中執行所有測試**。所有測試都應通過，以綠色核取記號圖示表示。  | 應用程式開發人員、測試工程師 | 

### 將 CQRS Lambda 函數發佈至 AWS
<a name="publish-the-cqrs-lambda-functions-to-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 發佈第一個 Lambda 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員、DevOps 工程師 | 
| 驗證函數上傳。 | （選用） 您可以透過導覽至 AWS Explorer 並展開 **AWS Lambda** 來驗證函數是否已成功載入。若要開啟測試視窗，請選擇 Lambda 函數 （按兩下）。 | 應用程式開發人員、DevOps 工程師 | 
| 測試 Lambda 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html)所有 CQRS Lambda 專案都位於 `CQRS AWS Serverless\CQRS\Command Microservice`和` CQRS AWS Serverless\CQRS\Command Microservice` 解決方案資料夾下。如需解決方案目錄和專案，請參閱[其他資訊](#decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-additional)區段中的**原始程式碼目錄**。 | 應用程式開發人員、DevOps 工程師 | 
| 發佈剩餘的 函數。 | 針對下列專案重複上述步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員、DevOps 工程師 | 

### 將 Lambda 函數設定為事件接聽程式
<a name="set-up-the-lambda-function-as-an-event-listener"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 發佈 Customer and Reward Lambda 事件處理常式。 | 若要發佈每個事件處理常式，請遵循上述史詩中的步驟。專案位於 `CQRS AWS Serverless\Event Source\Customer Event`和 `CQRS AWS Serverless\Event Source\Reward Event` 解決方案資料夾下。如需詳細資訊，請參閱[其他資訊](#decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-additional)區段中的*原始程式碼目錄*。 | 應用程式開發人員 | 
| 連接事件來源 Lambda 事件接聽程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html)接聽程式成功連接到 DynamoDB 資料表後，它將顯示在 Lambda 設計工具頁面上。 | 應用程式開發人員 | 
| 發佈並連接 EventSourceReward Lambda 函數。 | 若要發佈並連接 `EventSourceReward` Lambda 函數，請重複前兩個故事中的步驟，從 **DynamoDB 資料表**下拉式清單中選取 **cqrses-reward-cmd**。 | 應用程式開發人員 | 

### 測試和驗證 DynamoDB 串流和 Lambda 觸發
<a name="test-and-validate-the-dynamodb-streams-and-lambda-trigger"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試串流和 Lambda 觸發。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員 | 
| 驗證，使用 DynamodDB 獎勵查詢表。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員 | 
| 使用 CloudWatch Logs 驗證。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing.html) | 應用程式開發人員 | 
| 驗證 EventSourceCustomer 觸發程序。 | 若要驗證`EventSourceCustomer`觸發條件，請使用`EventSourceCustomer`觸發條件各自的客戶資料表和 CloudWatch 日誌，重複此史詩中的步驟。 | 應用程式開發人員 | 

## 相關資源
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-resources"></a>

**參考**
+ [Visual Studio 2019 Community Edition 下載](https://visualstudio.microsoft.com/downloads/)
+ [AWS Toolkit for Visual Studio 下載](https://aws.amazon.com/visualstudio/)
+ [AWS Toolkit for Visual Studio 使用者指南](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/welcome.html)
+ [AWS 上的無伺服器](https://aws.amazon.com/serverless/)
+ [DynamoDB 使用案例和設計模式](https://aws.amazon.com/blogs/database/dynamodb-streams-use-cases-and-design-patterns/)
+ [Martin Fowler CQRS](https://martinfowler.com/bliki/CQRS.html)
+ [Martin Fowler 事件來源](https://martinfowler.com/eaaDev/EventSourcing.html)

**影片**
+ [AWS Toolkit for Visual Studio 示範](https://www.youtube.com/watch?v=B190tcu1ERk)
+ [如何為新的 IAM 使用者建立存取金鑰 ID？](https://www.youtube.com/watch?v=665RYobRJDY)

## 其他資訊
<a name="decompose-monoliths-into-microservices-by-using-cqrs-and-event-sourcing-additional"></a>

**CQRS 和事件來源**

*CQRS*

CQRS 模式會將單一概念操作模型，例如資料存取物件單一 CRUD （建立、讀取、更新、刪除） 模型，分成命令和查詢操作模型。命令模型是指變更狀態的任何操作，例如建立、更新或刪除。查詢模型是指傳回值的任何操作。

![\[具有服務介面、CRUD 模型和資料庫的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/3f64756d-681e-4f0e-8034-746263d857b2.png)


1. Customer CRUD 模型包含下列界面：
   + `Create Customer()`
   + `UpdateCustomer()`
   + `DeleteCustomer()`
   + `AddPoints()`
   + `RedeemPoints()`
   + `GetVIPCustomers()`
   + `GetCustomerList()`
   + `GetCustomerPoints()`

隨著您的需求變得更加複雜，您可以從此單一模型方法中移動。CQRS 使用命令模型和查詢模型來區隔寫入和讀取資料的責任。如此一來，資料就可以獨立維護和管理。透過明確的責任分離，每個模型的增強功能不會影響另一個模型。此區隔可改善維護和效能，並降低應用程式的複雜性。

![\[應用程式分成命令和查詢模型，共用單一資料庫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/12db023c-eb81-4c27-bbb9-b085b13176ae.png)


 

1. Customer Command 模型中的界面：
   + `Create Customer()`
   + `UpdateCustomer()`
   + `DeleteCustomer()`
   + `AddPoints()`
   + `RedeemPoints()`

1. 客戶查詢模型中的界面：
   + `GetVIPCustomers()`
   + `GetCustomerList()`
   + `GetCustomerPoints()`
   + `GetMonthlyStatement()`

如需範例程式碼，請參閱*原始程式碼目錄*。

然後，CQRS 模式會解耦資料庫。這種解耦會導致每個服務的整體獨立性，這是微服務架構的主要組成部分。

![\[命令和查詢模型的個別資料庫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/016dbfa8-3bd8-42ee-afa1-38a98986c7d5.png)


 在 AWS 雲端中使用 CQRS，您可以進一步最佳化每個服務。例如，您可以設定不同的運算設定，或在無伺服器或容器型微服務之間進行選擇。您可以使用 Amazon ElastiCache 取代內部部署快取。如果您有內部部署發佈/訂閱訊息，您可以將其取代為 Amazon Simple Notification Service (Amazon SNS)。此外，您可以利用pay-as-you-go定價和各種 AWS 服務，這些服務僅針對您使用的項目付費。

CQRS 包含下列優點：
+ 獨立擴展 – 每個模型都可以調整其擴展策略，以滿足服務的需求。與高效能應用程式類似，分開讀取和寫入可讓模型獨立擴展，以滿足每個需求。您也可以新增或減少運算資源，以滿足某個模型的可擴展性需求，而不會影響另一個模型。
+ 獨立維護 – 查詢和命令模型的分離可改善模型的可維護性。您可以對一個模型進行程式碼變更和增強功能，而不會影響另一個模型。
+ 安全 – 將許可和政策套用至個別模型以進行讀取和寫入更為容易。
+ 最佳化讀取 – 您可以定義針對查詢最佳化的結構描述。例如，您可以為彙總資料定義結構描述，並為事實資料表定義單獨的結構描述。
+ 整合 – CQRS 非常適合事件型程式設計模型。
+ 受管複雜性 – 對查詢和命令模型的分離適用於複雜的網域。

使用 CQRS 時，請記住下列注意事項：
+ CQRS 模式僅適用於應用程式的特定部分，而非整個應用程式。如果實作在不符合 模式的網域上，它可以降低生產力、增加風險並引入複雜性。
+ 此模式最適合具有不平衡讀取和寫入操作的常用模型。
+ 對於大量讀取的應用程式，例如需要時間處理的大型報告，CQRS 可讓您選擇正確的資料庫並建立結構描述來存放彙總資料。這可透過僅處理一次報告資料並將其傾印在彙總資料表中，來改善讀取和檢視報告的回應時間。
+ 對於寫入密集型應用程式，您可以設定用於寫入操作的資料庫，並允許命令微服務在寫入需求增加時獨立擴展。如需範例，請參閱 `AWS.APG.CQRSES.CommandRedeemRewardLambda`和 `AWS.APG.CQRSES.CommandAddRewardLambda` 微服務。

*事件來源*

下一個步驟是使用事件來源，在執行命令時同步查詢資料庫。例如，請考慮下列事件：
+ 新增的客戶獎勵點需要更新查詢資料庫中的客戶總獎勵點或彙總獎勵點。
+ 命令資料庫中會更新客戶的姓氏，這需要更新查詢資料庫中的代理客戶資訊。

在傳統 CRUD 模型中，您可以鎖定資料直到完成交易，以確保資料的一致性。在事件來源中，資料會透過發佈一系列事件來同步，訂閱者將使用該事件來更新其個別資料。

事件來源模式可確保並記錄對資料採取的完整一系列動作，並透過一系列事件發佈。這些事件代表一組對資料所做的變更，該事件的訂閱者必須處理這些變更，才能讓記錄保持最新狀態。訂閱者會使用這些事件，同步訂閱者資料庫中的資料。在這種情況下，這是查詢資料庫。

下圖顯示與 AWS 上的 CQRS 搭配使用的事件來源。

![\[使用 AWS 無伺服器服務的 CQRS 和事件來源模式的微服務架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/cc9bc84a-60b4-4459-9a5c-2334c69dbb4e.png)


1. 命令 Lambda 函數會在資料庫上執行寫入操作，例如建立、更新或刪除。

1. 查詢 Lambda 函數會在資料庫上執行讀取操作，例如取得或選取。

1. 此 Lambda 函數會從命令資料庫處理 DynamoDB 串流，並更新查詢資料庫以進行變更。您也可以使用此函數來發佈訊息至 Amazon SNS，以便其訂閱者可以處理資料。

1. （選用） Lambda 事件訂閱者會處理 Amazon SNS 發佈的訊息，並更新查詢資料庫。

1. （選用） Amazon SNS 會傳送寫入操作的電子郵件通知。

在 AWS 上，DynamoDB Streams 可以同步查詢資料庫。DynamoDB 會以近乎即時的方式擷取 DynamobDB 資料表中項目層級修改的時間順序，並在 24 小時內持久儲存資訊。

啟用 DynamoDB Streams 可讓資料庫發佈一系列事件，使事件來源模式成為可能。事件來源模式會新增事件訂閱者。事件訂閱者應用程式會使用事件，並根據訂閱者的責任來處理事件。在上圖中，事件訂閱者會將變更推送至 Query DynamoDB 資料庫，以保持資料同步。使用 Amazon SNS、訊息中介裝置和事件訂閱者應用程式會保持架構解耦。

事件來源包含下列優點：
+ 交易資料的一致性
+ 可靠的稽核線索和動作歷史記錄，可用於監控資料中採取的動作
+ 允許微型服務等分散式應用程式跨環境同步其資料
+ 每當狀態變更時，可靠發佈事件
+ 重建或重播過去狀態
+ 鬆散耦合的實體，交換事件以從單體應用程式遷移到微服務
+ 減少並行更新所造成的衝突；事件來源可避免直接在資料存放區中更新物件的需求
+ 解耦任務和事件的彈性和可擴展性
+ 外部系統更新
+ 在單一事件中管理多個任務

使用事件來源時，請記住下列注意事項：
+ 由於來源訂閱者資料庫之間的資料更新有所延遲，復原變更的唯一方法是將補償事件新增至事件存放區。
+ 實作事件來源具有自其程式設計風格不同的學習曲線。

**測試資料**

成功部署後，請使用下列測試資料來測試 Lambda 函數。

**CommandCreate 客戶**

```
{  "Id":1501,  "Firstname":"John",  "Lastname":"Done",  "CompanyName":"AnyCompany",  "Address": "USA",  "VIP":true }
```

**CommandUpdate 客戶**

```
{  "Id":1501,  "Firstname":"John",  "Lastname":"Doe",  "CompanyName":"Example Corp.",  "Address": "Seattle, USA",  "VIP":true }
```

**CommandDelete 客戶**

輸入客戶 ID 做為請求資料。例如，如果客戶 ID 為 151，請輸入 151 做為請求資料。

```
151
```

**QueryCustomerList**

這是空白的。調用時，它會傳回所有客戶。

**CommandAddReward**

這會新增 40 點給 ID 為 1 的客戶 (Richard)。

```
{
  "Id":10101,
  "CustomerId":1,
  "Points":40
}
```

**CommandRedeemReward**

這會扣除 ID 為 1 (Richard) 的客戶 15 點。

```
{
  "Id":10110,
  "CustomerId":1,
  "Points":15
}
```

**QueryReward**

輸入客戶的 ID。例如，輸入 1 表示 Richard，2 表示 Arnav，3 表示 Shirley。

```
2 
```

**原始程式碼目錄**

使用下表做為 Visual Studio 解決方案目錄結構的指南。 

*CQRS 現場部署程式碼範例解決方案目錄*

![\[擴展 Command and Query 服務的解決方案目錄。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/4811c2c0-643b-410f-bb87-0b86ec5e194c.png)


**客戶 CRUD 模型**

CQRS 現場部署程式碼範例\$1CRUD Model\$1AWS.APG.CQRSES.DAL 專案

**Customer CRUD 模型的 CQRS 版本**
+ 客戶命令：`CQRS On-Premises Code Sample\CQRS Model\Command Microservice\AWS.APG.CQRSES.Command`專案
+ 客戶查詢：`CQRS On-Premises Code Sample\CQRS Model\Query Microservice\AWS.APG.CQRSES.Query`專案

**命令和查詢微服務**

命令微服務位於解決方案資料夾 下`CQRS On-Premises Code Sample\CQRS Model\Command Microservice`：
+ `AWS.APG.CQRSES.CommandMicroservice` ASP.NET Core API 專案可做為消費者與服務互動的進入點。
+ `AWS.APG.CQRSES.Command` .NET Core 專案是託管命令相關物件和界面的物件。

查詢微服務位於解決方案資料夾 下`CQRS On-Premises Code Sample\CQRS Model\Query Microservice`：
+ `AWS.APG.CQRSES.QueryMicroservice` ASP.NET Core API 專案做為消費者與服務互動的進入點。
+ `AWS.APG.CQRSES.Query` .NET Core 專案是託管查詢相關物件和界面的物件。

*CQRS AWS Serverless 程式碼解決方案目錄*

![\[顯示微服務和事件來源已展開的解決方案目錄。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9f1bc700-def4-4201-bb2d-f1fa27404f15/images/23f8655c-95ad-422c-b20a-e29dc145e995.png)


 

此程式碼是使用 AWS 無伺服器服務的現場部署程式碼的 AWS 版本。

在 C\$1 .NET Core 中，每個 Lambda 函數都由一個 .NET Core 專案表示。在此模式的範例程式碼中，命令和查詢模型中的每個界面都有單獨的專案。

**使用 AWS 服務的 CQRS**

您可以在 `CQRS AWS Serverless\CQRS`資料夾中找到使用 AWS 無伺服器服務的 CQRS 根解決方案目錄。此範例包含兩種模型：客戶和獎勵。

Customer and Reward 的命令 Lambda 函數位於 `CQRS\Command Microservice\Customer`和 `CQRS\Command Microservice\Reward` 資料夾下。它們包含下列 Lambda 專案：
+ 客戶命令：`CommandDeleteLambda`、 `CommandCreateLambda`和 `CommandUpdateLambda`
+ 獎勵命令： `CommandAddRewardLambda` 和 `CommandRedeemRewardLambda`

客戶和獎勵的查詢 Lambda 函數位於 `CQRS\Query Microservice\Customer`和 `CQRS\QueryMicroservice\Reward`資料夾下。它們包含 `QueryCustomerListLambda`和 `QueryRewardLambda` Lambda 專案。

**CQRS 測試專案**

測試專案位於 `CQRS\Tests` 資料夾下。此專案包含測試指令碼，可自動測試 CQRS Lambda 函數。

**使用 AWS 服務的事件來源**

客戶和獎勵 DynamoDB 串流會啟動下列 Lambda 事件處理常式，以處理和同步查詢資料表中的資料。
+ `EventSourceCustomer` Lambda 函數會映射至客戶資料表 (`cqrses-customer-cmd`) DynamoDB 串流。
+ `EventSourceReward` Lambda 函數會映射至獎勵資料表 (`cqrses-reward-cmd`) DynamoDB 串流。

## 附件
<a name="attachments-9f1bc700-def4-4201-bb2d-f1fa27404f15"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/9f1bc700-def4-4201-bb2d-f1fa27404f15/attachments/attachment.zip)

# 更多模式
<a name="modernization-more-patterns-pattern-list"></a>

**Topics**
+ [使用 AWS PrivateLink 和 Network Load Balancer 在 Amazon EKS 上私下存取容器應用程式](access-container-applications-privately-on-amazon-eks-using-aws-privatelink-and-a-network-load-balancer.md)
+ [使用 AWS Systems Manager 自動化新增或更新 Windows 登錄項目](automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager.md)
+ [使用 DR Orchestrator Framework 自動化跨區域容錯移轉和容錯回復](automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.md)
+ [使用 CI/CD 管道自動建置 Java 應用程式並將其部署到 Amazon EKS](automatically-build-and-deploy-a-java-application-to-amazon-eks-using-a-ci-cd-pipeline.md)
+ [使用 AWS CDK 自動為微服務建置 CI/CD 管道和 Amazon ECS 叢集](automatically-build-ci-cd-pipelines-and-amazon-ecs-clusters-for-microservices-using-aws-cdk.md)
+ [使用 BMC AMI Cloud Data 將大型主機資料備份並封存至 Amazon S3](back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.md)
+ [使用 Amazon EC2 Auto Scaling 和 Systems Manager 建置 Micro Focus Enterprise Server PAC](build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager.md)
+ [使用 Amazon DataZone 建置企業資料網格 AWS CDK，以及 AWS CloudFormation](build-enterprise-data-mesh-amazon-data-zone.md)
+ [容器化已由 Blu Age 現代化的大型主機工作負載](containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.md)
+ [使用 Python 將 EBCDIC 資料轉換為 AWS 上的 ASCII](convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.md)
+ [使用 Micro Focus 轉換具有複雜記錄配置的大型主機資料檔案](convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.md)
+ [使用、 AWS Amplify Angular 和 Module Federation 建立微型前端的入口網站](create-amplify-micro-frontend-portal.md)
+ [使用 Elastic Beanstalk 部署容器](deploy-containers-by-using-elastic-beanstalk.md)
+ [使用 PostgreSQL 相容 Aurora 全域資料庫模擬 Oracle DR](emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database.md)
+ [在 Quick Sight 中使用 AWS Mainframe Modernization 和 Amazon Q 產生資料洞見](generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.md)
+ [使用 Quick Sight 中的 AWS Mainframe Modernization 和 Amazon Q 產生 Db2 z/OS 資料洞見](generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.md)
+ [遷移至 Amazon ECR 儲存庫時，自動識別重複的容器映像](identify-duplicate-container-images-automatically-when-migrating-to-ecr-repository.md)
+ [使用 K8sGPT 和 Amazon Bedrock 整合實作採用 AI 技術的 Kubernetes 診斷和故障診斷](implement-ai-powered-kubernetes-diagnostics-and-troubleshooting-with-k8sgpt-and-amazon-bedrock-integration.md)
+ [在 AWS Blu Age 現代化大型主機應用程式中實作 Microsoft Entra ID 型身分驗證](implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application.md)
+ [在 Amazon API Gateway 中使用自訂網域實作路徑型 API 版本控制](implement-path-based-api-versioning-by-using-custom-domains.md)
+ [使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.md)
+ [將stonebranch 通用控制器與 AWS Mainframe Modernization 整合](integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.md)
+ [在多個 AWS 帳戶和 AWS 區域中管理 AWS Service Catalog 產品](manage-aws-service-catalog-products-in-multiple-aws-accounts-and-aws-regions.md)
+ [將 AWS 成員帳戶從 遷移 AWS Organizations 至 AWS Control Tower](migrate-an-aws-member-account-from-aws-organizations-to-aws-control-tower.md)
+ [使用來自 Precisely 的 Connect 將 VSAM 檔案遷移和複寫至 Amazon RDS 或 Amazon MSK](migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.md)
+ [使用 AWS DMS 從 SAP ASE 遷移至 Amazon RDS for SQL Server](migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms.md)
+ [將 Oracle 外部資料表遷移至 Amazon Aurora PostgreSQL 相容](migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible.md)
+ [使用 現代化 CardDemo 大型主機應用程式 AWS Transform](modernize-carddemo-mainframe-app.md)
+ [使用 和 Terraform 現代化 AWS Transform 和部署大型主機應用程式](modernize-mainframe-app-transform-terraform.md)
+ [使用 Rocket Enterprise Server 和 LRS VPSX/MFI AWS 在 上現代化大型主機批次列印工作負載](modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.md)
+ [使用 Micro Focus Enterprise Server 和 LRS VPSX/MFI 將 AWS 上的大型主機線上列印工作負載現代化](modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.md)
+ [AWS 使用 Rocket Enterprise Server 和 LRS PageCenterX 在 上現代化大型主機輸出管理](modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.md)
+ [使用 Transfer 系列將大型主機檔案直接移至 Amazon S3](move-mainframe-files-directly-to-amazon-s3-using-transfer-family.md)
+ [使用 AWS CDK 和 GitHub Actions 工作流程最佳化多帳戶無伺服器部署](optimize-multi-account-serverless-deployments.md)
+ [最佳化 AWS Blu Age 現代化應用程式的效能](optimize-performance-aws-blu-age-modernized-application.md)
+ [使用 IaC 原則自動化 Amazon Aurora 全域資料庫的藍/綠部署](p-automate-blue-green-deployments-aurora-global-databases-iac.md)
+ [使用 Precisely Connect 將大型主機資料庫複寫至 AWS](replicate-mainframe-databases-to-aws-by-using-precisely-connect.md)
+ [使用 Amazon ECS Anywhere 在 Amazon WorkSpaces 上執行 Amazon ECS 任務 Amazon ECS Anywhere](run-amazon-ecs-tasks-on-amazon-workspaces-with-amazon-ecs-anywhere.md)
+ [將遙測資料從 AWS Lambda 傳送至 OpenSearch，以進行即時分析和視覺化](send-telemetry-data-from-lambda-to-opensearch-for-analytics-visualization.md)
+ [在多區域、多帳戶組織中設定 CloudFormation 偏離偵測](set-up-aws-cloudformation-drift-detection-in-a-multi-region-multi-account-organization.md)
+ [使用 AWS Lambda 在六邊形架構中建構 Python 專案](structure-a-python-project-in-hexagonal-architecture-using-aws-lambda.md)
+ [使用 LocalStack 和 Terraform Tests 測試 AWS 基礎設施](test-aws-infra-localstack-terraform.md)
+ [使用 AWS Transform 自訂將 Easytrieve 轉換為現代語言](transform-easytrieve-modern-languages.md)
+ [從 ENSA1 升級 SAP Pacemaker 叢集到 ENSA2](upgrade-sap-pacemaker-clusters-from-ensa1-to-ensa2.md)
+ [使用 Amazon Q Developer 作為編碼助理，以提高您的生產力](use-q-developer-as-coding-assistant-to-increase-productivity.md)
+ [在本機驗證帳戶工廠的 Terraform (AFT) 程式碼](validate-account-factory-for-terraform-aft-code-locally.md)

# 大型主機
<a name="mainframe-pattern-list"></a>

**Topics**
+ [安裝 以 AWS 服務 從 IBM z/OS 存取 AWS CLI](access-aws-services-from-ibm-z-os-by-installing-aws-cli.md)
+ [使用 BMC AMI Cloud Data 將大型主機資料備份並封存至 Amazon S3](back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.md)
+ [使用 AWS Mainframe Modernization 和 建置 COBOL Db2 程式 AWS CodeBuild](build-cobol-db2-programs-mainframe-modernization-codebuild.md)
+ [使用 Amazon EC2 Auto Scaling 和 Systems Manager 建置 Micro Focus Enterprise Server PAC](build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager.md)
+ [在 AWS 雲端中建置進階大型主機檔案檢視器](build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.md)
+ [容器化已由 Blu Age 現代化的大型主機工作負載](containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.md)
+ [使用 Python 將 EBCDIC 資料轉換為 AWS 上的 ASCII](convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.md)
+ [使用 Amazon S3 將大型主機檔案從 EBCDIC 格式轉換為字元分隔 ASCII 格式 AWS Lambda](convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda.md)
+ [使用 Micro Focus 轉換具有複雜記錄配置的大型主機資料檔案](convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.md)
+ [使用 Terraform 部署容器化 Blu Age 應用程式的環境](deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform.md)
+ [使用 Quick Sight 中的 AWS Mainframe Modernization 和 Amazon Q 產生 Db2 z/OS 資料洞見](generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.md)
+ [在 Quick Sight 中使用 AWS Mainframe Modernization 和 Amazon Q 產生資料洞見](generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.md)
+ [在 AWS Blu Age 現代化大型主機應用程式中實作 Microsoft Entra ID 型身分驗證](implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application.md)
+ [將stonebranch 通用控制器與 AWS Mainframe Modernization 整合](integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.md)
+ [使用來自 Precisely 的 Connect 將 VSAM 檔案遷移和複寫至 Amazon RDS 或 Amazon MSK](migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.md)
+ [使用 現代化 CardDemo 大型主機應用程式 AWS Transform](modernize-carddemo-mainframe-app.md)
+ [使用 和 Terraform 現代化 AWS Transform 和部署大型主機應用程式](modernize-mainframe-app-transform-terraform.md)
+ [AWS 使用 Rocket Enterprise Server 和 LRS PageCenterX 在 上現代化大型主機輸出管理](modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.md)
+ [使用 Rocket Enterprise Server 和 LRS VPSX/MFI AWS 在 上現代化大型主機批次列印工作負載](modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.md)
+ [大型主機現代化：DevOps on AWS with Rocket Software Enterprise Suite](mainframe-modernization-devops-on-aws-with-micro-focus.md)
+ [使用 Micro Focus Enterprise Server 和 LRS VPSX/MFI 將 AWS 上的大型主機線上列印工作負載現代化](modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.md)
+ [使用 Transfer 系列將大型主機檔案直接移至 Amazon S3](move-mainframe-files-directly-to-amazon-s3-using-transfer-family.md)
+ [最佳化 AWS Blu Age 現代化應用程式的效能](optimize-performance-aws-blu-age-modernized-application.md)
+ [使用信任的內容來保護和簡化 AWS 上 Db2 聯合資料庫中的使用者存取](secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts.md)
+ [以 CSV 檔案將大規模 Db2 z/OS 資料傳輸至 Amazon S3](transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.md)
+ [使用 AWS Transform 自訂將 Easytrieve 轉換為現代語言](transform-easytrieve-modern-languages.md)
+ [更多模式](mainframe-more-patterns-pattern-list.md)

# 安裝 以 AWS 服務 從 IBM z/OS 存取 AWS CLI
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli"></a>

*Souma Ghosh、Paulo Vitor Pereira 和 Phil de Valence，Amazon Web Services*

## 總結
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-summary"></a>

[AWS Command Line Interface (AWS CLI)](https://aws.amazon.com/cli/) 是一種開放原始碼工具，可透過在命令列 Shell 中使用命令來管理多個 AWS 服務。透過最少的組態，您可以從命令列工作階段執行命令，例如命令提示字元、終端機和 bash shell，以實作相當於瀏覽器型提供的功能 AWS 管理主控台。

API 和 AWS 管理主控台 提供 中所有 AWS 基礎設施即服務 (IaaS) 管理、管理和存取函數 AWS AWS CLI。您可以在 IBM z/OS 大型主機 AWS CLI 上安裝 ，以 AWS 服務 從 z/OS 直接存取、管理和與 互動。 AWS CLI 可讓使用者和應用程式執行各種任務，例如：
+ 在 z/OS 和 Amazon Simple Storage Service (Amazon S3) 物件儲存體之間傳輸檔案或資料集，並檢視儲存貯體的內容
+ 啟動和停止不同的 AWS 資源；例如，在 AWS Mainframe Modernization 環境中啟動批次任務
+ 呼叫 AWS Lambda 函數以實作常見的商業邏輯
+ 與人工智慧和機器學習 (AI/ML) 和分析服務整合

此模式說明如何在 z/OS AWS CLI 上安裝、設定和使用 。您可以全域安裝，以便所有 z/OS 使用者或在使用者層級使用。模式也詳細說明如何在來自 z/OS Unix System Services (USS) 的互動式命令列工作階段 AWS CLI 中使用 ，或用作批次任務。

## 先決條件和限制
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-prereqs"></a>

**先決條件**
+ **從 z/OS 到 的網路通訊 AWS**

  根據預設， AWS 服務 會在 TCP 連接埠 443 上使用 HTTPS 將請求 AWS CLI 傳送至 。若要 AWS CLI 成功使用 ，您必須能夠在 TCP 連接埠 443 上進行傳出連線。您可以使用下列任何 z/OS USS 命令 （其中一些可能未安裝在您的環境中） 來測試從 z/OS 到 的網路連線 AWS：

  ```
  ping amazonaws.com
  dig amazonaws.com
  traceroute amazonaws.com
  curl -k https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-welcome.html
  ```
+ **AWS 登入資料**

  為了與來自 z/OS AWS 雲端 的服務通訊， AWS CLI 要求您設定一些具有存取目標權限的登入資料 AWS 帳戶。對於 的程式設計命令 AWS，您可以使用存取金鑰，其中包含存取金鑰 ID 和私密存取金鑰。如果您沒有存取金鑰，可以從 AWS 管理主控台建立。最佳實務是，除非 AWS 帳戶 需要根使用者，否則請勿將根使用者的存取金鑰用於任何任務。反之，[請建立新的管理員 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-set-up.html#create-an-admin)，並[準備最低權限的許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-set-up.html#LeastPrivilege)** **，以使用存取金鑰設定使用者。建立使用者之後，您可以為此使用者[建立存取金鑰 ID 和私密存取金鑰](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html)
+ **適用於 z/OS 的 IBM Python**

   AWS CLI 需要 Python 3.8 或更新版本。IBM 已使用適用於 z/OS [的 IBM Open Enterprise Python 在 z/OS ](https://www.ibm.com/products/open-enterprise-python-zos)上執行 Python。IBM Open Enterprise Python 可透過 Shopz SMP/E 免費取得，您也可以從 [IBM 網站](https://www.ibm.com/account/reg/signup?formid=urx-49465)下載 PAX 檔案。如需說明，請參閱適用於 z/OS 的 IBM Open Enterprise Python 安裝[和組態文件](https://www.ibm.com/docs/en/python-zos)。

**限制**
+ 此模式中提供的安裝指示**AWS CLI 僅適用於版本 1**。的最新版本 AWS CLI 是第 2 版。不過，此模式使用較舊的版本，因為第 2 版的安裝方法不同，而第 2 版可用的二進位可執行檔與 z/OS 系統不相容。

**產品版本**
+ AWS CLI 第 1 版
+ Python 3.8 或更高版本

## Architecture
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-architecture"></a>

**技術堆疊**
+ 執行 z/OS 的大型主機
+ 大型主機 z/OS UNIX 系統服務 (USS)
+ Mainframe Open MVS (OMVS) – z/OS UNIX shell 環境命令界面
+ 大型主機磁碟，例如直接存取儲存裝置 (DASD)
+ AWS CLI

**目標架構**

下圖顯示 IBM z/OS 上的 AWS CLI 部署。您可以從 AWS CLI 互動式使用者工作階段叫用 ，例如 SSH 和 telnet 工作階段。您也可以使用任務控制語言 (JCL) 或任何可呼叫 z/OS Unix shell 命令的程式，從批次任務叫用它。

![\[存取 AWS 服務的 IBM z/OS 大型主機上的 AWS CLI。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4e3188d8-287f-4ced-8c29-80a01cbbdf50/images/c3883500-bd00-4c56-982a-26d5e0b8b093.png)


會透過 TCP/IP 網路與 AWS 服務 端點 AWS CLI 通訊。這種網路連線可以透過網際網路，或透過從客戶資料中心到 AWS 雲端 資料中心的私有 AWS Direct Connect 連線進行。通訊會使用 AWS 登入資料進行身分驗證並加密。

**自動化和擴展**

您可以使用 探索 的功能， AWS 服務 AWS CLI 並開發 USS shell 指令碼以從 z/OS 管理您的 AWS 資源。您也可以從 z/OS 批次環境執行 AWS CLI 命令和 shell 指令碼，也可以透過與大型主機排程器整合來自動化批次任務，以在特定排程執行。 AWS CLI 命令或指令碼可以在參數 (PARMs) 和程序 (PROCs) 內編碼，並且可以透過使用不同參數從不同批次任務呼叫 PARM 或 PROC 的標準方法進行擴展。

## 工具
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-tools"></a>
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您 AWS 服務 透過命令列 shell 中的命令與 互動。

## 最佳實務
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-best-practices"></a>
+ 基於安全考量，請將存取許可限制在存放 AWS 存取金鑰詳細資訊的 USS 目錄。僅允許存取使用 的使用者或程式 AWS CLI。
+ 請勿將 AWS 帳戶 根使用者存取金鑰用於任何任務。反之，請為自己[建立新的管理員 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-set-up.html#create-an-admin)，並使用存取金鑰進行設定。


| 
| 
| IAM 使用者具有存在安全風險的長期登入資料。為了協助降低此風險，建議您只為這些使用者提供執行任務所需的許可，並在不再需要這些使用者時將其移除。 | 
| --- |

## 史詩
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-epics"></a>

### 在 z/OS USS 上安裝 AWS CLI 版本 1
<a name="install-cli-version-1-on-z-os-uss"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 Python 3.8 或更新版本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 大型主機 z/OS 管理員 | 
| 設定 USS 環境變數。 | 將環境變數新增至設定檔。您可以將這些項目新增至個別使用者 (`cliuser`) 的 `/u/cliuser/.profile` 檔案，或新增至所有使用者的 `/etc/profile` 檔案。此模式假設 Python 已安裝在 `/u/awscli/python`目錄中。如果您的安裝目錄不同，請相應地更新程式碼。<pre># Python configuration<br />export BPXKAUTOCVT='ON'<br />export CEERUNOPTS='FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)'<br />export TAGREDIR_ERR=txt<br />export TAGREDIR_IN=txt<br />export TAGREDIR_OUT=txt<br /><br /># AWS CLI configuration<br />export PATH=/u/cliuser/python/bin:$PATH<br />export PYTHONPATH=/u/cliuser/python:$PYTHONPATH</pre> | 大型主機 z/OS 管理員 | 
| 測試 Python 安裝。 | 執行 **python** 命令：<pre>python --version</pre>輸出應確認您已正確安裝 Python 3.8 或更新版本。 | 大型主機 z/OS 管理員 | 
| 驗證或安裝 **pip**。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 大型主機 z/OS 管理員 | 
| 安裝 AWS CLI 版本 1。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 大型主機 z/OS 管理員 | 

### 從 z/OS 設定 AWS CLI 存取權
<a name="configure-cli-access-from-z-os"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS 存取金鑰、預設區域和輸出。 | [AWS CLI 文件](https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html)說明設定 AWS 存取權的不同選項。您可以根據組織的標準來選擇組態。此範例使用短期憑證組態。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | AWS 管理員、大型主機 z/OS 管理員、大型主機 z/OS 開發人員 | 
| 測試 AWS CLI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 大型主機 z/OS 管理員、大型主機 z/OS 開發人員 | 

### 選項 1 ‒ 從 USS 工作階段以互動方式將資料從 USS 傳輸到 Amazon S3
<a name="option-1-transfer-data-from-uss-to-s3-interactively-from-a-uss-session"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載並傳輸範例 CSV 檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 應用程式開發人員、大型主機 z/OS 開發人員 | 
| 建立 S3 儲存貯體並上傳 CSV 檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 應用程式開發人員、大型主機 z/OS 開發人員 | 
| 檢視 S3 儲存貯體和上傳的檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html)如需上傳物件的詳細資訊，請參閱 [Amazon S3 文件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/GetStartedWithS3.html)中的 Amazon S3 入門。 | 一般 AWS | 
| 在 Amazon Athena 資料表上執行 SQL 查詢。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html)SQL 查詢的輸出會顯示 CSV 檔案的內容。 | General AWS，應用程式開發人員 | 

### 選項 2 ‒ 使用批次 JCL 將資料從 USS 傳輸到 Amazon S3
<a name="option-2-transfer-data-from-uss-to-s3-by-using-batch-jcl"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 上傳範例檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 大型主機 z/OS 開發人員 | 
| 建立批次 JCL。 | 將批次 JCL 編碼如下，以建立目的地 S3 儲存貯體、上傳資料集，並列出儲存貯體內容。請務必將目錄名稱、檔案名稱和儲存貯體名稱取代為您自己的值。<pre>//AWSCLICP JOB ACTINFO1,'IBMUSER',CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1), <br />// NOTIFY=&SYSUID,TIME=1440 <br />//*---------------------------------------------------------<br />//* Sample job for AWS CLI <br />//*--------------------------------------------------------- <br />//USSCMD EXEC PGM=BPXBATCH<br />//STDERR  DD SYSOUT=*<br />//STDOUT  DD SYSOUT=*<br />//STDENV  DD *<br /> export PATH=/u/cliuser/python/bin:$PATH<br />//STDPARM DD *<br />SH<br /> export _BPXK_AUTOCVT=ON;<br /> aws s3 mb s3://DOC-EXAMPLE-BUCKET2;<br /> cp "//'USER.DATA.FIXED'" /tmp/tmpfile;<br /> aws s3 cp /tmp/tmpfile s3://DOC-EXAMPLE-BUCKET2/USER.DATA.FIXED; <br /> rm /tmp/tmpfile;<br /> aws s3 ls s3://DOC-EXAMPLE-BUCKET2;<br />/*</pre> | 大型主機 z/OS 開發人員 | 
| 提交批次 JCL 任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 大型主機 z/OS 開發人員 | 
| 檢視上傳至 S3 儲存貯體的資料集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-aws-services-from-ibm-z-os-by-installing-aws-cli.html) | 一般 AWS | 

## 相關資源
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-resources"></a>
+ [AWS CLI 第 1 版文件](https://docs.aws.amazon.com/cli/v1/userguide/cli-chap-welcome.html)
+ [AWS Mainframe Modernization CLI 命令參考](https://docs.aws.amazon.com/cli/latest/reference/m2/)
+ [AWS Mainframe Modernization](https://aws.amazon.com/mainframe-modernization/)

## 其他資訊
<a name="access-aws-services-from-ibm-z-os-by-installing-aws-cli-additional"></a>

**ISPF 選項 3.4 中的 USER.DATA.FIXED （資料集清單公用程式）**

![\[以 z/OS 檢視資料集的內容。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4e3188d8-287f-4ced-8c29-80a01cbbdf50/images/96c25145-3d4d-4007-99f6-5eeb9e88642d.png)


**已提交批次任務的 SYSOUT**

![\[任務日誌的標準輸出。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4e3188d8-287f-4ced-8c29-80a01cbbdf50/images/03fffbd2-7d2b-43b2-bf14-736b3d150e38.png)


## 附件
<a name="attachments-4e3188d8-287f-4ced-8c29-80a01cbbdf50"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/4e3188d8-287f-4ced-8c29-80a01cbbdf50/attachments/attachment.zip)

# 使用 BMC AMI Cloud Data 將大型主機資料備份並封存至 Amazon S3
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data"></a>

*Santosh Kumar Singh、Gilberto Biondo 和 Maggie Li，Amazon Web Services*

*Mikhael Liberman，Model9 大型主機軟體*

## 總結
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data-summary"></a>

此模式示範如何將大型主機資料直接備份和封存至 Amazon Simple Storage Service (Amazon S3)，然後使用 BMC AMI Cloud Data （先前稱為 Model9 Manager) 將資料回收並還原至大型主機。如果您正在尋找一種方法將備份和封存解決方案現代化為大型主機現代化專案的一部分，或滿足合規要求，此模式有助於實現這些目標。

一般而言，在大型主機上執行核心業務應用程式的組織會使用虛擬磁帶庫 (VTL) 來備份資料存放區，例如檔案和日誌。此方法可能很昂貴，因為它會耗用計費 MIPS，而且無法存取存放在大型主機外部磁帶上的資料。若要避免這些問題，您可以使用 BMC AMI Cloud Data，以快速且經濟實惠的方式將操作和歷史大型主機資料直接傳輸至 Amazon S3。您可以使用 BMC AMI Cloud Data 透過 TCP/IP 備份和封存資料至 ， AWS 同時利用 IBM z 整合式資訊處理器 (zIIP) 引擎來降低成本、平行處理和傳輸時間。

## 先決條件和限制
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 具有有效授權金鑰的 BMC AMI 雲端資料
+ 大型主機與 AWS 之間的 TCP/IP 連線
+ 用於讀取/寫入存取 S3 儲存貯體的 AWS Identity and Access Management (IAM) 角色
+ 具備大型主機安全產品 (RACF) 存取權以執行 BMC AMI Cloud 程序
+ BMC AMI Cloud z/OS 代理程式 (Java 版本 8 64 位元 SR5 FP16 或更新版本），具有可用的網路連接埠、允許存取 S3 儲存貯體的防火牆規則，以及專用 z/FS 檔案系統
+ BMC AMI 雲端管理伺服器[滿足的需求](https://docs.bmc.com/docs/cdacv27/management-server-requirements-1245343255.html)

**限制**
+ BMC AMI Cloud Data 將其操作資料存放在 PostgreSQL 資料庫中，該資料庫中以 Docker 容器的形式在與管理伺服器相同的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行。Amazon Relational Database Service (Amazon RDS) 目前不支援做為 BMC AMI Cloud Data 的後端。如需最新產品更新的詳細資訊，請參閱《BMC 文件》中的[最新消息？](https://docs.bmc.com/docs/cdacv27/what-s-new-1245343246.html)。
+ 此模式只會備份和封存 z/OS 大型主機資料。BMC AMI Cloud Data 只會備份和封存大型主機檔案。
+ 此模式不會將資料轉換為標準開放格式，例如 JSON 或 CSV。使用額外的轉換服務，例如 [BMC AMI Cloud Analytics](https://www.bmc.com/it-solutions/bmc-ami-cloud-analytics.html) （先前稱為 Model9 Gravity)，將資料轉換為標準開放格式。雲端原生應用程式和資料分析工具可以在資料寫入雲端後存取資料。

**產品版本**
+ BMC AMI Cloud Data 2.x 版

## Architecture
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data-architecture"></a>

**來源技術堆疊**
+ 執行 z/OS 的大型主機
+ 大型主機檔案，例如資料集和 z/OS UNIX System Services (USS) 檔案
+ 大型主機磁碟，例如直接存取儲存裝置 (DASD)
+ 大型主機磁帶 （虛擬或實體磁帶庫）

**目標技術堆疊**
+ Amazon S3
+ 虛擬私有雲端 (VPC) 中的 Amazon EC2 執行個體
+ AWS Direct Connect
+ Amazon Elastic File System (Amazon EFS)

**目標架構**

下圖顯示參考架構，其中大型主機上的 BMC AMI Cloud Data 軟體代理程式會驅動將資料存放在 Amazon S3 中的舊版資料備份和封存程序。

![\[大型主機上的 BMC AMI Cloud Data 軟體代理程式可驅動舊版資料備份和封存程序\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bde3b029-184e-4eb0-933b-f8caf6cc40ab/images/a24cd6c1-b131-49ea-8238-f3aea5ab8134.png)


該圖顯示以下工作流程：

1. BMC AMI Cloud Data 軟體代理程式會在大型主機邏輯分割區 (LPARs) 上執行。軟體代理程式會透過 TCP/IP 從 DASD 或磁帶直接讀取和寫入大型主機資料至 Amazon S3。

1. AWS Direct Connect 設定內部部署網路與 之間的實體隔離連線 AWS。為了增強安全性，請在 上執行site-to-site Direct Connect 以加密傳輸中的資料。

1. S3 儲存貯體會將大型主機檔案儲存為物件儲存資料，BMC AMI Cloud Data 代理程式會直接與 S3 儲存貯體通訊。憑證用於代理程式和 Amazon S3 之間所有通訊的 HTTPS 加密。Amazon S3 資料加密用於加密和保護靜態資料。

1. BMC AMI 雲端資料管理伺服器會在 EC2 執行個體上以 Docker 容器的形式執行。執行個體會與在大型主機 LPARs代理程式通訊。 S3 

1. Amazon EFS 同時掛載在主動和被動 EC2 執行個體上，以共用網路檔案系統 (NFS) 儲存。這是為了確保與管理伺服器上建立的政策相關的中繼資料在容錯移轉時不會遺失。如果作用中伺服器發生容錯移轉，則可以存取被動伺服器，而不會遺失任何資料。如果被動伺服器失敗，則可以存取作用中伺服器，而不會遺失任何資料。

## 工具
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 中提供可擴展的運算容量 AWS 雲端。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Elastic File System (Amazon EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) 可協助您在 中建立和設定共用檔案系統 AWS 雲端。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取幾乎任何數量的資料。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html)會透過標準乙太網路光纖纜線將您的內部網路連結至某個 AWS Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的虛擬介面，同時略過網路路徑中的網際網路服務供應商。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。

**BMC 工具**
+ [BMC AMI 雲端管理伺服器](https://docs.bmc.com/docs/cdacv27/bmc-ami-cloud-overview-1245343249.html)是一種 GUI 應用程式，在 Amazon EC2 的 Amazon Linux Amazon Machine Image (AMI) 上執行為 Docker 容器。管理伺服器提供管理 BMC AMI Cloud 活動的功能，例如報告、建立和管理政策、執行封存，以及執行備份、召回和還原。
+ [BMC AMI Cloud 代理程式](https://docs.bmc.com/docs/cdacv27/bmc-ami-cloud-overview-1245343249.html)會在內部部署大型主機 LPAR 上執行，該 LPAR 會使用 TCP/IP 直接讀取和寫入檔案至物件儲存體。已啟動的任務會在大型主機 LPAR 上執行，並負責讀取和寫入往返 Amazon S3 的備份和封存資料。
+ [BMC AMI Cloud Mainframe Command Line Interface (M9CLI)](https://docs.bmc.com/docs/cdacv27/command-line-interface-cli-reference-1245343519.html) 為您提供一組命令，讓您直接從 TSO/E 或批次操作中執行 BMC AMI Cloud 動作，而不需要依賴管理伺服器。

## 史詩
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data-epics"></a>

### 建立 S3 儲存貯體和 IAM 政策
<a name="create-an-s3-bucket-and-iam-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | [建立 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體，以存放您要從大型主機環境備份和封存的檔案和磁碟區。 | 一般 AWS | 
| 建立 IAM 政策。 | 所有 BMC AMI Cloud 管理伺服器和代理程式都需要存取您在上一個步驟中建立的 S3 儲存貯體。若要授予必要的存取權，請建立下列 IAM 政策：<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Sid": "Listfolder",<br />            "Action": [<br />                "s3:ListBucket",<br />                "s3:GetBucketLocation",<br />                "s3:ListBucketVersions"<br />            ],<br />            "Effect": "Allow",<br />            "Resource": [<br />                "arn:aws:s3:::<Bucket Name>"<br />            ]<br />        },<br />        {<br />            "Sid": "Objectaccess",<br />            "Effect": "Allow",<br />            "Action": [<br />                "s3:PutObject",<br />                "s3:GetObjectAcl",<br />                "s3:GetObject",<br />                "s3:DeleteObjectVersion",<br />                "s3:DeleteObject",<br />                "s3:PutObjectAcl",<br />                "s3:GetObjectVersion"<br />            ],<br />            "Resource": [<br />                "arn:aws:s3:::<Bucket Name>/*"<br />            ]<br />        }<br />    ]<br />}</pre> | 一般 AWS | 

### 取得 BMC AMI Cloud 軟體授權並下載軟體
<a name="get-the-bmc-ami-cloud-software-license-and-download-the-software"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得 BMC AMI Cloud 軟體授權。 | 若要取得軟體授權金鑰，請聯絡 [BMC AMI 雲端團隊](https://www.bmc.com/it-solutions/bmc-ami-cloud.html?vd=model9-io)。產生授權需要 z/OS `D M=CPU`命令的輸出。 | 建置潛在客戶 | 
| 下載 BMC AMI Cloud 軟體和授權金鑰。 | 依照 [BMC 文件](https://docs.bmc.com/docs/cdacv27/preparing-to-install-the-bmc-ami-cloud-agent-1245343285.html)的指示取得安裝檔案和授權金鑰。 | 大型主機基礎設施管理員 | 

### 在大型主機上安裝 BMC AMI Cloud 軟體代理程式
<a name="install-the-bmc-ami-cloud-software-agent-on-the-mainframe"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 BMC AMI Cloud 軟體代理程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html) | 大型主機基礎設施管理員 | 

### 在 EC2 執行個體上設定 BMC AMI 雲端管理伺服器
<a name="set-up-a-bmc-ami-cloud-management-server-on-an-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon EC2 Linux 2 執行個體。 | 依照 Amazon EC2 文件中的[步驟 1：啟動執行個體中的指示，在不同可用區域中啟動兩個 Amazon EC2 Linux 2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/EC2_GetStarted.html#ec2-launch-instance)。 Amazon EC2 執行個體必須符合下列建議的硬體和軟體需求：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html)如需詳細資訊，請參閱 [BMC 文件](https://docs.bmc.com/docs/cdacv27/preparing-to-install-the-management-server-on-linux-1245343268.html)。 | 雲端架構師、雲端管理員 | 
| 建立 Amazon EFS 檔案系統。 | 遵循 Amazon EFS 文件中[步驟 1：建立 Amazon EFS 檔案系統的指示來建立 Amazon EFS 檔案系統](https://docs.aws.amazon.com/efs/latest/ug/gs-step-two-create-efs-resources.html)。 EFS 建立檔案系統時，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html) | 雲端管理員、雲端架構師 | 
| 安裝 Docker 並設定管理伺服器。 | **連線至 EC2 執行個體：**遵循 Amazon EC2 文件中來自[連接至 Linux 執行個體的指示，連線至 EC2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html)。 Amazon EC2 **設定 EC2 執行個體：**對於每個 EC2 執行個體，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html) | 雲端架構師、雲端管理員 | 
| 安裝管理伺服器軟體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html)若要疑難排解問題，請前往存放在 `/data/model9/logs/`****資料夾中的日誌。如需詳細資訊，請參閱 [BMC 文件](https://docs.bmc.com/docs/cdacv27/performing-the-management-server-installation-on-linux-1245343272.html)。 | 雲端架構師、雲端管理員 | 

### 新增代理程式，並在 BMC AMI 雲端管理伺服器上定義備份或封存政策
<a name="add-an-agent-and-define-a-backup-or-archive-policy-on-the-bmc-ami-cloud-management-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 新增客服人員。 | 新增客服人員之前，請確認下列事項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html)您必須先在管理伺服器上建立 代理程式，才能定義任何備份和封存政策。若要建立代理程式，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html)建立代理程式後，您會在資料表中出現的新視窗中看到物件儲存體和大型主機代理程式的**連線**狀態。 | 大型主機儲存管理員或開發人員 | 
| 建立備份或封存政策。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html) | 大型主機儲存管理員或開發人員 | 

### 從管理伺服器執行備份或封存政策
<a name="run-the-backup-or-archive-policy-from-the-management-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行備份或封存政策。 | 手動或自動 （根據排程） 執行您先前從管理伺服器建立的資料備份或封存政策。若要手動執行政策：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html) | 大型主機儲存管理員或開發人員 | 
| 還原備份或封存政策。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html) | 大型主機儲存管理員或開發人員 | 

### 從大型主機執行備份或封存政策
<a name="run-the-backup-or-archive-policy-from-the-mainframe"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 M9CLI 執行備份或封存政策。 | 使用 M9CLI 從 TSO/E、REXX 或透過 JCLs 執行備份和還原程序，而無需在 BMC AMI 雲端管理伺服器上設定規則。**使用 TSO/E：**如果您使用 TSO/E，請確定 `M9CLI REXX` 與 串連`TSO`。若要透過 TSO/E 備份資料集，請使用 `TSO M9CLI BACKDSN <DSNAME>`命令。如需 M9CLI 命令的詳細資訊，請參閱《BMC 文件》中的 [CLI 參考](https://docs.bmc.com/docs/cdacv27/command-line-interface-cli-reference-1245343519.html)。**使用 JCLs：**若要使用 JCLs 執行備份和封存政策，請執行 `M9CLI`命令。**使用批次操作：**下列範例示範如何透過批次執行 `M9CLI`命令來封存資料集：<pre>//JOBNAME JOB …<br />//M9CLI EXEC PGM=IKJEFT01<br />//STEPLIB DD DISP=SHR,DSN=<MODEL9 LOADLIB><br />//SYSEXEC DD DISP=SHR,DSN=<MODEL9 EXEC LIB><br />//SYSTSPRT DD SYSOUT=*<br />//SYSPRINT DD SYSOUT=*<br />//SYSTSIN DD TSO M9CLI ARCHIVE <br /> M9CLI ARCHIVE <DSNNAME OR DSN PATTERN>   <br />/</pre> | 大型主機儲存管理員或開發人員 | 
| 在 JCL 批次中執行備份或封存政策。 | BMC AMI Cloud 提供名為 **M9SAPIJ** 的範例 JCL 常式。您可以自訂 **M9SAPIJ**，以使用 JCL 在管理伺服器上建立的特定政策。此任務也可以是批次排程器的一部分，用於自動執行備份和還原程序。批次任務預期下列必要值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data.html)您也可以遵循範例任務的指示來變更其他值。 | 大型主機儲存管理員或開發人員 | 

## 相關資源
<a name="back-up-and-archive-mainframe-data-to-amazon-s3-using-bmc-ami-cloud-data-resources"></a>
+ [Mainframe Modernization with AWS](https://aws.amazon.com/mainframe/) (AWS 文件）
+ [適用於大型主機的雲端備份如何使用 Model9 和 AWS 降低成本](https://aws.amazon.com/blogs/apn/how-cloud-backup-for-mainframes-cuts-costs-with-model9-and-aws/) (AWS 合作夥伴網路部落格）
+ [如何使用 Model9 在 AWS 上啟用大型主機資料分析](https://aws.amazon.com/blogs/apn/how-to-enable-mainframe-data-analytics-on-aws-using-model9/) (AWS 合作夥伴網路部落格）
+ [AWS Direct Connect 彈性建議 ](https://aws.amazon.com/directconnect/resiliency-recommendation/?nc=sn&loc=4&dn=2)(AWS 文件）
+ [BMC AMI Cloud 文件](https://docs.bmc.com/docs/cdacv27/getting-started-1245343248.html) (BMC 網站）

# 使用 AWS Mainframe Modernization 和 建置 COBOL Db2 程式 AWS CodeBuild
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild"></a>

*Luis Gustavo Dantas 和 Eduardo Zimelewicz，Amazon Web Services*

## 總結
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-summary"></a>

**注意**  
AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

此模式說明如何建立簡單的 AWS CodeBuild 專案，以使用 Replatform AWS Mainframe Modernization 工具預先編譯和繫結 COBOL Db2 程式。這可在 Replatform AWS Mainframe Modernization 執行時間環境中部署和執行這些程式。

COBOL 是一種業務導向的程式設計語言，由於其可靠性和可讀性，為許多關鍵應用程式提供支援。IBM Db2 是關聯式資料庫管理系統，可有效管理大量資料，並透過 SQL 與 COBOL 程式整合。COBOL 和 Db2 共同構成金融和政府等產業中關鍵任務操作的骨幹，儘管有較新的技術出現。

從大型主機環境遷移 COBOL 和 Db2 元件到其他平台會導致平台相容性、整合複雜性、資料遷移和效能最佳化等挑戰。移動這些關鍵元件需要仔細的規劃、技術專業知識和資源，以確保順利遷移，同時保持可靠性和功能。

 AWS Mainframe Modernization 此服務提供工具和資源，以重建要在 AWS 基礎設施上執行的大型主機應用程式和資料庫，例如 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體。這涉及在不重大程式碼變更的情況下將大型主機工作負載移至雲端。

Db2 預先編譯和繫結程序對於最佳化資料庫應用程式的效能和可靠性至關重要。預先編譯會將內嵌 SQL 陳述式轉換為可執行程式碼，從而降低執行時間負荷並提高效率。繫結程序會將預先編譯的程式碼與資料庫結構連結，促進存取路徑和查詢最佳化。此程序可確保資料完整性、改善應用程式回應能力，並防止安全漏洞。正確預先編譯和繫結的應用程式可將資源消耗降至最低、增強可擴展性，並降低 SQL Injection 攻擊的風險。

## 先決條件和限制
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-prereqs"></a>

**先決條件 **
+  AWS 帳戶 和管理層級主控台存取。
+ IBM Db2 資料庫系統，例如 z/OS 的 IBM Db2 或 Linux、Unix 和 Windows (LUW) 的 Db2。
+ IBM Data Server Client 軟體，可從 [IBM 網站](https://www.ibm.com/support/pages/download-initial-version-115-clients-and-drivers)下載。如需詳細資訊，請參閱 [IBM Data Server 用戶端和資料伺服器驅動程式類型](https://www.ibm.com/docs/en/db2/11.5?topic=overviews-data-server-clients)。
+ 要編譯和繫結的 COBOL Db2 程式。或者，此模式提供您可以使用的基本範例程式。
+ 上的虛擬私有雲端 (VPC) AWS 與私有網路。如需建立 VPC 的資訊，請參閱 [Amazon Virtual Private Cloud (Amazon VPC) 文件](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html)。
+ 來源控制儲存庫，例如 GitHub 或 GitLab。

**限制 **
+ 如需 AWS CodeBuild 配額，請參閱 [的配額 AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/limits.html)。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-architecture"></a>

**來源技術堆疊**

來源堆疊包括：
+ 使用 Db2 資料庫存放資料的 COBOL 程式
+ z/OS 前置編譯器的 IBM COBOL 編譯器和 Db2 
+ 大型主機設定的其他部分，例如檔案系統、交易管理員和多工緩衝處理

**目標技術堆疊**

此模式的方法適用於兩個選項：將資料從 z/OS 的 Db2 移至 LUW 的 Db2，或保留在 z/OS 的 Db2 上。目標架構包括：
+ 使用 Db2 資料庫存放資料的 COBOL 程式
+ AWS Mainframe Modernization Replatform 編譯工具
+ AWS CodeBuild 做為建置應用程式的基礎設施
+ 其他 AWS 雲端 資源，例如 Amazon Linux

**目標架構**

![\[在 AWS 上建置 COBOL Db2 程式的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5895fa34-f05b-4cc3-a59f-a596f9116c66/images/0dda414a-21a7-41d1-b86b-7ff3b1c6fbda.png)


此圖展示了以下要點：

1. 使用者將其程式碼上傳至來源控制儲存庫，例如 GitHub 或 GitLab。

1. AWS CodePipeline 會注意到變更，並從儲存庫取得程式碼。

1. CodePipeline 會啟動 AWS CodeBuild 並傳送程式碼。

1. CodeBuild 遵循`buildspec.yml`範本中的指示 ([在其他資訊](#build-cobol-db2-programs-mainframe-modernization-codebuild-additional)區段中提供），以：

   1. 從 Amazon Simple Storage Service (Amazon S3) 儲存貯體取得 IBM Data Server 用戶端。

   1. 安裝和設定 IBM Data Server 用戶端。

   1. 從 擷取 Db2 登入資料 AWS Secrets Manager。

   1. 連線至 Db2 伺服器。

   1. 預先編譯、編譯和繫結 COBOL 程式。

   1. 將成品儲存在 S3 儲存貯體中 AWS CodeDeploy 以供使用。

1. CodePipeline 啟動 CodeDeploy。

1. CodeDeploy 會協調其代理程式，這些代理程式已安裝在執行時間環境中。代理程式會從 Amazon S3 擷取應用程式，並根據 中的指示進行安裝`appspec.yml`。

為了保持建置簡單且專注於建置，此模式中的指示涵蓋步驟 1 到 4，但不包含 COBOL Db2 程式的部署。

**自動化和擴展**

為了簡化，此模式說明如何手動佈建資源。不過，有許多自動化選項可供使用 CloudFormation AWS Cloud Development Kit (AWS CDK)，例如， 和 HashiCorp Terraform，可自動化這些任務。如需詳細資訊，請參閱 [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)和 [AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/home.html) 文件。

## 工具
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-tools"></a>

**AWS 服務**
+ [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html) 是一種全受管建置服務，可協助您編譯原始程式碼、執行單元測試，並產生準備好部署的成品。
+ [AWS CodeDeploy](https://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html) 會自動部署到 Amazon EC2 或內部部署執行個體、 AWS Lambda 函數或 Amazon Elastic Container Service (Amazon ECS) 服務。
+ [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html) 可協助您快速建模和設定軟體版本的不同階段，並自動化持續發行軟體變更所需的步驟。
+ [AWS Mainframe Modernization](https://docs.aws.amazon.com/m2/latest/userguide/what-is-m2.html) 提供工具和資源，協助您規劃和實作從大型主機到 AWS 受管執行期環境的遷移和現代化。

**其他工具**
+ **Replatform 工具的 Amazon ECR AWS Mainframe Modernization 映像**。若要編譯 COBOL 應用程式，您需要使用包含 Replatform AWS Mainframe Modernization 工具的 Amazon Elastic Container Registry (Amazon ECR) 映像來啟動 CodeBuild：

  `673918848628.dkr.ecr.<your-region>.amazonaws.com/m2-enterprise-build-tools:9.0.7.R1`

  如需可用 ECR 映像的詳細資訊，請參閱*AWS Mainframe Modernization 《 使用者指南*》中的[教學](https://docs.aws.amazon.com/m2/latest/userguide/tutorial-build-mf.html)課程。
+ [IBM Data Server Client](https://www.ibm.com/docs/en/db2/11.5?topic=overviews-data-server-clients) 軟體對於在 CodeBuild 中預先編譯和繫結 COBOL Db2 程式至關重要。它充當 COBOL 編譯器和 Db2 之間的橋樑。

## 最佳實務
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-best-practices"></a>
+ 並非每個 COBOL 程式都依賴 Db2 作為其資料持久性層。確保用於存取 Db2 的編譯指令僅適用於專門設計用於與 Db2 互動的 COBOL 程式。實作邏輯來區分 COBOL Db2 程式和不使用 Db2 的 COBOL 程式。
+ 我們建議您避免編譯尚未修改的程式。實作程序來識別哪些程式需要編譯。

## 史詩
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-epics"></a>

### 建立雲端基礎設施
<a name="create-the-cloud-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體以託管 IBM Data Server 用戶端和管道成品。 | 您需要設定 S3 儲存貯體以 (a) 上傳 IBM Data Server 用戶端、(b) 從儲存庫存放程式碼，以及 (c) 存放建置程序的結果。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html)如需建立 S3 儲存貯體的方法，請參閱 [Amazon S3 文件。](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html) | 一般 AWS | 
| 將 IBM Data Server 用戶端上傳至 S3 儲存貯體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html) | 一般 AWS | 
| 為您的 Db2 登入資料建立 AWS Secrets Manager 秘密。 | 若要建立秘密以安全地存放您的 DB2 登入資料：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html)如需建立秘密的詳細資訊，請參閱 [Secrets Manager 文件](https://docs.aws.amazon.com/secretsmanager/latest/userguide/create_secret.html)。 | 一般 AWS | 
| 確認 Db2 可從 VPC 子網路存取。 | AWS CodeBuild 需要與 Db2 伺服器的連線，資料伺服器用戶端才能執行預先編譯和繫結操作。確定 CodeBuild 可以透過安全連線到達 Db2 伺服器。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html) | 網路管理員，一般 AWS | 

### 建立應用程式成品
<a name="create-the-application-artifacts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 COBOL Db2 資產。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html) | 應用程式開發人員 | 
| 建立 `buildspec.yml` 檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html) | AWS DevOps | 
| 將您的儲存庫連線至 CodePipeline。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html)在後續步驟中為 CodePipeline 建立 (IAM) 政策時，您將需要連線的 Amazon Resource Name AWS Identity and Access Management (ARN)。 | AWS DevOps | 

### 設定 許可
<a name="configure-permissions"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 CodeBuild 建立 IAM 政策。 | CodeBuild 專案需要存取一些資源，包括 Secrets Manager 和 Amazon S3。設定必要的許可：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html)如需建立 IAM 政策的詳細資訊，請參閱 [IAM 文件](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)。 | 一般 AWS | 
| 為 CodeBuild 建立 IAM 角色。 | 若要讓 CodeBuild 提供安全政策，您需要設定 IAM 角色。若要建立此角色：1. 在 [IAM 主控台](https://console.aws.amazon.com/iam)的導覽窗格中，選擇**角色**、**建立角色**。3. 對於**信任的實體類型**，請保留**AWS 服務**預設設定。4. 針對**使用案例**，選取 CodeBuild 服務，然後選擇**下一步**。4. 在可用的 IAM 政策清單中，找到您為 CodeBuild 建立的政策，然後選擇**下一步**將其連接至角色。5. 指定角色的名稱，然後選擇**建立角色**以儲存該角色，以供未來在 CodeBuild 中參考。如需為 建立 IAM 角色的詳細資訊 AWS 服務，請參閱[ IAM 文件](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)。 | 一般 AWS | 
| 建立 CodePipeline 的 IAM 政策。 |  AWS CodePipeline 管道需要存取一些資源，包括您的程式碼儲存庫和 Amazon S3。重複先前為 CodeBuild 提供的步驟，以建立 CodePipeline 的 IAM 政策 （在步驟 2 中，選擇 **CodePipeline** 而非 **CodeBuild**)。 | AWS DevOps | 
| 為 CodePipeline 建立 IAM 角色。 | 若要讓 CodePipeline 可以使用安全政策，您需要設定 IAM 角色。若要建立此角色：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html) | AWS DevOps | 

### 編譯並繫結 COBOL Db2 程式
<a name="compile-and-bind-the-cobol-db2-program"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 CodePipeline 管道和 CodeBuild 專案。 | 若要建立 CodePipeline 管道和 CodeBuild 專案，以編譯和繫結 COBOL Db2 程式：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-cobol-db2-programs-mainframe-modernization-codebuild.html) | AWS DevOps | 
| 檢閱輸出。 | 透過檢閱 CodePipeline 建置日誌來驗證建置是否成功。 | AWS DevOps | 
| 在 Db2 中檢查結果。 | 驗證 SYSPLAN 資料表上的套件版本。<pre>select CAST(NAME AS VARCHAR(10)) as name, VALIDATE, LAST_BIND_TIME, LASTUSED, CAST(PKGVERSION AS VARCHAR(10)) as PKGVERSION from SYSIBM.SYSPLAN where NAME = 'CDB2SMP' order by LAST_BIND_TIME desc<br /></pre>版本必須符合 CodeBuild 組建 ID，這`CDB2SMP`在我們的範例中：<pre>NAME       VALIDATE LAST_BIND_TIME             LASTUSED   PKGVERSION<br />---------- -------- -------------------------- ---------- ----------<br />CDB2SMP    B        2024-05-18-11.53.11.503738 01/01/0001 19</pre> |  | 

## 疑難排解
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 當您在服務之間移動時， AWS 主控台偶爾會切換區域。 | 每當您切換服務 AWS 區域 時，請務必驗證選取的 。選擇 AWS 區域 器位於主控台視窗的右上角。 | 
| 從 CodeBuild 識別 Db2 連線問題可能很困難。 | 若要疑難排解連線問題，請將下列 DB2 連線命令新增至 `buildspec.yml` 檔案。此新增可協助您偵錯和解決連線問題。<pre>db2 connect to $DB_NAME user $DB2USER using $DB2PASS</pre> | 
| 有時，IAM 主控台中的角色窗格不會立即顯示您建立的 IAM 政策。 | 如果您遇到延遲，請重新整理畫面以顯示最新資訊。 | 

## 相關資源
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-resources"></a>

**IBM 文件**
+ [IBM Data Server 用戶端和驅動程式類型](https://www.ibm.com/docs/en/db2/11.5?topic=overviews-data-server-clients)
+ [下載 IBM Data Server 用戶端和驅動程式類型](https://www.ibm.com/support/pages/download-initial-version-115-clients-and-drivers)

**AWS 文件**
+ [Amazon S3 使用者指南](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
+ [AWS CodeBuild 使用者指南](https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html)
+ [AWS Mainframe Modernization 使用者指南](https://docs.aws.amazon.com/m2/latest/userguide/what-is-m2.html)
+ [AWS Secrets Manager 使用者指南](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)
+ [AWS CodePipeline 使用者指南](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html)
+ [AWS CodeDeploy 使用者指南** **](https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-codedeploy.html)

## 其他資訊
<a name="build-cobol-db2-programs-mainframe-modernization-codebuild-additional"></a>

**CodeBuild 政策**

將預留位置 `<RegionID>`、`<AccountID>`、`<BucketARN>`、 `<SubnetARN>`和 取代`<DB2CredSecretARN>`為您的值。

```
{"Version": "2012-10-17",		 	 	 
    "Statement": [
        {"Action": "ecr:GetAuthorizationToken", "Effect": "Allow", "Resource": "*" },
        {"Action": ["ecr:GetDownloadUrlForLayer", "ecr:BatchGetImage", 
                    "ecr:BatchCheckLayerAvailability"],
         "Effect": "Allow", 
         "Resource": "arn:aws:ecr:*:673918848628:repository/m2-enterprise-build-tools"},
        {"Action": "s3:PutObject", "Effect": "Allow", "Resource": "arn:aws:s3:::aws-m2-repo-*/*"},
        {"Action": ["logs:PutLogEvents", "logs:CreateLogStream", "logs:CreateLogGroup"],
         "Effect": "Allow", "Resource": "arn:aws:logs:<RegionId>:<AccountId>:*"},
        {"Action": ["ec2:DescribeVpcs", "ec2:DescribeSubnets", 
                    "ec2:DescribeSecurityGroups", "ec2:DescribeNetworkInterfaces", 
                    "ec2:DescribeDhcpOptions", "ec2:DeleteNetworkInterface", 
                    "ec2:CreateNetworkInterface"],
         "Effect": "Allow", "Resource": "*"},
        {"Action": "ec2:CreateNetworkInterfacePermission", 
         "Effect": "Allow", "Resource": ["<SubnetARN>"]},
        {"Action": "s3:*", "Effect": "Allow", "Resource": ["<BucketARN>/*","<BucketARN>"]},
        {"Action": "secretsmanager:GetSecretValue", 
         "Effect": "Allow", "Resource": "<DB2CredSecretARN>"}
    ]
}
```

**CodePipeline 政策**

將預留位置 `<BucketARN>`和 取代`<ConnectionARN>`為您的值。

```
{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {"Action": ["s3:List*", "s3:GetObjectVersion", "s3:GetObject", "s3:GetBucketVersioning" ], 
        "Effect": "Allow",
        "Resource": ["<BucketARN>/*", "<BucketARN>"]},
        {"Action": ["codebuild:StartBuild", "codebuild:BatchGetBuilds"], 
         "Effect": "Allow", "Resource": "*"},
        {"Action": ["codestar-connections:UseConnection"],
         "Effect": "Allow", "Resource": "<ConnectionARN>"}
        ]
}
```

**`buildspec.yml`**

將`<your-bucket-name>`預留位置取代為您實際的 S3 儲存貯體名稱。

```
version: 0.2
phases:
  pre_build:
    commands:
      - /var/microfocuslicensing/bin/mfcesd -no > /var/microfocuslicensing/logs/mfcesd_startup.log 2>&1 &
      - |
        mkdir $CODEBUILD_SRC_DIR/db2client
        aws s3 cp s3://<your-bucket-name>/v11.5.8_linuxx64_client.tar.gz $CODEBUILD_SRC_DIR/db2client/ >> /dev/null 2>&1
        tar -xf $CODEBUILD_SRC_DIR/db2client/v11.5.8_linuxx64_client.tar.gz -C $CODEBUILD_SRC_DIR/db2client/
        cd $CODEBUILD_SRC_DIR/db2client/
        ./client/db2_install -f sysreq -y -b /opt/ibm/db2/V11.5 >> /dev/null 2>&1        
        useradd db2cli
        /opt/ibm/db2/V11.5/instance/db2icrt -s client -u db2cli db2cli
        DB2CRED=$(aws secretsmanager get-secret-value --secret-id dev-db2-cred | jq -r '.SecretString | fromjson')
        read -r DB2USER DB2PASS DB_NODE DB_HOST DB_PORT DB_NAME DB_QUAL <<<$(echo $DB2CRED | jq -r '.username, .password, .db2node, .db2host, .db2port, .db2name, .qualifier')
        . /home/db2cli/sqllib/db2profile
        db2 catalog tcpip node $DB_NODE remote $DB_HOST server $DB_PORT
        db2 catalog db $DB_NAME as $DB_NAME at node $DB_NODE authentication server
  build:
    commands:
      - |
        revision=$CODEBUILD_SRC_DIR/loadlib
        mkdir -p $revision; cd $revision
        . /opt/microfocus/EnterpriseDeveloper/bin/cobsetenv
        cob -zU $CODEBUILD_SRC_DIR/CDB2SMP.cbl -C "DB2(DB==${DB_NAME} PASS==${DB2USER}.${DB2PASS} VERSION==${CODEBUILD_BUILD_NUMBER} COLLECTION==DB2AWSDB"
artifacts:
  files:
    - "**/*"
  base-directory: $revision
```

# 使用 Amazon EC2 Auto Scaling 和 Systems Manager 建置 Micro Focus Enterprise Server PAC
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager"></a>

*Kevin Yung 和 Krithika Palani Selvam，Amazon Web Services*

*Peter Woods，無*

*Abraham Rondon，微型焦點*

## 總結
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-summary"></a>

此模式為在[橫向擴展效能和可用性叢集 (PAC) 中使用 Micro Focus Enterprise Server](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-F6E1BBB7-AEC2-45B1-9E36-1D86B84D2B85.html) 的大型主機應用程式引入可擴展架構，以及在 Amazon Web Services () 上使用 Amazon Elastic Compute Cloud (Amazon EC2) Auto Scaling 群組AWS。解決方案使用 AWS Systems Manager 和 Amazon EC2 Auto Scaling 生命週期掛鉤進行全自動化。透過使用此模式，您可以設定大型主機線上和批次應用程式，根據您的容量需求自動擴展和擴展，以達到高彈性。

**注意**  
此模式已使用 Micro Focus Enterprise Server 6.0 版進行測試。對於版本 8，請參閱[設定 Micro Focus 執行期 （在 Amazon EC2 上）](https://docs.aws.amazon.com/m2/latest/userguide/mf-runtime-setup.html)。

## 先決條件和限制
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Micro Focus Enterprise Server 軟體和授權。如需詳細資訊，請聯絡 [Micro Focus 銷售](https://www.microfocus.com/en-us/contact/contactme)。
+ 了解重建和交付大型主機應用程式的概念，以便在 Micro Focus Enterprise Server 中執行。如需高階概觀，請參閱 [Micro Focus Enterprise Server 資料表](https://www.microfocus.com/media/data-sheet/enterprise_server_ds.pdf)。
+ 了解 Micro Focus Enterprise Server 向外擴展效能和可用性叢集中的概念。如需詳細資訊，請參閱 [Micro Focus Enterprise Server 文件](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-F6E1BBB7-AEC2-45B1-9E36-1D86B84D2B85.html)。
+ 了解具有持續整合 (CI) 的大型主機應用程式 DevOps 的整體概念。如需 AWS和 Micro Focus 開發的 AWS 方案指引模式，請參閱[大型主機現代化： AWS 使用 Micro Focus 在 上進行 DevOps](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/mainframe-modernization-devops-on-aws-with-micro-focus.html)。

**注意**  
此模式已使用 Micro Focus Enterprise Server 第 6 版進行測試。對於版本 8，請參閱[設定 Micro Focus 執行期 （在 Amazon EC2 上）](https://docs.aws.amazon.com/m2/latest/userguide/mf-runtime-setup.html)。

**限制**
+ 如需 Micro Focus Enterprise Server 支援的平台清單，請參閱 [Micro Focus Enterprise Server 資料表](https://www.microfocus.com/media/data-sheet/enterprise_server_ds.pdf)。
+ 此模式中使用的指令碼和測試是以 Amazon EC2 Windows Server 2019 為基礎；未針對此模式測試其他 Windows Server 版本和作業系統。
+ 模式是以適用於 Windows 的 Micro Focus Enterprise Server 6.0 為基礎；此模式的開發中未測試較舊版本或較新版本。

**產品版本**
+ Micro Focus Enterprise Server 6.0
+ Windows Server 2019

## Architecture
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-architecture"></a>

在傳統大型主機環境中，您必須佈建硬體來託管應用程式和公司資料。為了滿足季節性、每月、每季或甚至前所未見或非預期需求的高峰，大型主機使用者必須透過購買額外的儲存和運算容量來*橫向擴展*。增加儲存和運算容量資源的數量可改善整體效能，但擴展不是線性的。

當您使用 Amazon EC2 Auto Scaling 和 Micro Focus Enterprise Server 開始在 AWS 上採用隨需耗用模型時，並非如此。下列各節詳細說明如何使用 Micro Focus Enterprise Server 橫向擴展效能和可用性叢集 (PAC) 搭配 Amazon EC2 Auto Scaling 群組來建置全自動化、可擴展的大型主機應用程式架構。 

**Micro Focus Enterprise Server 自動擴展架構**

首先，請務必了解 Micro Focus Enterprise Server 的基本概念。此環境為傳統上在 IBM 大型主機上執行的應用程式提供與大型主機相容的 x86 部署環境。它同時提供線上和批次執行，以及支援下列項目的交易環境：
+ IBM COBOL
+ IBM PL/I
+ IBM JCL 批次任務
+ IBM CICS 和 IMS TM 交易
+ Web 服務
+ 常見的批次公用程式，包括 SORT

Micro Focus Enterprise Server 可讓大型主機應用程式以最少的變更執行。現有的大型主機工作負載可以移至 x86 平台並進行現代化，以利用 AWS 雲端原生擴充功能快速擴展到新市場或地理。 

AWS 規範指引模式 [大型主機現代化：使用 Micro Focus 的 AWS 上的 DevOps ](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/mainframe-modernization-devops-on-aws-with-micro-focus.html) 引進了 架構，以使用 Micro Focus Enterprise Developer 和 Enterprise Test Server 搭配 AWS CodePipeline 和 AWS CodeBuild 來加速開發和測試 AWS 上的大型主機應用程式。此模式著重於將大型主機應用程式部署到 AWS 生產環境，以實現高可用性和彈性。

在大型主機生產環境中，您可能已在大型主機中設定 IBM Parallel Sysplex，以實現高效能和高可用性。為了建立類似於 Sysplex 的向外擴展架構，Micro Focus 將效能和可用性叢集 (PAC) 引入企業伺服器。PACs支援在多個 Enterprise Server 區域部署大型主機應用程式，並以單一映像形式管理，並在 Amazon EC2 執行個體中向外擴展。PACs也支援可預測的應用程式效能和隨需系統輸送量。 

在 PAC 中，多個 Enterprise Server 執行個體可做為單一邏輯實體一起運作。因此，一個 Enterprise Server 執行個體的故障不會中斷業務連續性，因為容量會與其他區域共用，而新的執行個體會使用產業標準功能自動啟動，例如 Amazon EC2 Auto Scaling 群組。這可移除單一故障點，改善硬體、網路和應用程式問題的彈性。向外擴展的 Enterprise Server 執行個體可以使用 Enterprise Server Common Web Administration (ESCWA) APIs 操作和管理，簡化 Enterprise Server 的操作維護和服務性。 

**注意**  
Micro Focus 建議[效能和可用性叢集 (PAC)](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-C06DC883-8A67-44DB-8553-8F0DD2062DAB.html) 應至少包含三個企業伺服器區域，以便在企業伺服器區域故障或需要維護時，可用性不會受到影響。

PAC 組態需要支援的關聯式資料庫管理服務 (RDBMS) 來管理區域資料庫、跨區域資料庫和選用的資料存放區資料庫。資料存放區資料庫應使用 Micro Focus 資料庫檔案處理常式支援來管理虛擬儲存存取方法 (VSAM) 檔案，以改善可用性和可擴展性。支援的 RDBMSs包括下列項目：
+ Microsoft SQL Server 2009 R2 及更新版本
+ PostgreSQL 10.x，包括 Amazon Aurora PostgreSQL 相容版本
+ DB2 10.4 及更新版本

如需支援的 RDBMS 和 PAC 需求的詳細資訊，請參閱 [Micro Focus Enterprise Server - 先決條件](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-486C5A4B-E3CD-4B17-81F3-32F9DE970EA5.html)和 [Micro Focus Enterprise Server - 建議的 PAC 組態](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-7038DB6F-E89F-4B5F-BCAA-BD1456F6CCA3.html)。

下圖顯示 Micro Focus PAC 的一般 AWS 架構設定。 

![\[三可用區域架構，在圖表後面的資料表中說明五個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/64e3c22b-1058-4ab8-855f-18bbbed5dc13/images/df291568-a442-454f-80bf-49e4ffff4f6d.png)


 


| 
| 
|  | **元件** | **Description** | 
| --- |--- |--- |
| 1 | Enterprise Server 執行個體自動擴展群組 | 設定在 PAC 中使用 Enterprise Server 執行個體部署的自動擴展群組。Amazon CloudWatch 警示可以使用 CloudWatch 指標向外或向內擴展執行個體數量。 | 
| 2 | Enterprise Server ESCWA 執行個體自動擴展群組  | 設定使用 Enterprise Server Common Web Administration (ESCWA) 部署的自動擴展群組。ESCWA 提供叢集管理 APIs。  ESCWA 伺服器做為控制平面，以在 Enterprise Server 執行個體自動擴展事件期間新增或移除 Enterprise Server，以及啟動或停止 PAC 中的 Enterprise Server 區域。  由於 ESCWA 執行個體僅用於 PAC 管理，其流量模式是可預測的，而且其自動擴展所需的容量需求可以設定為 1。  | 
| 3 | 多可用區設定中的 Amazon Aurora 執行個體 | 設定關聯式資料庫管理系統 (RDBMS) 來託管要跨企業伺服器執行個體共用的使用者和系統資料檔案。 | 
| 4 | Amazon ElastiCache (Redis OSS) 執行個體和複本 | 設定 ElastiCache (Redis OSS) 主要執行個體和至少一個複本來託管使用者資料，並做為 Enterprise Server 執行個體的橫向擴展儲存庫 (SOR)。您可以設定一或多個[橫向擴展儲存庫](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-3840E10F-80AA-4109-AF2C-894237D3AD00.html)來存放特定類型的使用者資料。  Enterprise Server 使用 Redis NoSQL 資料庫做為 SOR，[這是維護 PAC 完整性的需求](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-176B97CA-4F9F-4CE1-952F-C3F4FB0ADD25.html)。 | 
| 5 | Network Load Balancer | 設定負載平衡器，為應用程式提供主機名稱，以連線至 Enterprise Server 執行個體提供的服務 （例如，透過 3270 模擬器存取應用程式）。 | 

這些元件構成 Micro Focus Enterprise Server PAC 叢集的最低需求。下一節涵蓋叢集管理自動化。

**使用 AWS Systems Manager 自動化進行擴展**

在 AWS 上部署 PAC 叢集之後，會透過 Enterprise Server Common Web Administration (ESCWA) APIs 來管理 PAC。 

若要在自動擴展事件期間自動化叢集管理任務，您可以使用 Systems Manager Automation Runbook 和 Amazon EC2 Auto Scaling 搭配 Amazon EventBridge。這些自動化的架構如下圖所示。

![\[AWS architecture diagram showing EventBridge, Systems Manager, and EC2 Auto Scaling integration.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/64e3c22b-1058-4ab8-855f-18bbbed5dc13/images/6f9e4035-fafd-4aee-a6cc-d5e95d6514c2.png)


 


| 
| 
|  | **元件** | **Description** | 
| --- |--- |--- |
| 1 | 自動擴展生命週期掛鉤 | 設定自動擴展生命週期關聯，並在啟動新執行個體並在自動擴展群組中終止現有執行個體時將通知傳送至 Amazon EventBridge。 | 
| 2 | Amazon EventBridge | 設定 Amazon EventBridge 規則，將自動擴展事件路由至 Systems Manager Automation Runbook 目標。 | 
| 3 | 自動化 Runbook | 設定 Systems Manager Automation Runbook 以執行 Windows PowerShell 指令碼，並叫用 ESCWA APIs 來管理 PAC。如需範例，請參閱*其他資訊*一節。 | 
| 4 | 自動擴展群組中的 Enterprise Server ESCWA 執行個體 | 在自動擴展群組中設定 Enterprise Server ESCWA 執行個體。ESCWA 執行個體提供 APIs 來管理 PAC。  | 

## 工具
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-tools"></a>
+ [Micro Focus Enterprise Server](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-A2F23243-962B-440A-A071-480082DF47E7.html) – Micro Focus Enterprise Server 為使用 Enterprise Developer 的任何整合開發環境 (IDE) 變體建立的應用程式提供執行環境。
+ [Amazon EC2 Auto Scaling](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html) – Amazon EC2 Auto Scaling 可協助您確保有正確數量的 Amazon EC2 執行個體可用於處理應用程式的負載。您可以建立稱為 Auto Scaling 群組的 EC2 執行個體集合，並指定執行個體的最小和最大數量。
+ [Amazon ElastiCache (Redis OSS)](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/WhatIs.html) – Amazon ElastiCache 是一種 Web 服務，用於設定、管理和擴展雲端中的分散式記憶體內資料存放區或快取環境。它提供高效能、可擴展且符合成本效益的快取解決方案。
+ [Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) – Amazon Relational Database Service (Amazon RDS) 是一種 Web 服務，可讓您更輕鬆地在 AWS 雲端中設定、操作和擴展關聯式資料庫。它為關聯式資料庫提供經濟實惠、可擴展的容量，並管理常見的資料庫管理任務。 
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) – AWS Systems Manager 是一種 AWS 服務，可用來檢視和控制 AWS 上的基礎設施。使用 Systems Manager 主控台，您可以檢視來自多個 AWS 服務的操作資料，並自動化 AWS 資源的操作任務。Systems Manager 透過掃描您的受管執行個體並報告 (或採取修正動作) 其偵測的任何政策違規，協助您保持安全與合規。

## 史詩
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-epics"></a>

### 建立 Amazon Aurora 執行個體
<a name="create-an-amazon-aurora-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 Amazon Aurora 執行個體建立 AWS CloudFormation 範本。 | 使用 [AWS 範例程式碼片段](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_RDS.html)建立 CloudFormation 範本，以建立 Amazon Aurora PostgreSQL 相容版本執行個體。 | 雲端架構師 | 
| 部署 CloudFormation 堆疊以建立 Amazon Aurora 執行個體。 | 使用 CloudFormation 範本建立 Aurora PostgreSQL 相容執行個體，該執行個體已針對生產工作負載啟用異地同步備份複寫。 | 雲端架構師 | 
| 設定 Enterprise Server 的資料庫連線設定。 | 遵循 [Micro Focus 文件](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-40748F62-84B3-4B7B-8E96-5484ADEDFB5F.html)中的指示，為 Micro Focus Enterprise Server 準備連線字串和資料庫組態。 | 資料工程師、DevOps 工程師 | 

### 為 Redis 執行個體建立 Amazon ElastiCache 叢集
<a name="create-an-elclong-cluster-for-the-redis-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 Redis 執行個體的 Amazon ElastiCache 叢集建立 CloudFormation 範本。 | 使用 [AWS 範例程式碼片段](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_ElastiCache.html)建立 CloudFormation 範本，為 Redis 執行個體建立 Amazon ElastiCache 叢集。 | 雲端架構師 | 
| 部署 CloudFormation 堆疊，為 Redis 執行個體建立 Amazon ElastiCache 叢集。 | 為已針對生產工作負載啟用異地同步備份複寫的 Redis 執行個體建立 Amazon ElastiCache 叢集。 | 雲端架構師 | 
| 設定 Enterprise Server PSOR 連線設定。 | 遵循 [Micro Focus 文件](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-2A420ADD-4CA6-472D-819F-371C037C0653.html)中的指示，為 Micro Focus Enterprise Server PAC 準備 PAC 橫向擴展儲存庫 (PSOR) 連線組態。 | DevOps 工程師 | 

### 建立 Micro Focus Enterprise Server ESCWA 自動擴展群組
<a name="create-a-micro-focus-enterprise-server-escwa-automatic-scaling-group"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Micro Focus Enterprise Server AMI。 | 建立 Amazon EC2 Windows Server 執行個體，並在 EC2 執行個體中安裝 Micro Focus Enterprise Server 二進位檔。建立 EC2 執行個體的 Amazon Machine Image (AMI)。如需詳細資訊，請參閱[Enterprise Server 安裝文件](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-FACEF60F-BAE3-446C-B2B4-4379A5DF6D9F.html)。 | 雲端架構師 | 
| 為 Enterprise Server ESCWA 建立 CloudFormation 範本。 | 使用 [AWS 範例程式碼片段](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_AutoScaling.html)建立範本，以在自動擴展群組中建立 Enterprise Server ESCWA 的自訂堆疊。 | 雲端架構師 | 
| 部署 CloudFormation 堆疊，為 Enterprise Server ESCWA 建立 Amazon EC2 擴展群組。 | 使用 CloudFormation 範本，使用上一個案例建立的 Micro Focus Enterprise Server ESCWA AMI 部署自動擴展群組。 | 雲端架構師 | 

### 建立 AWS Systems Manager Automation Runbook
<a name="create-an-aws-systems-manager-automation-runbook"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Systems Manager Automation Runbook 的 CloudFormation 範本。 | 使用*其他資訊*區段中的範例程式碼片段來建立 CloudFormation 範本，該範本將建立 Systems Manager Automation Runbook 以自動化 PAC 建立、Enterprise Server 向內擴展和 Enterprise Server 向外擴展。 | 雲端架構師 | 
| 部署包含 Systems Manager Automation Runbook 的 CloudFormation 堆疊。 | 使用 CloudFormation 範本部署堆疊，其中包含用於建立 PAC、企業伺服器向內擴展和企業伺服器向外擴展的 Automation Runbook。 | 雲端架構師 | 

### 建立 Micro Focus Enterprise Server 的自動擴展群組
<a name="create-an-automatic-scaling-group-for-micro-focus-enterprise-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 CloudFormation 範本，以設定 Micro Focus Enterprise Server 的自動擴展群組。 | 使用 [AWS 範例程式碼片段](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_AutoScaling.html)建立將建立自動擴展群組的 CloudFormation 範本。此範本將重複使用為 Micro Focus Enterprise Server ESCWA 執行個體建立的相同 AMI。 然後使用 [AWS 範例程式碼片段](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)來建立自動擴展生命週期事件，並設定 Amazon EventBridge 來篩選相同 CloudFormation 範本中的擴展和縮減事件。 | 雲端架構師 | 
| 部署 Micro Focus Enterprise Servers 自動擴展群組的 CloudFormation 堆疊。 | 部署包含 Micro Focus Enterprise Servers 自動擴展群組的 CloudFormation 堆疊。 | 雲端架構師 | 

## 相關資源
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-resources"></a>
+ [Micro Focus Enterprise Server 效能和可用性叢集 (PAC)](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-613F5E2D-2FBC-47AE-9327-48CA4FF84C5B.html) 
+ [Amazon EC2 Auto Scaling lifecycle hooks](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html)
+ [使用 EventBridge 搭配觸發執行自動化](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-cwe-target.html)

## 其他資訊
<a name="build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager-additional"></a>

下列案例必須自動化以擴展或擴展 PAC 叢集。

**啟動或重新建立 PAC 的自動化**

在 PAC 叢集開始時，Enterprise Server 需要 ESCWA 呼叫 APIs來建立 PAC 組態。這會啟動 Enterprise Server 區域並將其新增至 PAC。若要建立或重新建立 PAC，請使用下列步驟： 

1. 使用指定名稱在 ESCWA 中設定 [PAC 橫向擴展儲存庫 (PSOR)](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-2A420ADD-4CA6-472D-819F-371C037C0653.html)。

   ```
   POST /server/v1/config/groups/sors
   ```

1. 建立具有指定名稱的 PAC，並將 PSOR 連接到該 PAC。

   ```
   POST /server/v1/config/groups/pacs
   ```

1. 如果這是您第一次設定 PAC，請設定區域資料庫和跨區域資料庫。
**注意**  
此步驟使用 SQL 查詢和 Micro Focus Enterprise Suite 命令列 **dbhfhadmin** 工具來建立資料庫並匯入初始資料。

1. 將 PAC 定義安裝到企業伺服器區域。

   ```
   POST /server/v1/config/mfds 
   POST /native/v1/config/groups/pacs/${pac_uid}/install
   ```

1. 在 PAC 中啟動企業伺服器區域。

   ```
   POST /native/v1/regions/${host_ip}/${port}/${region_name}/start
   ```

您可以使用 Windows PowerShell 指令碼來實作先前的步驟。 

下列步驟說明如何透過重複使用 Windows PowerShell 指令碼來建置建立 PAC 的自動化。

1. 建立 Amazon EC2 啟動範本，以下載或建立 WindowsPowerShell 指令碼做為引導程序的一部分。例如，您可以使用 EC2 使用者資料從 Amazon Simple Storage Service (Amazon S3) 儲存貯體下載指令碼。

1. 建立 AWS Systems Manager Automation Runbook 以叫用 Windows PowerShell 指令碼。

1. 使用執行個體標籤將 Runbook 與 ESCWA 執行個體建立關聯。

1. 使用啟動範本建立 ESCWA 自動擴展群組。 

您可以使用下列範例 AWS CloudFormation 程式碼片段來建立 Automation Runbook。

*用於建立 PAC 的 Systems Manager Automation Runbook 的範例 CloudFormation 程式碼片段*

```
  PACInitDocument:
     Type: AWS::SSM::Document
     Properties:
       DocumentType: Command
       Content:
         schemaVersion: '2.2'
         description: Operation Runbook to create Enterprise Server PAC
         mainSteps:
         - action: aws:runPowerShellScript
           name: CreatePAC
           inputs:
             onFailure: Abort
             timeoutSeconds: "1200"
             runCommand:
             - | 
               C:\Scripts\PAC-Init.ps1
  PacInitAutomation:
     Type: AWS::SSM::Document
     Properties:
       DocumentType: Automation
       Content:
         description: Prepare Micro Focus PAC Cluster via ESCWA Server
         schemaVersion: '0.3'
         assumeRole: !GetAtt SsmAssumeRole.Arn
         mainSteps:
           - name: RunPACInitDocument
             action: aws:runCommand
             timeoutSeconds: 300
             onFailure: Abort
             inputs:
               DocumentName: !Ref PACInitDocument
               Targets:
                 - Key: tag:Enterprise Server - ESCWA
                   Values:
                     - "true"
   PacInitDocumentAssociation:
     Type: AWS::SSM::Association
     Properties:
       DocumentVersion: "$LATEST"
       Name: !Ref PACInitDocument
       Targets:
         - Key: tag:Enterprise Server - ESCWA
           Values:
             - "true"
```

如需詳細資訊，請參閱 [Micro Focus Enterprise Server - 設定 PAC](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-2B15EBA5-84AF-47C3-9F8E-EE57EB17245F.html)。

**使用新的 Enterprise Server 執行個體進行擴展的自動化**

向外擴展 Enterprise Server 執行個體時，必須將其 Enterprise Server 區域新增至 PAC。下列步驟說明如何叫用 ESCWA APIs，並將企業伺服器區域新增至 PAC。 

1. 將 PAC 定義安裝到企業伺服器區域。

   ```
   POST '/server/v1/config/mfds'
   POST /native/v1/config/groups/pacs/${pac_uid}/install
   ```

1. 暖啟動 PAC 中的區域。

   ```
   POST /native/v1/regions/${host_ip}/${port}/${region_name}/start
   ```

1. 透過將自動擴展群組與負載平衡器建立關聯，將 Enterprise Server 執行個體新增至負載平衡器。

您可以使用 Windows PowerShell 指令碼來實作先前的步驟。如需詳細資訊，請參閱 [Micro Focus Enterprise Server - 設定 PAC](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-2B15EBA5-84AF-47C3-9F8E-EE57EB17245F.html)。

下列步驟可用來建置事件驅動自動化，透過重複使用 Windows PowerShell 指令碼將新啟動的 Enterprise Server 執行個體新增至 PAC。 

1. 為 Enterprise Server 執行個體建立 Amazon EC2 啟動範本，在 Enterprise Server 執行個體的引導期間佈建 Enterprise Server 區域。例如，您可以使用 Micro Focus Enterprise Server 命令 mfds 來匯入區域組態。如需此命令可用的更多詳細資訊和選項，請參閱[企業伺服器參考](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/HRADRHCOMM06.html)。

1. 建立使用上一個步驟中建立的啟動範本的 Enterprise Server 自動擴展群組。

1. 建立 Systems Manager Automation Runbook 以叫用 Windows PowerShell 指令碼。 

1. 使用執行個體標籤將 Runbook 與 ESCWA 執行個體建立關聯。

1. 建立 Amazon EventBridge 規則來篩選 Enterprise Server 自動擴展群組的 EC2 執行個體啟動成功事件，並建立目標以使用 Automation Runbook。

您可以使用下列範例 CloudFormation 程式碼片段來建立 Automation Runbook 和 EventBridge 規則。

*用於擴展 Enterprise Server 執行個體之 Systems Manager 的範例 CloudFormation 程式碼片段*

```
  ScaleOutDocument:
     Type: AWS::SSM::Document
     Properties:
       DocumentType: Command
       Content:
         schemaVersion: '2.2'
         description: Operation Runbook to Adding MFDS Server into an existing PAC 
         parameters:
           MfdsPort:
             type: String
           InstanceIpAddress:
             type: String
             default: "Not-Available"
           InstanceId:
             type: String
             default: "Not-Available"
         mainSteps:
         - action: aws:runPowerShellScript
           name: Add_MFDS
           inputs:
             onFailure: Abort
             timeoutSeconds: "300"
             runCommand:
             - |
               $ip = "{{InstanceIpAddress}}"
               if ( ${ip} -eq "Not-Available" ) {
                 $ip = aws ec2 describe-instances --instance-id {{InstanceId}} --output text --query "Reservations[0].Instances[0].PrivateIpAddress"
               }            
               C:\Scripts\Scale-Out.ps1 -host_ip ${ip} -port {{MfdsPort}}
 
   PacScaleOutAutomation:
     Type: AWS::SSM::Document
     Properties:
       DocumentType: Automation
       Content:
         parameters:
           MfdsPort:
             type: String
           InstanceIpAddress:
             type: String
             default: "Not-Available"
           InstanceId:
             type: String
             default: "Not-Available"
         description: Scale Out 1 New Server in Micro Focus PAC Cluster via ESCWA Server
         schemaVersion: '0.3'
         assumeRole: !GetAtt SsmAssumeRole.Arn
         mainSteps:
           - name: RunScaleOutCommand
             action: aws:runCommand
             timeoutSeconds: 300
             onFailure: Abort
             inputs:
               DocumentName: !Ref ScaleOutDocument
               Parameters:
                 InstanceIpAddress: "{{InstanceIpAddress}}"
                 InstanceId: "{{InstanceId}}"
                 MfdsPort: "{{MfdsPort}}"
               Targets:
                 - Key: tag:Enterprise Server - ESCWA
                   Values:
                     - "true"
```

**在 Enterprise Server 執行個體中擴展的自動化**

與向外擴展類似，在*向內擴展* Enterprise Server 執行個體時，會啟動事件 EC2 執行個體終止生命週期動作，並且需要下列程序和 API 呼叫，才能從 PAC 中移除 Micro Focus Enterprise Server 執行個體。 

1. 在終止 Enterprise Server 執行個體中停止 區域。

   ```
   POST "/native/v1/regions/${host_ip}/${port}/${region_name}/stop"
   ```

1. 從 PAC 移除企業伺服器執行個體。

   ```
   DELETE "/server/v1/config/mfds/${uid}"
   ```

1. 傳送訊號以繼續終止 Enterprise Server 執行個體。

先前的步驟可以在 Windows PowerShell 指令碼中實作。如需此程序的其他詳細資訊，請參閱 [Micro Focus Enterprise Server 文件 - 管理 PAC](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-E864E2E9-EB49-43BF-9AAD-7FE334749441.html)。

下列步驟說明如何建置事件驅動型自動化，透過重複使用 Windows PowerShell 指令碼從 PAC 終止 Enterprise Server 執行個體。 

1. 建立 Systems Manager Automation Runbook 以叫用 Windows PowerShell 指令碼。

1. 使用執行個體標籤將 Runbook 與 ESCWA 執行個體建立關聯。

1. 建立 EC2 執行個體終止的自動擴展群組生命週期關聯。

1. 建立 Amazon EventBridge 規則來篩選 Enterprise Server 自動擴展群組的 EC2 執行個體終止生命週期動作事件，並建立目標以使用 Automation Runbook。 

您可以使用下列範例 CloudFormation 範本來建立 Systems Manager Automation Runbook、 lifecycle hook 和 EventBridge 規則。

*用於在 Enterprise Server 執行個體中擴展的 Systems Manager Automation Runbook 的範例 CloudFormation 程式碼片段*

```
  ScaleInDocument:
     Type: AWS::SSM::Document
     Properties:
       DocumentType: Command
       Content:
         schemaVersion: '2.2'
         description: Operation Runbook to Remove MFDS Server from PAC 
         parameters:
           MfdsPort:
             type: String
           InstanceIpAddress:
             type: String
             default: "Not-Available"
           InstanceId:
             type: String
             default: "Not-Available"
         mainSteps:
         - action: aws:runPowerShellScript
           name: Remove_MFDS
           inputs:
             onFailure: Abort
             runCommand:
             - |
               $ip = "{{InstanceIpAddress}}"
               if ( ${ip} -eq "Not-Available" ) {
                 $ip = aws ec2 describe-instances --instance-id {{InstanceId}} --output text --query "Reservations[0].Instances[0].PrivateIpAddress"
               }            
               C:\Scripts\Scale-In.ps1 -host_ip ${ip} -port {{MfdsPort}}
 
   PacScaleInAutomation:
     Type: AWS::SSM::Document
     Properties:
       DocumentType: Automation
       Content:
         parameters:
           MfdsPort:
             type: String
           InstanceIpAddress:
             type: String
             default: "Not-Available"            
           InstanceId:
             type: String
             default: "Not-Available"                
         description: Scale In 1 New Server in Micro Focus PAC Cluster via ESCWA Server
         schemaVersion: '0.3'
         assumeRole: !GetAtt SsmAssumeRole.Arn
         mainSteps:
           - name: RunScaleInCommand
             action: aws:runCommand
             timeoutSeconds: "600"
             onFailure: Abort
             inputs:
               DocumentName: !Ref ScaleInDocument
               Parameters:
                 InstanceIpAddress: "{{InstanceIpAddress}}"
                 MfdsPort: "{{MfdsPort}}"
                 InstanceId: "{{InstanceId}}"
               Targets:
                 - Key: tag:Enterprise Server - ESCWA
                   Values:
                     - "true"
           - name: TerminateTheInstance
             action: aws:executeAwsApi
             inputs:
               Service: autoscaling
               Api: CompleteLifecycleAction
               AutoScalingGroupName: !Ref AutoScalingGroup
               InstanceId: "{{ InstanceId }}"
               LifecycleActionResult: CONTINUE
               LifecycleHookName: !Ref ScaleInLifeCycleHook
```

**Amazon EC2 自動擴展觸發程序的自動化**

為 Enterprise Server 執行個體設定擴展政策的程序需要了解應用程式行為。在大多數情況下，您可以設定目標追蹤擴展政策。例如，您可以使用平均 CPU 使用率做為 Amazon CloudWatch 指標，來設定自動擴展政策。如需詳細資訊，請參閱 [Amazon EC2 Auto Scaling 的目標追蹤擴展政策](https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html)。對於具有一般流量模式的應用程式，請考慮使用預測擴展政策。如需詳細資訊，請參閱 [Amazon EC2 Auto Scaling 的預測擴展](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-predictive-scaling.html)。 

# 在 AWS 雲端中建置進階大型主機檔案檢視器
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud"></a>

*Bopath GOPALSAMY 和 Jeremiah O'Connor，Amazon Web Services*

## 總結
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-summary"></a>

此模式提供程式碼範例和步驟，協助您建置進階工具，以使用 AWS 無伺服器服務來瀏覽和檢閱大型主機固定格式檔案。模式提供範例，說明如何將大型主機輸入檔案轉換為 Amazon OpenSearch Service 文件以進行瀏覽和搜尋。檔案檢視器工具可協助您達成下列目標：
+ 保留相同的大型主機檔案結構和配置，以在 AWS 目標遷移環境中保持一致性 （例如，您可以在將檔案傳輸至外部各方的批次應用程式中維護相同的檔案配置）
+ 在大型主機遷移期間加速開發和測試
+ 支援遷移後的維護活動

## 先決條件和限制
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 虛擬私有雲端 (VPC)，具有傳統平台可存取的子網路
+ 
**注意**  
輸入檔案及其對應的常見業務導向語言 (COBOL) 複製手冊 (：如需輸入檔案和 COBOL 複製手冊範例，請參閱 GitHub 儲存庫上的 [gfs-mainframe-solutions](https://github.com/aws-samples/gfs-mainframe-patterns.git)。 如需 COBOL 複本手冊的詳細資訊，請參閱 IBM 網站上的[適用於 z/OS 6.3 的企業 COBOL](https://publibfp.boulder.ibm.com/epubs/pdf/igy6pg30.pdf) 程式設計指南。)

**限制**
+ 複製手冊剖析限制為不超過兩個巢狀層級 (OCCURS)

## Architecture
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-architecture"></a>

**來源技術堆疊**
+ [FB （固定封鎖） 格式的](https://www.ibm.com/docs/en/zos-basic-skills?topic=set-data-record-formats)輸入檔案
+ COBOL 複製手冊配置

**目標技術堆疊**
+ Amazon Athena
+ Amazon OpenSearch Service
+ Amazon Simple Storage Service (Amazon S3)
+ AWS Lambda
+ AWS Step Functions

**目標架構**

下圖顯示剖析大型主機輸入檔案並將其轉換為 OpenSearch Service 文件以供瀏覽和搜尋的程序。

![\[剖析大型主機輸入檔案並將其轉換為 OpenSearch Service 的程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36d72b00-d163-455f-9e59-e2c872e7c28a/images/cce68438-bcf2-48c1-b86b-01242235ec76.png)


該圖顯示以下工作流程：

1. 管理員使用者或應用程式會將輸入檔案推送至一個 S3 儲存貯體，並將 COBOL 複製手冊推送至另一個 S3 儲存貯體。

1. 
**注意**  
具有輸入檔案的 S3 儲存貯體會叫用 Lambda 函數，以啟動無伺服器 Step Functions 工作流程。：使用此模式使用 S3 事件觸發和 Lambda 函數來驅動 Step Functions 工作流程是選用的。此模式中的 GitHub 程式碼範例不包含這些服務的使用，但您可以根據您的需求使用這些服務。

1. Step Functions 工作流程會協調來自下列 Lambda 函數的所有批次程序：
   + `s3copybookparser.py` 函數會剖析複製手冊配置，並擷取欄位屬性、資料類型和位移 （輸入資料處理時需要）。
   + `s3toathena.py` 函數會建立 Athena 資料表配置。Athena 會剖析`s3toathena.py`函數處理的輸入資料，並將資料轉換為 CSV 檔案。
   + `s3toelasticsearch.py` 函數會從 S3 儲存貯體擷取結果檔案，並將檔案推送至 OpenSearch Service。

1. 使用者使用 OpenSearch Service 存取 OpenSearch Dashboards，以各種資料表和資料欄格式擷取資料，然後針對索引資料執行查詢。

## 工具
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-tools"></a>

**AWS 服務**
+ [Amazon Athena](https://docs.aws.amazon.com/athena/latest/ug/what-is.html) 是一種互動式查詢服務，可協助您使用標準 SQL 直接在 Amazon Simple Storage Service (Amazon S3) 中分析資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，可協助您執行程式碼，而不需要佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需支付使用的運算時間。在此模式中，您可以使用 Lambda 實作核心邏輯，例如剖析檔案、轉換資料，以及將資料載入 OpenSearch Service 以進行互動式檔案存取。
+ [Amazon OpenSearch Service](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/what-is.html) 是一項受管服務，可協助您在 AWS 雲端中部署、操作和擴展 OpenSearch Service 叢集。在此模式中，您可以使用 OpenSearch Service 為轉換的檔案編製索引，並為使用者提供互動式搜尋功能。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [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 Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) 是一種無伺服器協同運作服務，可協助您結合 Lambda 函數和其他 AWS 服務來建置業務關鍵應用程式。在此模式中，您可以使用 Step Functions 來協調 Lambda 函數。

**其他工具**
+ [GitHub](https://github.com/) 是一種程式碼託管服務，可提供協作工具和版本控制。
+ [Python](https://www.python.org/) 是一種高階程式設計語言。

**Code**

此模式的程式碼可在 GitHub [gfs-mainframe-patterns](https://github.com/aws-samples/gfs-mainframe-patterns.git) 儲存庫中使用。

## 史詩
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-epics"></a>

### 準備目標環境
<a name="prepare-the-target-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | [建立 anS3 ](https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-bucket.html) 儲存貯體以存放複本、輸入檔案和輸出檔案。建議您的 S3 儲存貯體使用下列資料夾結構：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 
| 建立 s3copybookparser 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 
| 建立 s3toathena 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 
| 建立 s3toelasticsearch 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 
| 建立 OpenSearch Service 叢集。 | **建立叢集**[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html)**授予 IAM 角色的存取權**若要提供 Lambda 函數 IAM 角色 (`arn:aws:iam::**:role/service-role/s3toelasticsearch-role-**`) 的精細存取權，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 
| 建立用於協同運作的 Step Functions。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 

### 部署和執行
<a name="deploy-and-run"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將輸入檔案和複製手冊上傳至 S3 儲存貯體。 | 從 [GitHub ](https://github.com/aws-samples/gfs-mainframe-patterns.git)儲存庫範例資料夾下載範例檔案，並將檔案上傳至您先前建立的 S3 儲存貯體。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 
| 叫用 Step Functions。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html)<pre>{<br />  "s3_copybook_bucket_name": "<BUCKET NAME>",<br />  "s3_copybook_bucket_key": "<COPYBOOK PATH>",<br />  "s3_source_bucket_name": "<BUCKET NAME",<br />  "s3_source_bucket_key": "INPUT FILE PATH"<br />}</pre>例如：<pre>{<br />  "s3_copybook_bucket_name": "fileaidtest",<br />  "s3_copybook_bucket_key": "copybook/acctix.cpy",<br />  "s3_source_bucket_name": "fileaidtest",<br />  "s3_source_bucket_key": "input/acctindex"<br />}</pre> | 一般 AWS | 
| 驗證 Step Functions 中的工作流程執行。 | 在 [Step Functions 主控台](https://console.aws.amazon.com/states/home)中，檢閱**圖形檢查器**中的工作流程執行。執行執行狀態會以顏色編碼來表示執行狀態。例如，藍色表示**進行中**，綠色表示**成功**，紅色表示**失敗**。您也可以檢閱**執行事件歷史記錄**區段中的資料表，以取得執行事件的詳細資訊。如需圖形工作流程執行的範例，請參閱此模式*額外資訊*區段中的 *Step Functions 圖形*。 | 一般 AWS | 
| 驗證 Amazon CloudWatch 中的交付日誌。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html)如需成功交付日誌的範例，請參閱此模式*額外資訊*區段中的 *CloudWatch 交付日誌*。 | 一般 AWS | 
| 驗證 OpenSearch Dashboards 中的格式化檔案，並執行檔案操作。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 一般 AWS | 

## 相關資源
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-resources"></a>

**參考**
+ [COBOL 複製手冊範例](https://www.ibm.com/docs/en/record-generator/3.0?topic=SSMQ4D_3.0.0/documentation/cobol_rcg_examplecopybook.html) (IBM 文件）
+ [BMC Compuware File-AID](https://www.bmc.com/it-solutions/bmc-compuware-file-aid.html) (BMC 文件）

**教學課程**
+ [教學課程：使用 Amazon S3 觸發程序來叫用 Lambda 函數 ](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html)(AWS Lambda 文件）
+ [如何使用 AWS Step Functions 和 AWS Lambda 建立無伺服器工作流程](https://aws.amazon.com/getting-started/hands-on/create-a-serverless-workflow-step-functions-lambda/) (AWS 文件）
+ [搭配 Amazon OpenSearch Service 使用 OpenSearch Dashboards](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/dashboards.html) (AWS 文件）

## 其他資訊
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-additional"></a>

**Step Functions 圖形**

下列範例顯示 Step Functions 圖形。此圖表顯示此模式中所用 Lambda 函數的執行執行狀態。

![\[Step Functions 圖形顯示此模式中所用 Lambda 函數的執行執行狀態。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36d72b00-d163-455f-9e59-e2c872e7c28a/images/11093e5d-2f9e-4bbf-8abc-f3b2980dd550.png)


**CloudWatch 交付日誌**

下列範例顯示執行成功交付日誌`s3toelasticsearch`。


| 
| 
| 2022-08-10T15：53：33.033 年 5 月 00 日 | 處理文件數量：100 |  | 
| --- |--- |--- |
|  | 2022-08-10T15：53：33.171 年 5 月 00 日 | 【INFO】 2022-08-10T20：53：33.171Z a1b2c3d4-5678-90ab-cdef-EXAMPLE11111POST https://search-essearch-3h4uqclifeqaj2vg4mphe7ffle.us-east-2.es.amazonaws.com:443/\$1bulk 【status：200 request：0.100s】 | 
|  | 2022-08-10T15：53：33.172 年 5 月 00 日 | 大量寫入成功：100 個文件 | 

# 容器化已由 Blu Age 現代化的大型主機工作負載
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age"></a>

*Richard Milner-Watts，Amazon Web Services*

## 總結
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-summary"></a>

此模式提供範例容器環境，用於執行已使用 [Blu Age](https://www.bluage.com/) 工具進行現代化的大型主機工作負載。Blu Age 會將舊版大型主機工作負載轉換為現代 Java 程式碼。此模式提供 Java 應用程式的包裝函式，因此您可以使用 [Amazon Elastic Container Service (Amazon ECS)](https://aws.amazon.com/ecs/) 或 [Amazon Elastic Kubernetes Service (Amazon EKS)](https://aws.amazon.com/eks/) 等容器協同運作服務來執行它。

如需使用 Blu Age 和 AWS 服務來現代化工作負載的詳細資訊，請參閱下列 AWS 規範指引出版物：
+ [在無伺服器 AWS 基礎設施上執行現代化 Blu Age 大型主機工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/run-bluage-modernized-mainframes/)
+ [使用 Terraform 部署容器化 Blu Age 應用程式的環境](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform.html)

如需使用 Blu Age 來現代化大型主機工作負載的協助，請在 Blu Age 網站上選擇**聯絡我們的專家**[，以聯絡 Blu Age](https://www.bluage.com/) 團隊。如需協助將現代化工作負載遷移至 AWS、將它們與 AWS 服務整合，並將它們移至生產環境，請聯絡您的 AWS 客戶經理或填寫 [AWS Professional Services 表單](https://pages.awscloud.com/AWS-Professional-Services.html)。

## 先決條件和限制
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-prereqs"></a>

**先決條件**
+ 由 Blu Age 建立的現代化 Java 應用程式。基於測試目的，此模式提供範例 Java 應用程式，可用來做為概念驗證。
+ 您可以使用 [Docker](https://aws.amazon.com/docker/) 環境來建置容器。

**限制**

根據您使用的容器協同運作平台，可供容器使用的資源 （例如 CPU、RAM 和儲存） 可能會受到限制。例如，如果您使用 Amazon ECS 搭配 AWS Fargate，請參閱 [Amazon ECS 文件](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html)以了解限制和考量事項。

## Architecture
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-architecture"></a>

**來源技術堆疊**
+ 藍齡
+ Java

**目標技術堆疊**
+ Docker

**目標架構**

下圖顯示 Docker 容器內 Blu Age 應用程式的架構。

![\[Docker 容器中的 Blu Age 應用程式\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/c1747094-357b-4222-b4eb-b1336d810f83/images/0554332d-eff5-49ca-9789-da39b5a10045.png)


1. 容器的進入點是包裝函式指令碼。此 bash 指令碼負責準備 Blu Age 應用程式和處理輸出的執行期環境。

1. 容器內的環境變數用於設定包裝函式指令碼中的變數，例如 Amazon Simple Storage Service (Amazon S3) 儲存貯體名稱和資料庫登入資料。環境變數是由 AWS Secrets Manager 或 Parameter Store 提供，AWS Systems Manager 的功能。如果您使用 Amazon ECS 做為容器協同運作服務，您也可以硬式編碼 Amazon ECS 任務定義中的環境變數。

1. 在您執行 Blu Age 應用程式之前，包裝函式指令碼負責將任何輸入檔案從 S3 儲存貯體提取至容器。AWS Command Line Interface (AWS CLI) 安裝在容器內。這提供了一種機制，可透過閘道虛擬私有雲端 (VPC) 端點存取存放在 Amazon S3 中的物件。

1. Blu Age 應用程式的 Java Archive (JAR) 檔案可能需要與其他資料來源通訊，例如 Amazon Aurora。

1. 完成後，包裝函式指令碼會將產生的輸出檔案傳送到 S3 儲存貯體，以供進一步處理 （例如，Amazon CloudWatch 記錄服務）。如果您使用標準 CloudWatch 記錄的替代方案， 模式也支援將壓縮日誌檔案交付至 Amazon S3。

## 工具
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-tools"></a>

**AWS 服務**
+ [Amazon Elastic Container Registry (Amazon ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html) 是一種受管容器映像登錄服務，安全、可擴展且可靠。
+ [Amazon Elastic Container Service (Amazon ECS)](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) 是快速、可擴展的容器管理服務，可協助您執行、停止和管理叢集上的容器。

**工具**
+ [Docker](https://aws.amazon.com/docker/) 是一種軟體平台，用於建置、測試和部署應用程式。Docker 會將軟體封裝至稱為[容器](https://aws.amazon.com/containers/)的標準化單位，其中包含軟體執行所需的一切，包括程式庫、系統工具、程式碼和執行時間。您可以使用 Docker 將應用程式部署並擴展到任何環境。
+ [Bash](https://www.gnu.org/software/bash/manual/) 是 GNU 作業系統的命令語言界面 （殼層）。
+ [Java](https://www.java.com/) 是此模式中使用的程式設計語言和開發環境。
+ [Blu Age](https://www.bluage.com/) 是一種 AWS 大型主機現代化工具，可將舊版大型主機工作負載，包括應用程式碼、相依性和基礎設施，轉換為雲端的現代工作負載。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [Blu Age 範例容器儲存庫](https://github.com/aws-samples/aws-blu-age-sample-container)中找到。

## 最佳實務
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-best-practices"></a>
+ 使用環境變數將變數外部化，以變更應用程式的行為。這些變數可讓容器協同運作解決方案變更執行時間環境，而無需重建容器。此模式包含可用於 Blu Age 應用程式的環境變數範例。
+ 執行 Blu Age 應用程式之前，請先驗證任何應用程式相依性。例如，確認資料庫可用且登入資料有效。在包裝函式指令碼中寫入測試，以驗證相依性，如果不符合，則提早失敗。
+ 在包裝函式指令碼中使用詳細記錄。直接與執行中的容器互動可能具有挑戰性，具體取決於協同運作平台和任務需要多長時間。請務必將有用的輸出寫入 `STDOUT`，以協助診斷任何問題。例如，輸出可能會在您執行應用程式之前和之後包含應用程式工作目錄的內容。

## 史詩
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-epics"></a>

### 取得 Blu Age 應用程式 JAR 檔案
<a name="obtain-a-blu-age-application-jar-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選項 1 - 使用 Blu Age 來取得應用程式的 JAR 檔案。 | 此模式中的容器需要 Blu Age 應用程式。或者，您可以使用此模式隨附的範例 Java 應用程式進行原型。與 Blu Age 團隊合作，為您的應用程式取得可製作到容器中的 JAR 檔案。如果 JAR 檔案無法使用，請參閱下一個任務以改用範例應用程式。 | 雲端架構師 | 
| 選項 2 - 建置或使用提供的範例應用程式 JAR 檔案。 | 此模式提供預先建置的範例 JAR 檔案。此檔案會在休眠 30 秒並結束`STDOUT`之前，將應用程式的環境變數輸出至 。此檔案名為 `bluAgeSample.jar`，位於 GitHub 儲存庫的 [docker 資料夾中](https://github.com/aws-samples/aws-blu-age-sample-container/tree/main/docker)。如果您想要更改程式碼並建置自己的 JAR 檔案版本，請使用位於 GitHub 儲存庫中 [./java\$1sample/src/sample\$1java\$1app.java](https://github.com/aws-samples/aws-blu-age-sample-container/tree/main/java_sample/src) 的原始程式碼。您可以使用位於 [./java\$1sample/build.sh](https://github.com/aws-samples/aws-blu-age-sample-container/tree/main/java_sample) 的建置指令碼來編譯 Java 來源並建置新的 JAR fie。 | 應用程式開發人員 | 

### 建置 Blu Age 容器
<a name="build-the-blu-age-container"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 GitHub 儲存庫。 | 使用 命令複製範本程式碼儲存庫：<pre>git clone https://github.com/aws-samples/aws-blu-age-sample-container</pre> | AWS DevOps | 
| 使用 Docker 建置容器。 | 使用 Docker 建置容器，然後再將其推送至 Docker 登錄檔，例如 Amazon ECR：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.html) | AWS DevOps | 
| 測試 Blu Age 容器。 | （選用） 如有必要，請使用 命令在本機測試容器：<pre>docker run -it <tag> /bin/bash</pre> | AWS DevOps | 
| 驗證至您的 Docker 儲存庫。 | 如果您打算使用 Amazon ECR，請遵循 [Amazon ECR 文件](https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html)中的指示來安裝和設定 AWS CLI，並將 Docker CLI 驗證為您的預設登錄檔。我們建議您使用 [get-login-password 命令](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/get-login-password.html)進行身分驗證。  如果您使用**檢視推送命令**按鈕，[Amazon ECR 主控台](https://console.aws.amazon.com/ecr/)會提供此命令的預先填入版本。如需詳細資訊，請參閱 [Amazon ECR 文件](https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-console.html)。<pre>aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account>.dkr.ecr.<region>.amazonaws.com</pre>如果您不打算使用 Amazon ECR，請遵循為容器登錄系統提供的指示。 | AWS DevOps | 
| 建立容器儲存庫。 | 在 Amazon ECR 中建立儲存庫。如需說明，請參閱 模式[使用 Terraform 部署容器化 Blu Age 應用程式的環境](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform.html)。如果您使用的是另一個容器登錄系統，請遵循該系統提供的指示。 | AWS DevOps | 
| 標記您的容器並將其推送至目標儲存庫。 | 如果您使用的是 Amazon ECR：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.html)如需詳細資訊，請參閱《*Amazon ECR 使用者指南*》中的[推送 Docker 映像](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)。 | AWS DevOps | 

## 相關資源
<a name="containerize-mainframe-workloads-that-have-been-modernized-by-blu-age-resources"></a>

**AWS 資源**
+ [AWS Blu Age 範例容器儲存庫](https://github.com/aws-samples/aws-blu-age-sample-container)
+ [在無伺服器 AWS 基礎設施上執行現代化 Blu Age 大型主機工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/run-bluage-modernized-mainframes/)
+ [使用 Terraform 部署容器化 Blu Age 應用程式的環境](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform.html)
+ [搭配 AWS CLI 使用 Amazon ECR ](https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html)(*Amazon ECR 使用者指南*)
+ [私有登錄檔身分驗證](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html) (*Amazon ECR 使用者指南*)
+ [Amazon ECS 文件](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html)
+ [Amazon EKS 文件](https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html)

**其他資源**
+ [Blu Age 網站](https://www.bluage.com/)
+ [Docker 網站](https://docker.com/)

# 使用 Python 將 EBCDIC 資料轉換為 AWS 上的 ASCII
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python"></a>

*Luis Gustavo Dantas，Amazon Web Services*

## 總結
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python-summary"></a>

由於大型主機通常會託管關鍵業務資料，因此將資料遷移至 Amazon Web Services (AWS) 雲端或其他美國資訊交換標準碼 (ASCII) 環境時，現代化資料是最重要的任務之一。在大型主機上，資料通常會以延伸二進位編碼的小數交換碼 (EBCDIC) 格式進行編碼。匯出資料庫、虛擬儲存存取方法 (VSAM) 或一般檔案通常會產生封裝的二進位 EBCDIC 檔案，這些檔案更複雜的遷移。最常用的資料庫遷移解決方案是變更資料擷取 (CDC)，在大多數情況下會自動轉換資料編碼。不過，CDC 機制可能無法用於這些資料庫、VSAM 或一般檔案。對於這些檔案，需要替代方法來現代化資料。

此模式說明如何透過將其轉換為 ASCII 格式來現代化 EBCDIC 資料。轉換後，您可以將資料載入分散式資料庫，或讓雲端中的應用程式直接處理資料。模式會使用[mainframe-data-utilities](https://github.com/aws-samples/mainframe-data-utilities) GitHub 儲存庫中的轉換指令碼和範例檔案。

## 先決條件和限制
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ EBCDIC 輸入檔案及其對應的常見商業導向語言 (COBOL) 複製本。範例 EBCDIC 檔案和 COBOL 複製手冊包含在[mainframe-data-utilities](https://github.com/aws-samples/mainframe-data-utilities) GitHub 儲存庫中。如需 COBOL 複本手冊的詳細資訊，請參閱 IBM 網站上的[適用於 z/OS 6.4 的企業 COBOL 程式設計指南](https://publibfp.dhe.ibm.com/epubs/pdf/igy6pg40.pdf)。

**限制**
+ 不支援 COBOL 程式中定義的檔案配置。它們必須單獨提供。

**產品版本**
+ Python 3.8 版或更新版本

## Architecture
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python-architecture"></a>

**來源技術堆疊**
+ 大型主機上的 EBCDIC 資料
+ COBOL 複製手冊

**目標技術堆疊**
+ 虛擬私有雲端 (VPC) 中的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體
+ Amazon Elastic Block Store (Amazon EBS)
+ Python 及其所需的套件、JavaScript 物件標記法 (JSON)、sys 和日期時間
+ ASCII 平面檔案已準備好供現代應用程式讀取或載入關聯式資料庫資料表

**目標架構**

![\[使用 Python 指令碼和 COBOL 複製手冊，在 EC2 執行個體上將 EBCDIC 資料轉換為 ASCII\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f5907bfe-7dff-4cd0-8523-57015ad48c4b/images/4f97b1dd-3f20-4966-a291-22180680ea99.png)


架構圖顯示將 EBCDIC 檔案轉換為 EC2 執行個體上 ASCII 檔案的程序：

1. 使用 **parse\$1copybook\$1to\$1json.py** 指令碼，您可以將 COBOL 複製手冊轉換為 JSON 檔案。

1. 使用 JSON 檔案和 **extract\$1ebcdic\$1to\$1ascii.py** 指令碼，您可以將 EBCDIC 資料轉換為 ASCII 檔案。

**自動化和擴展**

在第一個手動檔案轉換所需的資源就緒之後，您就可以自動化檔案轉換。此模式不包含自動化的指示。有多種方法可自動化轉換。以下是一種可能方法的概觀：

1. 將 AWS Command Line Interface (AWS CLI) 和 Python 指令碼命令封裝為 shell 指令碼。

1. 建立 AWS Lambda 函數，以非同步方式將 shell 指令碼任務提交至 EC2 執行個體。如需詳細資訊，請參閱[使用 AWS Lambda 排程 SSH 任務](https://aws.amazon.com/blogs/compute/scheduling-ssh-jobs-using-aws-lambda/)。

1. 建立 Amazon Simple Storage Service (Amazon S3) 觸發程序，在每次上傳舊版檔案時叫用 Lambda 函數。如需詳細資訊，請參閱[使用 Amazon S3 觸發來叫用 Lambda 函數](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html)。

## 工具
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/?id=docs_gateway) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，並快速向上或向下擴展。
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 提供區塊層級儲存磁碟區，可與 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體搭配使用。
+ [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 資源的存取。

**其他工具**
+ [GitHub](https://github.com/) 是一種程式碼託管服務，可提供協作工具和版本控制。
+ [Python](https://www.python.org/) 是一種高階程式設計語言。

**程式碼儲存庫**

此模式的程式碼可在[mainframe-data-utilities](https://github.com/aws-samples/mainframe-data-utilities) GitHub 儲存庫中使用。

## 史詩
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python-epics"></a>

### 準備 EC2 執行個體
<a name="prepare-the-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動 EC2 執行個體。 | EC2 執行個體必須具有傳出網際網路存取。這可讓執行個體存取 GitHub 上可用的 Python 原始程式碼。若要建立執行個體：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html) | 一般 AWS | 
| 安裝 Git。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html) | 一般 AWS、Linux | 
| 安裝 Python。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html) | 一般 AWS、Linux | 
| 複製 GitHub 儲存庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html) | 一般 AWS、GitHub | 

### 從 EBCDIC 資料建立 ASCII 檔案
<a name="create-the-ascii-file-from-the-ebcdic-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 COBOL 複製手冊剖析到 JSON 配置檔案中。 | 在 `mainframe-data-utilities` 資料夾內，執行 **parse\$1copybook\$1to\$1json.py **指令碼。此自動化模組會從 COBOL 複製手冊讀取檔案配置，並建立 JSON 檔案。JSON 檔案包含從來源檔案解譯和擷取資料所需的資訊。這會從 COBOL 複製手冊建立 JSON 中繼資料。下列命令會將 COBOL 複製手冊轉換為 JSON 檔案。<pre>python3 parse_copybook_to_json.py \<br />-copybook LegacyReference/COBPACK2.cpy \<br />-output sample-data/cobpack2-list.json \<br />-dict sample-data/cobpack2-dict.json \<br />-ebcdic sample-data/COBPACK.OUTFILE.txt \<br />-ascii sample-data/COBPACK.ASCII.txt \<br />-print 10000</pre>指令碼會列印收到的引數。<pre>-----------------------------------------------------------------------<br />Copybook file...............| LegacyReference/COBPACK2.cpy<br />Parsed copybook (JSON List).| sample-data/cobpack2-list.json<br />JSON Dict (documentation)...| sample-data/cobpack2-dict.json<br />ASCII file..................| sample-data/COBPACK.ASCII.txt<br />EBCDIC file.................| sample-data/COBPACK.OUTFILE.txt<br />Print each..................| 10000<br />-----------------------------------------------------------------------</pre>如需引數的詳細資訊，請參閱 GitHub 儲存庫中的 [README 檔案](https://github.com/aws-samples/mainframe-data-utilities/blob/main/README.md)。 | 一般 AWS、Linux | 
| 檢查 JSON 配置檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html)<pre> "input": "extract-ebcdic-to-ascii/COBPACK.OUTFILE.txt",<br /> "output": "extract-ebcdic-to-ascii/COBPACK.ASCII.txt",<br /> "max": 0,<br /> "skip": 0,<br /> "print": 10000,<br /> "lrecl": 150,<br /> "rem-low-values": true,<br /> "separator": "|",<br /> "transf": [<br /> {<br /> "type": "ch",<br /> "bytes": 19,<br /> "name": "OUTFILE-TEXT"<br /> } </pre>JSON 配置檔案最重要的屬性為：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html)如需 JSON 配置檔案的詳細資訊，請參閱 GitHub 儲存庫中的[README 檔案](https://github.com/aws-samples/mainframe-data-utilities/blob/main/README.md)。 | 一般 AWS、JSON | 
| 建立 ASCII 檔案。 | 執行 **extract\$1ebcdic\$1to\$1ascii.py** 指令碼，此指令碼包含在複製的 GitHub 儲存庫中。此指令碼會讀取 EBCDIC 檔案，並寫入已轉換且可讀取的 ASCII 檔案。<pre>python3 extract_ebcdic_to_ascii.py -local-json sample-data/cobpack2-list.json</pre>當指令碼處理 EBCDIC 資料時，它會列印每批次 10，000 筆記錄的訊息。請參閱以下範例。<pre>------------------------------------------------------------------<br />2023-05-15 21:21:46.322253 | Local Json file   | -local-json | sample-data/cobpack2-list.json<br />2023-05-15 21:21:47.034556 | Records processed | 10000<br />2023-05-15 21:21:47.736434 | Records processed | 20000<br />2023-05-15 21:21:48.441696 | Records processed | 30000<br />2023-05-15 21:21:49.173781 | Records processed | 40000<br />2023-05-15 21:21:49.874779 | Records processed | 50000<br />2023-05-15 21:21:50.705873 | Records processed | 60000<br />2023-05-15 21:21:51.609335 | Records processed | 70000<br />2023-05-15 21:21:52.292989 | Records processed | 80000<br />2023-05-15 21:21:52.938366 | Records processed | 89280<br />2023-05-15 21:21:52.938448 Seconds 6.616232</pre>如需如何變更列印頻率的資訊，請參閱 GitHub 儲存庫中的 [README 檔案](https://github.com/aws-samples/mainframe-data-utilities/blob/main/README.md)。 | 一般 AWS | 
| 檢查 ASCII 檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html)如果您使用提供的範例 EBCDIC 檔案，以下是 ASCII 檔案中的第一個記錄。<pre>00000000: 2d30 3030 3030 3030 3030 3130 3030 3030  -000000000100000<br />00000010: 3030 307c 3030 3030 3030 3030 3031 3030  000|000000000100<br />00000020: 3030 3030 3030 7c2d 3030 3030 3030 3030  000000|-00000000<br />00000030: 3031 3030 3030 3030 3030 7c30 7c30 7c31  0100000000|0|0|1<br />00000040: 3030 3030 3030 3030 7c2d 3130 3030 3030  00000000|-100000<br />00000050: 3030 307c 3130 3030 3030 3030 307c 2d31  000|100000000|-1<br />00000060: 3030 3030 3030 3030 7c30 3030 3030 7c30  00000000|00000|0<br />00000070: 3030 3030 7c31 3030 3030 3030 3030 7c2d  0000|100000000|-<br />00000080: 3130 3030 3030 3030 307c 3030 3030 3030  100000000|000000<br />00000090: 3030 3030 3130 3030 3030 3030 307c 2d30  0000100000000|-0<br />000000a0: 3030 3030 3030 3030 3031 3030 3030 3030  0000000001000000<br />000000b0: 3030 7c41 7c41 7c0a                      00|A|A|.</pre> | 一般 AWS、Linux | 
| 評估 EBCDIC 檔案。 | 在 Amazon EC2 主控台中，輸入下列命令。這會開啟 EBCDIC 檔案的第一個記錄。<pre>head sample-data/COBPACK.OUTFILE.txt -c 150 | xxd</pre>如果您使用範例 EBCDIC 檔案，結果如下。<pre> 00000000: 60f0 f0f0 f0f0 f0f0 f0f0 f1f0 f0f0 f0f0 `...............<br /> 00000010: f0f0 f0f0 f0f0 f0f0 f0f0 f0f0 f1f0 f0f0 ................<br /> 00000020: f0f0 f0f0 f0f0 f0f0 f0f0 f0f0 f0f0 f1f0 ................<br /> 00000030: f0f0 f0f0 f0f0 d000 0000 0005 f5e1 00fa ................<br /> 00000040: 0a1f 0000 0000 0005 f5e1 00ff ffff fffa ................<br /> 00000050: 0a1f 0000 000f 0000 0c10 0000 000f 1000 ................<br /> 00000060: 0000 0d00 0000 0000 1000 0000 0f00 0000 ................<br /> 00000070: 0000 1000 0000 0dc1 c100 0000 0000 0000 ................<br /> 00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................<br /> 00000090: 0000 0000 0000 ......</pre>若要評估來源和目標檔案之間的等效性，需要 EBCDIC 的完整知識。例如，範例 EBCDIC 檔案的第一個字元是連字號 (`-`)。在 EBCDIC 檔案的十六進位表示法中，此字元以 表示`60`，而在 ASCII 檔案的十六進位表示法中，此字元以 表示`2D`。如需 EBCDIC-to-ASCII轉換表，請參閱 IBM 網站上的 [EBCDIC 至 ASCII](https://www.ibm.com/docs/en/iis/11.3?topic=tables-ebcdic-ascii)。 | 一般 AWS、Linux、EBCDIC | 

## 相關資源
<a name="convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python-resources"></a>

**參考**
+ [EBCDIC 字元集 ](https://www.ibm.com/docs/en/zos-basic-skills?topic=mainframe-ebcdic-character-set)(IBM 文件）
+ [EBCDIC 到 ASCII](https://www.ibm.com/docs/en/iis/11.3?topic=tables-ebcdic-ascii) (IBM 文件）
+ [COBOL](https://www.ibm.com/docs/en/i/7.1?topic=languages-cobol) (IBM 文件）
+ [基本 JCL 概念](https://www.ibm.com/docs/en/zos-basic-skills?topic=collection-basic-jcl-concepts) (IBM 文件）
+ [連線至 Linux 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html) (Amazon EC2 文件）

**教學課程**
+ [使用 AWS Lambda 排程 SSH 任務](https://aws.amazon.com/blogs/compute/scheduling-ssh-jobs-using-aws-lambda/) (AWS 部落格文章）
+ [使用 Amazon S3 觸發來叫用 Lambda 函數](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html) (AWS Lambda 文件）

# 使用 Amazon S3 將大型主機檔案從 EBCDIC 格式轉換為字元分隔 ASCII 格式 AWS Lambda
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda"></a>

*Luis Gustavo Dantas，Amazon Web Services*

## 總結
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-summary"></a>

此模式說明如何啟動 AWS Lambda 函數，自動將大型主機延伸二進位編碼十進位交換碼 (EBCDIC) 檔案轉換為字元分隔的美國資訊交換標準碼 (ASCII) 檔案。Lambda 函數會在 ASCII 檔案上傳至 Amazon Simple Storage Service (Amazon S3) 儲存貯體後執行。在檔案轉換之後，您可以讀取以 x86 為基礎的工作負載上的 ASCII 檔案，或將檔案載入現代資料庫。

此模式中示範的檔案轉換方法可協助您克服在現代環境中使用 EBCDIC 檔案的挑戰。以 EBCDIC 編碼的檔案通常包含以二進位或封裝小數格式表示的資料，欄位為固定長度。這些特性會產生障礙，因為現代 x86 型工作負載或分散式環境通常使用 ASCII 編碼資料，且無法處理 EBCDIC 檔案。

## 先決條件和限制
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ Amazon S3 儲存貯體
+ 具有管理許可的 AWS Identity and Access Management (IAM) 使用者
+ AWS CloudShell
+ [Python 3.8.0](https://www.python.org/downloads/release/python-380/) 或更新版本
+ 以 EBCDIC 及其對應資料結構編碼的平面檔案，採用常見的商業導向語言 (COBOL) 複製本

**注意**  
此模式使用範例 EBCDIC 檔案 ([CLIENT.EBCDIC.txt](https://github.com/aws-samples/mainframe-data-utilities/blob/main/sample-data/CLIENT.EBCDIC.txt)) 及其對應的 COBOL 複製手冊 ([COBKS05.cpy)。](https://github.com/aws-samples/mainframe-data-utilities/blob/main/LegacyReference/COBKS05.cpy)這兩個檔案都可在 GitHub [mainframe-data-utilities](https://github.com/aws-samples/mainframe-data-utilities)儲存庫中使用。

**限制**
+ COBOL 複製手冊通常包含多個配置定義。[mainframe-data-utilities](https://github.com/aws-samples/mainframe-data-utilities) 專案可以剖析這種類型的複製手冊，但無法推斷要在資料轉換時考慮哪種配置。這是因為複製手冊不會保留此邏輯 （而是保留在 COBOL 程式中）。因此，在剖析複製手冊之後，您必須手動設定用於選取配置的規則。
+ 此模式受限於 [Lambda 配額](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)。

## Architecture
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-architecture"></a>

**來源技術堆疊**
+ IBM z/OS、IBM i 和其他 EBCDIC 系統
+ 具有以 EBCDIC 編碼資料的序列檔案 （例如 IBM Db2 卸載）
+ COBOL 複製手冊

**目標技術堆疊**
+ Amazon S3
+ Amazon S3 事件通知
+ IAM
+ Lambda 函式
+ Python 3.8 或更高版本
+ 大型主機資料公用程式
+ JSON 中繼資料
+ 字元分隔 ASCII 檔案

**目標架構**

下圖顯示將大型主機 EBCDIC 檔案轉換為 ASCII 檔案的架構。

![\[將大型主機 EBCDIC 檔案轉換為 ASCII 檔案的架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/97ab4129-2639-4733-86cb-962d91526df4/images/3ca7ca44-373a-434f-8c40-09e7c2abf5ec.png)


該圖顯示以下工作流程：

1. 使用者執行複製手冊剖析器指令碼，將 COBOL 複製手冊轉換為 JSON 檔案。

1. 使用者將 JSON 中繼資料上傳至 Amazon S3 儲存貯體。這可讓資料轉換 Lambda 函數讀取中繼資料。

1. 使用者或自動化程序會將 EBCDIC 檔案上傳至 Amazon S3 儲存貯體。

1. Amazon S3 通知事件會觸發資料轉換 Lambda 函數。

1. AWS 驗證 Lambda 函數的 Amazon S3 儲存貯體讀寫許可。

1. Lambda 會從 Amazon S3 儲存貯體讀取檔案，並在本機將檔案從 EBCDIC 轉換為 ASCII。

1. Lambda 會在 Amazon CloudWatch 中記錄程序狀態。

1. Lambda 會將 ASCII 檔案寫回 Amazon S3。

**注意**  
複製手冊剖析器指令碼會執行一次，以將中繼資料轉換為 JSON 格式，隨後會存放在 Amazon S3 儲存貯體中。在初始轉換之後，在 Amazon S3 儲存貯體中參考相同 JSON 檔案的所有後續 EBCDIC 檔案將使用現有的中繼資料組態。

## 工具
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-tools"></a>

**AWS 服務**
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 可協助您 AWS 即時監控 AWS 資源的指標，以及您在其上執行的應用程式。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) 是一種瀏覽器型 shell，您可以使用 AWS Command Line Interface (AWS CLI) 和一系列預先安裝的開發工具 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) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。Lambda 只會在需要時執行程式碼並自動擴展，因此您只需支付您使用的運算時間。

**其他工具**
+ [GitHub](https://github.com/) 是一種程式碼託管服務，可提供協作工具和版本控制。
+ [Python](https://www.python.org/) 是一種高階程式設計語言。

**Code**

此模式的程式碼可在 GitHub [mainframe-data-utilities](https://github.com/aws-samples/mainframe-data-utilities)儲存庫中使用。

## 最佳實務
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-best-practices"></a>

請考慮下列最佳實務：
+ 在 Amazon Resource Name (ARN) 層級設定必要的許可。
+ 一律授予 IAM 政策的最低權限許可。如需詳細資訊，請參閱 [IAM 文件中的 IAM 安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)。

## 史詩
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-epics"></a>

### 建立環境變數和工作資料夾
<a name="create-environment-variables-and-a-working-folder"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立環境變數。 | 將下列環境變數複製到文字編輯器，然後將下列範例中`<placeholder>`的值取代為您的資源值：<pre>bucket=<your_bucket_name><br />account=<your_account_number><br />region=<your_region_code></pre>您將建立 Amazon S3 儲存貯體的參考 AWS 帳戶，以及 AWS 區域 更新版本。若要定義環境變數，請開啟 [CloudShell 主控台](https://console.aws.amazon.com/cloudshell/)，然後將更新後的環境變數複製並貼到命令列。每次 CloudShell 工作階段重新啟動時，您必須重複此步驟。 | 一般 AWS | 
| 建立工作資料夾。 | 若要在稍後簡化資源清除程序，請執行下列命令，在 CloudShell 中建立工作資料夾：<pre>mkdir workdir; cd workdir</pre>每次失去與 CloudShell 工作階段的連線時，您必須將目錄變更為工作目錄 (`workdir`)。 | 一般 AWS | 

### 定義 IAM 角色和政策
<a name="define-an-iam-role-and-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Lambda 函數的信任政策。 | EBCDIC 轉換器會在 Lambda 函數中執行。函數必須具有 IAM 角色。在建立 IAM 角色之前，您必須定義信任政策文件，讓資源能夠擔任該政策。從 CloudShell 工作資料夾中，執行下列命令來建立政策文件：<pre>E2ATrustPol=$(cat <<EOF<br />{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Effect": "Allow",<br />            "Principal": {<br />                "Service": "lambda.amazonaws.com"<br />            },<br />            "Action": "sts:AssumeRole"<br />        }<br />    ]<br />}<br />EOF<br />)<br />printf "$E2ATrustPol" > E2ATrustPol.json</pre> | 一般 AWS | 
| 建立用於 Lambda 轉換的 IAM 角色。 | 若要建立 IAM 角色，請從 CloudShell 工作資料夾執行下列 AWS CLI 命令：<pre>aws iam create-role --role-name E2AConvLambdaRole --assume-role-policy-document file://E2ATrustPol.json</pre> | 一般 AWS | 
| 建立 Lambda 函數的 IAM 政策文件。 | Lambda 函數必須具有 Amazon S3 儲存貯體的讀寫存取權，以及 Amazon CloudWatch Logs 的寫入許可。若要建立 IAM 政策，請從 CloudShell 工作資料夾執行下列命令：<pre>E2APolicy=$(cat <<EOF<br />{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Sid": "Logs",<br />            "Effect": "Allow",<br />            "Action": [<br />                "logs:PutLogEvents",<br />                "logs:CreateLogStream",<br />                "logs:CreateLogGroup"<br />            ],<br />            "Resource": [<br />                "arn:aws:logs:*:*:log-group:*",<br />                "arn:aws:logs:*:*:log-group:*:log-stream:*"<br />            ]<br />        },<br />        {<br />            "Sid": "S3",<br />            "Effect": "Allow",<br />            "Action": [<br />                "s3:GetObject",<br />                "s3:PutObject",<br />                "s3:GetObjectVersion"<br />            ],<br />            "Resource": [<br />                "arn:aws:s3:::%s/*",<br />                "arn:aws:s3:::%s"<br />            ]<br />        }<br />    ]<br />}<br />EOF<br />)<br />printf "$E2APolicy" "$bucket" "$bucket" > E2AConvLambdaPolicy.json</pre> | 一般 AWS | 
| 將 IAM 政策文件連接至 IAM 角色。 | 若要將 IAM 政策連接至 IAM 角色，請從 CloudShell 工作資料夾輸入下列命令：<pre>aws iam put-role-policy --role-name E2AConvLambdaRole --policy-name E2AConvLambdaPolicy --policy-document file://E2AConvLambdaPolicy.json</pre> | 一般 AWS | 

### 建立用於 EBCDIC 轉換的 Lambda 函數
<a name="create-the-lam-function-for-ebcdic-conversion"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載 EBCDIC 轉換原始程式碼。 | 從 CloudShell 工作資料夾中，執行下列命令，從 GitHub 下載 mainframe-data-utilities 原始碼：<pre>git clone https://github.com/aws-samples/mainframe-data-utilities.git mdu</pre> | 一般 AWS | 
| 建立 ZIP 套件。 | 從 CloudShell 工作資料夾中，輸入下列命令來建立 ZIP 套件，以建立用於 EBCDIC 轉換的 Lambda 函數：<pre>cd mdu; zip ../mdu.zip *.py; cd ..</pre> | 一般 AWS | 
| 建立 Lambda 函數。 | 從 CloudShell 工作資料夾中，輸入下列命令來建立用於 EBCDIC 轉換的 Lambda 函數：<pre>aws lambda create-function \<br />--function-name E2A \<br />--runtime python3.9 \<br />--zip-file fileb://mdu.zip \<br />--handler extract_ebcdic_to_ascii.lambda_handler \<br />--role arn:aws:iam::$account:role/E2AConvLambdaRole \<br />--timeout 10 \<br />--environment "Variables={layout=$bucket/layout/}"</pre> 環境變數配置會告知 Lambda 函數 JSON 中繼資料所在的位置。 | 一般 AWS | 
| 建立 Lambda 函數的資源型政策。 | 從 CloudShell 工作資料夾中，輸入下列命令，以允許 Amazon S3 事件通知觸發 Lambda 函數以進行 EBCDIC 轉換：<pre>aws lambda add-permission \<br />--function-name E2A \<br />--action lambda:InvokeFunction \<br />--principal s3.amazonaws.com \<br />--source-arn arn:aws:s3:::$bucket \<br />--source-account $account \<br />--statement-id 1</pre> | 一般 AWS | 

### 建立 Amazon S3 事件通知
<a name="create-the-s3-event-notification"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon S3 事件通知的組態文件。 | 當檔案放置在輸入資料夾中時，Amazon S3 事件通知會啟動 EBCDIC 轉換 Lambda 函數。從 CloudShell 工作資料夾中，執行下列命令來建立 Amazon S3 事件通知的 JSON 文件：<pre>S3E2AEvent=$(cat <<EOF<br />{<br />"LambdaFunctionConfigurations": [<br />    {<br />      "Id": "E2A",<br />      "LambdaFunctionArn": "arn:aws:lambda:%s:%s:function:E2A",<br />      "Events": [ "s3:ObjectCreated:Put" ],<br />      "Filter": {<br />        "Key": {<br />          "FilterRules": [<br />            {<br />              "Name": "prefix",<br />              "Value": "input/"<br />            }<br />          ]<br />        }<br />      }<br />    }<br />  ]<br />}<br />EOF<br />)<br />printf "$S3E2AEvent" "$region" "$account" > S3E2AEvent.json</pre> | 一般 AWS | 
| 建立 Amazon S3 事件通知。 | 從 CloudShell 工作資料夾中，輸入下列命令來建立 Amazon S3 事件通知：<pre>aws s3api put-bucket-notification-configuration --bucket $bucket --notification-configuration file://S3E2AEvent.json</pre> | 一般 AWS | 

### 建立和上傳 JSON 中繼資料
<a name="create-and-upload-the-json-metadata"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 剖析 COBOL 複製手冊。 | 從 CloudShell 工作資料夾中，輸入下列命令，將範例 COBOL 複製手冊剖析為 JSON 檔案 （定義如何正確讀取和分割資料檔案）：<pre>python3       mdu/parse_copybook_to_json.py \<br />-copybook     mdu/LegacyReference/COBKS05.cpy \<br />-output       CLIENT.json \<br />-output-s3key CLIENT.ASCII.txt \<br />-output-s3bkt $bucket \<br />-output-type  s3 \<br />-print        25</pre> | 一般 AWS | 
| 新增轉換規則。 | 範例資料檔案及其對應的 COBOL 複製手冊是多配置檔案。這表示轉換必須根據特定規則分割資料。在此情況下，每一列位置 3 和 4 上的位元組會定義配置。從 CloudShell 工作資料夾中，編輯 `CLIENT.json` 檔案並將內容從 `"transf-rule": [],` 變更為下列項目：<pre>"transf-rule": [<br />{<br />"offset": 4,<br />"size": 2,<br />"hex": "0002",<br />"transf": "transf1"<br />},<br />{<br />"offset": 4,<br />"size": 2,<br />"hex": "0000",<br />"transf": "transf2"<br />}<br />],</pre> | General AWS、IBM Mainframe、Cobol | 
| 將 JSON 中繼資料上傳至 Amazon S3 儲存貯體。 | 從 CloudShell 工作資料夾中，輸入下列 AWS CLI 命令，將 JSON 中繼資料上傳至您的 Amazon S3 儲存貯體：<pre>aws s3 cp CLIENT.json s3://$bucket/layout/CLIENT.json</pre> | 一般 AWS | 

### 轉換 EBCDIC 檔案
<a name="convert-the-ebcdic-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 EBCDIC 檔案傳送至 Amazon S3 儲存貯體。 | 從 CloudShell 工作資料夾中，輸入下列命令將 EBCDIC 檔案傳送至 Amazon S3 儲存貯體：<pre>aws s3 cp mdu/sample-data/CLIENT.EBCDIC.txt s3://$bucket/input/</pre> 我們建議您為輸入 (EBCDIC) 和輸出 (ASCII) 檔案設定不同的資料夾，以避免在 ASCII 檔案上傳至 Amazon S3 儲存貯體時再次呼叫 Lambda 轉換函數。 | 一般 AWS | 
| 檢查輸出。 | 從 CloudShell 工作資料夾中，輸入下列命令來檢查 ASCII 檔案是否在您的 Amazon S3 儲存貯體中產生：<pre>aws s3 ls s3://$bucket/</pre> 資料轉換可能需要幾秒鐘的時間才會發生。建議您檢查 ASCII 檔案幾次。在 ASCII 檔案可用後，輸入下列命令以檢視 Amazon S3 儲存貯體中轉換後檔案的內容。您可以視需要從 Amazon S3 儲存貯體下載或使用它：<pre>aws s3 cp s3://$bucket/CLIENT.ASCII.txt - | head</pre>檢查 ASCII 檔案內容：<pre>0|0|220|<br />1|1|HERBERT MOHAMED|1958-08-31|BACHELOR|0010000.00|<br />1|2|36|THE ROE AVENUE|<br />2|1|JAYLEN GEORGE|1969-05-29|ELEMENTARY|0020000.00|<br />2|2|365|HEATHFIELD ESPLANADE|<br />3|1|MIKAEEL WEBER|1982-02-17|MASTER|0030000.00|<br />3|2|4555|MORRISON STRAND|<br />4|1|APRIL BARRERA|1967-01-12|DOCTOR|0030000.00|<br />4|2|1311|MARMION PARK|<br />5|1|ALEEZA PLANT|1985-03-01|BACHELOR|0008000.00|</pre> | 一般 AWS | 

### 清除環境
<a name="clean-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| （選用） 準備變數和資料夾。 | 如果您失去與 CloudShell 的連線，請重新連線，然後輸入下列命令將目錄變更為工作資料夾：<pre>cd workdir</pre>確定已定義環境變數：<pre>bucket=<your_bucket_name><br />account=<your_account_number><br />region=<your_region_code></pre> | 一般 AWS | 
| 移除儲存貯體的通知組態。 | 從 CloudShell 工作資料夾中，執行下列命令來移除 Amazon S3 事件通知組態：<pre>aws s3api put-bucket-notification-configuration \<br />--bucket=$bucket \<br />--notification-configuration="{}"</pre> | 一般 AWS | 
| 刪除 Lambda 函數。 | 從 CloudShell 工作資料夾中，輸入下列命令來刪除 EBCDIC 轉換器的 Lambda 函數：<pre>aws lambda delete-function \<br />--function-name E2A</pre> | 一般 AWS | 
| 刪除 IAM 角色和政策。 | 從 CloudShell 工作資料夾中，輸入下列命令來移除 EBCDIC 轉換器角色和政策：<pre>aws iam delete-role-policy \<br />--role-name E2AConvLambdaRole \<br />--policy-name E2AConvLambdaPolicy<br /><br />aws iam delete-role \<br />--role-name E2AConvLambdaRole</pre> | 一般 AWS | 
| 刪除 Amazon S3 儲存貯體中產生的檔案。 | 從 CloudShell 工作資料夾中，輸入下列命令來刪除 Amazon S3 儲存貯體中產生的檔案：<pre>aws s3 rm s3://$bucket/layout --recursive<br />aws s3 rm s3://$bucket/input --recursive<br />aws s3 rm s3://$bucket/CLIENT.ASCII.txt</pre> | 一般 AWS | 
| 刪除工作資料夾。 | 從 CloudShell 工作資料夾中，輸入下列命令來移除 `workdir`及其內容：<pre>cd ..; rm -Rf workdir</pre> | 一般 AWS | 

## 相關資源
<a name="convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda-resources"></a>
+ [大型主機資料公用程式 README](https://github.com/aws-samples/mainframe-data-utilities/blob/main/README.md) (GitHub)
+ [EBCDIC 字元集 ](https://www.ibm.com/docs/en/zos-basic-skills?topic=mainframe-ebcdic-character-set)(IBM 文件）
+ [EBCDIC 到 ASCII](https://www.ibm.com/docs/en/iis/11.7.0?topic=tables-ebcdic-ascii) (IBM 文件）
+ [COBOL](https://www.ibm.com/docs/en/i/7.6.0?topic=languages-cobol) (IBM 文件）
+ [使用 Amazon S3 觸發來叫用 Lambda 函數 ](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html)(AWS Lambda 文件）

# 使用 Micro Focus 轉換具有複雜記錄配置的大型主機資料檔案
<a name="convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus"></a>

*Peter West，Amazon Web Services*

## 總結
<a name="convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus-summary"></a>

注意： AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

此模式說明如何使用 Micro Focus 結構檔案，將具有非文字資料和複雜記錄配置的大型主機資料檔案，從 EBCDIC （延伸二進位編碼十進位交換碼） 字元編碼轉換為 ASCII （美國資訊交換標準碼） 字元編碼。若要完成檔案轉換，您必須執行下列動作：

1. 準備單一來源檔案，描述大型主機環境中所有資料項目和記錄配置。

1. 使用 Micro Focus 資料檔案編輯器作為 Micro Focus Classic Data File Tools 或 Data File Tools 的一部分，建立包含資料記錄配置的結構檔案。結構檔案會識別非文字資料，讓您可以正確地將大型主機檔案從 EBCDIC 轉換為 ASCII。

1. 使用傳統資料檔案工具或資料檔案工具測試結構檔案。

## 先決條件和限制
<a name="convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Micro Focus Enterprise Developer for Windows，可透過 [AWS Mainframe Modernization](https://aws.amazon.com/mainframe-modernization/) 取得

**產品版本**
+ Micro Focus Enterprise Server 7.0 及更新版本

## 工具
<a name="convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus-tools"></a>
+ [Micro Focus Enterprise Developer](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/GUID-8D6B7358-AC35-4DAF-A445-607D8D97EBB2.html) 為使用 Enterprise Developer 的任何整合開發環境 (IDE) 變體建立的應用程式提供執行環境。
+ Micro Focus [Classic Data File Tools](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/GUID-06115324-0FBC-4CB7-BE9D-04BCFEA5821A.html) 可協助您轉換、導覽、編輯和建立資料檔案。傳統資料檔案工具包括[資料檔案轉換器](https://www.microfocus.com/documentation/visual-cobol/vc60/VS2017/BKFHFHDFCV.html)、[記錄配置編輯器](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/BKFHFHRLMF.html)和[資料檔案編輯器](https://www.microfocus.com/documentation/visual-cobol/vc60/VS2017/BKFHFHDFED.html)。
+ Micro Focus [資料檔案工具](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/GUID-B1BCB613-6947-451C-8F71-72FB8254076A.html)可協助您建立、編輯和移動資料檔案。資料檔案工具包括[資料檔案編輯器](https://www.microfocus.com/documentation/visual-cobol/vc60/VS2017/BKFHFHDFED.html)、[檔案轉換公用程式](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/BKFHFHCONV.html)和[資料檔案結構命令列公用程式](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/GUID-E84348EB-A93A-481A-A47C-61B0E1C076E6.html)。

## 史詩
<a name="convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus-epics"></a>

### 準備來源檔案
<a name="prepare-the-source-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別來源元件。 | 識別檔案的所有可能記錄配置，包括包含非文字資料的任何重新定義。如果您有包含重新定義的配置，您必須將這些配置分解為唯一配置，描述資料結構的每個可能變動。一般而言，資料檔案的記錄配置可以由下列原型描述：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html)如需為包含複雜記錄配置的檔案建立平面化記錄配置的詳細資訊，請參閱[在 ASCII 環境中託管 EBCDIC 應用程式以進行大型主機遷移](https://docs.aws.amazon.com/prescriptive-guidance/latest/mainframe-rehost-ebcdic-ascii/introduction.html)。 | 應用程式開發人員 | 
| 識別記錄配置條件。 | 對於具有多個記錄配置的檔案，或包含複雜配置且具有 REDEFINES 子句的檔案，請識別記錄中的資料和條件，供您用來定義轉換期間要使用的配置。我們建議您與主題專家 (SME) 討論此任務，該專家了解處理這些檔案的程式。例如，檔案可能包含兩種包含非文字資料的記錄類型。您可以檢查來源，並可能找到類似下列的程式碼：<pre>MOVE "M" TO PART-TYPE<br /> MOVE "MAIN ASSEMBLY" TO PART-NAME<br />MOVE "S" TO PART-TYPE<br /> MOVE "SUB ASSEMBLY 1" TO PART-NAME</pre>此程式碼可協助您識別下列項目：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html)您可以記錄此欄位所使用的值，將記錄配置與檔案中正確的資料記錄建立關聯。 | 應用程式開發人員 | 
| 建置來源檔案。 | 如果透過多個來源檔案描述檔案，或記錄配置包含屬於 REDEFINES 子句的非文字資料，則請建立新的來源檔案，其中包含記錄配置。新程式不需要使用 SELECT 和 FD 陳述式描述檔案。程式可以直接在 Working-Storage 中將記錄描述包含為 01 個層級。您可以為每個資料檔案建立來源檔案，或建立描述所有資料檔案的主來源檔案。 | 應用程式開發人員 | 
| 編譯來源檔案。 | 編譯來源檔案以建置資料字典。建議您使用 EBCDIC 字元集來編譯來源檔案。如果使用 IBMCOMP 指令或 ODOSLIDE 指令，則您也必須在來源檔案中使用這些指令。IBMCOMP 會影響 COMP 欄位的位元組儲存，ODOSLIDE 會影響 OCCURS VARYING 結構的填補。如果這些指令設定不正確，轉換工具將無法正確讀取資料記錄。這會導致轉換後檔案中的資料錯誤。 | 應用程式開發人員 | 

### （選項 A) 使用傳統資料檔案工具建立結構檔案
<a name="option-a-create-the-structure-file-using-classic-data-file-tools"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動工具並載入字典。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 
| 建立預設記錄配置。 | 針對不符合任何條件配置的所有記錄，使用預設記錄配置。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html)預設配置會出現在**配置**窗格中，可透過紅色資料夾圖示識別。 | 應用程式開發人員 | 
| 建立條件式記錄配置。 | 當檔案中有多個記錄配置時，請使用條件式記錄配置。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 

### （選項 B) 使用資料檔案工具建立結構檔案
<a name="option-b-create-the-structure-file-using-data-file-tools"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動工具並載入字典。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 
| 建立預設記錄配置。 | 針對不符合任何條件式配置的所有記錄，使用預設記錄配置。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html)預設配置會出現在**配置**窗格中，並且可以透過藍色「D」圖示來識別。 | 應用程式開發人員 | 
| 建立條件式記錄配置。 | 當檔案中有多個記錄配置時，請使用條件式記錄配置。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 

### （選項 A) 使用傳統資料檔案工具測試結構檔案
<a name="option-a-test-the-structure-file-using-classic-data-file-tools"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試 EBCDIC 資料檔案。 | 確認您可以使用結構檔案來正確檢視 EBCDIC 測試資料檔案。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 

### （選項 B) 使用資料檔案工具測試結構檔案
<a name="option-b-test-the-structure-file-using-data-file-tools"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試 EBCDIC 資料檔案。 | 確認您可以使用結構檔案來正確檢視 EBCDIC 測試資料檔案。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 

### 測試資料檔案轉換
<a name="test-data-file-conversion"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試 EBCDIC 檔案的轉換。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus.html) | 應用程式開發人員 | 

## 相關資源
<a name="convert-mainframe-data-files-with-complex-record-layouts-using-micro-focus-resources"></a>
+ [Micro Focus](https://www.microfocus.com/en-us/products/enterprise-suite/overview) (Micro Focus 文件）
+ [大型主機和舊版程式碼](https://aws.amazon.com/blogs/?awsf.blog-master-category=category%23mainframe-and-legacy) (AWS 部落格文章）
+ [AWS 規範指引](https://docs.aws.amazon.com/prescriptive-guidance/) (AWS 文件）
+ [AWS 文件](https://docs.aws.amazon.com/index.html) (AWS 文件）
+ [AWS 一般參考](https://docs.aws.amazon.com/general/latest/gr/Welcome.html) (AWS 文件）
+ [AWS 詞彙表](https://docs.aws.amazon.com/general/latest/gr/glos-chap.html) (AWS 文件）

# 使用 Terraform 部署容器化 Blu Age 應用程式的環境
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform"></a>

*Richard Milner-Watts，Amazon Web Services*

## 總結
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-summary"></a>

將舊版大型主機工作負載遷移至現代雲端架構，可以免除維護大型主機的成本，而這些成本只會隨著環境的老化而增加。不過，從大型主機遷移任務可能會帶來獨特的挑戰。內部資源可能不熟悉任務邏輯，與商品化、一般化 CPUs 相比，在這些特殊任務中大型主機的高效能可能很難複寫。重寫這些任務可能是一項大型任務，需要大量精力。

Blu Age 會將舊版大型主機工作負載轉換為現代 Java 程式碼，然後您可以做為容器執行。

此模式提供範例無伺服器架構，用於執行已使用 Blu Age 工具進行現代化化的容器化應用程式。隨附的 HashiCorp Terraform 檔案將建置安全架構，以協調 Blu Age 容器，同時支援批次任務和即時服務。

如需使用 Blu Age 和 AWS 服務來現代化工作負載的詳細資訊，請參閱下列 AWS 規範指引出版物：
+ [在 AWS 無伺服器基礎設施上使用 Blu Age 進行現代化的大型主機工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/run-bluage-modernized-mainframes/)
+ [容器化已由 Blu Age 現代化的大型主機工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.html)

如需使用 Blu Age 來現代化大型主機工作負載的協助，請在 Blu Age 網站上選擇**聯絡我們的專家**[，以聯絡 Blu Age](https://www.bluage.com/) 團隊。如需協助將現代化工作負載遷移至 AWS、將它們與 AWS 服務整合，並將它們移至生產環境，請聯絡您的 AWS 客戶經理或填寫 [AWS Professional Services 表單](https://pages.awscloud.com/AWS-Professional-Services.html)。

## 先決條件和限制
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-prereqs"></a>

**先決條件**
+ [Containerize 大型主機工作負載所提供的範例容器化 Blu Age 應用程式，已透過 Blu Age 模式進行現代化](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.html)。範例應用程式提供邏輯來處理現代化應用程式的輸入和輸出處理，並可與此架構整合。
+ 部署這些資源需要 Terraform。

**限制**
+ Amazon Elastic Container Service (Amazon ECS) 會限制可供容器使用的任務資源。這些資源包括 CPU、RAM 和儲存。例如，使用 Amazon ECS 搭配 AWS Fargate 時，會[套用任務資源限制](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html)。

**產品版本**

此解決方案已使用下列版本進行測試：
+ Terraform 1.3.6
+ Terraform AWS 提供者 4.46.0

## Architecture
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-architecture"></a>

**來源技術堆疊**
+ 藍齡
+ Terraform

**目標技術堆疊**
+ Amazon Aurora PostgreSQL-Compatible Edition
+ AWS Backup
+ Amazon Elastic Container Registry (Amazon ECR)
+ Amazon ECS
+ AWS Identity and Access Management Service (IAM)
+ AWS Key Management Server (AWS KMS)
+ AWS Secrets Manager
+ Amazon Simple Notification Service (Amazon SNS)
+ Amazon Simple Storage Service (Amazon S3)
+ AWS Step Functions
+ AWS Systems Manager

**目標架構**

下圖顯示解決方案架構。

![\[描述遵循圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/12825490-2622-4f0b-80c9-2c5076d50fa3/images/c0708b0a-aa36-458a-8d6c-d42e3dec7727.png)


1. 解決方案會部署下列 IAM 角色：
   + 批次任務角色
   + 批次任務執行角色
   + 服務任務角色
   + 服務任務執行角色
   + Step Functions 角色
   + AWS Backup角色
   + RDS 增強型監控角色。

   角色符合最低權限的存取原則。

1. Amazon ECR 用於存放由此模式協調的容器映像。

1. AWS Systems Manager 參數存放區會在執行時間將每個環境的組態資料提供給 Amazon ECS 任務定義。

1. AWS Secrets Manager 會在執行時間將環境的敏感組態資料提供給 Amazon ECS 任務定義。資料已由 AWS KMS 加密。

1. Terraform 模組會為所有即時和批次任務建立 Amazon ECS 任務定義。

1. Amazon ECS 使用 AWS Fargate 作為運算引擎來執行批次任務。這是短期任務，由 AWS Step Functions 視需要啟動。

1. Amazon Aurora PostgreSQL 相容提供資料庫以支援現代化應用程式。這會取代大型主機資料庫，例如 IBM Db2 或 IBM IMS 資料庫。

1. Amazon ECS 會執行長期服務，以提供現代化即時工作負載。這些無狀態應用程式會隨著跨可用區域的容器永久執行。

1. Network Load Balancer 用於授予即時工作負載的存取權。Network Load Balancer 支援舊版通訊協定，例如 IBM CICS。或者，您可以將 Application Load Balancer 與 HTTP 型工作負載搭配使用。

1. Amazon S3 為任務輸入和輸出提供物件儲存。容器應處理 Amazon S3 的提取和推送操作，以準備 Blu Age 應用程式的工作目錄。

1. AWS Step Functions 服務用於協調執行 Amazon ECS 任務以處理批次工作負載。

1. 每個批次工作負載的 SNS 主題會用來整合現代化應用程式與其他系統，例如電子郵件，或啟動其他動作，例如將輸出物件從 Amazon S3 交付至 FTP。

**注意**  
根據預設，解決方案無法存取網際網路。此模式假設虛擬私有雲端 (VPC) 將使用 [AWS Transit Gateway](https://aws.amazon.com/transit-gateway/) 等服務連接到其他網路。因此，部署了多個界面 VPC 端點，以授予對解決方案所用 AWS 服務的存取權。若要開啟直接網際網路存取，您可以使用 Terraform 模組中的切換，將 VPC 端點取代為網際網路閘道和相關聯的資源。

**自動化和擴展**

在整個模式中使用無伺服器資源有助於確保，透過向外擴展，此設計的規模幾乎沒有限制。這可減少*雜訊的鄰里問題*，例如在原始大型主機上可能遇到的運算資源競爭。批次任務可以排程為視需要同時執行。

個別容器受限於 Fargate 支援的大小上限。如需詳細資訊，請參閱 Amazon ECS 文件中的[https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-tasks-size](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-tasks-size)一節。

若要[水平擴展即時工作負載](https://nathanpeck.com/amazon-ecs-scaling-best-practices/)，您可以新增容器。

## 工具
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [AWS Backup](https://docs.aws.amazon.com/aws-backup/latest/devguide/whatisbackup.html) 是一項全受管服務，可協助您集中和自動化跨雲端和內部部署 AWS 服務的資料保護。
+ [Amazon Elastic Container Registry (Amazon ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html) 是一種受管容器映像登錄服務，安全、可擴展且可靠。
+ [Amazon Elastic Container Service (Amazon ECS)](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html) 是快速、可擴展的容器管理服務，可協助您執行、停止和管理叢集上的容器。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您以 API 呼叫 Secrets Manager，以程式設計方式擷取秘密，取代程式碼中的硬式編碼登入資料，包括密碼。
+ [Amazon Simple Notification Service (Amazon SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 可協助您協調和管理發佈者和用戶端之間的訊息交換，包括 Web 伺服器和電子郵件地址。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) 是一種無伺服器協同運作服務，可協助您結合 AWS Lambda 函數和其他 AWS 服務 來建置業務關鍵應用程式。
+ [AWS Systems Manager 參數存放區](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)為組態資料管理和秘密管理提供安全的階層式儲存。

**其他服務**
+ [HashiCorp Terraform](https://www.terraform.io/docs) 是一種基礎設施即程式碼 (IaC) 工具，可協助您使用程式碼來佈建和管理雲端基礎設施和資源。此模式使用 Terraform 來建立範例架構。

**程式碼儲存庫**

此模式的原始程式碼可在 GitHub [Blu Age Sample ECS Infrastructure (Terraform)](https://github.com/aws-samples/aws-blu-age-sample-ecs-infrastructure-using-terraform#aws-blu-age-sample-ecs-infrastructure-terraform) 儲存庫中使用。

## 最佳實務
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-best-practices"></a>
+ 對於測試環境，請使用 等功能`forceDate`來設定現代化應用程式，藉由一律在已知期間內執行 來產生一致的測試結果。
+ 個別調校每個任務，以取用最佳數量的資源。您可以使用 [Amazon CloudWatch Container Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContainerInsights.html) 來取得潛在瓶頸的指引。

## 史詩
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-epics"></a>

### 準備環境以進行部署
<a name="prepare-the-environment-for-deployment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製解決方案原始程式碼。 | 從 [GitHub 專案](https://github.com/aws-samples/aws-blu-age-sample-ecs-infrastructure-using-terraform)複製解決方案程式碼。 | DevOps 工程師 | 
| 透過部署資源來存放 Terraform 狀態來引導環境。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform.html) | DevOps 工程師 | 

### 部署解決方案基礎設施
<a name="deploy-the-solution-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱並更新 Terraform 組態。 | 在根目錄中，開啟 檔案`main.tf,`檢閱內容，並考慮進行下列更新：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform.html) | DevOps 工程師 | 
| 部署 Terraform 檔案。 | 從終端機執行 `terraform apply`命令來部署所有資源。檢閱 Terraform 產生的變更，然後輸入 **yes** 以啟動建置。請注意，部署此基礎設施可能需要超過 15 分鐘的時間。 | DevOps 工程師 | 

### （選用） 部署有效的 Blu Age 容器化應用程式
<a name="optional-deploy-a-valid-blu-age-containerized-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 Blu Age 容器映像推送至 Amazon ECR。 | 將容器推送到您在上一個 epic 中建立的 Amazon ECR 儲存庫。如需說明，請參閱 [Amazon ECR 文件](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)。記下容器映像 URI。 | DevOps 工程師 | 
| 更新 Terraform 以參考 Blu Age 容器映像。 | 更新 檔案`main.tf`** **以參考您上傳的容器映像。 | DevOps 工程師 | 
| 重新部署 Terraform 檔案。 | 從終端機執行 `terraform apply`以部署所有資源。從 Terraform 檢閱建議的更新，然後輸入 **yes** 以繼續部署。 | DevOps 工程師 | 

## 相關資源
<a name="deploy-an-environment-for-containerized-blu-age-applications-by-using-terraform-resources"></a>
+ [藍齡](https://www.bluage.com/)
+ [在 AWS 無伺服器基礎設施上使用 Blu Age 進行現代化的大型主機工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/run-bluage-modernized-mainframes/)
+ [容器化已由 Blu Age 現代化的大型主機工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/containerize-mainframe-workloads-that-have-been-modernized-by-blu-age.html)

# 使用 Quick Sight 中的 AWS Mainframe Modernization 和 Amazon Q 產生 Db2 z/OS 資料洞見
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight"></a>

*Shubham Roy、Roshna Razack 和 Santosh Kumar Singh，Amazon Web Services*

## 總結
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-summary"></a>

注意： AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

如果您的組織在 IBM Db2 大型主機環境中託管業務關鍵資料，從該資料中獲得洞見對於推動成長和創新至關重要。透過解鎖大型主機資料，您可以建立更快、安全和可擴展的商業智慧，以加速 Amazon Web Services (AWS) 雲端中的資料驅動型決策、成長和創新。

此模式提供解決方案，用於產生商業洞見，並從適用於 z/OS 資料表的 IBM Db2 中大型主機資料建立可分割敘述。大型主機資料變更會使用[AWS Mainframe Modernization 資料複寫搭配 Precisely](https://docs.aws.amazon.com/m2/latest/userguide/precisely.html) 串流至 [Amazon Managed Streaming for Apache Kafka (Amazon MSK)](https://docs.aws.amazon.com/msk/latest/developerguide/what-is-msk.html) 主題。使用 [Amazon Redshift 串流擷取](https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-streaming-ingestion.html)，Amazon MSK 主題資料會存放在 [Amazon Redshift Serverless](https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-whatis.html) 資料倉儲資料表中，以在 Amazon Quick Sight 中進行分析。

在 Quick Sight 中提供資料後，您可以使用自然語言提示搭配 [Amazon Q in Quick Sight](https://docs.aws.amazon.com/quicksight/latest/user/quicksight-gen-bi.html) 來建立資料摘要、提出問題和產生資料案例。您不需要撰寫 SQL 查詢或學習商業智慧 (BI) 工具。

**商業內容**

此模式提供大型主機資料分析和資料洞察使用案例的解決方案。使用 模式，您可以為公司資料建立視覺化儀表板。為了示範解決方案，此模式使用提供醫療、牙科和視覺計劃給美國成員的醫療保健公司。在此範例中，成員人口統計特性和計劃資訊會存放在 z/OS 資料表的 IBM Db2 中。視覺化儀表板會顯示下列項目：
+ 區域的成員分佈
+ 依性別分配成員
+ 按年齡劃分的成員分佈
+ 依計劃類型分配成員
+ 尚未完成預防性預防預防接種的成員

如需依區域和尚未完成預防性預防預防接種的成員分發的範例，請參閱其他資訊一節。

建立儀表板後，您會產生一個資料案例，說明先前分析的洞見。資料案例提供建議，以增加已完成預防性預防接種的成員人數。

## 先決條件和限制
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。此解決方案是在 Amazon Elastic Compute Cloud (Amazon EC2) 上的 Amazon Linux 2 上建置和測試。
+ 具有子網路的虛擬私有雲端 (VPC)，可由您的大型主機系統存取。
+ 具有商業資料的大型主機資料庫。如需用於建置和測試此解決方案的範例資料，請參閱*附件*一節。
+ 在 Db2 z/OS 資料表上啟用變更資料擷取 (CDC)。若要在 Db2 z/OS 上啟用 CDC，請參閱 [IBM 文件](https://www.ibm.com/docs/en/daafz/7.5?topic=cdc-enabling-data-capture-changes)。
+ 在託管來源資料庫的 z/OS 系統上安裝的 z/OS 的精確連線 CDC。Precisely Connect CDC for z/OS 映像會以 zip 檔案的形式提供於 [AWS Mainframe Modernization - Data Replication for IBM z/OS](https://aws.amazon.com/marketplace/pp/prodview-doe2lroefogia?applicationId=AWSMPContessa&ref_=beagle&sr=0-1) Amazon Machine Image (AMI)。若要在大型主機上安裝適用於 z/OS 的 Precisely Connect CDC，請參閱 [Precisely 安裝文件](https://help.precisely.com/r/AWS-Mainframe-Modernization/Latest/en-US/AWS-Mainframe-Modernization-Data-Replication-for-IBM-z/OS/Install-Precisely-Connect-CDC-z/OS)。

**限制**
+ 您的大型主機 Db2 資料應該位於 Precisely Connect CDC 支援的資料類型中。如需支援的資料類型清單，請參閱 [Precisely Connect CDC 文件](https://help.precisely.com/r/AWS-Mainframe-Modernization/Latest/en-US/AWS-Mainframe-Modernization-Data-Replication-for-IBM-z/OS/Data-replication-overview/Supported-source-data-types)。
+ 您在 Amazon MSK 的資料應位於 Amazon Redshift 支援的資料類型中。如需支援的資料類型清單，請參閱 [Amazon Redshift 文件](https://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html)。
+ Amazon Redshift 對不同的資料類型有不同的行為和大小限制。如需詳細資訊，請參閱 [Amazon Redshift 文件](https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-streaming-ingestion.html#materialized-view-streaming-ingestion-limitations)。
+ Quick Sight 中近乎即時的資料取決於為 Amazon Redshift 資料庫設定的重新整理間隔。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。Amazon Q in Quick Sight 目前不適用於支援 Quick Sight 的每個區域。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

**產品版本**
+ AWS Mainframe Modernization 使用精確的 4.1.44 版進行資料複寫
+ Python 3.6 版或更新版本
+ Apache Kafka ** **3.5.1 版

## Architecture
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-architecture"></a>

**目標架構**

下圖顯示使用[AWS Mainframe Modernization 資料複寫搭配 Precisely](https://aws.amazon.com/mainframe-modernization/capabilities/data-replication/) 和 Amazon Q in Quick Sight 從大型主機資料產生商業洞見的架構。

![\[從 z/OS 大型主機到 Amazon QuickSight 的七個步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/cddb6d20-14ae-4276-90d8-14df435db824.png)


該圖顯示以下工作流程：

1. Precisely Log Reader Agent 會從 Db2 日誌讀取資料，並將資料寫入大型主機上 OMVS 檔案系統的暫時性儲存體。

1. 發佈者代理程式會從暫時性儲存讀取原始 Db2 日誌。

1. 內部部署控制器協助程式會驗證、授權、監控和管理操作。

1. Apply Agent 是使用預先設定的 AMI 部署在 Amazon EC2 上。它會使用 TCP/IP 透過控制器常駐程式與發佈者代理程式連線。Apply Agent 使用多個工作者將資料推送到 Amazon MSK 以進行高輸送量。

1. 工作者會以 JSON 格式將資料寫入 Amazon MSK 主題。作為複寫訊息的中繼目標，Amazon MSK 提供高可用性和自動化容錯移轉功能。

1. Amazon Redshift 串流擷取提供從 Amazon MSK 到 Amazon Redshift Serverless 資料庫的低延遲、高速資料擷取。Amazon Redshift 中的預存程序會對 Amazon Redshift 資料表執行大型主機變更資料 (insert/update/deletes) 調校。這些 Amazon Redshift 資料表做為 Quick Sight 的資料分析來源。

1. 使用者存取 Quick Sight 中的資料，以取得分析和洞見。您可以使用 Amazon Q in Quick Sight，透過自然語言提示與資料互動。

## 工具
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，並快速將其向外擴展或向內擴展。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [Amazon Managed Streaming for Apache Kafka (Amazon MSK)](https://docs.aws.amazon.com/msk/latest/developerguide/what-is-msk.html) 是一種全受管服務，可協助您建置和執行使用 Apache Kafka 處理串流資料的應用程式。
+ [Amazon Quick Sight](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) 是一種雲端規模的商業智慧 (BI) 服務，可協助您在單一儀表板中視覺化、分析和報告您的資料。此模式使用 Quick Sight 中 Amazon Q 的生成式 BI 功能。
+ [Amazon Redshift Serverless](https://aws.amazon.com/redshift/redshift-serverless/) 是 Amazon Redshift 的無伺服器選項，可讓您在幾秒鐘內更有效率地執行和擴展分析，而無需設定和管理資料倉儲基礎設施。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您將程式碼中的硬式編碼憑證 (包括密碼) 取代為 Secrets Manager 的 API 呼叫，以便透過程式設計方法來擷取機密。

**其他工具**
+ [Precisely Connect CDC](https://support.precisely.com/products/connect-cdc-formerly-sqdata/) 會收集舊版系統的資料，並將其整合到雲端和資料平台。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [Mainframe\$1DataInsights\$1change\$1data\$1reconciliation](https://github.com/aws-samples/Mainframe_DataInsights_change_data_reconcilition) 儲存庫中使用。此程式碼是 Amazon Redshift 中的預存程序。此預存程序會將大型主機資料變更 （插入、更新和刪除） 從 Amazon MSK 協調至 Amazon Redshift 資料表。這些 Amazon Redshift 資料表可做為 Quick Sight 的資料分析來源。

## 最佳實務
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-best-practices"></a>
+ 設定 Amazon MSK 叢集時，請遵循[最佳實務](https://docs.aws.amazon.com/msk/latest/developerguide/bestpractices.html)。
+ 遵循 Amazon Redshift [資料剖析最佳實務](https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-streaming-ingestion.html#materialized-view-streaming-recommendations)來改善效能。
+ 當您為精確設定建立 AWS Identity and Access Management (IAM) 角色時，請遵循最低權限原則，並授予執行任務所需的最低許可。如需詳細資訊，請參閱 IAM 文件中的[授予最低權限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#grant-least-priv)和[安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)。

## 史詩
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-epics"></a>

### 在 Amazon EC2 上使用精確設定 AWS Mainframe Modernization 資料複寫
<a name="set-up-m2long-data-replication-with-precisely-on-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定安全群組。 | 若要連線至控制器協助程式和 Amazon MSK 叢集，請為 EC2 執行個體[建立安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/creating-security-groups.html)。新增下列傳入和傳出規則：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html)請記下安全群組的名稱。當您啟動 EC2 執行個體並設定 Amazon MSK 叢集時，將需要參考名稱。 | DevOps 工程師，AWS DevOps | 
| 建立 IAM 政策和 IAM 角色。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | DevOps 工程師、AWS 系統管理員 | 
| 佈建 EC2 執行個體。 | 若要佈建 EC2 執行個體來執行精確 CDC 並連線至 Amazon MSK，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | AWS 管理員、DevOps 工程師 | 

### 設定 Amazon MSK
<a name="set-up-msk"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon MSK 叢集。 | 若要建立 Amazon MSK 叢集，請執行下列 ：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html)建立典型的佈建叢集最多需要 15 分鐘。建立叢集之後，其狀態會從**建立**變更為**作用中**。 | AWS DevOps，雲端管理員 | 
| 設定 SASL/SCRAM 身分驗證。 | 若要設定 Amazon MSK 叢集的 SASL/SCRAM 身分驗證，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 雲端架構師 | 
| 建立 Amazon MSK 主題。 | 若要建立 Amazon MSK 主題，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 雲端管理員 | 

### 在 Amazon EC2 上設定精確套用引擎
<a name="configure-the-precisely-apply-engine-on-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定精確指令碼以複寫資料變更。 | 若要設定 Precisely Connect CDC 指令碼，將已變更的資料從大型主機複寫至 Amazon MSK 主題，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html)如需範例 .ddl 檔案，請參閱[其他資訊](#generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-additional)一節。 | 應用程式開發人員、雲端架構師 | 
| 產生網路 ACL 金鑰。 | 若要產生網路存取控制清單 （網路 ACL) 金鑰，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 雲端架構師，AWS DevOps | 

### 準備大型主機來源環境
<a name="prepare-the-mainframe-source-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 ISPF 畫面中設定預設值。 | 若要在互動式系統生產力設施 (ISPF) 中設定預設設定，請遵循[精確文件中](https://help.precisely.com/r/AWS-Mainframe-Modernization/Latest/en-US/AWS-Mainframe-Modernization-Data-Replication-for-IBM-z/OS/Install-Precisely-Connect-CDC-z/OS/Start-ISPF-Panel-Interface)的指示。 | 大型主機系統管理員 | 
| 設定控制器協助程式。 | 若要設定控制器協助程式，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 大型主機系統管理員 | 
| 設定發布者。 | 若要設定發佈者，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 大型主機系統管理員 | 
| 更新協助程式組態檔案。 | 若要更新控制器常駐程式組態檔案中的發佈者詳細資訊，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 大型主機系統管理員 | 
| 建立任務以啟動控制器協助程式。 | 若要建立任務，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 大型主機系統管理員 | 
| 產生擷取發佈者 JCL 檔案。 | 若要產生擷取發佈者 JCL 檔案，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 大型主機系統管理員 | 
| 檢查並更新 CDC。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 大型主機系統管理員 | 
| 提交 JCL 檔案。 | 提交您在先前步驟中設定的下列 JCL 檔案：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html)提交 JCL 檔案後，您可以在 EC2 執行個體上精確地啟動套用引擎。 | 大型主機系統管理員 | 

### 執行並驗證 CDC
<a name="run-and-validate-cdc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動套用引擎並驗證 CDC。 | 若要在 EC2 執行個體上啟動套用引擎並驗證 CDC，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 雲端架構師、應用程式開發人員 | 
| 驗證 Amazon MSK 主題上的記錄。 | 若要從 Kafka 主題讀取訊息，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 應用程式開發人員、雲端架構師 | 

### 將大型主機變更資料儲存在 Amazon Redshift Serverless 資料倉儲中
<a name="store-mainframe-change-data-in-an-rsslong-data-warehouse"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Amazon Redshift Serverless。 | 若要建立 Amazon Redshift Serverless 資料倉儲，請遵循 [AWS 文件](https://docs.aws.amazon.com/redshift/latest/gsg/new-user-serverless.html)中的指示。在 Amazon Redshift Serverless 儀表板上，驗證命名空間和工作群組已建立且可供使用。在此範例模式中，程序可能需要 2-5 分鐘。 | 資料工程師 | 
| 設定串流擷取所需的 IAM 角色和信任政策。 | 若要從 Amazon MSK 設定 Amazon Redshift Serverless 串流擷取，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 資料工程師 | 
| 將 Amazon Redshift Serverless 連線至 Amazon MSK。 | 若要連線至 Amazon MSK 主題，請在 Amazon Redshift Serverless 中建立外部結構描述。在 Amazon Redshift 查詢編輯器 v2 中，執行下列 SQL 命令，`'iam_role_arn'`將 取代為您先前建立的角色，並將 `'MSK_cluster_arn`' 取代為您叢集的 ARN。<pre>CREATE EXTERNAL SCHEMA member_schema<br />FROM MSK<br />IAM_ROLE 'iam_role_arn'<br />AUTHENTICATION iam<br />URI 'MSK_cluster_arn';</pre> | 遷移工程師 | 
| 建立具體化視觀表。 | 若要使用 Amazon Redshift Serverless 中 Amazon MSK 主題的資料，請建立具體化檢視。在 Amazon Redshift 查詢編輯器 v2 中，執行下列 SQL 命令，`<MSK_Topic_name>`將 取代為 Amazon MSK 主題的名稱。<pre>CREATE MATERIALIZED VIEW member_view<br />AUTO REFRESH YES<br />AS SELECT<br />kafka_partition, <br />kafka_offset, <br />refresh_time, <br />json_parse(kafka_value) AS Data<br />FROM member_schema.<MSK_Topic_name><br />WHERE CAN_JSON_PARSE(kafka_value); <br /></pre> | 遷移工程師 | 
| 在 Amazon Redshift 中建立目標資料表。 | Amazon Redshift 資料表提供 Quick Sight 的輸入。此模式使用與大型主機上的來源 Db2 資料表`member_plans`相符的資料表 `member_dtls`和 。若要在 Amazon Redshift 中建立兩個資料表，請在 Amazon Redshift 查詢編輯器 v2 中執行下列 SQL 命令：<pre>-- Table 1: members_dtls<br />CREATE TABLE members_dtls (<br /> memberid INT ENCODE AZ64,<br /> member_name VARCHAR(100) ENCODE ZSTD,<br /> member_type VARCHAR(50) ENCODE ZSTD,<br /> age INT ENCODE AZ64,<br /> gender CHAR(1) ENCODE BYTEDICT,<br /> email VARCHAR(100) ENCODE ZSTD,<br /> region VARCHAR(50) ENCODE ZSTD<br />) DISTSTYLE AUTO;<br /><br />-- Table 2: member_plans<br />CREATE TABLE member_plans (<br /> memberid INT ENCODE AZ64,<br /> medical_plan CHAR(1) ENCODE BYTEDICT,<br /> dental_plan CHAR(1) ENCODE BYTEDICT,<br /> vision_plan CHAR(1) ENCODE BYTEDICT,<br /> preventive_immunization VARCHAR(50) ENCODE ZSTD<br />) DISTSTYLE AUTO;</pre> | 遷移工程師 | 
| 在 Amazon Redshift 中建立預存程序。 | 此模式使用預存程序，將變更資料 (`INSERT`、`UPDATE`、`DELETE`) 從來源大型主機同步到目標 Amazon Redshift 資料倉儲資料表，以便在 Quick Sight 中進行分析。若要在 Amazon Redshift 中建立預存程序，請使用查詢編輯器 v2 來執行 GitHub 儲存庫中的預存程序程式碼。 | 遷移工程師 | 
| 從串流具體化檢視讀取並載入目標資料表。 | 預存程序會從串流具體化檢視讀取資料變更，並將資料變更載入目標資料表。若要執行預存程序，請使用下列命令：<pre>call SP_Members_Load();</pre>您可以使用 [Amazon EventBridge](https://aws.amazon.com/eventbridge/) 來排程 Amazon Redshift 資料倉儲中的任務，以根據您的資料延遲需求呼叫此預存程序。EventBridge 會以固定間隔執行任務。若要監控先前對程序的呼叫是否已完成，您可能需要使用[AWS Step Functions](https://aws.amazon.com/step-functions/)狀態機器等機制。如需詳細資訊，請參閱下列資源：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html)另一個選項是使用 Amazon Redshift 查詢編輯器 v2 來排程重新整理。如需詳細資訊，請參閱[使用查詢編輯器 v2 排程查詢](https://docs.aws.amazon.com/redshift/latest/mgmt/query-editor-v2-schedule-query.html)。 | 遷移工程師 | 

### 將 Quick Sight 連線至 Amazon Redshift 中的資料
<a name="connect-quick-sight-to-data-in-rs"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Quick Sight。 | 若要設定 Quick Sight，請遵循 [AWS 文件](https://docs.aws.amazon.com/quicksight/latest/user/setting-up.html)中的指示。 | 遷移工程師 | 
| 設定 Quick Sight 和 Amazon Redshift 之間的安全連線。 | 若要設定 Quick Sight 與 Amazon Redshift 之間的連線，請執行下列動作[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 遷移工程師 | 
| 建立 Quick Sight 的資料集。 | 若要從 Amazon Redshift 建立 Quick Sight 的資料集，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 遷移工程師 | 
| 加入資料集。 | 若要在 Quick Sight 中建立分析，請依照[AWS 文件中](https://docs.aws.amazon.com/quicksight/latest/user/joining-data.html#create-a-join)的指示加入兩個資料表。在**聯結組態**窗格中，選擇**左**表示**聯結類型**。在**聯結子句**下，使用 `memberid from member_plans = memberid from members_details`。 | 遷移工程師 | 

### 使用 Quick Sight 中的 Amazon Q 從大型主機資料中取得商業洞見
<a name="get-business-insights-from-the-mainframe-data-by-using-qdev-in-quick-sight"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Quick Sight 中設定 Amazon Q。 | 若要設定 Amazon Q in Quick Sight 生成式 BI 功能，請遵循[AWS 文件中](https://docs.aws.amazon.com/quicksight/latest/user/generative-bi-get-started.html)的指示。 | 遷移工程師 | 
| 分析大型主機資料並建置視覺化儀表板。 | 若要在 Quick Sight 中分析和視覺化您的資料，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html)完成後，您可以發佈儀表板，與組織中的其他人共用。如需範例，請參閱[其他資訊](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html#generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-additional)區段中的*大型主機視覺化儀表板*。 | 遷移工程師 | 

### 從大型主機資料使用 Quick Sight 中的 Amazon Q 建立資料案例
<a name="create-a-data-story-with-qdev-in-quick-sight-from-mainframe-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料案例。 | 建立資料案例來解釋先前分析的洞見，並產生建議，以增加成員的預防性預防預防接種：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 遷移工程師 | 
| 檢視產生的資料案例。 | 若要檢視產生的資料案例，請在資料案例頁面上選擇該**案例**。 | 遷移工程師 | 
| 編輯產生的資料案例。 | 若要變更資料案例中的格式、配置或視覺效果，請遵循[AWS 文件中](https://docs.aws.amazon.com/quicksight/latest/user/working-with-stories-edit.html)的指示。 | 遷移工程師 | 
| 分享資料案例。 | 若要分享資料案例，請遵循[AWS 文件中](https://docs.aws.amazon.com/quicksight/latest/user/working-with-stories-share.html)的指示。 | 遷移工程師 | 

## 疑難排解
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 對於 Quick Sight 到 Amazon Redshift 資料集建立， `Validate Connection`已淡出。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 
| 嘗試在 EC2 執行個體上啟動套用引擎會傳回下列錯誤：`-bash: sqdeng: command not found` | 執行下列命令以匯出`sqdata`安裝路徑：<pre>export PATH=$PATH:/usr/sbin:/opt/precisely/di/sqdata/bin</pre> | 
| 嘗試啟動 Apply Engine 會傳回下列其中一個連線錯誤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight.html) | 檢查大型主機集區，確認控制器協助程式任務正在執行。 | 

## 相關資源
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-resources"></a>
+ [使用 Quick Sight 中的 AWS Mainframe Modernization 和 Amazon Q 產生洞](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html?did=pg_card&trk=pg_card)見 （模式）
+ [使用 Quick Sight 中的 AWS Mainframe Modernization 和 Amazon Q 產生資料洞](https://youtu.be/F8b7l79p6TM?si=gASuQtFbMVuEm7IJ)見 （示範）
+ [AWS Mainframe Modernization - IBM z/OS 的資料複寫](https://aws.amazon.com/marketplace/pp/prodview-doe2lroefogia?sr=0-4&ref_=beagle&applicationId=AWSMPContessa)
+ [Amazon Redshift 串流擷取到具體化視觀表](https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-streaming-ingestion.html)

## 其他資訊
<a name="generate-db2-zos-data-insights-aws-mainframe-modernization-amazon-q-in-quicksight-additional"></a>

**範例 .ddl 檔案**

*members\$1details.ddl*

```
CREATE TABLE MEMBER_DTLS (
memberid INTEGER NOT NULL,
member_name VARCHAR(50),
member_type VARCHAR(20),
age INTEGER,
gender CHAR(1),
email VARCHAR(100),
region VARCHAR(20)
);
```

*member\$1plans.ddl*

```
CREATE TABLE MEMBER_PLANS (
memberid INTEGER NOT NULL,
medical_plan CHAR(1),
dental_plan CHAR(1),
vision_plan CHAR(1),
preventive_immunization VARCHAR(20)
);
```

**範例 .sqd 檔案**

將 取代** **`<kafka topic name>`為您的 Amazon MSK 主題名稱。

*script.sqd*

```
-- Name: DB2ZTOMSK: DB2z To MSK JOBNAME DB2ZTOMSK;REPORT EVERY 1;OPTIONS CDCOP('I','U','D');-- Source Descriptions
JOBNAME DB2ZTOMSK;
REPORT EVERY 1;
OPTIONS CDCOP('I','U','D');

-- Source Descriptions 
BEGIN GROUP DB2_SOURCE; 
DESCRIPTION DB2SQL /var/precisely/di/sqdata/apply/DB2ZTOMSK/ddl/mem_details.ddl AS MEMBER_DTLS;
DESCRIPTION DB2SQL /var/precisely/di/sqdata/apply/DB2ZTOMSK/ddl/mem_plans.ddl AS MEMBER_PLANS; 
END GROUP;
-- Source Datastore 
DATASTORE cdc://<zos_host_name>/DB2ZTOMSK/DB2ZTOMSK
OF UTSCDC 
AS CDCIN 
DESCRIBED BY GROUP DB2_SOURCE ;
-- Target Datastore(s)
DATASTORE 'kafka:///<kafka topic name>/key'
OF JSON
AS TARGET
DESCRIBED BY GROUP DB2_SOURCE;
PROCESS INTO TARGET
SELECT
{
REPLICATE(TARGET)
}
FROM CDCIN;
```

**大型主機視覺化儀表板**

下列資料視覺效果是由 Amazon Q in Quick Sight 針對分析問題 所建立`show member distribution by region`*。*

![\[美國東北部和西南部有 8 個成員，西南部有 5 個成員，中西部有 4 個成員。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/b40a784c-c1fc-444b-b6df-8bd1f7a6abaa.png)


以下資料視覺效果是由 Amazon Q in Quick Sight 為問題 建立`show member distribution by Region who have not completed preventive immunization, in pie chart`。

![\[Southeast 顯示 6， Southwest 顯示 5，而 Midwest 顯示 4。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/8a95da3c-df4a-458b-9cfe-44e34f80a235.png)


**資料案例輸出**

下列螢幕擷取畫面顯示 Amazon Q in Quick Sight 為提示 建立的資料案例區段`Build a data story about Region with most numbers of members. Also show the member distribution by age, member distribution by gender. Recommend how to motivate members to complete immunization. Include 4 points of supporting data for this pattern`。

在簡介中，資料案例建議選擇擁有最多成員的區域，以從防盜工作中獲得最大的影響。

![\[根據成員基礎的地理、人口統計和年齡進行分析的簡介畫面。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/40f13957-2db4-42b7-b7a4-a0dd3dad6899.png)


資料案例提供四個區域的成員號碼分析。美國東北部、西南部和東南亞區域的成員最多。

![\[美國東部和西南部區域有 8 個成員，東南亞有 6 個成員，中西部有 4 個成員。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/fc6ed0a0-b79c-4397-95ac-a2fc4c87482a.png)


資料案例會呈現各年齡的成員分析。

![\[圖表顯示成員基礎偏向較年幼和中年成人。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/8c56f1ec-3a2e-47a6-bbc4-3631782aa333.png)


資料案例著重於中西部的預防工作。

![\[個人拓展行銷活動和區域挑戰的建議。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/84a647e8-c7d5-4637-94f0-03a611f899b3.png)


![\[繼續進行資料案例分析，以及預期成果和結論。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/18e72bcb-1b9a-406a-8220-83aca7743ad2/images/fc9094fc-2a20-485d-b238-e5e4ec70f1d3.png)


## 附件
<a name="attachments-18e72bcb-1b9a-406a-8220-83aca7743ad2"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/18e72bcb-1b9a-406a-8220-83aca7743ad2/attachments/attachment.zip)

# 在 Quick Sight 中使用 AWS Mainframe Modernization 和 Amazon Q 產生資料洞見
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight"></a>

*Shubham Roy、Roshna Razack 和 Santosh Kumar Singh，Amazon Web Services*

## 總結
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-summary"></a>

注意： AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

如果您的組織在大型主機環境中託管業務關鍵資料，從該資料中獲得洞見對於推動成長和創新至關重要。透過解鎖大型主機資料，您可以建立更快、安全和可擴展的商業智慧，以加速 Amazon Web Services (AWS) 雲端中的資料驅動型決策、成長和創新。

此模式透過使用[AWS Mainframe Modernization 檔案傳輸](https://docs.aws.amazon.com/m2/latest/userguide/filetransfer.html)搭配 BMC 和 [Quick Sight 中的 Amazon Q，](https://docs.aws.amazon.com/quicksight/latest/user/quicksight-gen-bi.html)提供產生商業洞見並從大型主機資料建立可共享敘述的解決方案。大型主機資料集會使用 AWS Mainframe Modernization 檔案傳輸搭配 BMC 傳輸至 [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)。 AWS Lambda 函數會格式化和準備大型主機資料檔案，以載入 Quick Sight。

在 Quick Sight 中提供資料之後，您可以使用自然語言提示搭配 [Amazon Q](https://docs.aws.amazon.com/quicksight/latest/user/quicksight-gen-bi.html) in Quick Sight 來建立資料摘要、提出問題和產生資料案例。您不需要撰寫 SQL 查詢或學習商業智慧 (BI) 工具。

**商業內容**

此模式提供大型主機資料分析和資料洞察使用案例的解決方案。使用 模式，您可以為公司資料建置視覺化儀表板。為了示範解決方案，此模式使用提供醫療、牙科和視覺計劃給美國成員的醫療保健公司。在此範例中，成員人口統計特性和計劃資訊會存放在大型主機資料集。視覺化儀表板會顯示下列項目：
+ 區域的成員分佈
+ 依性別分配成員
+ 按年齡分配成員
+ 依計劃類型分配成員
+ 尚未完成預防性預防預防接種的成員

建立儀表板後，您會產生一個資料案例，說明先前分析的洞見。資料案例提供建議，以增加已完成預防性預防預防接種的成員人數。

## 先決條件和限制
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 具有業務資料的大型主機資料集
+ 在大型主機上安裝檔案傳輸代理程式的存取權

**限制**
+ 您的大型主機資料檔案應該採用 Quick Sight 支援的其中一種檔案格式。如需支援的檔案格式清單，請參閱[支援的資料來源](https://docs.aws.amazon.com/quicksuite/latest/userguide/supported-data-sources.html)。
+ 此模式使用 Lambda 函數，將大型主機檔案轉換為 Quick Sight 支援的格式。

## Architecture
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-architecture"></a>

下圖顯示透過使用 AWS Mainframe Modernization 檔案傳輸搭配 BMC 和 Amazon Q in Quick Sight 從大型主機資料產生商業洞見的架構。

![\[架構圖描述遵循圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/53572abb-06c6-4dd7-add4-8fad7e9bfa68/images/6fe0f1d9-961c-4089-a746-e5b8d5fd6c1e.png)


該圖顯示以下工作流程：

1. 包含商業資料的大型主機資料集會使用 AWS Mainframe Modernization 檔案傳輸搭配 BMC 傳輸至 Amazon S3。

1. Lambda 函數會將檔案傳輸目的地 S3 儲存貯體中的檔案轉換為逗號分隔值 (CSV) 格式。

1. Lambda 函數會將轉換後的檔案傳送至來源資料集 S3 儲存貯體。

1. Quick Sight 會擷取 檔案中的資料。

1. 使用者存取 Quick Sight 中的資料。您可以使用 Amazon Q in Quick Sight，透過自然語言提示與資料互動。

## 工具
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-tools"></a>

**AWS 服務**
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [AWS Mainframe Modernization 使用 BMC 進行檔案傳輸](https://docs.aws.amazon.com/m2/latest/userguide/filetransfer.html)會將大型主機資料集轉換和傳輸到 Amazon S3，以用於大型主機現代化、遷移和擴增使用案例。
+ [Amazon Quick Sight](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) 是一種雲端規模的 BI 服務，可協助您在單一儀表板中視覺化、分析和報告您的資料。此模式使用 [Quick Sight 中 Amazon Q 的生成式 BI ](https://docs.aws.amazon.com/quicksight/latest/user/working-with-quicksight-q.html)功能。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

## 最佳實務
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-best-practices"></a>
+ 當您使用 BMC 和 Lambda 函數建立 AWS Mainframe Modernization 檔案傳輸的 AWS Identity and Access Management (IAM) 角色時，請遵循[最低權限](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)原則。
+ 確保您的來源資料集支援 [Quick Sight 的資料類型](https://docs.aws.amazon.com/quicksight/latest/user/supported-data-types-and-values.html)。如果您的來源資料集包含不支援的資料類型，請將它們轉換為支援的資料類型。如需有關不支援的大型主機資料類型以及如何將其轉換為 Amazon Q in Quick Sight 支援的資料類型的資訊，請參閱[相關資源](#generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-resources)一節。

## 史詩
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-epics"></a>

### 使用 BMC 設定 AWS Mainframe Modernization 檔案傳輸
<a name="set-up-m2long-file-transfer-with-bmc"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 檔案傳輸代理程式。 | 若要安裝 AWS Mainframe Modernization 檔案傳輸代理程式，請遵循 [AWS 文件](https://docs.aws.amazon.com/m2/latest/userguide/m2-agent-installation.html)中的指示。 | 大型主機系統管理員 | 
| 建立用於大型主機檔案傳輸的 S3 儲存貯體。 | [建立 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體以存放使用 BMC AWS Mainframe Modernization 進行檔案傳輸的輸出檔案。在架構圖中，這是檔案傳輸目的地儲存貯體。 | 遷移工程師 | 
| 建立資料傳輸端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html) | AWS Mainframe Modernization 專家 | 

### 轉換大型主機檔案名稱副檔名以進行 Quick Sight 整合
<a name="convert-the-mainframe-file-name-extension-for-quick-sight-integration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 為 Lambda 函數[建立 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體，將轉換後的大型主機檔案從來源複製到最終目的地儲存貯體。 | 遷移工程師 | 
| 建立 Lambda 函式。 | 若要建立 Lambda 函數來變更副檔名，並將大型主機檔案複製到目的地儲存貯體，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html) | 遷移工程師 | 
| 建立 Amazon S3 觸發程序來叫用 Lambda 函數。 | 若要設定叫用 Lambda 函數的觸發，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html)如需詳細資訊，請參閱[教學課程：使用 Amazon S3 觸發條件叫用 Lambda 函數](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html)。 | 遷移潛在客戶 | 
| 提供 Lambda 函數的 IAM 許可。 | Lambda 函數需要 IAM 許可才能存取檔案傳輸目的地和來源資料集 S3 儲存貯體。透過允許檔案傳輸目的地 S3 儲存貯** **體的 `s3:GetObject` 和 `s3:DeleteObject`** **許可，以及來源資料集 S3 儲存貯體的 `s3:PutObject` 存取，更新與 Lambda 函數執行角色相關聯的政策。如需詳細資訊，請參閱*教學課程：使用 Amazon S3 觸發來叫用 Lambda 函數*中的[建立許可政策](https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html#with-s3-example-create-policy)** **一節。 | 遷移潛在客戶 | 

### 定義大型主機資料傳輸任務
<a name="define-a-mainframe-data-transfer-task"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立傳輸任務，將大型主機檔案複製到 S3 儲存貯體。 | 若要建立大型主機檔案傳輸任務，請遵循 [AWS Mainframe Modernization 文件中的指示。](https://docs.aws.amazon.com/m2/latest/userguide/filetransfer-transfer-tasks.html)將**來源碼頁面**編碼指定為 **IBM1047**，並將**目標碼頁面**編碼指定為** UTF-8**。 | 遷移工程師 | 
| 驗證傳輸任務。 | 若要驗證資料傳輸是否成功，請遵循 [AWS Mainframe Modernization 文件](https://docs.aws.amazon.com/m2/latest/userguide/filetransfer-transfer-tasks.html#filetransfer-ts-view-console)中的指示。確認大型主機檔案位於檔案傳輸目的地 S3 儲存貯體中。 | 遷移潛在客戶 | 
| 驗證 Lambda 複製函數。 | 確認 Lambda 函數已啟動，且檔案已使用 .csv 副檔名複製到來源資料集 S3 儲存貯體。Lambda 函數建立的 .csv 檔案是 Quick Sight 的輸入資料檔案。如需範例資料，請參閱[附件](#attachments-53572abb-06c6-4dd7-add4-8fad7e9bfa68)區段中的 `Sample-data-member-healthcare-APG` 檔案。 | 遷移潛在客戶 | 

### 將 Quick Sight 連線至大型主機資料
<a name="connect-quick-sight-to-the-mainframe-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Quick Sight。 | 若要設定 Quick Sight，請遵循 [AWS 文件](https://docs.aws.amazon.com/quicksight/latest/user/setting-up.html)中的指示。 | 遷移潛在客戶 | 
| 建立 Quick Sight 的資料集。 | 若要建立 Quick Sight 的資料集，請遵循 [AWS 文件](https://docs.aws.amazon.com/quicksight/latest/user/create-a-data-set-s3.html)中的指示。輸入資料檔案是在您定義大型主機資料傳輸任務時建立的轉換大型主機檔案。 | 遷移潛在客戶 | 

### 使用 Quick Sight 中的 Amazon Q 從大型主機資料中取得商業洞見
<a name="get-business-insights-from-the-mainframe-data-by-using-qdev-in-quick-sight"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Quick Sight 中設定 Amazon Q。 | 此功能需要 Enterprise Edition。若要在 Quick Sight 中設定 Amazon Q，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html) | 遷移潛在客戶 | 
| 分析大型主機資料並建置視覺化儀表板。 | 若要在 Quick Sight 中分析和視覺化您的資料，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html)完成後，您可以發佈儀表板，與組織中的其他人共用。如需範例，請參閱[其他資訊](#generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-additional)區段中的*大型主機視覺化儀表板*。 | 遷移工程師 | 

### 從大型主機資料使用 Quick Sight 中的 Amazon Q 建立資料案例
<a name="create-a-data-story-with-qdev-in-quick-sight-from-the-mainframe-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料案例。 | 建立資料案例來解釋先前分析的洞見，並產生建議，以增加成員的預防性預防預防接種：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html) | 遷移工程師 | 
| 檢視產生的資料案例。 | 若要檢視產生的資料案例，請遵循 [AWS 文件](https://docs.aws.amazon.com/quicksight/latest/user/working-with-stories-view.html)中的指示。 | 遷移潛在客戶 | 
| 編輯產生的資料案例。 | 若要變更資料案例中的格式、配置或視覺效果，請遵循[AWS 文件中](https://docs.aws.amazon.com/quicksight/latest/user/working-with-stories-edit.html)的指示。 | 遷移潛在客戶 | 
| 分享資料案例。 | 若要分享資料案例，請遵循[AWS 文件中](https://docs.aws.amazon.com/quicksight/latest/user/working-with-stories-share.html)的指示。 | 遷移工程師 | 

## 疑難排解
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 無法探索在**資料集搜尋條件**中輸入的大型主機檔案或資料集，以使用 BMC 在 AWS Mainframe Modernization 檔案**傳輸中建立傳輸任務**。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight.html) | 

## 相關資源
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-resources"></a>

若要將 [PACKED-DECIMAL (COMP-3)](https://www.ibm.com/docs/en/cobol-zos/6.3?topic=v6-packed-decimal-comp-3) 或 [BINARY (COMP 或 COMP-4)](https://www.ibm.com/docs/en/cobol-zos/6.3?topic=v6-binary-comp-comp-4) 等大型主機資料類型轉換為 Quick Sight 支援的[資料類型](https://docs.aws.amazon.com/quicksight/latest/user/supported-data-types-and-values.html)，請參閱下列模式：
+ [AWS 使用 Python 將 EBCDIC 資料轉換為 上的 ASCII](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.html)
+ [使用 在 Amazon S3 中將大型主機檔案從 EBCDIC 格式轉換為字元分隔 ASCII 格式 AWS Lambda](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/convert-mainframe-files-from-ebcdic-format-to-character-delimited-ascii-format-in-amazon-s3-using-aws-lambda.html)

## 其他資訊
<a name="generate-data-insights-by-using-aws-mainframe-modernization-and-amazon-q-in-quicksight-additional"></a>

**S3CopyLambda.py**

下列 Python 程式碼是透過在 IDE 中使用 Amazon Q 的提示產生：

```
#Create a lambda function triggered by S3. display the S3 bucket name and key
import boto3
s3 = boto3.client('s3')
def lambda_handler(event, context):
print(event)
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
print(bucket, key)
#If key starts with object_created, skip copy, print "copy skipped". Return lambda with key value.
if key.startswith('object_created'):
print("copy skipped")
return {
'statusCode': 200,
'body': key
}
# Copy the file from the source bucket to the destination bucket. Destination_bucket_name = 'm2-filetransfer-final-opt-bkt'. Destination_file_key = 'healthdata.csv'
copy_source = {'Bucket': bucket, 'Key': key}
s3.copy_object(Bucket='m2-filetransfer-final-opt-bkt', Key='healthdata.csv', CopySource=copy_source)
print("file copied")
#Delete the file from the source bucket.
s3.delete_object(Bucket=bucket, Key=key)
return {
'statusCode': 200,
'body': 'Copy Successful'
}
```

**大型主機視覺化儀表板**

下列資料視覺效果是由 Amazon Q in Quick Sight 為分析問題 所建立`show member distribution by region`*。*

![\[圖表顯示西南部、中西部、東北部和東南部的成員數量。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/53572abb-06c6-4dd7-add4-8fad7e9bfa68/images/e5c1d049-407d-42ff-bc51-28f9d2b24d4f.png)


以下資料視覺效果是由 Amazon Q in Quick Sight 為問題 建立`show member distribution by Region who have not completed preventive immunization, in pie chart`。

![\[Pie chart showing preventive immunization incompletion by region: Southeast 40%, Southwest 33%, Midwest 27%.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/53572abb-06c6-4dd7-add4-8fad7e9bfa68/images/47efa1c1-54c9-47cc-b668-416090021d34.png)


**資料案例輸出**

下列螢幕擷取畫面顯示 Amazon Q in Quick Sight 建立的資料案例區段提示 `Build a data story about Region with most numbers of members. Also show the member distribution by medical plan, vision plan, dental plan. Recommend how to motivate members to complete immunization. Include 4 points of supporting data.`

在簡介中，資料案例建議選擇最多成員的區域，以從防制措施中獲得最大的影響。

![\[著重於預防接種完成率的資料案例簡介頁面。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/53572abb-06c6-4dd7-add4-8fad7e9bfa68/images/4612fcc7-51fd-48a5-bc58-b6b0aa9b0ef3.png)


資料案例提供前三個區域的成員號碼分析，並將西南地區命名為專注於防制措施的領導區域。

![\[Pie chart showing member distribution by region, with Southwest and Northeast leading at 31% each.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/53572abb-06c6-4dd7-add4-8fad7e9bfa68/images/30d3b56b-3b92-4748-9cef-a73ff9339fee.png)


**注意**  
西南部和東北部各有八個成員。不過，西南部有更多成員未完全進行預防，因此更有可能受益於提高預防接種率的計劃。

## 附件
<a name="attachments-53572abb-06c6-4dd7-add4-8fad7e9bfa68"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/53572abb-06c6-4dd7-add4-8fad7e9bfa68/attachments/attachment.zip)

# 在 AWS Blu Age 現代化大型主機應用程式中實作 Microsoft Entra ID 型身分驗證
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application"></a>

*Vishal Jaswani 和 Rimpy Tewani，Amazon Web Services*

## 總結
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-summary"></a>

**注意**  
AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

使用重構模式進行現代化的大型主機應用程式，例如 [AWS Mainframe Modernization Refactor with AWS Blu Age](https://docs.aws.amazon.com/m2/latest/userguide/refactoring-m2.html)，需要謹慎地將身分驗證機制整合到新的應用程式架構。此整合通常會以後建化活動的形式處理。任務可能很複雜，通常涉及現有身分驗證系統的遷移或外部化，以符合現代安全標準和雲端原生實務。開發人員需要考慮如何在現代化應用程式執行期環境和程式庫的限制範圍內有效實作身分驗證。現代化之後， AWS 提供方法讓您更輕鬆地整合 AWS Blu Age 現代程式碼與身分和存取管理系統，例如 [Amazon Cognito](https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html) 和 [Microsoft Entra ID](https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id) （先前稱為 Azure AD)。

此模式說明如何在身分驗證提供者為 Microsoft Entra ID 時，在現代化應用程式中實作身分驗證機制，而不必花時間進行研究和試驗。模式提供：
+ 來自 Microsoft Authentication Library (MSAL) 和其他 Microsoft Entra ID 文件且對身分驗證實作至關重要的欄位測試和相關角度程式庫。 
+ 使用 OAuth 2.0 在 AWS Blu Age Runtime 上啟用 Spring Security 所需的組態。
+ 擷取已驗證使用者身分並將其傳遞至 AWS Blu Age Runtime 的程式庫。
+ 我們建議實作的安全措施。
+ 針對 Microsoft Entra ID 設定中常見問題的疑難排解秘訣。

**注意**  
此模式使用 AWS Blu Age OAuth 延伸程式庫，該程式庫作為其[AWS 專業服務](https://aws.amazon.com/professional-services/)業務的一部分提供給客戶。此程式庫不屬於 AWS Blu Age 執行期。

## 先決條件和限制
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-prereqs"></a>

**先決條件**
+ 由 AWS Blu Age 大型主機現代化重構工具產生的現代化應用程式。此模式使用 [CardDemo](https://github.com/aws-samples/aws-mainframe-modernization-carddemo) 做為範例開放原始碼大型主機應用程式。
+  AWS Blu Age OAuth 延伸程式庫，由 AWS Blu Age 團隊在您與 [AWS Professional Services](https://aws.amazon.com/professional-services/) 互動期間提供。
+ 部署和測試現代化應用程式的作用中 AWS 帳戶 。
+ 熟悉 AWS Blu Age 組態檔案和 Microsoft Entra ID 基本概念。

**限制**
+ 此模式涵蓋 OAuth 2.0 身分驗證和基本字符型授權流程。進階授權案例和精細存取控制機制不在範圍內。
+ 有些 AWS 服務 不適用於所有 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

**產品版本**

此模式的開發方式是使用：
+ AWS Blu Age Runtime 4.1.0 版 （此模式也適用於回溯相容的更新版本）
+ MSAL 程式庫 3.0.23 版
+ Java 開發套件 (JDK) 第 17 版
+ 角度版本 16.1

## Architecture
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-architecture"></a>

**來源技術堆疊**

在一般大型主機環境中，身分驗證是透過使用者設定檔實作。這些設定檔可識別系統的使用者、定義誰可以登入，並指定使用者可以在系統資源上執行哪些函數。使用者設定檔由安全主管或安全管理員管理。

**目標技術堆疊**
+ Microsoft Entra ID
+ 現代化 Java Spring 型後端
+ AWS Blu Age 執行時間
+ 使用 OAuth 2.0 的 Spring Security
+ 角度單頁應用程式 (SPA)

**目標架構**

AWS Blu Age 執行時間預設支援以 OAuth 2.0 為基礎的身分驗證，因此模式會使用該標準來保護後端 APIs。

下圖說明程序流程。

**注意**  
圖表包含 Amazon Aurora 做為資料庫現代化的範例，雖然此模式的步驟中不包含 Aurora。

![\[AWS Blu Age 應用程式的 Entra ID 型身分驗證程序流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e51f24b8-178f-4974-aae9-23a0cc8540f5/images/0fdcdb22-9e46-4b02-86b2-395cba3e2f81.png)


其中：

1. 使用者嘗試使用 Microsoft Entra ID 進行身分驗證。

1. Microsoft Entra ID 會傳回應用程式在後續呼叫中使用的重新整理、存取和 ID 字符。

1. MSAL 攔截器會在 HTTPS 請求的 `Authorization`標頭中包含存取字符，以呼叫 AWS Blu Age 執行期。

1.  AWS Blu Age `extension-oauth`程式庫會使用 AWS Blu Age Runtime 組態檔案 (`application-main.yml`) 從 標頭擷取使用者資訊，並將此資訊放在 `SharedContext` 物件中，讓商業邏輯可以使用它。
**注意**  
`SharedContext` 是由 AWS Blu Age 提供的執行期元件，可管理現代化應用程式中的應用程式內容和狀態資訊。如需 AWS Blu Age Runtime 元件和更新的詳細資訊，請參閱 AWS Mainframe Modernization 文件中的 [AWS Blu Age 版本備註](https://docs.aws.amazon.com/m2/latest/userguide/ba-release-notes.html)。如需 `application-main.yml` 檔案的詳細資訊，請參閱 AWS Mainframe Modernization 文件中的[設定 AWS Blu Age Runtime 組態](https://docs.aws.amazon.com/m2/latest/userguide/ba-runtime-config.html)。

1.  AWS Blu Age Runtime 會檢查字符是否存在。 

   1. 如果字符存在，它會透過與 Microsoft Entra ID 通訊來檢查字符的有效性。 

   1. 如果字符不存在， AWS 則 Blu Age Runtime 會傳回 HTTP 狀態碼為 403 的錯誤。

1. 如果字符有效， AWS 則藍時間執行時間允許業務邏輯繼續。如果字符無效， AWS 則 Blu Age Runtime 會傳回 HTTP 狀態碼為 403 的錯誤。

**OAuth 2.0 工作流程**

如需 OAuth 2.0 工作流程的高階圖表，請參閱 [Microsoft Entra 文件](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#protocol-details)。

## 工具
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-tools"></a>

**AWS 服務**

[AWS Mainframe Modernization](https://docs.aws.amazon.com/m2/latest/userguide/what-is-m2.html) 提供工具和資源，協助您規劃和實作從大型主機到 AWS 受管執行期環境的遷移和現代化。您可以使用 Blu AWS Age 提供的此服務重構功能，來轉換和現代化舊版大型主機應用程式。

**注意**  
AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

**程式碼儲存庫**

CardDemo 應用程式已更新，以示範與 Microsoft Entra ID 的整合。您可以從 [GitHub 儲存庫存取此模式的](https://github.com/aws-samples/sample-microsoft-entra-id-based-auth-in-aws-bluage-modernized-mainframe-app)程式碼。

**後端組態**

此模式需要變更`application-main.yml`** **組態檔案，才能在後端應用程式上使用 OAuth 2.0 來啟用 Spring Security。 `.yml` 檔案如下所示：

```
gapwalk-application.security: enabled
gapwalk-application:
  security: 
    identity: oauth
    issuerUri: ${issuerUrl}
    claim:
      claims:
        -
          claimName: upn
          claimMapValue: username
spring:
  autoconfigure:
    exclude:
     - org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration
     - org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration
  security:
    oauth2:
      client:
        registration: 
          azure:
            client-id: {clientId}
            client-secret: ${clientSecret}
            provider: azure
            authorization-grant-type: authorization_code
            redirect-uri: ${redirectUri}
            scope: openid
           
        provider:
          azure:
            authorization-uri: ${gapwalk-application.security.issuerUri}/oauth2/v2.0/authorize
            token-uri:  ${gapwalk-application.security.issuerUri}/oauth2/v2.0/token
            jwk-set-uri: ${gapwalk-application.security.issuerUri}/discovery/v2.0/keys
      resourceserver:
        jwt:
          jwk-set-uri: ${gapwalk-application.security.issuerUri}/discovery/v2.0/keys
```

**AWS Blu Age OAuth 延伸篩選條件程式庫**

 AWS Blu Age OAuth 延伸程式庫由 AWS Blu Age 團隊在您與 [AWS Professional Services](https://aws.amazon.com/professional-services/) 互動期間提供。

此程式庫會讀取上一個程式碼區塊中顯示的 `application-main.yml` fie 中的`claim.claims`組態。此組態是清單。清單中的每個項目提供兩個值： `claimName`和 `claimMapValue`。 `claimName`代表前端傳送的 JSON Web Token (JWT) 中的金鑰名稱，而 `claimMapValue`是 中的金鑰名稱`SharedContext`。例如，如果您想要在後端擷取使用者 ID，請將 `claimName`設定為 JWT 中的金鑰名稱，該 JWT 會保留由 Microsoft Entra ID `userId`提供的 ，並將 `claimMapValue`設定為金鑰名稱，以在後端程式碼中擷取使用者 ID。

例如，如果您在 `UserId`中設定 `claimMapValue`，您可以使用下列程式碼來擷取使用者 ID：

```
SharedContext.get().getValue("userId", [UserId]);
```

## 最佳實務
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-best-practices"></a>

在您實作此模式時，請考量下列重要安全考量。

**重要**  
此模式提供身分驗證整合的基礎。除了本節討論的安全措施之外，我們建議您在部署到生產環境之前，根據您的業務需求實作安全措施。
+ **AWS 組態安全性。 **將敏感組態值從 `application-main.yml` 移至 AWS Secrets Manager。例如，使用 Secrets Manager 設定下列屬性：

  ```
  security:
      oauth2:
        client:
          registration: 
            azure:
              client-id: {clientId}
              client-secret: ${clientSecret}
  ```

  如需如何使用 Secrets Manager 設定 AWS Blu Age 參數的詳細資訊，請參閱 AWS Mainframe Modernization 文件中的 [AWS Blu Age Runtime 秘密](https://docs.aws.amazon.com/m2/latest/userguide/ba-runtime-config-app-secrets.html)。
+ **執行期環境保護。**使用適當的 AWS 安全控制設定現代化應用程式環境：

  ```
  server: 
    tomcat: 
      remoteip: 
       protocol-header: X-Forwarded-Proto 
       remote-ip-header: X-Forwarded-For 
    forward-headers-strategy: NATIVE
  ```
+ **Amazon CloudWatch 記錄。**考慮新增 檔案`logback-spring.xml to src/main/resources`：

  ```
  <configuration> 
   <appender name="CLOUDWATCH" class="com.amazonaws.services.logs.logback.CloudWatchAppender">  
     <logGroup>/aws/bluage/application</logGroup> 
     <logStream>${AWS_REGION}-${ENVIRONMENT}</logStream> 
     <layout> 
      <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern> 
     </layout> 
   </appender> 
  
   <root level="INFO"> 
   <appender-ref ref="CLOUDWATCH"/> 
   </root> 
  </configuration>
  ```

  如需使用 CloudWatch 啟用追蹤的資訊，請參閱 CloudWatch 文件中的[啟用追蹤以記錄相互關聯](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Application-Signals-TraceLogCorrelation.html)。
+ **字符組態和處理。**在 Microsoft Entra ID 中設定權杖生命週期，以符合您的安全需求。將存取權杖設定為在 1 小時內過期，並將重新整理權杖設定為在 24 小時內過期。在 AWS Blu Age Runtime 組態 (`application-main.yml`) 中，請確定 JWT 驗證已使用來自 Entra ID 應用程式註冊的確切發行者 URI 和對象值正確設定。

  當字符過期並重新整理時：

  1. 角形應用程式的錯誤攔截器會透過 MSAL 取得新權杖來處理 401 回應。

  1. 新的字符會與後續請求一起傳送。

  1.  AWS Blu Age Runtime 的 OAuth 篩選條件會驗證新的權杖，並自動`SharedContext`更新目前的使用者資訊。這可確保商業邏輯繼續透過`SharedContext.get().getValue()`呼叫存取有效的使用者內容。

  如需 AWS Blu Age Runtime 元件及其更新的詳細資訊，請參閱 [AWS Blu Age 版本備註](https://docs.aws.amazon.com/m2/latest/userguide/ba-release-notes.html)。
+ **AWS Blu Age 執行期安全性。** AWS Blu Age 提供的`oauth2-ext`程式庫必須放置在具有適當檔案許可的正確共用目錄位置 (`{app-server-home}/shared/`)。透過檢查日誌中的`SharedContext`物件人口，確認程式庫已成功從 JWTs擷取使用者資訊。
+ **特定宣告組態。**在 中`application-main.yml`，明確定義您需要從 Microsoft Entra ID 取得的宣告。例如，若要擷取使用者的電子郵件和角色，請指定：

  ```
  gapwalk-application:
    security:
      claim:
        claims:
          - claimName: upn
            claimMapValue: username
          - claimName: roles
            claimMapValue: userRoles
          - claimName: email
            claimMapValue: userEmail
  ```
+ **錯誤處理。**新增錯誤處理，以解決 Angular 應用程式中的身分驗證失敗；例如：

  ```
  @Injectable()
  export class AuthErrorInterceptor implements HttpInterceptor {
    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
      return next.handle(request).pipe(
        catchError((error: HttpErrorResponse) => {
          if (error.status === 401) {
            // Handle token expiration
            this.authService.login();
          }
          if (error.status === 403) {
            // Handle unauthorized access
            this.router.navigate(['/unauthorized']);
          }
          return throwError(() => error);
        })
      );
    }
  }
  ```
+ **工作階段逾時組態。**在 AWS Blu Age Runtime 和 Microsoft Entra ID 中設定工作階段逾時設定。例如，將下列程式碼新增至您的 `application-main.yml` 檔案：

  ```
  server:
    servlet:
      session:
        timeout: 3600 # 1 hour in seconds
  ```
+ **MsalGuard。**您必須為所有受保護的路由實作 MsalGuard 功能，以防止未經授權的存取。例如：

  ```
  const routes: Routes = [
      { path: '', redirectTo: '/transaction-runner', pathMatch: 'full' },
      { path: 'transaction-runner', component: TransactionRunnerComponent, canActivate:guards },
      { path: 'user-info', component: UserInfoComponent, canActivate:guards },
      { path: 'term/:transid/:commarea', component: TermComponent, canActivate:guards },
  	{ path: 'code', component: TransactionRunnerComponent  }
  ];
  ```

  沒有 MsalGuard 保護的路由無需身分驗證即可存取，可能公開敏感功能。確定所有需要身分驗證的路由在其組態中都包含防護。

## 史詩
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-epics"></a>

### 設定 Microsoft Entra ID
<a name="set-up-a-microsoft-entra-id"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Microsoft Azure 帳戶以建立 Entra ID。 | 如需選項和說明，請參閱 [Microsoft Azure 網站](https://azure.microsoft.com/en-us/free/)。 | 應用程式開發人員 | 
| 在應用程式中設定 Microsoft Entra ID。 | 若要了解如何將 Microsoft Entra ID B2C (Azure AD B2C) 身分驗證新增至您的角度 SPA，請參閱 [Microsoft 文件](https://learn.microsoft.com/en-us/azure/active-directory-b2c/enable-authentication-angular-spa-app#add-the-authentication-components)。具體而言：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application.html) | 應用程式開發人員 | 

### 複製儲存庫並部署您的 AWS Blu Age 程式碼
<a name="clone-the-repository-and-deploy-your-aws-blu-age-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 GitHub 儲存庫以取得身分驗證所需的角度程式碼。 | 執行下列命令，將隨此模式提供的 [GitHub 儲存庫](https://github.com/aws-samples/sample-microsoft-entra-id-based-auth-in-aws-bluage-modernized-mainframe-app)複製到您的本機目前工作目錄：<pre>git clone https://github.com/aws-samples/sample-microsoft-entra-id-based-auth-in-aws-bluage-modernized-mainframe-app.git</pre> | 應用程式開發人員 | 
| 在 Tomcat 伺服器上部署 AWS Blu Age 現代化程式碼以實作身分驗證。 | 若要設定包含 Tomcat 和 Angular 開發伺服器的本機環境，請遵循 AWS Blu Age 團隊提供的安裝步驟，做為您與 AWS Professional Services 客戶互動的一部分。 | 應用程式開發人員 | 

### 建置身分驗證解決方案
<a name="build-the-authentication-solution"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟用 AWS Blu Age Runtime 安全性來保護 AWS Blu Age REST API 端點。 | 設定 AWS Blu Age Runtime 使用`application-main.yml`的檔案，如下所示。如需此檔案的範例，請參閱此模式中稍早的[程式碼儲存庫](#implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-tools)一節。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application.html) | 應用程式開發人員 | 
| 將來自您本機環境的範例程式碼併入您的 Blu Age 現代化角度程式碼基底。 | 如需有關如何將範例併入您的 AWS Blu Age 現代化角度程式碼庫的資訊，請參閱此模式稍早的[程式碼儲存庫](#implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-tools)一節。 | 應用程式開發人員 | 
| 將程式`oauth2-ext`庫放在共用目錄中。 | 將程式`oauth2-ext`庫放在應用程式伺服器的** **共用目錄中，以便您的** **AWS Blu Age 現代化應用程式可以使用它**。 **執行下列命令：<pre>cd oauth2-ext/target<br />cp extension-oauth-filter-<version>.jar /{app-server-home}/shared/</pre> | 應用程式開發人員 | 

### 部署身分驗證解決方案
<a name="deploy-the-authentication-solution"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署前端應用程式。 | 執行下列命令，在本機啟動前端應用程式：<pre>npm install <br />ng serve --ssl<br />npm start</pre>將 `--ssl` 旗標新增至 `ng serve`命令可確保開發伺服器使用 HTTPS，這比其他通訊協定更安全，並提供更好的生產環境模擬。 | 應用程式開發人員 | 
| 啟動後端應用程式。 | 在 Eclipse 中啟動 Tomcat 伺服器。 | 應用程式開發人員 | 

### 測試應用程式。
<a name="test-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試登入功能。 | 在 存取本機部署的應用程式，`http://localhost:4200`以確認要求使用者確認其身分。HTTP 在此處用於示範目的。在生產或其他可公開存取的環境中，為了安全起見，您必須使用 HTTPS。即使是本機開發，我們建議您盡可能設定 HTTPS。應該會出現 Microsoft 登入提示，而且應該允許在 Microsoft Entra ID 中設定的使用者存取應用程式。 | 應用程式開發人員 | 
| 在請求中測試授權標頭。 | 下列步驟使用 [CardDemo](https://github.com/aws-samples/aws-mainframe-modernization-carddemo) 應用程式做為範例。其他現代應用程式的測試步驟會有所不同。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application.html) | 應用程式開發人員 | 
| 測試登出功能。 | 選擇**退出**以登出，然後嘗試再次存取應用程式。它應該會顯示新的登入提示。 | 應用程式開發人員 | 

## 疑難排解
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Microsoft Entra ID 發行的權杖與 Spring Boot OAuth 2.0 安全性不相容。 | 如需問題的解決方法，請參閱 [OAuth 部落格上的 Microsoft Entra ID OAuth 流程](https://authguidance.com/azure-ad-troubleshooting/)。 OAuth  | 
| 一般字符相關問題。 | 若要解碼和檢視 JWT 權杖的內容，請使用 [https://jwt.io/](https://jwt.io/) 網站。 | 

## 相關資源
<a name="implement-entra-id-authentication-in-aws-blu-age-modernized-mainframe-application-resources"></a>
+ 如需有關使用 AWS Blu Age 重構應用程式的資訊，請參閱 [AWS Mainframe Modernization 文件](https://docs.aws.amazon.com/m2/latest/userguide/refactoring-m2.html)。
+ 若要了解 OAuth 2.0 的運作方式，請參閱 [OAuth 2.0 網站。](https://oauth.net/2/)
+ 如需 Microsoft Authentication Library (MSAL) 的概觀，請參閱 [Microsoft Entra 文件](https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-overview)。
+ 如需 AS/400 系統上使用者設定檔的資訊，請參閱 [IBM i (AS400) 教學](https://www.go4as400.com/subsystem-jobs-user-profile-in-as400/jobs.aspx?cid=14)課程。
+ 如需 Microsoft 身分平台中的 OAuth 2.0 和 OpenID Connect (OIDC) 身分驗證流程，請參閱 [Microsoft Entra 文件](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols)。

# 將stonebranch 通用控制器與 AWS Mainframe Modernization 整合
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization"></a>

*Vaidy Sankaran 和 Pablo Alonso Prieto，Amazon Web Services*

*Robert Lemieux 和 Huseyin Gomleksizoglu，斯通堡*

## 摘要
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-summary"></a>

注意： AWS Mainframe Modernization 服務 （受管執行期環境體驗） 不再開放給新客戶。對於類似 AWS Mainframe Modernization Service （受管執行期環境體驗） 的功能，請探索 AWS Mainframe Modernization Service （自我管理體驗）。現有客戶可以繼續正常使用該服務。如需詳細資訊，請參閱[AWS Mainframe Modernization 可用性變更](https://docs.aws.amazon.com/m2/latest/userguide/mainframe-modernization-availability-change.html)。

此模式說明如何將[stonebranch Universal Automation Center (UAC) 工作負載協同運作](https://www.stonebranch.com/stonebranch-platform/universal-automation-center)與 [Amazon Web Services (AWS) Mainframe Modernization 服務](https://aws.amazon.com/mainframe-modernization/)整合。AWS Mainframe Modernization 服務會將大型主機應用程式遷移和現代化至 AWS 雲端。它提供兩種模式：[AWS Mainframe Modernization Replatform](https://aws.amazon.com/mainframe-modernization/patterns/replatform/) with Micro Focus Enterprise technology 和 [AWS Mainframe Modernization Automated Refactor](https://aws.amazon.com/mainframe-modernization/patterns/refactor/?mainframe-blogs.sort-by=item.additionalFields.createdDate&mainframe-blogs.sort-order=desc) with AWS Blu Age。 

stonebranch UAC 是即時 IT 自動化和協同運作平台。UAC 旨在自動化和協調混合式 IT 系統的任務、活動和工作流程，從內部部署到 AWS。使用大型主機系統的企業用戶端正在轉換至以雲端為中心的現代化基礎設施和應用程式。stonebranch 的工具和專業服務有助於將現有的排程器和自動化功能遷移至 AWS 雲端。

當您使用 AWS Mainframe Modernization 服務將大型主機程式遷移或現代化至 AWS 雲端時，您可以使用此整合來自動化批次排程、提高敏捷性、改善維護並降低成本。

此模式提供將[stonebranch 排程器](https://www.stonebranch.com/)與遷移至 AWS Mainframe Modernization 服務 Micro Focus Enterprise 執行期的大型主機應用程式整合的指示。此模式適用於解決方案架構師、開發人員、顧問、遷移專家，以及其他在遷移、現代化、操作或 DevOps 工作的人員。

**目標成果**

此模式著重於提供下列目標結果：
+ 能夠排程、自動化和執行從stonebranch Universal Controller 在 AWS Mainframe Modernization 服務 (Microfocus 執行時間） 中執行的大型主機批次任務。
+ 從stonebranch 通用控制器監控應用程式的批次程序。
+ 從stonebranch 通用控制器自動或手動啟動Start/Restart/Rerun/停止批次處理。
+ 擷取 AWS Mainframe Modernization 批次程序的結果。
+ 在stonebranch Universal Controller 中擷取批次任務的 [AWS CloudWatch](https://aws.amazon.com/cloudwatch/) 日誌。

## 先決條件和限制
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 具有任務控制語言 (JCL) 檔案的 Micro Focus [Bankdemo](https://d1vi4vxke6c2hu.cloudfront.net/demo/bankdemo_runtime.zip) 應用程式，以及在 AWS Mainframe Modernization 服務 (Micro Focus 執行時間） 環境中部署的批次程序
+ 如何建置和部署在 Micro Focus [Enterprise Server](https://www.microfocus.com/media/data-sheet/enterprise_server_ds.pdf) 上執行之大型主機應用程式的基本知識
+ 對stonebranch Universal Controller 的基本了解
+ stonebranch 試用授權 （請聯絡[stonebranch](https://www.stonebranch.com/))
+ Windows 或 Linux Amazon Elastic Compute Cloud (Amazon EC2) 執行個體 （例如 xlarge)，至少包含四個核心、8 GB 記憶體和 2 GB 磁碟空間
+ Apache Tomcat 8.5.x 或 9.0.x 版
+ Oracle Java 執行期環境 (JRE) 或 OpenJDK 版本 8 或 11
+ [Amazon Aurora MySQL 相容版本](https://aws.amazon.com/rds/aurora/)
+ 匯出儲存庫的 [Amazon Simple Storage Service (Amazon S3)](https://aws.amazon.com/s3/) 儲存貯體
+ [Amazon Elastic File System (Amaon EFS)](https://aws.amazon.com/efs/) 適用於代理程式stonebranch Universal Message Service (OMS) 連線，以實現高可用性 (HA)
+ stonebranch Universal Controller 7.2 Universal Agent 7.2 安裝檔案
+ AWS Mainframe Modernization [任務排程範本](https://github.com/aws-samples/aws-mainframe-modernization-stonebranch-integration/releases) （最新發行的 .zip 檔案版本）

**限制**
+ 產品和解決方案已經過測試，且相容性僅通過 OpenJDK 8 和 11 的驗證。
+ [aws-mainframe-modernization-stonebranch-integration](https://github.com/aws-samples/aws-mainframe-modernization-stonebranch-integration/releases) 任務排程範本僅適用於 AWS Mainframe Modernization 服務。
+ 此任務排程範本僅適用於 Gemlibranch 代理程式的 Unix、Linux 或 Windows 版本。
+ 並非所有 AWS 區域都提供某些 AWS 服務。如需區域可用性，請參閱[依區域的 AWS 服務](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-architecture"></a>

**目標狀態架構**

下圖顯示此試驗所需的 AWS 環境範例。

![\[stonebranch UAC 與 AWS Mainframe Modernization 環境互動。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/01c6f9fa-87e6-459a-b694-5e03dd7f7952/images/4a7bea37-0a5b-4663-902b-9b051e92f0cb.png)


1. 斯通堡國際自動化中心 (UAC) 包含兩個主要元件：通用控制器和通用代理程式。stonebranch OMS 用作控制器和個別代理程式之間的訊息匯流排。

1. 通用控制器使用stonebranch UAC 資料庫。資料庫可以是 MySQL、Microsoft SQL Server、Oracle 或 Aurora MySQL 相容。

1. AWS Mainframe Modernization 服務 – 已[部署 BankDemo 應用程式的](https://aws.amazon.com/blogs/aws/modernize-your-mainframe-applications-deploy-them-in-the-cloud/) Micro Focus 執行期環境。BankDemo 應用程式檔案會存放在 S3 儲存貯體中。此儲存貯體也包含大型主機 JCL 檔案。

1. stonebranch UAC 可以針對批次執行執行下列函數：

   1. 使用與 AWS 大型主機現代化服務連結的 S3 儲存貯體中存在的 JCL 檔案名稱啟動批次任務。

   1. 取得批次任務執行的狀態。

   1. 等待批次任務執行完成。

   1. 擷取批次任務執行的日誌。

   1. 重新執行失敗的批次任務。

   1. 在任務執行時取消批次任務。

1. stonebranch UAC 可以為應用程式執行下列函數：

   1. 啟動應用程式

   1. 取得應用程式的狀態

   1. 等待應用程式啟動或停止

   1. 停止應用程式

   1. 應用程式操作的擷取日誌

**stonebranch 任務轉換**

下圖代表在現代化旅程中，Stonebranch 的任務轉換程序。它說明如何將任務排程和任務定義轉換為可執行 AWS Mainframe Modernization 批次任務的相容格式。

![\[從大型主機到 Amazon EC2 上任務排程器的程序，以及 Amazon S3 中的 JCL 檔案。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/01c6f9fa-87e6-459a-b694-5e03dd7f7952/images/4d2ed890-f143-455e-8180-4d967b71c494.png)


1. 對於轉換程序，任務定義會從現有的大型主機系統匯出。

1. JCL 檔案可以上傳到 Mainframe Modernization 應用程式的 S3 儲存貯體，以便 AWS Mainframe Modernization 服務可以部署這些 JCL 檔案。

1. 轉換工具會將匯出的任務定義轉換為 UAC 任務。

1. 建立所有任務定義和任務排程後，這些物件將匯入至通用控制器。轉換後的任務接著會在 AWS Mainframe Modernization 服務中執行程序，而不是在大型主機上執行。

**stonebranch UAC 架構**

下列架構圖代表高可用性 (HA) 通用控制器的active-active-passive模型。stonebranch UAC 部署在多個可用區域中，以提供高可用性並支援災難復原 (DR)。

![\[具有 DR 和控制器、Amazon EFS、Aurora 和 S3 儲存貯體的異地同步備份環境。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/01c6f9fa-87e6-459a-b694-5e03dd7f7952/images/3f94b855-c146-4fcb-902c-5d343438a558.png)


*通用控制器*

兩個 Linux 伺服器佈建為通用控制器。兩者都連接到相同的資料庫端點。每個伺服器都包含一個通用控制器應用程式和 OMS。最新版本的 Universal Controller 會在佈建時使用。

通用控制器部署在 Tomcat Webapp 中做為文件 ROOT，並在連接埠 80 上提供。此部署可簡化前端負載平衡器的組態。

HTTP over TLS 或 HTTPS 是使用stonebranch 萬用字元憑證啟用的 （例如，`https://customer.stonebranch.cloud`)。這可保護瀏覽器與應用程式之間的通訊。

*OMS*

通用代理程式和 OMS (Opswise Message Service) 位於每個通用控制器伺服器上。所有從客戶端部署的 Universal Agent 都會設定為連線至這兩個 OMS 服務。OMS 做為通用代理程式和通用控制器之間的常見傳訊服務。

Amazon EFS 會在每個伺服器上掛載多工緩衝處理目錄。OMS 使用此共用多工緩衝處理目錄來保留控制器和代理程式的連線和任務資訊。OMS 可在高可用性模式中運作。如果作用中 OMS 故障，被動 OMS 可以存取所有資料，並自動恢復作用中的操作。通用代理程式會偵測此變更，並自動連線至新的作用中 OMS。

*資料庫*

Amazon Relational Database Service (Amazon RDS) 存放 UAC 資料庫，Amazon Aurora MySQL 相容做為其引擎。Amazon RDS 有助於定期管理和提供排程備份。兩個通用控制器執行個體都連接到相同的資料庫端點。

*負載平衡器*

每個執行個體都會設定 Application Load Balancer。負載平衡器會在任何指定時間將流量導向作用中的控制器。您的執行個體網域名稱會指向個別的負載平衡器端點。

*URLs*

每個執行個體都有一個 URL，如下列範例所示。


| 
| 
| Environment | 執行個體 | 
| --- |--- |
| **生產** | `customer.stonebranch.cloud` | 
| **開發 （非生產）** | `customerdev.stonebranch.cloud` | 
| **測試 （非生產）** | `customertest.stonebranch.cloud` | 

**注意**  
  您可以根據您的需求設定非生產執行個體名稱。

*高可用性*

高可用性 (HA) 是系統在指定期間內持續運作而不會失敗的能力。此類故障包括但不限於儲存體、CPU 或記憶體問題導致的伺服器通訊回應延遲，以及網路連線能力。

若要符合 HA 要求：
+ 所有 EC2 執行個體、資料庫和其他組態都會鏡像在同一 AWS 區域內的兩個不同可用區域。
+ 控制器是透過 Amazon Machine Image (AMI) 在兩個可用區域的兩個 Linux 伺服器上佈建。例如，如果您在歐洲 eu-west-1 區域中佈建 ，則您在可用區域 eu-west-1a 和可用區域 eu-west-1c 中有通用控制器。
+ 不允許任何任務直接在應用程式伺服器上執行，也不允許將資料存放在這些伺服器上。
+ Application Load Balancer 會在每個 Universal Controller 上執行運作狀態檢查，以識別作用中的控制器，並將流量導向其中。如果一個伺服器發生問題，負載平衡器會自動將被動通用控制器提升為作用中狀態。然後，負載平衡器會從運作狀態檢查中識別新的作用中 Universal Controller 執行個體，並開始引導流量。容錯移轉會在四分鐘內發生，不會遺失任務，且前端 URL 保持不變。
+ Aurora MySQL 相容資料庫服務存放通用控制器資料。對於生產環境，資料庫叢集會在單一 AWS 區域內的兩個不同可用區域中建置兩個資料庫執行個體。兩個通用控制器都使用指向單一資料庫叢集端點的 Java Database Connectivity (JDBC) 介面。如果一個資料庫執行個體發生問題，資料庫叢集端點會動態指向運作狀態良好的執行個體。不需要手動介入。

*備份和清除*

stonebranch Universal Controller 設定為遵循表格中顯示的排程來備份和清除舊資料。


| 
| 
| Type | Schedule | 
| --- |--- |
| **活動** | 7 天 | 
| **稽核** | 90 天 | 
| **歷程記錄** | 60 天 | 

早於顯示日期的備份資料會匯出為 .xml 格式，並存放在檔案系統中。備份程序完成後，較舊的資料會從資料庫清除，並封存在 S3 儲存貯體中長達一年的生產執行個體。

您可以在通用控制器界面中調整此排程。不過，增加這些時間範圍可能會導致維護期間更長的停機時間。

## 工具
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-tools"></a>

**AWS 服務**
+ [AWS Mainframe Modernization](https://docs.aws.amazon.com/m2/latest/userguide/what-is-m2.html) 是一種 AWS 雲端原生平台，可協助您將大型主機應用程式現代化為 AWS 受管執行期環境。它提供工具和資源來協助您規劃和實作遷移和現代化。
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 提供區塊層級儲存體磁碟區，可搭配使用 Amazon EC2 執行個體。
+ [Amazon Elastic File System (Amazon EFS)](https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html) 可協助您在 AWS 雲端中建立和設定共用檔案系統。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。此模式使用 Amazon Aurora MySQL 相容版本。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [Elastic Load Balancing (ELB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) 會將傳入的應用程式或網路流量分散到多個目標。例如，您可以在一或多個可用區域中將流量分配到 Amazon EC2 執行個體、容器和 IP 地址。此模式使用 Application Load Balancer。

**斯通布蘭奇**
+ [Universal Automation Center (UAC)](https://stonebranchdocs.atlassian.net/wiki/spaces/SD/pages/239239169/Universal+Automation+Center) 是企業工作負載自動化產品的系統。此模式使用下列 UAC 元件：
  + [Universal Controller](https://www.stonebranch.com/documentation-universal-controller) 是在 Tomcat Web 容器中執行的 Java Web 應用程式，是 Universal Automation Center 的企業任務排程器和工作負載自動化代理程式解決方案。控制器提供用於建立、監控和設定控制器資訊的使用者介面；處理排程邏輯；處理所有往返 Universal Agents 的訊息；以及同步 Universal Automation Center 的大部分高可用性操作。
  + [Universal Agent](https://www.stonebranch.com/documentation-universal-agent) 是獨立於廠商的排程代理程式，可在所有主要運算平台上與現有的任務排程器協同合作，包括舊版和分散式。支援在 z/Series、i/Series、Unix、Linux 或 Windows 上執行的所有排程器。
+ [Universal Agent](https://www.stonebranch.com/documentation-universal-agent) 是獨立於廠商的排程代理程式，可在所有主要運算平台上與現有的任務排程器協同合作，包括舊版和分散式。支援在 z/Series、i/Series、Unix、Linux 或 Windows 上執行的所有排程器。
+ [stonebranch aws-mainframe-modernization-stonebranch-integration AWS Mainframe Modernization Universal Extension](https://github.com/aws-samples/aws-mainframe-modernization-stonebranch-integration/releases) 是在 AWS Mainframe Modernization 平台中執行、監控和重新執行批次任務的整合範本。

**Code**

此模式的程式碼可在 [aws-mainframe-modernization-stonebranch-integration](https://github.com/aws-samples/aws-mainframe-modernization-stonebranch-integration/releases/) GitHub 儲存庫中使用。

## 史詩
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-epics"></a>

### 在 Amazon EC2 上安裝通用控制器和通用代理程式
<a name="install-universal-controller-and-universal-agent-on-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載安裝檔案。 | 從stonebranch 伺服器下載安裝。若要取得安裝檔案，請聯絡stonebranch。 | 雲端架構師 | 
| 啟動 EC2 執行個體。 | 您將需要大約 3 GB 的額外空間來安裝通用控制器和通用代理程式。因此，請為執行個體提供至少 30 GB 的磁碟空間。將連接埠 8080 新增至安全群組，以便存取。 | 雲端架構師 | 
| 檢查先決條件。 | 在安裝之前，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 雲端管理員、Linux 管理員 | 
| 安裝通用控制器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 雲端架構師、Linux 管理員 | 
| 安裝 Universal Agent。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 雲端管理員、Linux 管理員 | 
| 將 OMS 新增至通用控制器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 

### 匯入 AWS Mainframe Modernization Universal Extension 並建立任務
<a name="import-aws-mainframe-modernization-universal-extension-and-create-a-task"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 匯入整合範本。 | 在此步驟中，您需要 [AWS Mainframe Modernization Universal Extension](https://github.com/aws-samples/aws-mainframe-modernization-stonebranch-integration/releases)。確保已下載最新版本的 .zip 檔案。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html)匯入整合範本後，您會在**可用服務**下看到 **AWS Mainframe Modernization Tasks**。 | 通用控制器管理員 | 
| 啟用可解析的登入資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 
| 啟動任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 

### 測試開始批次任務
<a name="test-starting-a-batch-job"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為批次任務建立任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 
| 啟動任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 

### 為多個任務建立工作流程
<a name="create-a-workflow-for-multiple-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 
| 更新任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 
| 建立工作流程。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 
| 檢查工作流程的狀態。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | Univeral Controller 管理員 | 

### 故障診斷失敗的批次任務並重新執行
<a name="troubleshoot-failed-batch-jobs-and-rerun"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修正失敗的任務並重新執行。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 

### 建立啟動應用程式和停止應用程式任務
<a name="create-start-application-and-stop-application-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立啟動應用程式動作。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) | 通用控制器管理員 | 

### 建立取消批次執行任務
<a name="create-a-cancel-batch-execution-task"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立取消批次動作。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/integrate-stonebranch-universal-controller-with-aws-mainframe-modernization.html) |  | 

## 相關資源
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-resources"></a>
+ [通用控制器](https://stonebranchdocs.atlassian.net/wiki/spaces/UC77/overview)
+ [通用代理程式](https://stonebranchdocs.atlassian.net/wiki/spaces/UA77/overview)
+ [LDAP 設定](https://stonebranchdocs.atlassian.net/wiki/spaces/UC77/pages/794552355/LDAP+Settings)
+ [SAML 單一登入](https://stonebranchdocs.atlassian.net/wiki/spaces/UC77/pages/794553130/SAML+Single+Sign-On)
+ [Xpress 轉換工具](https://www.stonebranch.com/resources/xpress-conversion-windows)

## 其他資訊
<a name="integrate-stonebranch-universal-controller-with-aws-mainframe-modernization-additional"></a>

**工作流程編輯器中的圖示**

![\[頂端的 RUNHELLO 任務、中間的 FOOBAR，以及第三層的其餘任務。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/01c6f9fa-87e6-459a-b694-5e03dd7f7952/images/837430ee-3159-4fe2-8e17-65168294ef1e.png)


**所有已連線的任務**

![\[RUNHELLO 連接到 FOOBAR，該 FOOBAR 連接到其餘三個任務。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/01c6f9fa-87e6-459a-b694-5e03dd7f7952/images/fe483348-9a6f-450b-87e6-ceae6b2bdaad.png)


**工作流程狀態**

![\[FOOBAR 任務失敗，其餘三個任務正在等待。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/01c6f9fa-87e6-459a-b694-5e03dd7f7952/images/5ea4e239-fbbe-4fa4-9ffa-b7a9443b7975.png)


# 使用來自 Precisely 的 Connect 將 VSAM 檔案遷移和複寫至 Amazon RDS 或 Amazon MSK
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely"></a>

*Prachi Khanna 和 Bopath GOPALSAMY，Amazon Web Services*

## 總結
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-summary"></a>

此模式說明如何使用 Connect [https://www.precisely.com/product/precisely-connect/connect](https://www.precisely.com/product/precisely-connect/connect) from Precisely，將虛擬儲存存取方法 (VSAM) 檔案從大型主機遷移並複寫至 AWS 雲端中的目標環境。此模式涵蓋的目標環境包括 Amazon Relational Database Service (Amazon RDS) 和 Amazon Managed Streaming for Apache Kafka (Amazon MSK)。Connect 使用[變更資料擷取 (CDC)](https://www.precisely.com/resource-center/productsheets/change-data-capture-with-connect) 持續監控來源 VSAM 檔案的更新，然後將這些更新傳輸到一或多個 AWS 目標環境。您可以使用此模式來滿足您的應用程式現代化或資料分析目標。例如，您可以使用 Connect 將 VSAM 應用程式檔案遷移至低延遲的 AWS 雲端，或將 VSAM 資料遷移至 AWS 資料倉儲或資料湖進行分析，以容忍高於應用程式現代化所需的同步延遲。

## 先決條件和限制
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-prereqs"></a>

**先決條件**
+ [IBM z/OS V2R1](https://www-40.ibm.com/servers/resourcelink/svc00100.nsf/pages/zosv2r1-pdf-download?OpenDocument) 或更新版本
+ [適用於 z/OS 的 CICS 交易伺服器 (CICS TS) V5.1](https://www.ibm.com/support/pages/cics-transaction-server-zos-51-detailed-system-requirements) 版或更新版本 (CICS/VSAM 資料擷取）
+ [IBM MQ 8.0](https://www.ibm.com/support/pages/downloading-ibm-mq-80) 或更新版本
+ 符合 [z/OS 安全要求](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Installation/Install-Connect-CDC-SQData-on-zOS/Prerequisites-for-z/OS/Security-authorization-requirements-for-z/OS) （例如 SQData 載入程式庫的 APF 授權）
+ VSAM 復原日誌已開啟
+ （選用） [CICS VSAM 復原版本 (CICS VR)](https://www.ibm.com/docs/en/cics-vr/5.1?topic=started-introducing-cics-vr) 以自動擷取 CDC 日誌
+ 作用中的 AWS 帳戶
+ [Amazon Virtual Private Cloud (VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-getting-started.html)，具有傳統平台可存取的子網路
+ 來自 Precisely 的 VSAM Connect 授權

**限制**
+ Connect 不支援根據來源 VSAM 結構描述或複製手冊自動建立目標資料表。您必須首次定義目標資料表結構。
+ 對於非串流目標，例如 Amazon RDS，您必須在套用引擎組態指令碼中指定目標映射的轉換來源。
+ 記錄、監控和提醒功能是透過 APIs且需要外部元件 （例如 Amazon CloudWatch) 才能完全運作。

**產品版本**
+ z/OS 的 SQData 40134
+ Amazon Elastic Compute Cloud (Amazon EC2) 上 Amazon Linux Amazon Machine Image (AMI) 的 SQData 4.0.43

## Architecture
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-architecture"></a>

**來源技術堆疊**
+ 任務控制語言 (JCL)
+ z/OS Unix shell 和互動式系統生產力設施 (ISPF)
+ VSAM 公用程式 (IDCAMS)

**目標技術堆疊**
+ Amazon EC2
+ Amazon MSK
+ Amazon RDS
+ Amazon VPC

**目標架構**

*將 VSAM 檔案遷移至 Amazon RDS*

下圖顯示如何在來源環境 （內部部署大型主機） 中使用 CDC 代理程式/發佈者，以及在目標環境 (AWS 雲端） 中使用[套用引擎](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Apply-engine)，即時或近乎即時地將 VSAM 檔案遷移至關聯式資料庫，例如 Amazon RDS。

![\[Diagram showing VSAM file migration from on-premises mainframe to AWS 雲端 using CDC and Apply Engine.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4ee183bd-1c0d-449d-8cdc-eb6e2c41a695/images/47cefbde-e0c8-4c36-ba48-cccc2c443074.png)


下圖顯示下列批次工作流程：

1. Connect 會比較備份檔案中的 VSAM 檔案以識別變更，然後將變更傳送至日誌串流，藉此擷取檔案的變更。

1. 發佈者會從系統日誌串流取用資料。

1. 發佈者會透過 TCP/IP 將擷取的資料變更傳達給目標引擎。Controller Daemon 會驗證來源和目標環境之間的通訊。

1. 目標環境中的套用引擎會從發佈者代理程式接收變更，並將其套用至關聯式或非關聯式資料庫。

圖表顯示下列線上工作流程：

1. Connect 會使用日誌複寫擷取線上檔案中的變更，然後將擷取的變更串流至日誌串流。

1. 發佈者會從系統日誌串流取用資料。

1. 發佈者會透過 TCP/IP 將擷取的資料變更傳達給目標引擎。控制器協助程式會驗證來源和目標環境之間的通訊。

1. 目標環境中的套用引擎會從發佈者代理程式接收變更，然後將其套用至關聯式或非關聯式資料庫。

*將 VSAM 檔案遷移至 Amazon MSK*

下圖顯示如何在高效能模式下將 VSAM 資料結構從大型主機串流至 Amazon MSK，並自動產生與 Amazon MSK 整合的 JSON 或 AVRO 結構描述轉換。

![\[Diagram showing data flow from on-premises mainframe to AWS 雲端 services via Amazon VPC.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4ee183bd-1c0d-449d-8cdc-eb6e2c41a695/images/13eb27ad-c0d2-489b-91e1-5b2a729fb8dd.png)


下圖顯示下列批次工作流程：

1. Connect 使用 CICS VR 或比較備份檔案的 VSAM 檔案來識別變更，以擷取檔案的變更。擷取的變更會傳送至日誌串流。

1. 發佈者會從系統日誌串流取用資料。

1. 發佈者會透過 TCP/IP 將擷取的資料變更傳達給目標引擎。控制器協助程式會驗證來源和目標環境之間的通訊。

1. 在平行處理模式下操作的複寫器引擎會將資料分割為工作快取單位。

1. 工作者執行緒會從快取擷取資料。

1. 資料會從工作者執行緒發佈至 Amazon MSK 主題。

1. 使用者使用[連接器](https://docs.aws.amazon.com/msk/latest/developerguide/msk-connect-connectors.html)，將 Amazon MSK 的變更套用至 Amazon DynamoDB、Amazon Simple Storage Service (Amazon S3) 或 Amazon OpenSearch Service 等目標。

圖表顯示下列線上工作流程：

1. 使用日誌複寫擷取線上檔案中的變更。擷取的變更會串流至日誌串流。

1. 發佈者會從系統日誌串流取用資料。

1. 發佈者會透過 TCP/IP 將擷取的資料變更傳達給目標引擎。控制器協助程式會驗證來源和目標環境之間的通訊。

1. 在平行處理模式下操作的複寫器引擎會將資料分割為工作快取單位。

1. 工作者執行緒會從快取擷取資料。

1. 資料會從工作者執行緒發佈至 Amazon MSK 主題。

1. 使用者使用[連接器](https://docs.aws.amazon.com/msk/latest/developerguide/msk-connect-connectors.html)將 Amazon MSK 的變更套用到 DynamoDB、Amazon S3 或 OpenSearch Service 等目標。

## 工具
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-tools"></a>
+ [Amazon Managed Streaming for Apache Kafka (Amazon MSK)](https://docs.aws.amazon.com/msk/latest/developerguide/what-is-msk.html) 是一項全受管服務，可協助您建置和執行使用 Apache Kafka 處理串流資料的應用程式。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。

## 史詩
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-epics"></a>

### 準備來源環境 （大型主機）
<a name="prepare-the-source-environment-mainframe"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 Connect CDC 4.1。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | IBM 大型主機開發人員/管理員 | 
| 設定 zFS 目錄。 | 若要設定 zFS 目錄，請遵循精確文件中 [zFS 變數目錄](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Installation/Install-Connect-CDC-SQData-on-zOS/Prerequisites-for-z/OS/Security-authorization-requirements-for-z/OS/zFS-variable-directories)的指示。控制器協助程式和擷取/發佈代理程式組態存放在 z/OS UNIX Systems Services 檔案系統中 （稱為 zFS)。Controller Daemon、Capture、Storage 和 Publisher 代理程式需要預先定義的 zFS 目錄結構，才能存放少量檔案。 | IBM 大型主機開發人員/管理員 | 
| 設定 TCP/IP 連接埠。 | 若要設定 TCP/IP 連接埠，請遵循精確文件中 [TCP/IP 連接埠](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Installation/Install-Connect-CDC-SQData-on-UNIX/Prerequisites-for-UNIX/Security-authorization-requirements-for-UNIX/TCP/IP-ports)的指示。Controller Daemon 需要來源系統的 TCP/IP 連接埠。引擎會在目標系統上參考連接埠 （其中處理擷取的變更資料）。 | IBM 大型主機開發人員/管理員 | 
| 建立 z/OS 日誌串流。 | 若要建立 [z/OS 日誌串流](https://www.ibm.com/docs/en/was/8.5.5?topic=SSEQTP_8.5.5/com.ibm.websphere.installation.zseries.doc/ae/cins_logstrm.html)，請遵循精確文件中[建立 z/OS 系統 logStreams](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-sources/IMS-z/OS/IMS-TM-EXIT-capture/Prepare-environment/Create-z/OS-system-logStreams?tocId=wy6243SXlIiEczwR8JE8WA) 的指示。Connect 使用 logstream 在遷移期間擷取和串流來源環境和目標環境之間的資料。如需建立 z/OS LogStream 的範例 JCL，請參閱精確文件中的[建立 z/OS 系統 logStreams](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-sources/IMS-z/OS/IMS-TM-EXIT-capture/Prepare-environment/Create-z/OS-system-logStreams?tocId=wy6243SXlIiEczwR8JE8WA)。 | IBM 大型主機開發人員 | 
| 識別並授權 zFS 使用者和已啟動任務IDs。 | 使用 RACF 授予 OMVS zFS 檔案系統的存取權。如需範例 JCL，請參閱精確文件中的[識別和授權 zFS 使用者和啟動的任務 IDs](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-sources/IMS-z/OS/IMS-log-reader-capture/Prepare-environment/Identify-and-authorize-zFS-user-and-started-task-IDs?tocId=MrBXpFu~N0iAy~8VTrH0tQ)。 | IBM 大型主機開發人員/管理員 | 
| 產生 z/OS 公有/私有金鑰和授權金鑰檔案。 | 執行 JCL 以產生金鑰對。如需範例，請參閱此模式*額外資訊*區段中的*金鑰對範例*。如需說明，請參閱精確文件中的[產生 z/OS 公有和私有金鑰和授權金鑰檔案](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-sources/Db2-z/OS/Prepare-the-environment/Generate-z/OS-public-and-private-keys-and-authorized-key-file?tocId=fceE77dWT8smZsSaE~FeMQ)。 | IBM 大型主機開發人員/管理員 | 
| 啟用 CICS VSAM Log Replicate 並將其連接至日誌串流。 | 執行下列 JCL 指令碼：<pre> //STEP1 EXEC PGM=IDCAMS<br /> //SYSPRINT DD SYSOUT=*<br /> //SYSIN DD *<br />   ALTER SQDATA.CICS.FILEA -<br />   LOGSTREAMID(SQDATA.VSAMCDC.LOG1) -<br />   LOGREPLICATE</pre> | IBM 大型主機開發人員/管理員 | 
| 透過 FCT 啟用 VSAM 檔案復原日誌。 | 修改檔案控制表 (FCT)，以反映下列參數變更：<pre> Configure FCT Parms<br />   CEDA ALT FILE(name) GROUP(groupname)<br />   DSNAME(data set name)<br />   RECOVERY(NONE|BACKOUTONLY|ALL)<br />   FWDRECOVLOG(NO|1–99)<br />   BACKUPTYPE(STATIC|DYNAMIC)<br />   RECOVERY PARAMETERS<br />   RECOVery : None | Backoutonly | All<br />   Fwdrecovlog : No | 1-99<br />   BAckuptype : Static | Dynamic</pre> | IBM 大型主機開發人員/管理員 | 
| 設定發佈者代理程式的 CDCzLog。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | IBM 大型主機開發人員/管理員 | 
| 啟用控制器協助程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | IBM 大型主機開發人員/管理員 | 
| 啟用發佈者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | IBM 大型主機開發人員/管理員 | 
| 啟用 logstream。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | IBM 大型主機開發人員/管理員 | 

### 準備目標環境 (AWS)
<a name="prepare-the-target-environment-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 EC2 執行個體上精確安裝 。 | 若要在 Amazon EC2 的 Amazon Linux AMI 上從 Precisely 安裝 Connect，請遵循 Precisely 文件中 [UNIX 上的 Install Connect CDC (SQData)](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Installation/Install-Connect-CDC-SQData-on-UNIX) 的指示。 | 一般 AWS | 
| 開啟 TCP/IP 連接埠。 | 若要修改安全群組以包含用於傳入和傳出存取的控制器協助程式連接埠，請遵循精確文件中 [TCP/IP](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-sources/Change-data-capture/Transient-storage-and-publishing/TCP/IP) 的指示。 | 一般 AWS | 
| 建立檔案目錄。 | 若要建立檔案目錄，請遵循 Precisely 文件中[準備目標套用環境](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-targets/Kafka/Prepare-target-apply-environment)的指示。 | 一般 AWS | 
| 建立 Apply Engine 組態檔案。 | 在 Apply Engine 的工作目錄中建立 Apply Engine 組態檔案。下列範例組態檔案顯示 Apache Kafka 為目標：<pre>builtin.features=SASL_SCRAM<br />  security.protocol=SASL_SSL<br />  sasl.mechanism=SCRAM-SHA-512<br />  sasl.username=<br />  sasl.password=<br />  metadata.broker.list=</pre>如需詳細資訊，請參閱 Apache Kafka 文件中[的安全性](https://kafka.apache.org/documentation/#security)。 | 一般 AWS | 
| 建立套用引擎處理的指令碼。 | 建立套用引擎的指令碼，以處理來源資料並將來源資料複寫至目標。如需詳細資訊，請參閱精確文件中[的建立套用引擎指令碼](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Apply-engine/Apply-engine-script-development/Create-an-apply-engine-script)。 | 一般 AWS | 
| 執行指令碼。 | 使用 `SQDPARSE`和 `SQDENG`命令來執行指令碼。如需詳細資訊，請參閱精確說明文件中[剖析 zOS 的指令碼](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Apply-engine/Apply-engine-script-development/Parse-a-script/Parse-a-script-for-zOS)。 | 一般 AWS | 

### 驗證環境
<a name="validate-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證用於 CDC 處理的 VSAM 檔案和目標資料表清單。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | 一般 AWS、大型主機 | 
| 確認 Connect CDC SQData 產品已連結。 | 執行測試任務，並確認此任務的傳回碼為 0 （成功）。Connect CDC SQData Apply Engine 狀態訊息應會顯示作用中的連線訊息。 | 一般 AWS、大型主機 | 

### 執行並驗證測試案例 （批次）
<a name="run-and-validate-test-cases-batch"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在大型主機中執行批次任務。 | 使用修改過的 JCL 執行批次應用程式任務。在修改後的 JCL 中包含執行下列動作的步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | 一般 AWS、大型主機 | 
| 檢查日誌串流。 | 檢查 logstream 以確認您可以查看已完成大型主機批次任務的變更資料。 | 一般 AWS、大型主機 | 
| 驗證來源差異變更和目標資料表的計數。 | 若要確認記錄的高度，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | 一般 AWS、大型主機 | 

### 執行並驗證測試案例 （線上）
<a name="run-and-validate-test-cases-online"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 CICS 區域中執行線上交易。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely.html) | IBM 大型主機開發人員 | 
| 檢查日誌串流。 | 確認日誌串流已填入特定的記錄層級變更。 | AWS Mainframe 開發人員 | 
| 驗證目標資料庫中的計數。 | 監控 Apply Engine 的記錄層級計數。 | 精確，Linux | 
| 驗證目標資料庫中的記錄計數和資料記錄。 | 查詢目標資料庫以驗證記錄計數和資料記錄。 | 一般 AWS | 

## 相關資源
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-resources"></a>
+ [VSAM z/OS](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Setup-and-configure-sources/VSAM-z/OS) （正確文件）
+ [套用引擎](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Apply-engine) （準確文件）
+ [複寫器引擎](https://help.precisely.com/r/Connect-CDC-SQData/4.1.43/en-US/Connect-CDC-SQData-Help/Source-and-Target-Configuration/Replicator-engine) （正確文件）
+ [日誌串流 ](https://www.ibm.com/docs/en/zos/2.3.0?topic=logger-log-stream)(IBM 文件）

## 其他資訊
<a name="migrate-and-replicate-vsam-files-to-amazon-rds-or-amazon-msk-using-connect-from-precisely-additional"></a>

**組態檔案範例**

這是日誌串流的範例組態檔案，其中來源環境是大型主機，而目標環境是 Amazon MSK：

```
 
  -- JOBNAME -- PASS THE SUBSCRIBER NAME
  -- REPORT  progress report will be produced after "n" (number) of Source records processed.
  
  JOBNAME VSMTOKFK;
  --REPORT EVERY 100;
  -- Change Op has been ‘I’ for insert, ‘D’ for delete , and ‘R’ for Replace. For RDS it is 'U' for update
  -- Character Encoding on z/OS is Code Page 1047, on Linux and UNIX it is Code Page 819 and on Windows, Code Page 1252
  OPTIONS
  CDCOP('I', 'U', 'D'),
  PSEUDO NULL = NO,
  USE AVRO COMPATIBLE NAMES,
  APPLICATION ENCODING SCHEME = 1208;
  
  --       SOURCE DESCRIPTIONS
  
  BEGIN GROUP VSAM_SRC;
  DESCRIPTION COBOL ../copybk/ACCOUNT AS account_file;
  END GROUP;
  
  --       TARGET DESCRIPTIONS
  
  BEGIN GROUP VSAM_TGT;
  DESCRIPTION COBOL ../copybk/ACCOUNT AS account_file;
  END GROUP;
  
  --       SOURCE DATASTORE (IP & Publisher name)
  
  DATASTORE cdc://10.81.148.4:2626/vsmcdct/VSMTOKFK
  OF VSAMCDC
  AS CDCIN
  DESCRIBED BY GROUP VSAM_SRC ACCEPT ALL;
  
  --       TARGET DATASTORE(s) - Kafka and topic name
  
  DATASTORE 'kafka:///MSKTutorialTopic/key'
  OF JSON
  AS CDCOUT
  DESCRIBED BY GROUP VSAM_TGT FOR INSERT;
  
  --       MAIN SECTION
  
  PROCESS INTO
  CDCOUT
  SELECT
  {
  SETURL(CDCOUT, 'kafka:///MSKTutorialTopic/key')
  REMAP(CDCIN, account_file, GET_RAW_RECORD(CDCIN, AFTER), GET_RAW_RECORD(CDCIN, BEFORE))
  REPLICATE(CDCOUT, account_file)
  }
  FROM CDCIN;
```

**金鑰對範例**

此範例說明如何執行 JCL 來產生金鑰對：

```
//SQDUTIL EXEC PGM=SQDUTIL //SQDPUBL DD DSN=&USER..NACL.PUBLIC, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=21200), // DISP=(,CATLG,DELETE),UNIT=SYSDA, // SPACE=(TRK,(1,1)) //SQDPKEY DD DSN=&USER..NACL.PRIVATE, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=21200), // DISP=(,CATLG,DELETE),UNIT=SYSDA, // SPACE=(TRK,(1,1)) //SQDPARMS DD  keygen //SYSPRINT DD SYSOUT= //SYSOUT DD SYSOUT=* //SQDLOG DD SYSOUT=* //*SQDLOG8 DD DUMMY
```

# 使用 現代化 CardDemo 大型主機應用程式 AWS Transform
<a name="modernize-carddemo-mainframe-app"></a>

*Santosh Kumar Singh 和 Cheryl du Preez，Amazon Web Services*

## 摘要
<a name="modernize-carddemo-mainframe-app-summary"></a>

[AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/what-is-service.html) 旨在加速大型主機應用程式的現代化。它使用生成式 AI 來簡化大型主機現代化程序。它可自動化複雜的任務，例如：舊版程式碼分析、大型主機文件、商業規則擷取、單體應用程式分解為商業網域，以及程式碼重構。它透過自動化複雜的任務來加速現代化專案，例如應用程式分析和遷移序列規劃。分解單體應用程式時， AWS Transform 智慧排序大型主機應用程式轉換，這可協助您平行 轉換業務功能。 AWS Transform 可以加速決策並增強操作敏捷性和遷移效率。

此模式提供step-by-step指示，協助您 AWS Transform 使用 [CardDemo](https://github.com/aws-samples/aws-mainframe-modernization-carddemo) 來測試 的大型主機現代化功能，這是範例開放原始碼大型主機應用程式。

## 先決條件和限制
<a name="modernize-carddemo-mainframe-app-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ AWS IAM Identity Center，[已啟用](https://docs.aws.amazon.com/singlesignon/latest/userguide/enable-identity-center.html)
+ 允許管理員啟用 [的許可](https://docs.aws.amazon.com/transform/latest/userguide/security_iam_id-based-policy-examples.html#id-based-policy-examples-admin-enable-transform) AWS Transform
+ 允許管理員接受 AWS Transform Web 應用程式的 Amazon Simple Storage Service (Amazon S3) 連線請求的[許可](https://docs.aws.amazon.com/transform/latest/userguide/security_iam_id-based-policy-examples.html#id-based-policy-examples-admin-connector) 

**限制**
+ AWS Transform 僅適用於部分 AWS 區域。如需支援區域的完整清單，請參閱[支援的 區域 AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/regions.html)。
+ AWS Transform 支援從常見商業導向語言 (COBOL) 到 Java 的程式碼分析、文件產生、業務規則擷取、分解和重構。如需詳細資訊，請參閱[功能和主要功能](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe.html#transform-app-mainframe-features)，以及[大型主機應用程式轉換支援的檔案類型](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe.html#transform-app-mainframe-supported-files)。
+ 中有大型主機轉換功能的服務配額 AWS Transform。如需詳細資訊，請參閱 [的配額 AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/transform-limits.html)。
+ 若要在共用工作區上協作，所有使用者都必須是與 AWS Transform Web 應用程式執行個體 AWS IAM Identity Center 相關聯的相同 執行個體的註冊使用者。
+ Amazon S3 儲存貯體和 AWS Transform 必須位於相同的 AWS 帳戶 和 區域。

## Architecture
<a name="modernize-carddemo-mainframe-app-architecture"></a>

下圖顯示您在此模式中設定的架構。

![\[使用 AWS 轉換來現代化存放在 Amazon S3 儲存貯體中的大型主機應用程式。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0e539474-b733-452d-b0fb-6b3f4cbd5075/images/75be6d78-5b43-448c-ad07-bf74b9ae14ad.png)


該圖顯示以下工作流程：

1. AWS Transform 使用連接器來存取存放在 Amazon S3 儲存貯體中的 CardDemo 大型主機應用程式。

1. AWS Transform 使用 AWS IAM Identity Center 來管理使用者存取和身分驗證。系統會實作多層安全控制以進行身分驗證、授權、加密和存取管理，以協助在處理期間保護程式碼和成品。使用者透過聊天界面與 AWS Transform 客服人員互動。您可以為 AI 代理器提供英文特定任務的說明。如需詳細資訊，請參閱 AWS Transform 文件[中的循環中的人工 (HITL)](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe.html#transform-app-mainframe-hitl)。

1. AI 代理程式會解譯使用者的指示、建立任務計畫、將任務分割為可執行任務，以及自動執行動作。使用者可以檢閱和核准轉換。轉換任務包括下列項目：
   + **程式碼分析** – AWS Transform 分析每個檔案中的程式碼，以取得檔案名稱、檔案類型、程式碼行及其路徑等詳細資訊。代理程式會分析原始程式碼、執行分類、建立相依性映射，以及識別任何遺失的成品。它也會識別重複的元件。
   + **文件產生** – AWS Transform 產生大型主機應用程式的文件。透過分析程式碼，它可以自動建立應用程式的詳細文件，包括存在於舊版系統中的商業邏輯、流程、整合和相依性的說明。
   + **業務邏輯擷取** - AWS Transform 分析 COBOL 程式以記錄其核心業務邏輯，協助您了解基本業務邏輯。
   + **程式碼分解** – 將程式碼 AWS Transform 分解為考量程式與元件之間相依性的網域。將相同網域中的相關檔案和程式分組可改善組織，並在將其分解為較小的元件時協助保留應用程式的邏輯結構。
   + **遷移波動規劃** – 根據您在分解階段建立的網域， 會以建議的現代化順序 AWS Transform 產生遷移波動計劃。
   + **程式碼重構** – 將所有或所選網域檔案中的程式碼 AWS Transform 重構為 Java 程式碼。此步驟的目標是保留應用程式的關鍵商業邏輯，同時將其重構為現代化、雲端最佳化的 Java 應用程式。

1. AWS Transform 會將重構程式碼、產生的文件、相關聯的成品和執行時間程式庫存放在 Amazon S3 儲存貯體中。您可以執行下列動作：
   + 存取 Amazon S3 儲存貯體中的執行時間資料夾。
   + 遵循 AWS Transform 文件中的建置和部署[現代化應用程式，以建置和部署](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow-build-deploy.html)應用程式。
   + 透過聊天界面，請求和下載範例 AWS CloudFormation AWS Cloud Development Kit (AWS CDK)，或 Hashicorp Terraform 範本。這些範本可協助您部署支援重構應用程式所需的 AWS 資源。
   + 使用 [Reforge](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-refactor-code-reforge) 透過使用大型語言模型 (LLMs) 來改善重構程式碼的品質。重構引擎會保留 COBOL 的功能等效性，同時將其轉換為 Java 程式碼。Reforge 是轉換後可用的選用步驟。此步驟使用 LLMs 來重組程式碼，使其與原生 Java 非常相似，這可以改善可讀性和可維護性。Reforge 也新增了人類可讀的註解，以協助您了解程式碼，並實作現代編碼模式和最佳實務。

## 工具
<a name="modernize-carddemo-mainframe-app-tools"></a>

**AWS 服務**
+ [AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/what-is-service.html) 使用代理式 AI 來協助您加速傳統工作負載的現代化，例如 .NET、大型主機和 VMware 工作負載。
+ [AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html) 可協助您集中管理 AWS 帳戶 和雲端應用程式的單一登入 (SSO) 存取。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**程式碼儲存庫**

您可以使用開放原始碼 AWS [CardDemo](https://github.com/aws-samples/aws-mainframe-modernization-carddemo) 大型主機應用程式做為範例應用程式，以開始使用大型主機現代化。

## 最佳實務
<a name="modernize-carddemo-mainframe-app-best-practices"></a>
+ **從小**開始 – 從較不複雜的小程式碼 (15，000–20，000 行程式碼） 開始，以了解 如何 AWS Transform 分析和轉換大型主機應用程式。
+ **結合人類專業知識** – AWS Transform 用作加速器，同時套用人類專業知識以獲得最佳結果。
+ **徹底檢閱和測試** – 務必仔細檢閱轉換後的程式碼，並在轉換後執行全面的測試，以驗證功能等效性。
+ **提供意見回饋** – 若要提供意見回饋和改進建議，請使用 中的**傳送意見回饋**按鈕， AWS 管理主控台 或使用 建立案例[AWS 支援](https://support.console.aws.amazon.com/)。如需詳細資訊，請參閱[建立支援案例](https://docs.aws.amazon.com/awssupport/latest/user/case-management.html)。您的輸入對於服務增強和未來的開發很有價值。

## 史詩
<a name="modernize-carddemo-mainframe-app-epics"></a>

### 準備大型主機應用程式
<a name="prepare-the-mainframe-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立儲存貯體。 | 在啟用 的相同 AWS 帳戶 和區域中建立 Amazon S3 AWS Transform 儲存貯體。您可以使用此儲存貯體來存放大型主機應用程式程式碼， AWS Transform 並使用此儲存貯體來存放產生的文件、重構程式碼，以及與轉換相關聯的其他檔案。如需說明，請參閱 Amazon S3 文件中的[建立儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體。 | 一般 AWS | 
| 準備範例大型主機應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html) | 應用程式開發人員、DevOps 工程師 | 

### 設定 IAM Identity Center 和 AWS Transform
<a name="configure-sso-and-trn"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將使用者新增至 IAM Identity Center。 | 將您的潛在使用者新增至 IAM Identity Center。遵循 AWS Transform 文件中在 [IAM Identity Center 中新增使用者](https://docs.aws.amazon.com/transform/latest/userguide/transform-user-management.html#transform-add-idc-users)的指示。 | AWS 管理員 | 
| 啟用 AWS Transform 並新增使用者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html) | AWS 管理員 | 
| 設定使用者存取 AWS Transform Web 應用程式。 | 每個使用者都必須接受存取 AWS Transform Web 應用程式的邀請。遵循 AWS Transform 文件中[接受邀請](https://docs.aws.amazon.com/transform/latest/userguide/transform-user-onboarding.html#transform-user-invitation)的指示。 | 應用程式開發人員、應用程式擁有者 | 
| 登入 AWS Transform Web 應用程式。 | 遵循[登入 AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/transform-user-onboarding.html#transform-user-signin)中的指示。 | 應用程式開發人員、應用程式擁有者 | 
| 設定工作區。 | 設定工作區，讓使用者可以在 AWS Transform Web 應用程式中協作。請遵循 AWS Transform 文件中[啟動專案](https://docs.aws.amazon.com/transform/latest/userguide/transform-environment.html#start-workflow)中的指示。 | AWS 管理員 | 

### 轉換大型主機應用程式
<a name="transform-the-mainframe-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立轉換任務。 | 建立轉換任務以現代化 CardDemo 大型主機應用程式。如需說明，請參閱 AWS Transform 文件中的[建立和啟動任務](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-start-job)。當您被要求在 AWS Transform 聊天界面中設定目標時，請選擇**執行大型主機現代化 (IBM z/OS 至 AWS)**，然後選擇**分析程式碼、產生技術文件、商業邏輯、分解程式碼、計劃遷移序列，以及將程式碼轉換為 Java**。 | 應用程式開發人員、應用程式擁有者 | 
| 設定連接器。 | 建立 Amazon S3 儲存貯體的連接器，其中包含 CardDemo 大型主機應用程式。此連接器允許 AWS Transform 存取儲存貯體中的資源，並執行連續的轉換函數。如需說明，請參閱 AWS Transform 文件中的[設定連接器](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-setup-connector)。 | AWS 管理員 | 
| 執行程式碼分析。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)如需詳細資訊，請參閱 AWS Transform 文件中的[程式碼分析](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-code-analysis)。 | 應用程式開發人員、應用程式擁有者 | 
| 產生技術文件。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)如需詳細資訊，請參閱 [文件中的產生技術](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-generate-documentation) AWS Transform 文件。 | 應用程式開發人員、應用程式擁有者 | 
| 擷取商業邏輯。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)如需詳細資訊，請參閱 AWS Transform 文件中的[擷取商業邏輯](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-extract-business-logic)。 | 應用程式開發人員、應用程式擁有者 | 
| 分解程式碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)如需分解和種子的詳細資訊，請參閱 AWS Transform 文件中的[分解](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-decomposition)。 | 應用程式開發人員、應用程式擁有者 | 
| 規劃遷移波紋。 | 規劃 CardDemo 應用程式的遷移波紋。遵循 AWS Transform 文件中的[遷移波動規劃](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-wave-planning)中的指示，以檢閱和編輯波動計畫。 | 應用程式開發人員、應用程式擁有者 | 
| 重構程式碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html) | 應用程式開發人員、應用程式擁有者 | 
| （選用） 使用 Reforge 改善 Java 程式碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)如需詳細資訊，請參閱 AWS Transform 文件中的[重新建構](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-refactor-code-reforge)。 | 應用程式開發人員、應用程式擁有者 | 
| 簡化部署。 | AWS Transform 可以為 CloudFormation AWS CDK或 Terraform 提供基礎設施作為程式碼 (IaC) 範本。這些範本可協助您部署核心元件，包括運算、資料庫、儲存和安全資源。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)如需詳細資訊，請參閱 AWS Transform 文件中的[部署功能](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-features-deployment)。 | 應用程式開發人員、應用程式擁有者 | 

## 疑難排解
<a name="modernize-carddemo-mainframe-app-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 您無法在 AWS Transform Web 應用程式中檢視原始程式碼或產生的文件。 | 將政策新增至 Amazon S3 儲存貯體的 CORS 許可，以允許 AWS Transform 做為原始伺服器。如需詳細資訊，請參閱 AWS Transform 文件中的 [S3 儲存貯體 CORS 許可](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-setup-connector-s3)。 | 

## 相關資源
<a name="modernize-carddemo-mainframe-app-resources"></a>

**AWS 文件**
+ [大型主機應用程式的轉換 ](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html)(AWS Transform 文件）

**其他 AWS 資源**
+ [使用 AI 代理器搭配 加速您的大型主機現代化旅程 AWS Transform](https://aws.amazon.com/blogs/migration-and-modernization/accelerate-your-mainframe-modernization-journey-using-ai-agents-with-aws-transform/)(AWS 部落格文章）
+ [AWS Transform FAQs](https://aws.amazon.com/transform/faq/)
+ [AWS IAM Identity Center FAQs](https://aws.amazon.com/iam/identity-center/faqs/)

**影片和教學課程**
+ [Amazon Q 開發人員簡介：轉換](https://explore.skillbuilder.aws/learn/courses/21893/aws-flash-introduction-to-amazon-q-developer-transform)AWS （技能建置器）
+ [AWS re：Invent 2024 - 使用 Amazon Q Developer (YouTube) 更快速地現代化大型主機應用程式](https://www.youtube.com/watch?v=pSi0XtYfY4o) YouTube
+ [AWS re：Invent 2024 - 自動化遷移和現代化以加速轉型](https://www.youtube.com/watch?v=9FjxnEoH5wg) (YouTube)
+ [AWS re：Invent 2024 - Toyota 透過新一代 AI (YouTube) 推動創新並增強營運效率](https://www.youtube.com/watch?v=_NXc1MJenw4) YouTube

**注意**  
AWS Transform 先前稱為*大型主機的 Amazon Q Developer 轉換*。

# 使用 和 Terraform 現代化 AWS Transform 和部署大型主機應用程式
<a name="modernize-mainframe-app-transform-terraform"></a>

*Mason Cahill、Qandi、Prachi Khanna、Sivasubramanian Ramani 和 Santosh Kumar Singh，Amazon Web Services*

## 摘要
<a name="modernize-mainframe-app-transform-terraform-summary"></a>

[AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/what-is-service.html) 可以加速 .NET、大型主機和 VMware 工作負載的大規模現代化。它部署專門的 AI 代理器，可自動化複雜的任務，例如評估、程式碼分析、重構、分解、相依性映射、驗證和轉型規劃。此模式示範如何使用 AWS Transform 來現代化大型主機應用程式，然後使用 [Hashicorp Terraform](https://developer.hashicorp.com/terraform/intro) 將其部署至 AWS 基礎設施。這些step-by-step說明可協助您將 [CardDemo](https://github.com/aws-samples/aws-mainframe-modernization-carddemo) 轉換為從 COBOL 到現代 Java 應用程式的範例開放原始碼大型主機應用程式。

## 先決條件和限制
<a name="modernize-mainframe-app-transform-terraform-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 建立 AWS 資源和部署應用程式的管理許可
+ Terraform 1.5.7 版或更新版本，[已設定](https://developer.hashicorp.com/terraform/tutorials/aws-get-started?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS)
+ AWS Terraform 提供者，[已設定](https://registry.terraform.io/providers/hashicorp/aws/2.36.0/docs#authentication)
+ AWS IAM Identity Center，[已啟用](https://docs.aws.amazon.com/singlesignon/latest/userguide/enable-identity-center.html)
+ AWS Transform，[已啟用](https://docs.aws.amazon.com/transform/latest/userguide/getting-started.html)
+ [加入](https://docs.aws.amazon.com/transform/latest/userguide/transform-user-management.html) AWS Transform 工作區的使用者，具有可執行轉換任務的貢獻者角色

**限制**
+ AWS Transform 僅適用於部分 AWS 區域。如需支援區域的完整清單，請參閱 [支援的 區域 AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/regions.html)。
+ 中有大型主機轉換功能的服務配額 AWS Transform。如需詳細資訊，請參閱 [的配額 AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/transform-limits.html)。
+ 若要在共用工作區上協作，所有使用者都必須是與 AWS Transform Web 應用程式執行個體 AWS IAM Identity Center 相關聯的相同 執行個體的註冊使用者。
+ Amazon Simple Storage Service (Amazon S3) 儲存貯體 和 AWS Transform 必須位於相同的 AWS 帳戶 和 區域。

## Architecture
<a name="modernize-mainframe-app-transform-terraform-architecture"></a>

下圖顯示舊版應用程式和部署至 的end-to-end現代化 AWS 雲端。應用程式和資料庫登入資料存放在 中 AWS Secrets Manager，Amazon CloudWatch 提供監控和記錄功能。

![\[AWS 透過 Terraform 將大型主機應用程式和部署現代化。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/78bc1e6e-cd3d-4c6d-ae4b-0675a6898fd9/images/332ccf35-f55a-449e-a05d-7e321b3867b7.png)


該圖顯示以下工作流程：

1. 透過 AWS IAM Identity Center，使用者會在 AWS Transform 中驗證和存取 AWS 帳戶。

1. 使用者將 COBOL 大型主機程式碼上傳至 Amazon S3 儲存貯體，並在其中啟動轉換 AWS Transform。

1. AWS Transform 將 COBOL 程式碼現代化為雲端原生 Java 程式碼，並將現代化程式碼存放在 Amazon S3 儲存貯體中。

1. Terraform 會建立 AWS 基礎設施來部署現代化應用程式，包括 Application Load Balancer、Amazon Elastic Compute Cloud (Amazon EC2) 執行個體和 Amazon Relational Database Service (Amazon RDS) 資料庫。Terraform 會將現代化程式碼部署到 Amazon EC2 執行個體。

1. VSAM 檔案會上傳至 Amazon EC2，並從 Amazon EC2 遷移至 Amazon RDS 資料庫。

## 工具
<a name="modernize-mainframe-app-transform-terraform-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。在此模式中，SQL Server 容錯移轉叢集執行個體會安裝在 Amazon EC2 執行個體上。
+ [AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html) 可協助您集中管理 AWS 帳戶 和雲端應用程式的單一登入 (SSO) 存取。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您將程式碼中的硬式編碼憑證 (包括密碼) 取代為 Secrets Manager 的 API 呼叫，以便透過程式設計方法來擷取機密。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/what-is-service.html) 使用代理式 AI 來協助您加速傳統工作負載的現代化，例如 .NET、大型主機和 VMware 工作負載。

**其他工具**
+ [Apache Maven](https://maven.apache.org/) 是一種開放原始碼軟體專案管理，並為 Java 專案建置自動化工具。
+ [Apache Tomcat](https://tomcat.apache.org/) 是適用於 Java 程式碼的開放原始碼 Servlet 容器和 Web 伺服器。
+ [HashiCorp Terraform](https://www.terraform.io/docs) 是一種基礎設施即程式碼 (IaC) 工具，可協助您使用程式碼來佈建和管理雲端基礎設施和資源。
+ [Spring Boot](https://spring.io/projects/spring-boot) 是一種開放原始碼架構，建置在 Java 中的 Spring Framework 之上。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [大型主機轉換 E2E](https://github.com/aws-samples/sample-mainframe-transformation-e2e) 儲存庫中使用。此模式使用開放原始碼 AWS [CardDemo](https://github.com/aws-samples/aws-mainframe-modernization-carddemo) 大型主機應用程式做為範例應用程式。

## 最佳實務
<a name="modernize-mainframe-app-transform-terraform-best-practices"></a>
+ 指派遷移目標程式碼和資源的完整擁有權。
+ 在擴展到完整遷移之前，開發並測試概念驗證。
+ 保護所有利益相關者的承諾。
+ 建立清晰的通訊管道。
+ 定義並記錄可行產品 (MVP) 的最低需求。
+ 設定明確的成功條件。

## 史詩
<a name="modernize-mainframe-app-transform-terraform-epics"></a>

### 準備和上傳大型主機應用程式程式碼
<a name="prepare-and-upload-the-mainframe-application-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立儲存貯體。 | 在啟用 的相同 AWS 帳戶 和區域中建立 Amazon S3 AWS Transform 儲存貯體。您可以使用此儲存貯體來存放建置和執行應用程式所需的大型主機應用程式程式碼、資料和其他指令碼。 AWS Transform 使用此儲存貯體來存放重構程式碼和與轉換相關聯的其他檔案。如需說明，請參閱 Amazon S3 文件中的 [建立儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html) 體。 | 一般 AWS、AWS 管理員 | 
| 設定儲存貯體的 CORS 許可。 | 設定儲存貯體進行 AWS Transform 存取時，您需要為儲存貯體設定跨來源資源共用 (CORS)。如果未正確設定，您可能無法使用 的內嵌檢視或檔案比較功能 AWS Transform。如需如何為儲存貯體設定 CORS 的說明，請參閱[在 Amazon S3 儲存貯體中使用跨來源資源共用](https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html)。 Amazon S3 如需政策，請參閱 AWS Transform 文件中的 [S3 儲存貯體 CORS 許可](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-setup-connector-s3)。 | 一般 AWS、AWS 管理員 | 
| 準備範例大型主機應用程式程式碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | General AWS，應用程式開發人員 | 

### 轉換大型主機應用程式
<a name="transform-the-mainframe-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 AWS Transform 任務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、應用程式擁有者 | 
| 設定連接器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、應用程式擁有者 | 
| 轉換程式碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、應用程式擁有者 | 

### 透過 Terraform 部署基礎設施
<a name="deploy-the-infrastructure-through-terraform"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新範本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html)對於生產環境或類似生產環境，請設定其他安全元件。例如，啟用 [AWS WAF Application Load Balancer 的保護](https://aws.amazon.com/about-aws/whats-new/2024/02/aws-application-load-balancer-one-click-waf-integrations/)。 | General AWS、AWS 管理員 | 
| 部署基礎設施。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | Terraform | 

### 在 Amazon EC2 執行個體上安裝和設定 Apache Tomcat
<a name="install-and-configure-apache-tomcat-on-the-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝所需的軟體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 
| 驗證軟體安裝。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 

### 編譯和封裝現代化應用程式程式碼
<a name="compile-and-package-the-modernized-application-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載並擷取產生的程式碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 
| 建置現代化應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 

### 遷移資料庫
<a name="migrate-the-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料庫和 JICS 結構描述。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 
| 驗證資料庫建立。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 
| 將資料遷移至 JICS 資料庫。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 

### 安裝現代化應用程式
<a name="install-the-modernized-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon EC2 執行個體上安裝現代化應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、雲端架構師 | 
| 重新啟動 Tomcat 伺服器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、雲端架構師 | 
| 遷移 VSAM 資料集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、遷移工程師 | 
| 更新 Groovy 指令碼中的參數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員 | 

### 測試應用程式。
<a name="test-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試現代化應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、測試工程師 | 
| 驗證批次指令碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 應用程式開發人員、測試工程師 | 

### 清除
<a name="clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 準備刪除基礎設施。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 一般 AWS | 
| 刪除基礎設施。 | 這些步驟將永久刪除您的 資源。在繼續之前，請確定您已備份任何重要資料。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 一般 AWS | 

## 疑難排解
<a name="modernize-mainframe-app-transform-terraform-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Terraform 身分驗證 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 
| Tomcat 相關錯誤 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-app-transform-terraform.html) | 
| URL 名稱未載入 | 請確定 Application Load Balancer 安全群組在傳入規則中具有您的 IP 地址做為來源。 | 
| Tomcat 日誌中的身分驗證問題 | 確認 中的資料庫秘密密碼 AWS Secrets Manager 和 **server.xml** 中的密碼相符。 | 

## 相關資源
<a name="modernize-mainframe-app-transform-terraform-resources"></a>

**AWS 方案指引**
+ [使用 AWS Transform 現代化 CardDemo 大型主機應用程式](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-carddemo-mainframe-app.html)

**AWS 服務文件**
+ [AWS Blu Age Blusam 管理主控台](https://docs.aws.amazon.com/m2/latest/userguide/ba-shared-bac-userguide.html)
+ [AWS Blu Age Runtime 的基礎設施設定需求 （非受管）](https://docs.aws.amazon.com/m2/latest/userguide/ba-infrastructure-setup.html)
+ [加入 AWS Blu Age 執行期](https://docs.aws.amazon.com/m2/latest/userguide/ba-runtime-setup-onboard.html)
+ [大型主機應用程式的現代化](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/transform-app-mainframe.html)
+ [設定 AWS Blu Age Runtime 的組態](https://docs.aws.amazon.com/m2/latest/userguide/ba-runtime-config.html)

**AWS 部落格文章**
+ [使用 AI 代理器搭配 加速您的大型主機現代化旅程 AWS Transform](https://aws.amazon.com/blogs/migration-and-modernization/accelerate-your-mainframe-modernization-journey-using-ai-agents-with-aws-transform/)

# AWS 使用 Rocket Enterprise Server 和 LRS PageCenterX 在 上現代化大型主機輸出管理
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx"></a>

*Shubham Roy，Amazon Web Services*

*Abraham Rondon，微型焦點*

*Guy Tucker、Levi、Ray 和 Shoup Inc*

## 總結
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-summary"></a>

透過現代化大型主機輸出管理，您可以節省成本、減輕維護舊版系統的技術負擔，並透過 DevOps 和 Amazon Web Services (AWS) 雲端原生技術提高彈性和敏捷性。此模式說明如何在 AWS 雲端上現代化業務關鍵型大型主機輸出管理工作負載。此模式使用 [Rocket Enterprise Server](https://www.rocketsoftware.com/en-us/products/enterprise-suite/enterprise-server) 做為現代化大型主機應用程式的執行時間，並搭配 Levi、Ray & Shoup， Inc.。 (LRS) VPSX/MFI (Micro Focus Interface) 作為列印伺服器，而 LRS PageCenterX 作為封存伺服器。LRS PageCenterX 提供輸出管理解決方案，用於檢視、編製索引、搜尋、封存和保護對業務輸出的存取。

模式是以[轉換大型](https://aws.amazon.com/blogs/apn/demystifying-legacy-migration-options-to-the-aws-cloud/)主機現代化方法為基礎。大型主機應用程式會由 Amazon Elastic Compute Cloud (Amazon EC2) 上的 [AWS Mainframe Modernization](https://docs.aws.amazon.com/m2/latest/userguide/what-is-m2.html) 進行遷移。大型主機輸出管理工作負載會遷移至 Amazon EC2，而大型主機資料庫，例如 z/OS 的 IBM Db2，則會遷移至 Amazon Relational Database Service (Amazon RDS)。LRS Directory Integration Server (LRS/DIS) 可與 AWS Directory Service for Microsoft Active Directory 搭配使用，以進行輸出管理工作流程身分驗證和授權。

## 先決條件和限制
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 大型主機輸出管理工作負載。
+ 如何重建和交付在 Rocket Enterprise Server 上執行之大型主機應用程式的基本知識。如需詳細資訊，請參閱 [Rocket 軟體文件中的 Rocket Enterprise Server](https://www.rocketsoftware.com/sites/default/files/resource_files/enterprise-server.pdf) 資料表。
+ LRS 雲端列印解決方案和概念的基本知識。如需詳細資訊，請參閱 LRS 文件中的*輸出現代化*。
+ Rocket Enterprise Server 軟體和授權。如需詳細資訊，請聯絡 [Rocket Software](https://www.rocketsoftware.com/products/enterprise-suite/request-contact)。
+ LRS VPSX/MFI、LRS PageCenterX、LRS/Queue 和 LRS/DIS 軟體和授權。如需詳細資訊，[請聯絡 LRS](https://www.lrsoutputmanagement.com/about-us/contact-us/)。您必須提供將安裝 LRS 產品的 EC2 執行個體主機名稱。


| 
| 
| 注意：如需大型主機輸出管理工作負載組態考量的詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-additional)區段中的*考量*事項。 | 
| --- |

**產品版本**
+ [Rocket Enterprise Server 10.0](https://www.rocketsoftware.com/products/enterprise-suite/enterprise-test-server)
+ [LRS VPSX/MFI](https://www.lrsoutputmanagement.com/products/modernization-products/)
+ [LRS PageCenterX](https://www.lrsoutputmanagement.com/products/content-management/pagecenterx-for-open-systems/) V1R3 或更新版本

## Architecture
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-architecture"></a>

**來源技術堆疊**
+ 作業系統 – IBM z/OS
+ 程式設計語言 – 常見商業導向語言 (COBOL)、工作控制語言 (JCL) 和客戶資訊控制系統 (CICS)
+ 資料庫 – z/OS 的 IBM Db2、IBM 資訊管理系統 (IMS) 資料庫和虛擬儲存存取方法 (VSAM)
+ 安全性 – 資源存取控制設施 (RACF)、z/OS 的 CA 最高秘密，以及存取控制設施 2 (ACF2)
+ 列印和封存解決方案 – IBM 大型主機 z/OS 輸出和列印產品 （適用於 z/OS、LRS 和 CA 交付的 IBM Infoprint 伺服器） 和封存解決方案 (CA 交付、ASG Mobius 或 CA 套件）

**來源架構**

下圖顯示大型主機輸出管理工作負載的典型目前狀態架構。

![\[大型主機輸出程序分為七個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f9ad041d-b9f0-4a9a-aba7-40fdc3088b27/images/d170394a-c9b2-43c0-a3d4-677b5f7c2473.png)


該圖顯示以下工作流程：

1. 使用者在以 COBOL 撰寫的 IBM CICS 應用程式上建置的參與系統 (SoE) 上執行商業交易。

1. SoE 會叫用大型主機服務，該服務會將商業交易資料記錄在system-of-records(SoR) 資料庫中，例如 z/OS 的 IBM Db2。

1. SoR 會保留來自 SoE 的業務資料。

1. 批次任務排程器會啟動批次任務以產生列印輸出。

1. 批次任務會從資料庫擷取資料。它會根據業務需求格式化資料，然後產生業務輸出，例如帳單、ID 卡或貸款陳述式。最後，批次任務會根據業務需求，將輸出路由至輸出管理的輸出格式、發佈和儲存。

1. 輸出管理會從批次任務接收輸出。輸出管理索引、排列輸出，並將輸出發佈至輸出管理系統中的指定目的地，例如 LRS PageCenterX 解決方案 （如此模式所示） 或 CA 檢視。

1. 使用者可以檢視、搜尋和擷取輸出。

**目標技術堆疊**
+ 作業系統 – 在 Amazon EC2 上執行的 Windows Server
+ 運算 – Amazon EC2
+ 儲存 – Amazon Elastic Block Store (Amazon EBS) 和 Amazon FSx for Windows File Server
+ 程式設計語言 – COBOL、JCL 和 CICS
+ 資料庫 – Amazon RDS
+ 安全性 – AWS Managed Microsoft AD
+ 列印和封存 – AWS 上的 LRS 列印 (VPSX) 和封存 (PageCenterX) 解決方案
+ 大型主機執行期環境 – Rocket Enterprise Server

**目標架構**

下圖顯示部署在 AWS 雲端中大型主機輸出管理工作負載的架構。

![\[批次應用程式和輸出管理的目標架構分為七個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f9ad041d-b9f0-4a9a-aba7-40fdc3088b27/images/3e25ab03-bf3a-4fea-b5eb-38cea9e50138.png)


該圖顯示以下工作流程：

1. 批次任務排程器會啟動批次任務來建立輸出，例如帳單陳述式、ID 卡或貸款陳述式。

1. 大型主機批次工作 ([已修改為 Amazon EC2](https://aws.amazon.com/blogs/apn/demystifying-legacy-migration-options-to-the-aws-cloud/)) 使用 Rocket Enterprise Server 執行期從應用程式資料庫擷取資料、將商業邏輯套用至資料，以及格式化資料。然後，它會使用 [Rocket Software 印表機結束模組](https://www.microfocus.com/documentation/enterprise-developer/ed100/ED-Eclipse/HCOMCMJCLOU020.html) (OpenText Micro Focus 文件） 將資料傳送至輸出目的地。

1. 應用程式資料庫 （在 Amazon RDS 上執行的 SoR) 會保留列印輸出的資料。

1. LRS VPSX/MFI 列印解決方案部署在 Amazon EC2 上，其操作資料存放在 Amazon EBS 中。LRS VPSX/MFI 使用 TCP/IP 型 LRS/佇列傳輸代理程式，透過 Rocket Software JES Print Exit API 收集輸出資料。

   LRS VPSX/MFI 會進行資料預先處理，例如 EBCDIC 轉換為 ASCII。它也會執行更複雜的任務，包括將大型主機獨佔資料串流，例如 IBM Advanced Function Presentation (AFP) 和 Xerox Line Conditioned Data Stream (LCDS)，轉換為更常見的檢視和列印資料串流，例如印表機命令語言 (PCL) 和 PDF。

   在 LRS PageCenterX 的維護時段期間，LRS VPSX/MFI 會保留輸出佇列，並做為輸出佇列的備份。LRS VPSX/MFI 會使用 LRS/佇列通訊協定來連接並傳送輸出至 LRS PageCenterX。LRS/Queue 會針對任務執行準備和完成的交換，以協助確保資料傳輸發生。

   **備註**：

   如需從 Rocket Software Print Exit 傳遞至 LRS/Queue 和 LRS VPSX/MFI 支援的大型主機批次機制之列印資料的詳細資訊，請參閱[其他資訊](#modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-additional)一節中的*列印資料擷取*。

   LRS VPSX/MFI 可以在印表機機群層級執行運作狀態檢查。如需詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-additional)區段中的*印表機機群運作狀態檢查*。

1. LRS PageCenterX 輸出管理解決方案部署在 Amazon EC2 上，其操作資料存放在 Amazon FSx for Windows File Server 中。LRS PageCenterX 提供匯入 LRS PageCenterX 的所有檔案的中央報告管理系統，以及可存取檔案的所有使用者。使用者可以檢視特定檔案內容，或跨多個檔案執行搜尋，以取得相符條件。

   LRS/NetX 元件是多執行緒 Web 應用程式伺服器，可為 LRS PageCenterX 應用程式和其他 LRS 應用程式提供常見的執行時間環境。LRS/Web Connect 元件安裝在您的 Web 伺服器上，並提供從 Web 伺服器到 LRS/NetX Web 應用程式伺服器的連接器。

1. LRS PageCenterX 提供檔案系統物件的儲存體。LRS PageCenterX 的操作資料存放在 Amazon FSx for Windows File Server 中。

1. 輸出管理身分驗證和授權是由 AWS Managed Microsoft AD 搭配 LRS/DIS 執行。

**注意**  
目標解決方案通常不需要變更應用程式來適應大型主機格式語言，例如 IBM AFP 或 Xerox LCDS。

**AWS 基礎設施架構**

下圖顯示大型主機輸出管理工作負載的高可用性和安全 AWS 基礎設施架構。

![\[具有工作流程的多可用區域 AWS 基礎設施，分為七個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/f9ad041d-b9f0-4a9a-aba7-40fdc3088b27/images/8d8aa995-b576-4ecd-8a7c-5f566740a515.png)


該圖顯示以下工作流程：

1. 批次排程器會啟動批次程序，並跨多個[可用區域](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/)部署在 Amazon EC2 上，以實現高可用性 (HA)。
**注意**  
此模式不包含批次排程器的實作。如需實作的詳細資訊，請參閱排程器的軟體廠商文件。

1. 大型主機批次工作 （以程式設計語言撰寫，例如 JCL 或 COBOL) 使用核心商業邏輯來處理和產生列印輸出，例如帳單、ID 卡和貸款陳述式。批次任務會跨 HA 的兩個可用區域部署在 Amazon EC2 上。它使用 Rocket Software Print Exit API 將列印輸出路由到 LRS VPSX/MFI 以進行資料預先處理。

1. LRS VPSX/MFI 列印伺服器部署在 Amazon EC2 上，跨 HA 的兩個可用區域 （主動待命備援對）。它使用 [Amazon EBS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 做為操作資料存放區。Network Load Balancer 會對 LRS VPSX/MFI EC2 執行個體執行運作狀態檢查。如果作用中執行個體處於運作狀態不良狀態，負載平衡器會將流量路由到其他可用區域中的熱待命執行個體。列印請求會保留在每個 EC2 執行個體的本機 LRS 任務佇列中。發生故障時，必須先重新啟動失敗的執行個體，LRS 服務才能繼續處理列印請求。
**注意**  
LRS VPSX/MFI 也可以在印表機機群層級執行運作狀態檢查。如需詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-additional)區段中的*印表機機群運作狀態檢查*。

1. LRS PageCenterX 輸出管理部署在 Amazon EC2 上，橫跨 HA 的兩個可用區域 （主動待命備援對）。它使用 [Amazon FSx for Windows File Server](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html) 作為操作資料存放區。如果作用中執行個體處於運作狀態不良狀態，負載平衡器會對 LRS PageCenterX EC2 執行個體執行運作狀態檢查，並將流量路由到其他可用區域中的待命執行個體。

1. [Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html) 提供 DNS 名稱，以整合 LRS VPSX/MFI 伺服器與 LRS PageCenterX。
**注意**  
LRS PageCenterX 支援第 4 層負載平衡器。

1. LRS PageCenterX 使用 Amazon FSx for Windows File Server 做為作業資料存放區，部署在 HA 的兩個可用區域。LRS PageCenterX 只了解檔案共享中的檔案，而不是外部資料庫中的檔案。

1. [AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 會與 LRS/DIS 搭配使用，以執行輸出管理工作流程身分驗證和授權。如需詳細資訊，請參閱[其他資訊](#modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-additional)區段中的*列印輸出身分驗證和授權*。

## 工具
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-tools"></a>

**AWS 服務**
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 可讓您的目錄感知工作負載和 AWS 資源在 AWS 雲端中使用 Microsoft Active Directory。
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 提供區塊層級儲存磁碟區，可與 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體搭配使用。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Elastic Load Balancing (ELB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) 會將傳入的應用程式或網路流量分配到多個目標。例如，您可以在一或多個可用區域中跨 Amazon EC2 執行個體、容器和 IP 地址分配流量。此模式使用 Network Load Balancer。
+ [Amazon FSx](https://docs.aws.amazon.com/fsx/?id=docs_gateway) 提供檔案系統，可支援業界標準的連線通訊協定，並跨 AWS 區域提供高可用性和複寫。此模式使用 Amazon FSx for Windows File Server。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。

**其他工具**
+ [LRS PageCenterX](https://www.lrsoutputmanagement.com/products/content-management/pagecenterx-for-open-systems/) 軟體提供可擴展的文件和報告內容管理解決方案，協助使用者透過自動化索引、加密和進階搜尋功能，從資訊中取得最大值。
+ [LRS VPSX/MFI (Micro Focus Interface)](https://www.lrsoutputmanagement.com/products/modernization-products/)，由 LRS 和 Rocket Software 編寫，可從 Rocket Software JES 多工緩衝區擷取輸出，並可靠地將其交付至指定的列印目的地。
+ LRS/Queue 是以 TCP/IP 為基礎的傳輸代理程式。LRS VPSX/MFI 使用 LRS/佇列透過 Rocket Software JES Print Exit 程式設計界面收集或擷取列印資料。
+ 在列印工作流程期間，LRS Directory Integration Server (LRS/DIS) 用於身分驗證和授權。
+ [Rocket Enterprise Server](https://www.microfocus.com/documentation/enterprise-developer/ed80/ES-WIN/GUID-F7D8FD6E-BDE0-4169-8D8C-96DDFFF6B495.html) 是大型主機應用程式的應用程式部署環境。它為使用任何版本的 Rocket Enterprise Developer 遷移或建立的大型主機應用程式提供執行期環境。

## 史詩
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-epics"></a>

### 設定 Rocket 執行時間並部署大型主機批次應用程式
<a name="set-up-the-rocket-runtime-and-deploy-a-mainframe-batch-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定執行時間並部署示範應用程式。 | 若要在 Amazon EC2 上設定 Rocket Enterprise Server 並部署 Rocket Software BankDemo 示範應用程式，請遵循 AWS Mainframe Modernization [使用者指南](https://docs.aws.amazon.com/m2/latest/userguide/mf-runtime-setup.html)中的指示。BankDemo 應用程式是一種大型主機批次應用程式，可建立並啟動列印輸出。 | 雲端架構師 | 

### 在 Amazon EC2 上設定 LRS 列印伺服器
<a name="set-up-an-lrs-print-server-on-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon EC2 Windows 執行個體。 | 若要啟動 Amazon EC2 Windows 執行個體，請遵循 [Amazon EC2 文件中的啟動 Amazon EC2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)中的指示。 Amazon EC2 使用與 LRS 產品授權相同的主機名稱。您的執行個體必須符合 LRS VPSX/MFI 的下列硬體和軟體需求：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html)上述硬體和軟體需求適用於小型印表機機群 （約 500-1000)。若要取得完整需求，請洽詢您的 LRS 和 AWS 聯絡人。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 在 EC2 執行個體上安裝 LRS VPSX/MFI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 安裝 LRS/佇列。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 安裝 LRS/DIS。 | LRS/DIS 產品通常包含在 LRS VPSX 安裝中。不過，如果 LRS/DIS 未與 LRS VPSX 一起安裝，請使用下列步驟進行安裝：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 建立目標群組。 | 遵循為 [Network Load Balancer 建立目標群組中的指示來建立目標群組](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-target-group.html)。當您建立目標群組時，請將 LRS VPSX/MFI EC2 執行個體註冊為目標：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 建立 Network Load Balancer。 | 若要建立 Network Load Balancer，請遵循 [Elastic Load Balancing 文件](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-network-load-balancer.html)中的指示。Network Load Balancer 會將流量從 Rocket Enterprise Server 路由到 LRS VPSX/MFI EC2 執行個體。當您建立 Network Load Balancer 時，請在**接聽程式和路由**頁面上選擇下列值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 整合 Rocket Enterprise Server 與 LRS/Queue 和 LRS VPSX/MFI
<a name="integrate-rocket-enterprise-server-with-lrs-queue-and-lrs-vpsx-mfi"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Rocket Enterprise Server for LRS/Queue 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 設定 Rocket Enterprise Server for LRS VPSX/MFI 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 設定列印佇列和列印使用者
<a name="set-up-the-print-queue-and-the-print-users"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 Rocket Software Print Exit 模組與 Rocket Enterprise Server 批次印表機伺服器執行程序建立關聯。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 在 LRS VPSX/MFI 中建立列印輸出佇列，並將其與 LRS PageCenterX 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 在 LRS VPSX/MFI 中建立列印使用者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 在 Amazon EC2 上設定 LRS PageCenterX 伺服器
<a name="set-up-an-lrs-pagecenterx-server-on-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon EC2 Windows 執行個體。 | 按照 Amazon EC2 文件中的[步驟 1：啟動執行個體中的指示啟動 Amazon EC2 Windows 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/EC2_GetStarted.html#ec2-launch-instance)。 Amazon EC2 使用您用於 LRS 產品授權的相同主機名稱。您的執行個體必須符合 LRS PageCenterX 的下列硬體和軟體需求：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html)上述硬體和軟體需求適用於小型印表機機群 （約 500–1000)。若要取得完整需求，請洽詢您的 LRS 和 AWS 聯絡人。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 在 EC2 執行個體上安裝 LRS PageCenterX。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 安裝 LRS/DIS。 | LRS/DIS 產品通常包含在 LRS VPSX 安裝中。不過，如果 LRS/DIS 未與 LRS VPSX 一起安裝，請使用下列步驟進行安裝：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 建立目標群組。 | 遵循為 [Network Load Balancer 建立目標群組中的指示來建立目標群組](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-target-group.html)。當您建立目標群組時，請將 LRS PageCenterX EC2 執行個體註冊為目標：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 建立 Network Load Balancer。 | 若要建立 Network Load Balancer，請遵循 [Elastic Load Balancing 文件](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-network-load-balancer.html)中的指示。Network Load Balancer 會將流量從 LRS VPSX/MFI 路由到 LRS PageCenterX EC2 執行個體。當您建立 Network Load Balancer 時，請在**接聽程式和路由**頁面上選擇下列值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 在 LRS PageCenterX 中設定輸出管理功能
<a name="set-up-output-management-features-in-lrs-pagecenterx"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 LRS PageCenterX 中啟用匯入函數。 | 您可以使用 LRS PageCenterX 匯入函數，根據任務名稱或表單 ID 等條件來辨識 LRS PageCenterX 上的輸出登陸。然後，您可以將輸出路由到 LRS PageCenterX 中的特定資料夾。若要啟用匯入函數，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 設定文件保留政策。 | LRS PageCenterX 使用文件保留政策來決定在 LRS PageCenterX 中保留文件的時間長度。若要設定文件保留政策，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 建立規則，將輸出文件路由到 LRS PageCenterX 中的特定資料夾。 | 在 LRS PageCenterX 中，**目的地**會決定**當報告定義**調用此目的地時，輸出將傳送的資料夾路徑。在此範例中，根據報告定義中的**表單 ID** 資料夾建立資料夾，並將輸出儲存到該資料夾。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 建立報告定義。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 設定輸出管理的身分驗證和授權
<a name="set-up-authentication-and-authorization-for-output-management"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用使用者和群組建立 AWS Managed Microsoft AD 網域。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 將 EC2 執行個體加入 AWS Managed Microsoft AD 網域。 | [自動](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-systems-manager-dx-domain/)將 LRS VPSX/MFI 和 LRS PageCenterX EC2 執行個體加入您的 AWS Managed Microsoft AD 網域 (AWS 知識中心文件） 或[手動](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/join_windows_instance.html) (AWS Directory Service 文件）。 | 雲端架構師 | 
| 設定 LRS/DIS 並與 LRS PageCenterX EC2 執行個體的 AWS Managed Microsoft AD 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 設定匯入群組，將輸出從 LRS VPSX 匯入 LRS PageCenterX。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 將安全規則新增至匯入群組。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 在 LRS PageCenterX 中建立使用者，以從 LRS VPSX/MFI 執行輸出匯入。 | 當您在 LRS PageCenterX 中建立使用者以執行輸出匯入時，使用者名稱應與 LRS **VPSX/MFI 中列印輸出佇列**的 VPSX ID 相同。在此範例中，VPSX ID 為 **VPS1**。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 將 LRS PageCenterX 匯入使用者新增至僅匯入群組。 | 若要提供從 LRS VPSX 匯入至 LRS PageCenterX 的必要許可，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 
| 使用 LRS VPSX/MFI EC2 執行個體的 AWS Managed Microsoft AD 設定 LRS/DIS。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 將 Amazon FSx for Windows File Server 設定為 LRS PageCenterX 的操作資料存放區
<a name="configure-amazon-fsx-for-windows-file-server-as-the-operational-data-store-for-lrs-pagecenterx"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 LRS PageCenterX 的檔案系統。 | 若要在多可用區環境中使用 Amazon FSx for Windows File Server 做為 LRS PageCenterX 的操作資料存放區，請遵循[步驟 1：建立檔案系統](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/getting-started-step1.html)中的指示。 | 雲端架構師 | 
| 將檔案共享映射至 LRS PageCenterX EC2 執行個體。 | 若要將上一個步驟中建立的檔案共享映射到 LRS PageCenterX EC2 執行個體，請遵循[步驟 2：將您的檔案共享映射到執行 Windows Server 的 EC2 執行個體](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/getting-started-step2.html)中的指示。 | 雲端架構師 | 
| 將 LRS PageCenterX 控制目錄和主資料夾目錄映射至 Amazon FSx 網路共享磁碟機。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 雲端架構師 | 

### 測試輸出管理工作流程
<a name="test-an-output-management-workflow"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Rocket Software BankDemo 應用程式啟動批次列印請求。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 測試工程師 | 
| 檢查 LRS PageCenterX 中的列印輸出。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx.html) | 測試工程師 | 

## 相關資源
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-resources"></a>
+ [LRS](https://www.lrsoutputmanagement.com/products/modernization-products)
+ [進階函數簡報資料串流 ](https://www.ibm.com/docs/en/i/7.4?topic=streams-advanced-function-presentation-data-stream)(IBM 文件）
+ [Line Conditioned Data Stream (LCDS)](https://www.compart.com/en/lcds) （組件文件）
+ [使用 Micro Focus 在 AWS 上增強企業大型主機工作負載 ](https://aws.amazon.com/blogs/apn/empowering-enterprise-grade-mainframe-workloads-on-aws-with-micro-focus/)（部落格文章）
+ [在 AWS 上現代化大型主機線上列印工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) (AWS 規範指引）
+ [在 AWS 上現代化大型主機批次列印工作負載](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) (AWS 規範指引）

## 其他資訊
<a name="modernize-mainframe-output-management-on-aws-by-using-rocket-enterprise-server-and-lrs-pagecenterx-additional"></a>

**考量**

在現代化旅程中，您可能會考慮大型主機批次和線上程序的各種組態，以及它們產生的輸出。大型主機平台是由每個使用大型主機平台的客戶和廠商自訂，其具有直接影響列印的特定要求。例如，您目前的平台可能會將 IBM AFP 資料串流或 Xerox LCD 納入目前的工作流程。此外，[大型主機運輸控制字元](https://www.ibm.com/docs/en/cmofz/10.5.0?topic=tips-ansi-machine-carriage-controls)和[頻道命令文字](https://www.ibm.com/docs/en/zos/3.1.0?topic=devices-channel-command-words)可能會影響列印頁面的外觀，而且可能需要特殊處理。作為現代化規劃程序的一部分，我們建議您評估並了解特定列印環境中的組態。 

**列印資料擷取**

Rocket Software Print Exit 會傳遞 LRS VPSX/MFI 的必要資訊，以有效地處理多工緩衝處理檔案。資訊由相關控制區塊中傳遞的欄位組成，如下所示：
+ JOBNAME
+ OWNER (USERID)
+ 目的地
+ FORM
+ FILENAME
+ 寫入

LRS VPSX/MFI 支援下列大型主機批次機制，用於從 Rocket Enterprise Server 擷取資料：
+ 使用標準 z/OS JCL SYSOUT DD/OUTPUT 陳述式進行批次 COBOL 列印/多工緩衝處理。
+ 使用標準 z/OS JCL CA-SPOOL SUBSYS DD 陳述式進行批次 COBOL 列印/多工緩衝處理。
+ IMS/COBOL 列印/多工緩衝處理使用 CBLTDLI 界面。如需支援的方法和程式設計範例的完整清單，請參閱產品授權隨附的 LRS 文件。

**印表機機群運作狀態檢查**

LRS VPSX/MFI (LRS LoadX) 可執行深入研究運作狀態檢查，包括裝置管理和操作最佳化。裝置管理可以偵測印表機裝置中的失敗，並將列印請求路由到運作狀態良好的印表機。如需印表機機群深入運作狀態檢查的詳細資訊，請參閱產品授權隨附的 LRS 文件。

**列印身分驗證和授權**

LRS/DIS 可讓 LRS 應用程式使用 Microsoft Active Directory 或輕量型目錄存取協定 (LDAP) 伺服器來驗證使用者 IDs 和密碼。除了基本列印授權之外，LRS/DIS 也可以在下列使用案例中套用精細層級的列印安全控制：
+ 管理誰可以瀏覽印表機任務。
+ 管理其他使用者任務的瀏覽層級。
+ 管理操作任務 - 例如，命令層級安全性，例如保留或釋出、清除、修改、複製和重新路由。安全可由 user-ID 或 群組設定，類似於 Active Directory 安全群組或 LDAP 群組。

## 附件
<a name="attachments-f9ad041d-b9f0-4a9a-aba7-40fdc3088b27"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/f9ad041d-b9f0-4a9a-aba7-40fdc3088b27/attachments/attachment.zip)

# 使用 Rocket Enterprise Server 和 LRS VPSX/MFI AWS 在 上現代化大型主機批次列印工作負載
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi"></a>

*Shubham Roy 和 Kevin Yung，Amazon Web Services*

*Abraham Rondon，微型焦點*

*Guy Tucker、Levi、Ray 和 Shoup Inc*

## 總結
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-summary"></a>

此模式說明如何使用 Rocket Enterprise Server 做為現代化大型主機應用程式的執行期，以及使用 LRS VPSX/MFI (Micro Focus Interface) 做為列印伺服器，在 Amazon Web Services (AWS) 雲端上現代化業務關鍵型大型主機批次列印工作負載。模式是以[轉換大型](https://aws.amazon.com/blogs/apn/demystifying-legacy-migration-options-to-the-aws-cloud/)主機現代化方法為基礎。在此方法中，您將大型主機批次任務遷移至 Amazon Elastic Compute Cloud (Amazon EC2)，並將大型主機資料庫遷移至 Amazon Relational Database Service (Amazon RDS)，例如 z/OS 的 IBM DB2。現代化列印工作流程的身分驗證和授權是由 AWS Directory Service for Microsoft Active Directory 執行，也稱為 AWS Managed Microsoft AD。LRS Directory Information Server (LRS/DIS) 已與 AWS Managed Microsoft AD 整合。透過現代化批次列印工作負載，您可以降低 IT 基礎設施成本、減輕維護舊版系統的技術負債、移除資料孤島、使用 DevOps 模型提高敏捷性和效率，以及利用 AWS 雲端中的隨需資源和自動化。

## 先決條件和限制
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 大型主機列印或輸出管理工作負載
+ 如何重建和交付在 Rocket Enterprise Server 上執行之大型主機應用程式的基本知識 （如需詳細資訊，請參閱 [Rocket 文件中的 Rocket Enterprise Server](https://www.rocketsoftware.com/sites/default/files/resource_files/enterprise-server.pdf) 資料表。)
+ [LRS 雲端列印](https://www.lrsoutputmanagement.com/solutions/solutions-cloud-printing/)解決方案和概念的基本知識
+ Rocket Enterprise Server 軟體和授權 （如需詳細資訊，請聯絡 [Rocket 銷售](https://www.rocketsoftware.com/en-us/products/enterprise-suite/request-contact)。)
+ LRS VPSX/MFI、LRS/Queue 和 LRS/DIS 軟體和授權 （如需詳細資訊，請聯絡 [LRS 銷售](https://www.lrsoutputmanagement.com/about-us/contact-us/))。

**注意**  
如需大型主機批次列印工作負載組態考量的詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-additional)區段中的*考量*事項。

**產品版本**
+ [Rocket Enterprise Server](https://www.microfocus.com/en-us/products/enterprise-server/overview?utm_campaign=7018e000000PgfnAAC&utm_content=SCH-BR-AMC-AppM-AMS&gclid=EAIaIQobChMIoZCQ6fvS9wIVxQN9Ch2MzAOlEAAYASAAEgKx2fD_BwE) 6.0 （產品更新 7)
+ [LRS VPSX/MFI](https://www.lrsoutputmanagement.com/products/vpsx-enterprise/) V1R3 或更高版本

## Architecture
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-architecture"></a>

**來源技術堆疊**
+ 作業系統 – IBM z/OS
+ 程式設計語言 – 常見商業導向語言 (COBOL)、工作控制語言 (JCL) 和客戶資訊控制系統 (CICS)
+ 資料庫 – z/OS 的 IBM DB2 和虛擬儲存存取方法 (VSAM)
+ 安全性 – 資源存取控制設施 (RACF)、z/OS 的 CA 最高秘密，以及存取控制設施 2 (ACF2)
+ 列印和輸出管理 – IBM 大型主機 z/OS 列印產品 （適用於 z/OS、LRS 和 CA 檢視的 IBM Tivoli 輸出管理員）

**目標技術堆疊**
+ 作業系統 – 在Amazon EC2 上執行的 Microsoft Windows Server
+ 運算 – Amazon EC2
+ 程式設計語言 – COBOL、JCL 和 CICS
+ 資料庫 – Amazon RDS
+ 安全性 – AWS Managed Microsoft AD
+ 列印和輸出管理 – AWS 上的 LRS 列印解決方案
+ 大型主機執行期環境 – Rocket Enterprise Server

**來源架構**

下圖顯示大型主機批次列印工作負載的典型目前狀態架構：

![\[從使用者到大型主機服務，z/OS 的 Db2、任務排程器、批次任務和輸出分成六個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36de7312-4860-4702-a325-c01cf74c4f33/images/83d82435-0aa6-4eb8-a5c8-0920102afb09.png)


該圖顯示以下工作流程：

1. 使用者在以 COBOL 撰寫的 IBM CICS 應用程式上建置的參與系統 (SoE) 上執行商業交易。

1. SoE 會叫用大型主機服務，將商業交易資料記錄在system-of-records(SoR) 資料庫中，例如 z/OS 的 IBM DB2。

1. SoR 會保留來自 SoE 的業務資料。

1. 批次任務排程器會啟動批次任務以產生列印輸出。

1. 批次任務會從資料庫擷取資料、根據業務需求格式化資料，然後產生業務輸出，例如帳單、ID 卡或貸款陳述式。最後，批次任務會根據業務需求，將輸出路由到列印輸出管理以進行處理和輸出交付。 

1. 列印輸出管理會從批次任務接收列印輸出，然後將該輸出交付至指定的目的地，例如電子郵件、使用安全 FTP 的檔案共用、使用 LRS 列印解決方案的實體印表機 （如此模式所示） 或 IBM Tivoli。

**目標架構**

下圖顯示部署在 AWS 雲端中大型主機批次列印工作負載的架構：

![\[AWS 上的批次應用程式包含排程器、Rocket Enterprise Server 和資料庫，分為四個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36de7312-4860-4702-a325-c01cf74c4f33/images/8cdd4ef7-3cbd-476a-9aa4-c1c0924f17c6.png)


該圖顯示以下工作流程：

1. 批次任務排程器會啟動批次任務來建立列印輸出，例如帳單陳述式、ID 卡或貸款陳述式。

1. 大型主機批次工作 ([已修改為 Amazon EC2](https://aws.amazon.com/blogs/apn/demystifying-legacy-migration-options-to-the-aws-cloud/)) 使用 Rocket Enterprise Server 執行期從應用程式資料庫擷取資料、將商業邏輯套用至資料、格式化資料，然後使用 [Rocket Software Print Exit](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/HCOMCMJCLOU020.html) (Micro Focus 文件） 將資料傳送至列印目的地。

1. 應用程式資料庫 （在 Amazon RDS 上執行的 SoR) 會保留列印輸出的資料。

1. LRS VPSX/MFI 列印解決方案部署在 Amazon EC2 上，其操作資料存放在 Amazon Elastic Block Store (Amazon EBS) 中。LRS VPSX/MFI 使用 TCP/IP 型 LRS/Queue 傳輸代理程式，透過 Rocket Software JES Print Exit API 收集列印資料，並將資料交付至指定的印表機目的地。

**注意**  
目標解決方案通常不需要應用程式變更來適應大型主機格式語言，例如 IBM 進階函數呈現 (AFP) 或 Xerox Line Condition Data Stream (LCDS)。如需在 AWS 上使用 Rocket Software 進行大型主機應用程式遷移和現代化的詳細資訊，請參閱[使用 Micro Focus 在 AWS 上增強企業大型主機工作負載](https://aws.amazon.com/blogs/apn/empowering-enterprise-grade-mainframe-workloads-on-aws-with-micro-focus/)部落格文章。

**AWS 基礎設施架構**

下圖顯示適用於大型主機批次列印工作負載的高可用性和安全 AWS 基礎設施架構：

![\[使用 Rocket Software 和 LRS 元件在 AWS 上以七個步驟進行異地同步備份部署。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/36de7312-4860-4702-a325-c01cf74c4f33/images/287dd143-338c-4d83-a9b2-8e39214a81b0.png)


該圖顯示以下工作流程：

1. 批次排程器會啟動批次程序，並跨多個[可用區域](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/)部署在 Amazon EC2 上，以實現高可用性 (HA)。
**注意**  
此模式不包含批次排程器的實作。如需實作的詳細資訊，請參閱排程器的軟體廠商文件。

1. 大型主機批次工作 （以 JCL 或 COBOL 等程式設計語言撰寫） 使用核心商業邏輯來處理和產生列印輸出，例如帳單、ID 卡和貸款陳述式。任務會跨 HA 的兩個可用區域部署在 Amazon EC2 上，並使用 Rocket Software Print Exit 將列印輸出路由到 LRS VPSX/MFI 以進行最終使用者列印。

1. LRS VPSX/MFI 使用 TCP/IP 型 LRS/佇列傳輸代理程式，從 Rocket Software JES Print Exit 程式設計界面收集或擷取列印資料。列印結束會傳遞必要資訊，讓 LRS VPSX/MFI 有效地處理多工緩衝處理檔案，並動態建置 LRS/佇列命令。接著會使用 Rocket Software 的標準內建函數執行命令。
**注意**  
如需從 Rocket Software Print Exit 傳遞至 LRS/Queue 和 LRS VPSX/MFI 支援之大型主機批次機制的列印資料的詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-additional)區段中的*列印資料擷取*。

1. 
**注意**  
[Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html) 提供 DNS 名稱，以整合 Rocket Enterprise Server 與 LRS VPSX/MFI。：LRS VPSX/MFI 支援第 4 層負載平衡器。Network Load Balancer 也會對 LRS VPSX/MFI 執行基本運作狀態檢查，並將流量路由至運作狀態良好的已註冊目標。

1. 
**注意**  
LRS VPSX/MFI 列印伺服器會跨 HA 的兩個可用區域部署在 Amazon EC2 上，並使用 [Amazon EBS](https://docs.aws.amazon.com/ebs/latest/userguide/what-is-ebs.html) 做為操作資料存放區。LRS VPSX/MFI 支援主動-主動和主動-被動服務模式。此架構使用主動-被動對中的多個 AZs 作為主動和熱待命。Network Load Balancer 會對 LRS VPSX/MFI EC2 執行個體執行運作狀態檢查，並在作用中執行個體處於運作狀態不佳時，將流量路由到其他 AZ 中的熱待命執行個體。列印請求會保留在每個 EC2 執行個體的本機 LRS 任務佇列中。在復原的情況下，必須重新啟動失敗的執行個體，LRS 服務才能繼續處理列印請求。：LRS VPSX/MFI 也可以在印表機機群層級執行運作狀態檢查。如需詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-additional)區段中的*印表機機群運作狀態檢查*。

1. [AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 與 LRS/DIS 整合，以執行列印工作流程身分驗證和授權。如需詳細資訊，請參閱此模式[額外資訊](#modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-additional)區段中的*列印身分驗證和授權*。

1. LRS VPSX/MFI 使用 Amazon EBS 進行區塊儲存。您可以將 Amazon EBS 資料以point-in-time快照的形式從作用中的 EC2 執行個體備份到 Amazon S3，並將其還原至熱待命 EBS 磁碟區。若要自動建立、保留和刪除 Amazon EBS 磁碟區快照，您可以使用 [Amazon Data Lifecycle Manager](https://aws.amazon.com/blogs/aws/new-lifecycle-management-for-amazon-ebs-snapshots/) 來設定自動快照的頻率，並根據 [RTO/RPO 需求](https://docs.aws.amazon.com/whitepapers/latest/disaster-recovery-workloads-on-aws/disaster-recovery-options-in-the-cloud.html)還原快照。

## 工具
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-tools"></a>

**AWS 服務**
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/ebs/latest/userguide/what-is-ebs.html) 提供區塊層級儲存磁碟區，可與 EC2 執行個體搭配使用。EBS 磁碟區的行為與未格式化的原始區塊型儲存設備相似。您可以將這些磁碟區做為裝置，掛載在您的執行個體上。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以使用 Amazon EC2 視需要啟動任意數量或任意數量的虛擬伺服器，也可以向外擴展或向內擴展。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 是一種 Web 服務，可讓您更輕鬆地在 AWS 雲端中設定、操作和擴展關聯式資料庫。它為關聯式資料庫提供經濟實惠、可擴展的容量，並管理常見的資料庫管理任務。
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html)，也稱為 AWS Managed Microsoft AD，可讓您的目錄感知工作負載和 AWS 資源在 AWS 雲端中使用 Microsoft Active Directory。

**其他工具**
+ [LRS VPSX/MFI (Micro Focus Interface)](https://www.lrsoutputmanagement.com/products/vpsx-enterprise/)，由 LRS 和 Rocket Software 共同開發，可從 Rocket Enterprise Server JES 多工緩衝區擷取輸出，並可靠地將其交付至指定的列印目的地。
+ LRS Directory Information Server (LRS/DIS) 用於在列印工作流程期間進行身分驗證和授權。
+ LRS VPSX/MFI 使用 TCP/IP 型 LRS/佇列傳輸代理程式，透過 Rocket Software JES Print Exit 程式設計界面收集或擷取列印資料。
+ [Rocket Enterprise Server](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-A2F23243-962B-440A-A071-480082DF47E7.html) 是大型主機應用程式的應用程式部署環境。它為使用任何版本的 Rocket Software Enterprise Developer 遷移或建立的大型主機應用程式提供執行環境。

## 史詩
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-epics"></a>

### 在 Amazon EC2 上設定 Rocket Enterprise Server 並部署大型主機批次應用程式
<a name="set-up-rocket-enterprise-server-on-amazon-ec2-and-deploy-a-mainframe-batch-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Rocket Enterprise Server 並部署示範應用程式。 | 在 Amazon EC2 上設定 Rocket Enterprise Server，然後在 Amazon EC2 上部署 Rocket Software BankDemo 示範應用程式。BankDemo 應用程式是一種大型主機批次應用程式，可建立並啟動列印輸出。 | 雲端架構師 | 

### 在 Amazon EC2 上設定 LRS 列印伺服器
<a name="set-up-an-lrs-print-server-on-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得用於列印的 LRS 產品授權。 | 若要取得 LRS VPSX/MFI、LRS/Queue 和 LRS/DIS 的 LRS 產品授權，請聯絡 [LRS 輸出管理團隊](https://www.lrsoutputmanagement.com/about-us/contact-us/)。您必須提供將安裝 LRS 產品的 EC2 執行個體的主機名稱。 | 建置潛在客戶 | 
| 建立 Amazon EC2 Windows 執行個體以安裝 LRS VPSX/MFI。 | 依照 Amazon EC2 文件中啟動 [Amazon EC2 執行個體的指示啟動 Amazon EC2 Windows 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)。 Amazon EC2 您的執行個體必須符合 LRS VPSX/MFI 的下列硬體和軟體需求： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html)上述硬體和軟體需求適用於小型印表機機群 （約 500–1000)。若要取得完整需求，請洽詢您的 LRS 和 AWS 聯絡人。當您建立 Windows 執行個體時，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 在 EC2 執行個體上安裝 LRS VPSX/MFI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 安裝 LRS/佇列。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 安裝 LRS/DIS。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 建立目標群組，並將 LRS VPSX/MFI EC2 註冊為目標。 | 遵循 Elastic Load Balancing 文件中[為 Network Load Balancer 建立目標群組的指示來建立](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-target-group.html)目標群組。當您建立目標群組時，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 建立 Network Load Balancer。 | 遵循 Elastic Load Balancing [ Load Balancing 文件中建立 Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-network-load-balancer.html) 的指示。Network Load Balancer 會將流量從 Rocket Enterprise Server 路由到 LRS VPSX/MFI EC2。當您建立 Network Load Balancer 時，請在**接聽程式和路由**頁面上執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 整合 Rocket Enterprise Server 與 LRS VPSX/MFI 和 LRS/Queue
<a name="integrate-rocket-enterprise-server-with-lrs-vpsx-mfi-and-lrs-queue"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Rocket Enterprise Server for LRS/Queue 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html)LRS 目前支援 DNS 名稱的字元限制上限為 50，但未來可能會有所變更。如果您的 DNS 名稱大於 50，則可以使用 Network Load Balancer 的 IP 地址做為替代方案。 | 雲端架構師 | 
| 設定 Rocket Enterprise Server for LRS VPSX/MFI 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 在 Rocket Enterprise Server 和 LRS VPSX/MFI 中設定印表機和列印使用者
<a name="set-up-printers-and-print-users-in-rocket-enterprise-server-and-lrs-vpsx-mfi"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 Rocket Software Print Exit 模組與 Rocket Enterprise Server 批次印表機伺服器執行程序建立關聯。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html)如需組態的詳細資訊，請參閱 Micro Focus 文件中的[使用結束](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/HCOMCMJCLOS025.html)。 | 雲端架構師 | 
| 在 LRS VPSX/MFI 中新增印表機。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 在 LRS VPSX/MFI 中建立列印使用者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 設定列印身分驗證和授權
<a name="set-up-print-authentication-and-authorization"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用使用者和群組建立 AWS Managed Microsoft AD 網域。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 將 LRS VPSX/MFI EC2 加入 AWS Managed Microsoft AD 網域。 | [自動](https://repost.aws/knowledge-center/ec2-systems-manager-dx-domain)將 LRS VPSX/MFI EC2 加入您的 AWS Managed Microsoft AD 網域 (AWS 知識中心文件） 或[手動](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/launching_instance.html) (AWS Directory Service 文件）。 | 雲端架構師 | 
| 設定 LRS/DIS 並與 AWS Managed Microsoft AD 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 測試列印工作流程
<a name="test-a-print-workflow"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Rocket Software BankDemo 應用程式啟動批次列印請求。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html) | 測試工程師 | 
| 檢查 LRS VPSX/MFI 中的列印輸出。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi.html)您現在可以查看帳戶陳述式的列印輸出，其中包含**帳戶編號**、**描述**、**日期**、**金額**和**餘額**的資料欄。如需範例，請參閱此模式的 **batch\$1print\$1output **附件。 | 測試工程師 | 

## 相關資源
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-resources"></a>
+ [LRS 輸出現代化 ](https://www.lrsoutputmanagement.com/)(LRS 文件）
+ [ANSI 和機器承載控制](https://www.ibm.com/docs/en/cmofz/9.5.0?topic=tips-ansi-machine-carriage-controls) (IBM 文件）
+ [頻道命令文字](https://www.ibm.com/docs/en/zos/2.3.0?topic=devices-channel-command-words) (IBM 文件）
+ [使用 Micro Focus 在 AWS 上增強企業大型主機工作負載 ](https://aws.amazon.com/blogs/apn/empowering-enterprise-grade-mainframe-workloads-on-aws-with-micro-focus/)(AWS 合作夥伴網路部落格）
+ [使用 Amazon EC2 Auto Scaling 和 Systems Manager 建置 Micro Focus Enterprise Server PAC](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager.html) (AWS 規範指引文件）
+ [進階函數呈現 (AFP) 資料串流 ](https://www.ibm.com/docs/en/i/7.4?topic=streams-advanced-function-presentation-data-stream)(IBM 文件）
+ [Line Conditioned Data Stream (LCDS)](https://www.compart.com/en/lcds) （組件文件）

## 其他資訊
<a name="modernize-mainframe-batch-printing-workloads-on-aws-by-using-rocket-enterprise-server-and-lrs-vpsx-mfi-additional"></a>

**考量**

在現代化旅程中，您可以考慮大型主機批次程序及其產生的輸出的各種組態。大型主機平台是由每個使用大型主機平台的客戶和廠商自訂，其具有直接影響列印的特定要求。例如，您目前的平台可能會將 IBM Advanced Function Presentation (AFP) 或 Xerox Line Condition Data Stream (LCDS) 納入目前的工作流程。此外，[大型主機運輸控制字元](https://www.ibm.com/docs/en/cmofz/9.5.0?topic=tips-ansi-machine-carriage-controls)和[頻道命令文字](https://www.ibm.com/docs/en/zos/2.3.0?topic=devices-channel-command-words)可能會影響列印頁面的外觀，而且可能需要特殊處理。作為現代化規劃程序的一部分，我們建議您評估並了解特定列印環境中的組態。

**列印資料擷取**

Rocket Software Print Exit 會傳遞必要資訊，讓 LRS VPSX/MFI 有效地處理多工緩衝處理檔案。資訊由相關控制區塊中傳遞的欄位組成，例如：
+ JOBNAME
+ OWNER (USERID)
+ 目的地
+ FORM
+ FILENAME
+ 寫入

LRS VPSX/MFI 支援下列大型主機批次機制，用於從 Rocket Enterprise Server 擷取資料。
+ 使用標準 z/OS JCL SYSOUT DD/OUTPUT 陳述式進行批次 COBOL 列印/多工緩衝處理
+ 使用標準 z/OS JCL CA-SPOOL SUBSYS DD 陳述式進行批次 COBOL 列印/多工緩衝處理
+ IMS/COBOL 列印/多工緩衝處理使用 CBLTDLI 介面 （如需支援的方法和程式設計範例的完整清單，請參閱產品授權隨附的 LRS 文件。)

**印表機機群運作狀態檢查**

LRS VPSX/MFI (LRS LoadX) 可執行深入研究運作狀態檢查，包括裝置管理和操作最佳化。裝置管理可以偵測印表機裝置中的失敗，並將列印請求路由到運作狀態良好的印表機。如需印表機機群深入研究運作狀態檢查的詳細資訊，請參閱產品授權隨附的 LRS 文件。

**列印身分驗證和授權**

LRS/DIS 可讓 LRS 應用程式使用 Microsoft Active Directory 或 LDAP 伺服器來驗證使用者 IDs 和密碼。除了基本列印授權之外，LRS/DIS 也可以在下列使用案例中套用精細層級的列印安全控制：
+ 管理誰可以瀏覽印表機任務。
+ 管理其他使用者任務的瀏覽層級。
+ 管理操作任務。例如，命令層級安全性，例如 hold/release、 purge、 modify、 copy 和 reroute。安全可由 User-ID 或 Group （類似 AD 群組或 LDAP 群組） 設定。****

## 附件
<a name="attachments-36de7312-4860-4702-a325-c01cf74c4f33"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/36de7312-4860-4702-a325-c01cf74c4f33/attachments/attachment.zip)

# 大型主機現代化：DevOps on AWS with Rocket Software Enterprise Suite
<a name="mainframe-modernization-devops-on-aws-with-micro-focus"></a>

*Kevin Yung，Amazon Web Services*

## 總結
<a name="mainframe-modernization-devops-on-aws-with-micro-focus-summary"></a>

**客戶挑戰**

當硬體需要擴展以滿足數位創新需求時，在大型主機硬體上執行核心應用程式的組織通常會遇到一些挑戰。這些挑戰包括下列限制條件。 
+ 由於大型主機硬體元件的彈性不足，以及變更的高成本，大型主機開發和測試環境無法擴展。
+ 大型主機開發正面臨技能不足，因為新開發人員不熟悉且對傳統大型主機開發工具不感興趣。容器、持續整合/持續交付 (CI/CD) 管道和現代測試架構等現代技術不適用於大型主機開發。

**模式結果**

為了解決這些挑戰，Amazon Web Services (AWS) 和 Rocket Software Micro Focus AWS Partner Network (APN) 合作夥伴合作建立此模式。解決方案旨在協助您達成下列結果。
+ 改善開發人員生產力。開發人員可以在幾分鐘內獲得新的大型主機開發執行個體。
+ 使用 AWS 雲端 建立具有幾乎無限容量的新大型主機測試環境。
+ 快速佈建新的大型主機 CI/CD 基礎設施。您可以在一小時內使用 AWS CloudFormation 和 在 上 AWS 完成佈建 AWS Systems Manager。
+ 原生使用 AWS DevOps 工具進行大型主機開發，包括 AWS CodeBuild、 AWS CodeCommit AWS CodePipeline AWS CodeDeploy、 和 Amazon Elastic Container Registry (Amazon ECR)。
+ 將傳統瀑布開發轉換為大型主機專案中的敏捷開發。

**技術摘要**

在此模式中，目標堆疊包含下列元件。


| 
| 
| 邏輯元件 | 實作解決方案 | Description | 
| --- |--- |--- |
| 原始程式碼儲存庫 | Rocket Software AccuRev Server、CodeCommit、Amazon ECR  | 原始程式碼管理 – 解決方案使用兩種類型的原始程式碼： 大型主機原始程式碼，例如 COBOL 和 JCL。 AWS 基礎設施範本和自動化指令碼 這兩種類型的原始程式碼都需要版本控制，但它們是在不同的 SCMs中進行管理。部署到大型主機或 Rocket Software Enterprise Servers 的原始程式碼在 Rocket Software Micro Focus AccuRev Server 中受管。 AWS 範本和自動化指令碼在 CodeCommit 中受管。Amazon ECR 用於 Docker 映像儲存庫。 | 
| 企業開發人員執行個體 | Amazon Elastic Compute Cloud (Amazon EC2)、Rocket Software Enterprise Developer for Eclipse | 大型主機開發人員可以使用 Rocket Software Enterprise Developer for Eclipse 在 Amazon EC2 中開發程式碼。這不需要依賴大型主機硬體來寫入和測試程式碼。  | 
| Rocket Software Enterprise Suite 授權管理 | Rocket Software Enterprise Suite License Manager | 對於集中式 Rocket Software Enterprise Suite 授權管理和管控，解決方案會使用 Rocket Software Enterprise Suite License Manager 來託管所需的授權。 | 
| CI/CD 管道 | CodePipeline、CodeBuild、CodeDeploy、容器中的 Rocket Software Enterprise Developer、容器中的 Rocket Software Enterprise Test Server、Rocket Software Micro Focus Enterprise Server | 大型主機開發團隊需要 CI/CD 管道來執行程式碼編譯、整合測試和迴歸測試。在 中 AWS，CodePipeline 和 CodeBuild 可以在原生容器中使用 Rocket Software Enterprise Developer 和 Enterprise Test Server。 | 

## 先決條件和限制
<a name="mainframe-modernization-devops-on-aws-with-micro-focus-prereqs"></a>

**先決條件**


| 
| 
| 名稱 | 描述 | 
| --- |--- |
| py3270 | py3270 是 x3270 的 Python 界面，這是 IBM 3270 終端機模擬器。它為 x3270 或 s3270 子程序提供 API。 | 
| x3270 | x3270 是適用於 X Window System 和 Windows 的 IBM 3270 終端機模擬器。 這可供開發人員用於本機單元測試。 | 
| Robot-Framework-Mainframe-3270-Library | Mainframe3270 是以 py3270 專案為基礎的機器人架構程式庫。 | 
| Rocket 軟體 Verastream | Rocket Software Verastream 是一種整合平台，可讓您以測試行動應用程式、Web 應用程式和 SOA Web 服務的方式測試大型主機資產。 | 
| Rocket 軟體統一功能測試 (UFT) 安裝程式和授權 | Rocket Software Unified Functional Testing 是一種軟體，可為軟體應用程式和環境提供功能和迴歸測試自動化。 | 
| Rocket Software Enterprise Server 安裝程式和授權 | Enterprise Server 為大型主機應用程式提供執行期環境。 | 
| Rocket Software Enterprise Test Server 安裝程式和授權 | Rocket Software Enterprise Test Server 是 IBM 大型主機應用程式測試環境。 | 
| 適用於 Server 的 Rocket Software AccuRev 安裝程式和授權，以及適用於 Windows 和 Linux 作業系統的 Rocket Software Micro Focus AccuRev 安裝程式和授權  | AccuRev 提供原始程式碼管理 (SCM)。AccuRev 系統旨在供開發一組檔案的人員團隊使用。 | 
| Rocket Software Enterprise Developer for Eclipse 安裝程式、修補程式和授權 | 企業開發人員為大型主機開發人員提供平台，以開發和維護核心大型主機線上和批次應用程式。 | 

**限制**
+ CodeBuild 不支援建置 Windows Docker 映像。此[回報的問題](https://github.com/docker-library/docker/issues/49)需要 Windows Kernel/HCS 和 Docker 團隊支援。解決方法是使用 Systems Manager 建立 Docker 映像建置 Runbook。此模式使用 因應措施來建置適用於 Eclipse 的 Rocket Software Enterpise 開發人員和 Rocket Software Micro Focus Enterprise Test Server 容器映像。 
+ Windows 尚未支援 CodeBuild 的虛擬私有雲端 (VPC) 連線，因此模式不會使用 Rocket Software License Manager 在 OpenText Rocket Software Enterprise Developer 和 Rocket Software Enterprise Test Server 容器中管理授權。

**產品版本**
+ Rocket Software Enterprise Developer 5.5 或更新版本
+ Rocket Software Enterprise Test Server 5.5 或更新版本
+ Rocket Software Enterprise Server 5.5 或更新版本
+ Rocket Software AccuRev 7.x 或更新版本
+ 適用於 Rocket Software Enterprise Developer 和 Enterprise Test Server 的 Windows Docker 基礎映像：**microsoft/dotnet-framework-4.7.2-runtime**
+ AccuRev 用戶端的 Linux Docker 基礎映像：**amazonlinux：2**

## Architecture
<a name="mainframe-modernization-devops-on-aws-with-micro-focus-architecture"></a>

**大型主機環境**

在傳統大型主機開發中，開發人員需要使用大型主機硬體來開發和測試程式。他們面臨容量限制，例如限制開發/測試環境的每秒數百萬次指令 (MIPS)，而且必須依賴大型主機電腦上可用的工具。

在許多組織中，大型主機開發遵循瀑布開發方法，團隊依賴長週期來發佈變更。這些發行週期通常比數位產品開發更長。  

下圖顯示共用大型主機硬體以進行開發的多個大型主機專案。在大型主機硬體中，擴展更多專案的開發和測試環境非常昂貴。

![\[Diagram showing mainframe architecture with z/OS, databases, programming languages, and user groups.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/84e717fc-5aea-41a6-977a-d7e7a7ca5da7.png)


 

 

*AWS*** 架構**

此模式會將大型主機開發延伸至 AWS 雲端。首先，它會使用 AccuRev SCM 託管大型主機原始碼 AWS。然後，它讓 Enterprise Developer 和 Enterprise Test Server 可用於建置和測試大型主機程式碼 AWS。 

下列各節說明模式的三個主要元件。

**1。SCM **

在 中 AWS， 模式使用 AccuRev 為大型主機原始程式碼建立一組 SCM 工作區和版本控制。其串流型架構可讓多個團隊進行平行大型主機開發。為了合併變更，AccuRev 使用提升概念。為了將該變更新增至其他工作區，AccuRev 會使用更新概念。

在專案層級，每個團隊都可以在 AccuRev 中建立一或多個串流，以追蹤專案層級的變更。這些稱為專案串流。這些專案串流繼承自相同的父串流。父串流用於合併來自不同專案串流的變更。

每個專案串流都可以將程式碼提升為 AccuRev，並設定提升後觸發以啟動 AWS CI/CD 管道。專案串流變更的成功建置可以提升為其父串流，以進行更多迴歸測試。 

通常，父串流稱為系統整合串流。當從專案串流提升到系統整合串流時，提升後觸發會啟動另一個 CI/CD 管道來執行迴歸測試。

除了大型主機程式碼之外，此模式還包括 AWS CloudFormation 範本、Systems Manager Automation 文件和指令碼。遵循infrastructure-as-code最佳實務，它們在 CodeCommit 中受版本控制。 

如果您需要將大型主機程式碼同步回大型主機環境以進行部署，Rocket Software 會提供 Enterprise Sync 解決方案，將程式碼從 AccuRev SCM 同步回大型主機 SCM。

**2. 開發人員和測試環境**

在大型組織中，擴展超過一百或甚至超過一千個大型主機開發人員具有挑戰性。為了解決此限制， 模式會使用 Amazon EC2 Windows 執行個體進行開發。在執行個體上，已安裝 Enterprise Developer for Eclipse 工具。開發人員可以在執行個體本機執行所有大型主機程式碼測試和偵錯。 

AWS Systems Manager 狀態管理員和自動化文件用於自動化開發人員執行個體佈建。建立開發人員執行個體的平均時間為 15 分鐘內。已備妥下列軟體和組態：
+ AccuRev Windows 用戶端，用於簽出並將原始程式碼遞交至 AccuRev
+ Enterprise Developers for Eclipse 工具，用於在本機寫入、測試和偵錯大型主機程式碼
+ 開放原始碼測試架構 Python 行為驅動開發 (BDD) 測試架構行為、py3270 和 x3270 模擬器，用於建立指令碼以測試應用程式
+ 用於建置 Enterprise Test Server Docker 映像並在 Enterprise Test Server Docker 容器中測試應用程式的 Docker 開發人員工具 

在開發週期中，開發人員會使用 EC2 執行個體在本機開發和測試大型主機程式碼。成功測試本機變更時，開發人員會將變更提升為 AccuRev 伺服器。 

**3. CI/CD 管道**

在 模式中，CI/CD 管道用於整合測試和迴歸測試，然後再部署到生產環境。 

如 SCM 一節所述，AccuRev 使用兩種類型的串流：專案串流和整合串流。每個串流都會與 CI/CD 管道連接。為了在 AccuRev 伺服器與 之間執行整合 AWS CodePipeline， 模式會使用 AccuRev 提升後指令碼來建立事件以啟動 CI/CD。

例如，當開發人員將變更提升為 AccuRev 中的專案串流時，會啟動提升後指令碼以在 AccuRev Server 中執行。然後，指令碼會將變更的中繼資料上傳至 Amazon Simple Storage Service (Amazon S3) 儲存貯體，以建立 Amazon S3 事件。此事件將啟動 CodePipeline 設定的管道來執行。 

相同的事件啟動機制用於整合串流及其相關聯的管道。 

在 CI/CD 管道中，CodePipeline 使用 CodeBuild 搭配 AccuRev Linux 用戶端容器，從 AccuRev 串流查看最新的程式碼。然後，管道會啟動 CodeBuild，以使用企業開發人員 Windows 容器來編譯原始程式碼，並使用 CodeBuild 中的企業測試伺服器 Windows 容器來測試大型主機應用程式。

CI/CD 管道是使用 CloudFormation 範本建置，藍圖將用於新專案。透過使用 範本，專案在其中建立新 CI/CD 管道所需的時間不到一小時 AWS。

為了擴展您的大型主機測試功能 AWS， 模式建置了 Rocket Software DevOps 測試套件、Verastream 和 UFT 伺服器。透過使用現代 DevOps 工具，您可以 AWS 視需要在 上執行任意數量的測試。

下圖 AWS 顯示開啟 Rocket Software 的大型主機開發環境範例。

![\[AWS development pipeline with shared components for multiple project teams.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/27da6a52-4573-44cb-8716-1ac49430f618.png)


 

*目標技術堆疊*

本節詳細介紹 模式中每個元件的架構。

**1。原始程式碼儲存庫 – AccuRev SCM**

AccuRev SCM 設定為管理大型主機原始碼版本。為了實現高可用性，AccuRev 支援主要和複本模式。在主節點上執行維護時，運算子可能會容錯移轉至複本。 

為了加速 CI/CD 管道的回應， 模式會使用 Amazon CloudWatch Events 來偵測原始程式碼變更，並啟動管道的啟動。

1. 管道設定為使用 Amazon S3 來源。

1. CloudWatch Events 規則設定為從來源 S3 儲存貯體擷取 S3 事件。

1. CloudWatch Events 規則會將目標設定為管道。

1. AccuRev SCM 設定為在提升完成後於本機執行提升後指令碼。

1. AccuRev SCM 會產生 XML 檔案，其中包含提升的中繼資料，而且指令碼會將 XML 檔案上傳至來源 S3 儲存貯體。

1. 上傳後，來源 S3 儲存貯體會傳送事件以符合 CloudWatch Events 規則，而 CloudWatch Events 規則會啟動管道以執行。 

當管道執行時，它會啟動 CodeBuild 專案，以使用 AccuRev Linux 用戶端容器，從相關聯的 AccuRev 串流查看最新的大型主機程式碼。  

下圖顯示 AccuRev Server 設定。

![\[AWS 雲端 diagram showing AccuRev setup with primary and replica instances across availability zones.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/e60345cc-2283-4b03-8f57-e3dac1770978.png)


**2. 企業開發人員範本** 

模式使用 Amazon EC2 範本來簡化開發人員執行個體的建立。透過使用 State Manager，它可以一致地將軟體和授權設定套用至 EC2 執行個體。

Amazon EC2 範本會在其 VPC 內容設定和預設執行個體設定中建置，並遵循企業標記要求。透過使用範本，團隊可以建立自己的新開發執行個體。 

當開發人員執行個體啟動時，透過與標籤建立關聯，Systems Manager 會使用 State Manager 套用自動化。自動化包含下列一般步驟。

1. 安裝 Enterprise Developer 軟體並安裝修補程式。

1. 安裝適用於 Windows 的 AccuRev 用戶端。

1. 安裝預先設定的指令碼，讓開發人員加入 AccuRev 串流。初始化 Eclipse 工作區。

1. 安裝開發工具，包括 x3270、py3270 和 Docker。

1. 設定授權設定以指向 License Manager 負載平衡器。

下圖顯示 Amazon EC2 範本建立的企業開發人員執行個體，其軟體和組態由 State Manager 套用至執行個體。企業開發人員執行個體會連線至 AWS License Manager 以啟用其授權。

![\[AWS 雲端 diagram showing Enterprise Developer Instance setup with License Manager and Systems Manager components.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/7ca8f538-8362-4a11-a842-7ecff6fa0248.png)


 

**3.  CI/CD 管道**

如 AWS 架構一節所述，在 模式中，有專案層級的 CI/CD 管道和系統整合管道。每個大型主機專案團隊都會建立管道或多個 CI/CD 管道，以建置他們在專案中開發的程式。這些專案 CI/CD 管道會從相關聯的 AccuRev 串流簽出原始程式碼。 

在專案團隊中，開發人員會在相關聯的 AccuRev 串流中提升程式碼。然後，提升會啟動專案管道來建置程式碼並執行整合測試。 

每個專案 CI/CD 管道使用 CodeBuild 專案搭配 Enterprise Developer 工具 Amazon ECR 映像和 Enterprise Test Server 工具 Amazon ECR 映像。 

CodePipeline 和 CodeBuild 用於建立 CI/CD 管道。由於 CodeBuild 和 CodePipeline 沒有預付費用或承諾，您只需為使用量付費。相較於大型主機硬體，此 AWS 解決方案可大幅縮短硬體佈建前置時間，並降低測試環境的成本。

在現代開發中，會使用多個測試方法。例如，測試驅動的開發 (TDD)、BDD 和機器人架構。透過此模式，開發人員可以使用這些現代工具進行大型主機測試。例如，透過使用 x3270、py3270 和 Behave python 測試工具，您可以定義線上應用程式的行為。您也可以在這些 CI/CD 管道中使用建置大型主機 3270 機器人架構。

下圖顯示團隊串流 CI/CD 管道。 

![\[AWS 雲端 CI/CD pipeline showing CodeCommit, CodePipeline, and CodeBuild with Micro Focus tools integration.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/da59f837-2f23-404f-948b-41402cc6fe0c.png)


下圖顯示 Mainframe3270 機器人架構中 CodePipeline 產生的專案 CI/CD 測試報告。

![\[Test report summary showing 100% pass rate for 3 test cases in 2.662 seconds.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/4752321a-c60d-455c-ac2f-6f0e2bc3dca0.png)


下圖顯示 CodePipeline 在 Py3270 和 Behave BDD 中產生的專案 CI/CD 測試報告。

![\[Test report summary showing 100% pass rate for 2 test cases in a pipeline.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/d005466e-aeb8-4fd6-8342-743ed049f98a.png)


成功傳遞專案層級測試後，測試的程式碼會在 AccuRev SCM 中手動提升為整合串流。您可以在團隊對其專案管道的測試涵蓋範圍有信心之後，自動執行此步驟。

提升程式碼時，系統整合 CI/CD 管道會檢查合併的程式碼並執行迴歸測試。合併的程式碼會從所有平行專案串流提升。

根據測試環境需要的精細程度，客戶可以在不同的環境中擁有更多系統整合 CI/CD 管道，例如 UAT、Pre-Production。 

在 模式中，系統整合管道中使用的工具是 Enterprise Test Server、UTF Server 和 Verastream。所有這些工具都可以部署到 Docker 容器中，並與 CodeBuild 搭配使用。

成功測試大型主機程式後，成品會以版本控制存放在 S3 儲存貯體中。 

下圖顯示系統整合 CI/CD 管道。

![\[CI/CD pipeline showing AWS 服務 and Micro Focus tools for source, build, test, and promote stages.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/693212e5-1cd0-4f82-a910-39b00d977c38.png)


 

在系統整合 CI/CD 管道中成功測試成品之後，即可提升成品以進行生產部署。 

如果您需要將原始碼部署回大型主機，Rocket Software 會提供 Enterprise Sync 解決方案，將原始碼從 AccuRev 同步回大型主機 Endeavour。

下圖顯示將成品部署到企業伺服器的生產 CI/CD 管道。在此範例中，CodeDeploy 會協調將測試過的大型主機成品部署至 Enterprise Server。

![\[CI/CD pipeline diagram showing CodePipeline, CodeBuild, and CodeDeploy stages for artifact deployment.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/2359db4c-f351-45a6-8516-88a3b62e61f9/images/56749c2a-e038-4e56-9487-b2ff83894725.png)


除了 CI/CD 管道的架構演練之外，請參閱 AWS DevOps 部落格文章[AWS 使用 Micro Focus Enterprise Suite 在 上自動化數千個大型主機測試](https://aws.amazon.com/blogs/devops/automate-mainframe-tests-on-aws-with-micro-focus/)，以取得在 CodeBuild 和 CodePipeline 中測試大型主機應用程式的詳細資訊。(Micro Focus 現在是 Rocket Software。) 如需執行大型主機測試的最佳實務和詳細資訊，請參閱部落格文章 AWS。

## 工具
<a name="mainframe-modernization-devops-on-aws-with-micro-focus-tools"></a>

**AWS 自動化工具**
+ [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [Amazon CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html)
+ [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html)
+ [AWS CodeDeploy](https://docs.aws.amazon.com/codedeploy/latest/userguide/welcome.html)
+ [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html)
+ [Amazon ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html)
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html)
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html)

**Rocket 軟體工具**
+ [適用於 Eclipse 的 Rocket Enterprise 開發人員](https://www.microfocus.com/documentation/enterprise-developer/ed60/ED-Eclipse/GUID-8D6B7358-AC35-4DAF-A445-607D8D97EBB2.html)
+ [Rocket Enterprise 測試伺服器](https://www.microfocus.com/documentation/enterprise-developer/ed60/ETS-help/GUID-ECA56693-D9FE-4590-8798-133257BFEBE7.html)
+ [Rocket Enterprise Server](https://www.microfocus.com/documentation/enterprise-developer/es_60/) （生產部署）
+ [Rocket 軟體 AccuRev](https://supportline.microfocus.com/documentation/books/AccuRev/AccuRev/6.2/webhelp/wwhelp/wwhimpl/js/html/wwhelp.htm)
+ [Rocket Software Enterprise Suite License Manager](https://www.microfocus.com/documentation/slm/)
+ [Rocket Software Verastream 主機整合器](https://www.microfocus.com/documentation/verastream-host-integrator/)
+ [Rocket 軟體 UFT One](https://admhelp.microfocus.com/uft/en/24.4/UFT_Help/Content/User_Guide/Ch_UFT_Intro.htm)

**其他工具**
+ x3270
+ [py3270](https://pypi.org/project/py3270/)
+ [Robot-Framework-Mainframe-3270-Library](https://github.com/Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library)

## 史詩
<a name="mainframe-modernization-devops-on-aws-with-micro-focus-epics"></a>

### 建立 AccuRev SCM 基礎設施
<a name="create-the-accurev-scm-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 CloudFormation 部署主要 AccuRev SCM 伺服器。 |  | AWS CloudFormation | 
| 建立 AccuRev 管理員使用者。 | 登入 AccuRev SCM Server，然後執行 CLI 命令來建立管理員使用者。 | AccuRev SCM 伺服器管理員 | 
| 建立 AccuRev 串流。 | 依序建立繼承自上方串流的 AccuRev 串流：生產、系統整合、團隊串流。 | AccuRev SCM 管理員 | 
| 建立開發人員 AccuRev 登入帳戶。 | 使用 AccuRev SCM CLI 命令為大型主機開發人員建立 AccuRev 使用者登入帳戶。 | AccuRev SCM 管理員 | 

### 建立企業開發人員 Amazon EC2 啟動範本
<a name="create-the-enterprise-developer-ec2-launch-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 CloudFormation 部署 Amazon EC2 啟動範本。 | 使用 CloudFormation 部署企業開發人員執行個體的 Amazon EC2 啟動範本。範本包含 Rocket Enterprise Developer 執行個體的 Systems Manager 自動化文件。 | AWS CloudFormation | 
| 從 Amazon EC2 範本建立企業開發人員執行個體。 |  | AWS 主控台登入和大型主機開發人員技能 | 

### 建立企業開發人員工具 Docker 映像
<a name="create-the-enterprise-developer-tool-docker-image"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立企業開發人員工具 Docker 映像。 | 使用 Docker 命令和企業開發人員工具 Dockerfile 來建立 Docker 映像。 | Docker | 
| 在 Amazon ECR 中建立 Docker 儲存庫。 | 在 Amazon ECR 主控台上，為企業開發人員 Docker 映像建立儲存庫。 | Amazon ECR | 
| 將企業開發人員工具 Docker 映像推送至 Amazon ECR。 | 執行 Docker 推送命令，以推送企業開發人員工具 Docker 映像檔，將其儲存在 Amazon ECR 的 Docker 儲存庫中。 | Docker | 

### 建立 Enterprise Test Server Docker 映像
<a name="create-the-enterprise-test-server-docker-image"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Enterprise Test Server Docker 映像。 | 使用 Docker 命令和 Enterprise Test Server Dockerfile 來建立 Docker 映像。 | Docker | 
| 在 Amazon ECR 中建立 Docker 儲存庫。 | 在 Amazon ECR 主控台上，為 Enterprise Test Server Docker 映像建立 Amazon ECR 儲存庫。 | Amazon ECR | 
| 將 Enterprise Test Server Docker 映像推送至 Amazon ECR。 | 執行 Docker push 命令，將 Enterprise Test Server Docker 映像推送並儲存在 Amazon ECR 中。 | Docker | 

### 建立團隊串流 CI/CD 管道
<a name="create-the-team-stream-ci-cd-pipeline"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 CodeCommit 儲存庫。 | 在 CodeCommit 主控台上，為基礎設施和 CloudFormation 程式碼建立 Git 型儲存庫。 | AWS CodeCommit | 
| 將 CloudFormation 範本和自動化程式碼上傳至 CodeCommit 儲存庫。 | 執行 Git push 命令，將 CloudFormation 範本和自動化程式碼上傳至儲存庫。 | Git | 
| 使用 CloudFormation 部署團隊串流 CI/CD 管道。 | 使用準備好的 CloudFormation 範本來部署團隊串流 CI/CD 管道。 | AWS CloudFormation | 

### 建立系統整合 CI/CD 管道
<a name="create-the-system-integration-ci-cd-pipeline"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 UFT Docker 映像。 | 使用 Docker 命令和 UFT Dockerfile 來建立 Docker 映像。 | Docker | 
| 在 UFT 映像的 Amazon ECR 中建立 Docker 儲存庫。 | 在 Amazon ECR 主控台上，為 UFT 映像建立 Docker 儲存庫。 | Amazon ECR | 
| 將 UFT Docker 映像推送至 Amazon ECR。 | 執行 Docker push 命令，將 Enterprise Test Server Docker 映像推送並儲存在 Amazon ECR 中。 | Docker | 
| 建立 Verastream Docker 映像。 | 使用 Docker 命令和 Verastream Dockerfile 來建立 Docker 映像。 | Docker | 
| 在 Amazon ECR 中為 Verastream 映像建立 Docker 儲存庫。 | 在 Amazon ECR 主控台上，為 Verastream 映像建立 Docker 儲存庫。 | Amazon ECR | 
| 使用 CloudFormation 部署系統整合 CI/CD 管道。 | 使用準備好的 CloudFormation 範本來部署系統整合 CI/CD 管道。 | AWS CloudFormation | 

### 建立生產部署 CI/CD 管道
<a name="create-production-deployment-ci-cd-pipeline"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 AWS Quick Start 部署 Enterprise Server。 | 若要使用 CloudFormation 部署 Enterprise Server，請在 AWS Quick Start 上啟動 Enterprise Server。 | AWS CloudFormation | 
| 部署生產部署 CI/CD 管道。 | 在 CloudFormation 主控台上，使用 CloudFormation 範本來部署生產部署 CI/CD 管道。 | AWS CloudFormation | 

## 相關資源
<a name="mainframe-modernization-devops-on-aws-with-micro-focus-resources"></a>

**參考**
+ [AWS DevOps 部落格 - AWS 使用 Micro Focus Enterprise Suite 在 上自動化數千個大型主機測試 ](https://aws.amazon.com/blogs/devops/automate-mainframe-tests-on-aws-with-micro-focus/)(Micro Focus 現在是 Rocket Software。)
+ [py3270/py3270 GitHub 儲存庫](https://github.com/py3270/py3270)
+ [Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library GitHub 儲存庫](https://github.com/Altran-PT-GDC/Robot-Framework-Mainframe-3270-Library)
+ [歡迎行為！](https://behave.readthedocs.io/en/latest/index.html)
+ [APN 合作夥伴部落格 - 標籤：Micro Focus ](https://aws.amazon.com/blogs/apn/tag/micro-focus/)(Micro Focus 現在是 Rocket 軟體。)
+ [從啟動範本啟動執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html)

**AWS Marketplace**
+ [Rocket 軟體 UFT One](https://aws.amazon.com/marketplace/pp/B01EGCA5OS?ref_=srh_res_product_title)

**AWS Quick Start**
+ [上的 Rocket Enterprise Server AWS](https://aws.amazon.com/quickstart/architecture/micro-focus-enterprise-server/)

# 使用 Micro Focus Enterprise Server 和 LRS VPSX/MFI 將 AWS 上的大型主機線上列印工作負載現代化
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi"></a>

*Shubham Roy 和 Kevin Yung，Amazon Web Services*

*Abraham Rondon，微型焦點*

*Guy Tucker、Levi、Ray 和 Shoup Inc*

## 總結
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-summary"></a>

此模式說明如何使用 Micro Focus Enterprise Server 做為現代化大型主機應用程式的執行期，以及使用 LRS VPSX/MFI (Micro Focus Interface) 做為列印伺服器，在 Amazon Web Services (AWS) 雲端上現代化業務關鍵型大型主機線上列印工作負載。模式是以[轉換大型](https://aws.amazon.com/blogs/apn/demystifying-legacy-migration-options-to-the-aws-cloud/)主機現代化方法為基礎。在此方法中，您將大型主機線上應用程式遷移至 Amazon Elastic Compute Cloud (Amazon EC2)，並將大型主機資料庫遷移至 Amazon Relational Database Service (Amazon RDS)，例如 z/OS 的 IBM DB2。現代化列印工作流程的身分驗證和授權是由 AWS Directory Service for Microsoft Active Directory 執行，也稱為 AWS Managed Microsoft AD。LRS Directory Information Server (LRS/DIS) 已與 AWS Managed Microsoft AD 整合，用於列印工作流程身分驗證和授權。透過現代化線上列印工作負載，您可以降低 IT 基礎設施成本、減輕維護舊版系統的技術責任、移除資料孤島、使用 DevOps 模型提高敏捷性和效率，以及利用 AWS 雲端中的隨需資源和自動化。

## 先決條件和限制
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 大型主機線上列印或輸出管理工作負載
+ 如何重建和交付在 Micro Focus Enterprise Server 上執行之大型主機應用程式的基本知識 （如需詳細資訊，請參閱 Micro Focus 文件中的[企業伺服器](https://www.microfocus.com/media/data-sheet/enterprise_server_ds.pdf)資料表。)
+ LRS 雲端列印解決方案和概念的基本知識 （如需詳細資訊，請參閱 LRS 文件中的[輸出現代化](https://www.lrsoutputmanagement.com/products/modernization-products)。)
+ Micro Focus Enterprise Server 軟體和授權 （如需詳細資訊，請聯絡 [Micro Focus 銷售](https://www.microfocus.com/en-us/contact/contactme)。)
+ LRS VPSX/MFI、LRS/Queue 和 LRS/DIS 軟體和授權 （如需詳細資訊，請聯絡 [LRS 銷售](https://www.lrsoutputmanagement.com/about-us/contact-us/))。

**注意**  
如需大型主機線上列印工作負載組態考量的詳細資訊，請參閱此模式*額外資訊*區段中的*考量*事項。

**產品版本**
+ [Micro Focus Enterprise Server](https://www.microfocus.com/en-us/products/enterprise-server/overview?utm_campaign=7018e000000PgfnAAC&utm_content=SCH-BR-AMC-AppM-AMS&gclid=EAIaIQobChMIoZCQ6fvS9wIVxQN9Ch2MzAOlEAAYASAAEgKx2fD_BwE) 8.0 或更新版本
+ [LRS VPSX/MFI](https://www.lrsoutputmanagement.com/products/modernization-products/) V1R3 或更新版本

## Architecture
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-architecture"></a>

**來源技術堆疊**
+ 作業系統 – IBM z/OS
+ 程式設計語言 – 常見商業導向語言 (COBOL) 和客戶資訊控制系統 (CICS) 
+ 資料庫 – IBM DB2 for z/OS IBM 資訊管理系統 (IMS) 和虛擬儲存存取方法 (VSAM)
+ 安全性 – 資源存取控制設施 (RACF)、z/OS 的 CA 最高機密，以及存取控制設施 2 (ACF2)
+ 列印和輸出管理 – IBM 大型主機 z/OS 列印產品 （適用於 z/OS、LRS 和 CA 檢視的 IBM Infoprint 伺服器）

**目標技術堆疊**
+ 作業系統 – 在Amazon EC2 上執行的 Microsoft Windows Server
+ 運算 – Amazon EC2
+ 程式設計語言 – COBOL 和 CICS
+ 資料庫 – Amazon RDS
+ 安全性 – AWS Managed Microsoft AD
+ 列印和輸出管理 – AWS 上的 LRS 列印解決方案
+ 大型主機執行期環境 – Micro Focus Enterprise Server

**來源架構**

下圖顯示大型主機線上列印工作負載的典型目前狀態架構。

![\[產生可檢視輸出的六步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/924cdae7-9265-4fc9-8e5e-bb2da5368e7e/images/293368f5-d102-4f4e-b290-71da4aeff347.png)


該圖顯示以下工作流程：

1. 使用者在以 COBOL 撰寫的 IBM CICS 應用程式上建置的參與系統 (SoE) 上執行商業交易。

1. SoE 會叫用大型主機服務，該服務會將商業交易資料記錄在system-of-records(SoR) 資料庫中，例如 z/OS 的 IBM DB2。

1. SoR 會保留來自 SoE 的業務資料。

1. 使用者啟動從 CICS SoE 產生列印輸出的請求，這會啟動列印交易應用程式來處理列印請求。 

1. 列印交易應用程式 （例如 CICS 和 COBOL 程式） 會從資料庫擷取資料、根據業務需求格式化資料，以及產生業務輸出 （列印資料），例如帳單、ID 卡或貸款陳述式。然後，應用程式會使用虛擬電信存取方法 (VTAM) 傳送列印請求。z/OS 列印伺服器 （例如 IBM Infoprint Server) 使用 NetSpool 或類似的 VTAM 元件來攔截列印請求，然後使用 JES 輸出參數在 JES 多工緩衝系統上建立列印輸出資料集。JES 輸出參數會指定路由資訊，供列印伺服器用來將輸出傳輸至特定網路印表機。*VTAM* 一詞是指 z/OS Communications Server 和 z/OS 的系統網路架構 (SNA) 服務元素。

1. 列印輸出傳輸元件會將輸出列印資料集從 JES 多工緩衝區傳輸至遠端印表機或列印伺服器，例如 LRS （如此模式所示）、IBM Infoprint Server 或電子郵件目的地。

**目標架構**

下圖顯示部署在 AWS 雲端中大型主機線上列印工作負載的架構：

![\[從啟動列印請求到處理 AWS 到 LRS 列印的四個步驟。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/924cdae7-9265-4fc9-8e5e-bb2da5368e7e/images/07c97b6f-1a86-493d-a4e0-b8321b46f9b7.png)


該圖顯示以下工作流程：

1. 使用者從線上 (CICS) 使用者介面啟動列印請求，以建立列印輸出，例如帳單、ID 卡或貸款陳述式。

1. 大型主機線上應用程式 ([已修改為 Amazon EC2](https://aws.amazon.com/blogs/apn/demystifying-legacy-migration-options-to-the-aws-cloud/)) 使用 Micro Focus Enterprise Server 執行期從應用程式資料庫擷取資料、將商業邏輯套用至資料、格式化資料，然後使用 [Micro Focus CICS Print Exit](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/HCOMCMJCLOU020.html) (DFHUPRNT) 將資料傳送至列印目的地。 

1. 應用程式資料庫 （在 Amazon RDS 上執行的 SoR) 會保留列印輸出的資料。

1. LRS VPSX/MFI 列印解決方案部署在 Amazon EC2 上，其操作資料存放在 Amazon Elastic Block Store (Amazon EBS) 中。LRS VPSX/MFI 使用 TCP/IP 型 LRS/Queue 傳輸代理程式，透過 Micro Focus CICS Print Exit API (DFHUPRNT) 收集列印資料，並將資料交付至指定的印表機目的地。現代化 CICS 應用程式中使用的原始 TERMID (TERM) 會用作 VPSX/MFI 佇列名稱。 

**注意**  
目標解決方案通常不需要應用程式變更來容納大型主機格式語言，例如 IBM Advanced Function Presentation (AFP) 或 Xerox Line Condition Data Stream (LCDS)。如需在 AWS 上使用 Micro Focus 進行大型主機應用程式遷移和現代化的詳細資訊，請參閱 AWS 文件中的[使用 Micro Focus 在 AWS 上增強企業大型主機工作負載](https://aws.amazon.com/blogs/apn/empowering-enterprise-grade-mainframe-workloads-on-aws-with-micro-focus/)。

**AWS 基礎設施架構**

下圖顯示適用於大型主機線上列印工作負載的高可用性和安全 AWS 基礎設施架構：

![\[EC2、Amazon RDS 和 LRS 列印上具有 Micro Focus Enterprise 伺服器的兩個可用區域。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/924cdae7-9265-4fc9-8e5e-bb2da5368e7e/images/093555a1-342c-420c-bb90-e9440d2e8650.png)


該圖顯示以下工作流程：

1. 大型主機線上應用程式 （以程式設計語言撰寫，例如 CICS 或 COBOL) 使用核心商業邏輯來處理和產生列印輸出，例如帳單、ID 卡和貸款陳述式。線上應用程式部署在跨兩個[可用區域 (AZ) 的](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/) Amazon EC2 上以獲得高可用性 (HA)，並使用 Micro Focus CICS 列印結束將列印輸出路由到 LRS VPSX/MFI 進行最終使用者列印。

1. LRS VPSX/MFI 使用 TCP/IP 型 LRS/佇列傳輸代理程式，從 Micro Focus 線上列印結束程式設計界面收集或擷取列印資料。線上列印結束會傳遞必要資訊，讓 LRS VPSX/MFI 有效地處理列印檔案，並動態建置 LRS/佇列命令。
**注意**  
如需各種用於列印的 CICS 應用程式程式設計方法，以及如何在 Micro Focus Enterprise 伺服器和 LRS VPSX/MFI 中支援它們的詳細資訊，請參閱此模式*的其他資訊*區段中的*列印資料擷取*。

1. 
**注意**  
[Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html) 提供 DNS 名稱，以整合 Micro Focus Enterprise Server 與 LRS VPSX/MFI。：LRS VPSX/MFI 支援第 4 層負載平衡器。Network Load Balancer 也會對 LRS VPSX/MFI 執行基本運作狀態檢查，並將流量路由至運作狀態良好的已註冊目標。

1. LRS VPSX/MFI 列印伺服器會跨 HA 的兩個可用區域部署在 Amazon EC2 上，並使用 [Amazon EBS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 做為操作資料存放區。LRS VPSX/MFI 支援主動-主動和主動-被動服務模式。此架構使用主動-被動配對中的多個可用區域作為主動和熱待命。Network Load Balancer 會對 LRS VPSX/MFI EC2 執行個體執行運作狀態檢查，並在作用中執行個體處於運作狀態不佳時，將流量路由到另一個可用區域中的熱待命執行個體。列印請求會保留在每個 EC2 執行個體的本機 LRS 任務佇列中。在復原的情況下，必須重新啟動失敗的執行個體，LRS 服務才能繼續處理列印請求。
**注意**  
LRS VPSX/MFI 也可以在印表機機群層級執行運作狀態檢查。如需詳細資訊，請參閱此模式*額外資訊*區段中的*印表機機群運作狀態檢查*。

1. [AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 與 LRS/DIS 整合，以執行列印工作流程身分驗證和授權。如需詳細資訊，請參閱此模式*額外資訊*區段中的*列印身分驗證和授權*。

1. LRS VPSX/MFI 使用 Amazon EBS 進行區塊儲存。您可以將 Amazon EBS 資料以point-in-time快照的形式從作用中的 EC2 執行個體備份到 Amazon S3，並將其還原至熱待命 EBS 磁碟區。若要自動建立、保留和刪除 Amazon EBS 磁碟區快照，您可以使用 [Amazon Data Lifecycle Manager](https://aws.amazon.com/blogs/aws/new-lifecycle-management-for-amazon-ebs-snapshots/) 來設定自動快照的頻率，並根據 [RTO/RPO 需求](https://docs.aws.amazon.com/whitepapers/latest/disaster-recovery-workloads-on-aws/disaster-recovery-options-in-the-cloud.html)還原快照。

## 工具
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-tools"></a>

**AWS 服務**
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 提供區塊層級儲存體磁碟區，可搭配使用 Amazon EC2 執行個體。EBS 磁碟區的行為與未格式化的原始區塊型儲存設備相似。您可以將這些磁碟區做為裝置，掛載在您的執行個體上。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [AWS Directory Service for Microsoft Active Directory (AD)](https://aws.amazon.com/directoryservice/active-directory/)，也稱為 AWS Managed Microsoft Active Directory，可讓您的目錄感知工作負載和 AWS 資源在 AWS 中使用受管 Active Directory。

**其他工具**
+ [LRS VPSX/MFI (Micro Focus Interface)](https://www.lrsoutputmanagement.com/products/modernization-products/)，由 LRS 和 Micro Focus 共同開發，可從 Micro Focus Enterprise Server JES 多工緩衝區擷取輸出，並可靠地將其交付至指定的列印目的地。
+ 在列印工作流程期間，LRS Directory Information Server (LRS/DIS) 用於身分驗證和授權。
+ LRS/Queue 是一種以 TCP/IP 為基礎的 LRS/Queue 傳輸代理程式，由 LRS VPSX/MFI 使用，透過 Micro Focus 線上列印結束程式設計界面收集或擷取列印資料。
+ [Micro Focus Enterprise Server](https://www.microfocus.com/documentation/enterprise-developer/ed60/ES-WIN/GUID-A2F23243-962B-440A-A071-480082DF47E7.html) 是大型主機應用程式的應用程式部署環境。它為使用任何版本的 Micro Focus Enterprise Developer 遷移或建立的大型主機應用程式提供執行環境。

## 史詩
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-epics"></a>

### 在 Amazon EC2 上設定 Micro Focus Enterprise Server 並部署大型主機線上應用程式
<a name="set-up-micro-focus-enterprise-server-on-amazon-ec2-and-deploy-a-mainframe-online-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Micro Focus Enterprise Server 並部署示範線上應用程式。 | 在 Amazon EC2 上設定 Micro Focus Enterprise Server，然後遵循 Micro Focus 文件中的[教學課程：CICS Support](https://www.microfocus.com/documentation/enterprise-developer/ed70/ED-Eclipse/GMWALK00.html) 指示，在 Amazon EC2 上部署 Micro Focus 帳戶示範應用程式 (ACCT 示範）。ACCT 示範應用程式是大型主機線上 (CICS) 應用程式，可建立並啟動列印輸出。 | 雲端架構師 | 

### 在 Amazon EC2 上設定 LRS 列印伺服器
<a name="set-up-an-lrs-print-server-on-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得用於列印的 LRS 產品授權。 | 若要取得 LRS VPSX/MFI、LRS/Queue 和 LRS/DIS 的 LRS 產品授權，請聯絡 [LRS 輸出管理團隊](https://www.lrsoutputmanagement.com/about-us/contact-us/)。您必須提供將安裝 LRS 產品的 EC2 執行個體的主機名稱。 | 建置潛在客戶 | 
| 建立 Amazon EC2 Windows 執行個體以安裝 LRS VPSX/MFI。 | 依照 Amazon EC2 文件中的[步驟 1：啟動執行個體中的指示啟動 Amazon EC2 Windows 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/EC2_GetStarted.html#ec2-launch-instance)。 Amazon EC2 您的執行個體必須符合 LRS VPSX/MFI 的下列硬體和軟體需求： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html)上述硬體和軟體需求適用於小型印表機機群 （約 500–1000)。若要取得完整需求，請洽詢您的 LRS 和 AWS 聯絡人。當您建立 Windows 執行個體時，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 在 EC2 執行個體上安裝 LRS VPSX/MFI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 安裝 LRS/佇列。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 安裝 LRS/DIS。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 建立目標群組，並將 LRS VPSX/MFI EC2 註冊為目標。 | 遵循 Elastic Load Balancing 文件中為 [Network Load Balancer 建立目標群組的指示來](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-target-group.html)建立目標群組。當您建立目標群組時，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 建立 Network Load Balancer。 | 遵循 Elastic Load Balancing [ Load Balancing 文件中建立 Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-network-load-balancer.html) 的指示。Network Load Balancer 會將流量從 Micro Focus Enterprise Server 路由到 LRS VPSX/MFI EC2。當您建立 Network Load Balancer 時，請在**接聽程式和路由**頁面上執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 將 Micro Focus Enterprise Server 與 LRS VPSX/MFI 和 LRS/Queue 整合
<a name="integrate-micro-focus-enterprise-server-with-lrs-vpsx-mfi-and-lrs-queue"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Micro Focus Enterprise Server for LRS/Queue 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 讓 Micro Focus Enterprise Server 初始化可使用 CICS 列印結束 (DFHUPRNT)。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html)**驗證 Micro Focus Enterprise Server 已偵測到 CICS 列印結束 (DFHUPRNT)**[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 將 CICS 印表機的終端機 ID (TERMIDs) 定義為 Micro Focus Enterprise Server。 | **在 Micro Focus Enterprise Server 中啟用 3270 列印**[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html)**在 Micro Focus Enterprise Server 中定義 CICS 印表機的終端機**[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 在 Micro Focus Enterprise Server 和 LRS VPSX/MFI 中設定印表機和列印使用者
<a name="set-up-printers-and-print-users-in-micro-focus-enterprise-server-and-lrs-vpsx-mfi"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 LRS VPSX 中建立列印佇列。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html)列印佇列必須等同於 Micro Focus Enterprise Server 中建立的列印 TERMIDs。 | 雲端架構師 | 
| 在 LRS VPSX/MFI 中建立列印使用者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 設定列印身分驗證和授權
<a name="set-up-print-authentication-and-authorization"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用使用者和群組建立 AWS Managed Microsoft AD 網域。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 
| 將 LRS VPSX/MFI EC2 加入 AWS Managed Microsoft AD 網域。 | [以自動方式](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-systems-manager-dx-domain/) (AWS 知識中心文件） 或[手動方式](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/join_windows_instance.html) (AWS Directory Service 文件） 將 LRS VPSX/MFI EC2 加入您的 AWS Managed Microsoft AD 網域。 | 雲端架構師 | 
| 設定 LRS/DIS 並與 AWS Managed Microsoft AD 整合。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html) | 雲端架構師 | 

### 測試線上列印工作流程
<a name="test-an-online-print-workflow"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Micro Focus ACCT 示範應用程式啟動線上列印請求。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html)「已排程列印請求」訊息會顯示在畫面底部。這確認線上列印請求是從 ACCT 示範應用程式產生，並傳送至 LRS VPS/MFI 進行列印處理。  | 雲端架構師 | 
| 檢查 LRS VPSX/MFI 中的列印輸出。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi.html)您現在可以查看 帳戶陳述式的列印輸出，其中包含帳戶編號、SURNAME、FIRST、ADDRESS、TELEPHONE、發行的卡片數量、發行日期、金額和餘額的資料欄。如需範例，請參閱此模式的 **online\$1print\$1output** 附件。 | 測試工程師 | 

## 相關資源
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-resources"></a>
+ [LRS 輸出現代化 ](https://www.lrsoutputmanagement.com/products/modernization-products)(LRS 文件）
+ [VTAM 聯網概念](https://www.ibm.com/docs/en/zos/2.1.0?topic=guide-vtam-networking-concepts) (IBM 文件）
+ [邏輯單位 (LU) 類型摘要 ](https://www.ibm.com/docs/en/wsfz-and-o/1.1?topic=installation-summary-logical-unit-lu-types)(IBM 文件）
+ [ANSI 和機器承載控制](https://www.ibm.com/docs/en/cmofz/9.5.0?topic=tips-ansi-machine-carriage-controls) (IBM 文件）
+ [使用 Micro Focus 在 AWS 上增強企業大型主機工作負載 ](https://aws.amazon.com/blogs/apn/empowering-enterprise-grade-mainframe-workloads-on-aws-with-micro-focus/)(AWS 合作夥伴網路部落格）
+ [使用 Amazon EC2 Auto Scaling 和 Systems Manager 建置 Micro Focus Enterprise Server PAC](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/build-a-micro-focus-enterprise-server-pac-with-amazon-ec2-auto-scaling-and-systems-manager.html) (AWS 規範性指導文件）
+ [進階函數呈現 (AFP) 資料串流 ](https://www.ibm.com/docs/en/i/7.4?topic=streams-advanced-function-presentation-data-stream)(IBM 文件）
+ [Line Conditioned Data Stream (LCDS)](https://www.compart.com/en/lcds) （組件文件）

## 其他資訊
<a name="modernize-mainframe-online-printing-workloads-on-aws-by-using-micro-focus-enterprise-server-and-lrs-vpsx-mfi-additional"></a>

**考量**

在現代化旅程中，您可以考慮大型主機線上程序及其產生的輸出的各種組態。大型主機平台是由每個使用大型主機平台的客戶和廠商自訂，其具有直接影響列印的特定要求。例如，您目前的平台可能會將 IBM 進階函數簡報 (AFP) 或 Xerox Line Condition Data Stream (LCDS) 納入目前的工作流程。此外，[大型主機運輸控制字元](https://www.ibm.com/docs/en/cmofz/9.5.0?topic=tips-ansi-machine-carriage-controls)和[頻道命令文字](https://www.ibm.com/docs/en/zos/2.3.0?topic=devices-channel-command-words)可能會影響列印頁面的外觀，並且可能需要特殊處理。作為現代化規劃程序的一部分，我們建議您評估並了解特定列印環境中的組態。

**列印資料擷取**

本節摘要說明您可以在 IBM 大型主機環境中用於列印的 CICS 應用程式程式設計方法。LRS VPSX/MFI 元件提供技術，允許相同的應用程式以相同的方式建立資料。下表說明如何在 AWS 和 Micro Focus Enterprise Server 中搭配 LRS VPSX/MFI 列印伺服器執行的現代化 CICS 應用程式中支援每個應用程式程式設計方法。


| 
| 
| Method | Description | 在現代化環境中支援 方法 | 
| --- |--- |--- |
| EXEC CICS SEND TEXT.. 或 EXEC CICS SEND MAP.。 | 這些 CICS 和 VTAM 方法負責建立 3270/SCS 列印資料串流並將其交付至 LUTYPE0, LUTYPE1和 LUTYPE3 列印裝置。 | Micro Focus 線上列印結束 (DFHUPRNT) 應用程式介面 (API) 可讓列印資料在建立 3270/SCS 列印資料串流時，由 VPSX/MFI 處理。 | 
| EXEC CICS SEND TEXT.. 或 EXEC CICS SEND MAP.. （使用第三方 IBM 大型主機軟體） | CICS 和 VTAM 方法負責建立 3270/SCS 列印資料串流並將其交付至 LUTYPE0, LUTYPE1和 LUTYPE3 列印裝置。第三方軟體產品會攔截列印資料、使用 ASA/MCH 控制字元將資料轉換為標準列印格式資料，並將資料放置在 JES 多工緩衝系統上，以供使用 JES 的大型主機列印系統處理。 | Micro Focus 線上列印結束 (DFHUPRNT) API 可讓使用其中一種方法建立 3270/SCS 列印資料串流時，VPSX/MFI 處理列印資料。 | 
| EXEC CICS SPOOLOPEN  | CICS 應用程式使用此方法直接將資料寫入 JES 多工緩衝處理。然後，資料可供使用 JES 的大型主機型列印系統處理。 | Micro Focus Enterprise Server 會將資料多工緩衝處理至 Enterprise Server 多工緩衝處理，而 VPSX/MFI 批次列印結束 (LRSPRTE6) 可將資料多工緩衝處理至 VPSX。 | 
| DRS/API | LRS 提供的程式設計界面用於將列印資料寫入 JES。 | VPSX/MFI 提供替換界面，可將列印資料直接多工緩衝處理至 VPSX。 | 

**印表機機群運作狀態檢查**

LRS VPSX/MFI (LRS LoadX) 可執行深入研究運作狀態檢查，包括裝置管理和操作最佳化。裝置管理可以偵測印表機裝置中的失敗，並將列印請求路由到運作狀態良好的印表機。如需印表機機群深入探索運作狀態檢查的詳細資訊，請參閱產品授權隨附的 LRS 文件。

**列印身分驗證和授權**

LRS/DIS 可讓 LRS 應用程式使用 Microsoft Active Directory 或 LDAP 伺服器來驗證使用者 IDs 和密碼。除了基本列印授權之外，LRS/DIS 也可以在下列使用案例中套用精細層級的列印安全控制：
+ 管理誰可以瀏覽印表機任務。
+ 管理其他使用者任務的瀏覽層級。
+ 管理操作任務。例如，命令層級安全性，例如 hold/release、 purge、 modify、 copy 和 reroute。安全可由 User-ID 或 Group （類似 AD 群組或 LDAP 群組） 設定。

## 附件
<a name="attachments-924cdae7-9265-4fc9-8e5e-bb2da5368e7e"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/924cdae7-9265-4fc9-8e5e-bb2da5368e7e/attachments/attachment.zip)

# 使用 Transfer 系列將大型主機檔案直接移至 Amazon S3
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family"></a>

*Luis Gustavo Dantas，Amazon Web Services*

## 總結
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family-summary"></a>

在現代化旅程中，您可能會面臨在內部部署伺服器與 Amazon Web Services (AWS) 雲端之間傳輸檔案的挑戰。從大型主機傳輸資料可能是一項重大挑戰，因為大型主機通常無法存取現代資料存放區，例如 Amazon Simple Storage Service (Amazon S3)、Amazon Elastic Block Store (Amazon EBS) 或 Amazon Elastic File System (Amazon EFS)。

許多客戶使用內部部署 Linux、Unix 或 Windows 伺服器等中繼預備資源，將檔案傳輸至 AWS 雲端。您可以避免這種間接方法，方法是使用 AWS Transfer Family 搭配 Secure Shell (SSH) 檔案傳輸通訊協定 (SFTP)，將大型主機檔案直接上傳至 Amazon S3。

## 先決條件和限制
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 虛擬私有雲端 (VPC)，具有傳統平台可存取的子網路
+ VPC 的 Transfer Family 端點
+ 大型主機虛擬儲存存取方法 (VSAM) 檔案轉換為循序、[固定長度的檔案 ](https://www.ibm.com/docs/en/zos/2.1.0?topic=reports-converting-vb-fb)(IBM 文件）

**限制**
+ 根據預設，SFTP 會以二進位模式傳輸檔案，這表示檔案會上傳到 Amazon S3 並保留 EBCDIC 編碼。如果您的檔案不包含二進位或封裝資料，則可以使用 **sftpascii**[ 子命令](https://www.ibm.com/docs/en/zos/2.3.0?topic=version-what-zos-openssh-supports) (IBM 文件） 在傳輸期間將檔案轉換為文字。
+ 您必須[解壓縮包含封裝和二進位內容的大型主機檔案](https://apg-library.amazonaws.com/content/f5907bfe-7dff-4cd0-8523-57015ad48c4b) (AWS 規範指引），才能在目標環境中使用這些檔案。
+ Amazon S3 物件的大小範圍從最小 0 個位元組到最大 5 TB。如需 Amazon S3 功能的詳細資訊，請參閱 [Amazon S3 FAQs](https://aws.amazon.com/s3/faqs/?nc1=h_ls)。

## Architecture
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family-architecture"></a>

**來源技術堆疊**
+ 工作控制語言 (JCL)
+ z/OS Unix shell 和 ISPF
+ SFTP
+ VSAM 和一般檔案

**目標技術堆疊**
+ Transfer 系列
+ Amazon S3
+ Amazon Virtual Private Cloud (Amazon VPC)

**目標架構**

下圖顯示使用 Transfer Family 搭配 SFTP 將大型主機檔案直接上傳至 S3 儲存貯體的參考架構。

![\[使用 Transfer Family 搭配 SFTP，將大型主機檔案直接上傳至 S3 儲存貯體\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/1f4fa1fd-b681-41bc-81d8-d556426b14c2/images/110491d5-b58d-4451-8de9-e742756bb192.png)


該圖顯示以下工作流程：

1. 您可以使用 JCL 任務，透過 Direct Connect 將大型主機檔案從舊版大型主機傳輸到 AWS 雲端。

1. Direct Connect 可讓您的網路流量保留在 AWS 全球網路上，並略過公有網際網路。Direct Connect 也會增強網路速度，從 50 Mbps 開始，擴展到 100 Gbps。

1. VPC 端點可在不使用公有網際網路的情況下，啟用 VPC 資源與支援的 服務之間的連線。存取 Transfer Family 和 Amazon S3 可透過位於兩個私有子網路和可用區域的彈性網路界面實現高可用性。

1. Transfer Family 會驗證使用者，並使用 SFTP 從舊版環境接收您的檔案，並將其移至 S3 儲存貯體。

**自動化和擴展**

使用 Transfer Family 服務後，您可以使用 JCL 任務做為 SFTP 用戶端，將無限數量的檔案從大型主機傳輸到 Amazon S3。您也可以使用大型主機批次任務排程器，在準備好傳輸大型主機檔案時執行 SFTP 任務，以自動化檔案傳輸。

## 工具
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family-tools"></a>
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。這個虛擬網路類似於您在自己的資料中心內操作的傳統網路，具有使用可擴展的 AWS 基礎設施的優勢。
+ [AWS Transfer Family](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-family.html) 可讓您使用 SFTP、FTPS 和 FTP 通訊協定，安全地將週期business-to-business檔案傳輸至 Amazon S3 和 Amazon EFS。 Amazon S3 

## 史詩
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family-epics"></a>

### 建立 S3 儲存貯體和存取政策
<a name="create-the-s3-bucket-and-the-access-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | [建立 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體以託管您從舊版環境傳輸的檔案。 | 一般 AWS | 
| 建立 IAM 角色和政策。 | Transfer Family 使用您的 AWS Identity and Access Management (IAM) 角色，授予您先前建立的 S3 儲存貯體存取權。[建立包含下列 IAM 政策的 IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)： [https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)<pre>{<br />    "Version": "2012-10-17",		 	 	 <br />    "Statement": [<br />        {<br />            "Sid": "UserFolderListing",<br />            "Action": [<br />                "s3:ListBucket",<br />                "s3:GetBucketLocation"<br />            ],<br />            "Effect": "Allow",<br />            "Resource": [<br />                "arn:aws:s3:::<your-bucket-name>"<br />            ]<br />        },<br />        {<br />            "Sid": "HomeDirObjectAccess",<br />            "Effect": "Allow",<br />            "Action": [<br />                "s3:PutObject",<br />                "s3:GetObjectAcl",<br />                "s3:GetObject",<br />                "s3:DeleteObjectVersion",<br />                "s3:DeleteObject",<br />                "s3:PutObjectAcl",<br />                "s3:GetObjectVersion"<br />            ],<br />            "Resource": "arn:aws:s3:::<your-bucket-name>/*"<br />        }<br />    ]<br />}</pre>建立 IAM 角色時，您必須選擇轉移使用案例。 | 一般 AWS | 

### 定義傳輸服務
<a name="define-the-transfer-service"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 SFTP 伺服器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/move-mainframe-files-directly-to-amazon-s3-using-transfer-family.html)如需如何設定 SFTP 伺服器的詳細資訊，請參閱[建立啟用 SFTP 的伺服器](https://docs.aws.amazon.com/transfer/latest/userguide/create-server-sftp.html) (AWS Transfer Family 使用者指南）。 | 一般 AWS | 
| 取得伺服器地址。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/move-mainframe-files-directly-to-amazon-s3-using-transfer-family.html) | 一般 AWS | 
| 建立 SFTP 用戶端金鑰對。 | 為 [Microsoft Windows](https://docs.aws.amazon.com/transfer/latest/userguide/key-management.html#windows-ssh) 或 [macOS/Linux/UNIX](https://docs.aws.amazon.com/transfer/latest/userguide/key-management.html#macOS-linux-unix-ssh) 建立 SSH 金鑰對。 | 一般 AWS、SSH | 
| 建立 SFTP 使用者。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/move-mainframe-files-directly-to-amazon-s3-using-transfer-family.html) | 一般 AWS | 

### 傳輸大型主機檔案
<a name="transfer-the-mainframe-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 SSH 私有金鑰傳送至大型主機。 | 使用 SFTP 或 SCP 將 SSH 私有金鑰傳送至舊版環境。SFTP 範例：<pre>sftp [USERNAME@mainframeIP]<br />[password]<br />cd [/u/USERNAME]<br />put [your-key-pair-file]</pre>SCP 範例：<pre>scp [your-key-pair-file] [USERNAME@MainframeIP]:/[u/USERNAME]</pre>接著，將 SSH 金鑰存放在 z/OS Unix 檔案系統中，並使用稍後將執行檔案傳輸批次任務的使用者名稱 （例如，`/u/CONTROLM`)。 如需 z/OS Unix shell 的詳細資訊，請參閱 [z/OS shell 簡介 ](https://www.ibm.com/docs/en/zos/2.2.0?topic=shells-introduction-zos)(IBM 文件）。 | Mainframe、z/OS Unix shell、FTP、SCP | 
| 建立 JCL SFTP 用戶端。 | 由於大型主機沒有原生 SFTP 用戶端，您必須使用 BPXBATCH 公用程式從 z/OS Unix shell 執行 SFTP 用戶端。在 ISPF 編輯器中，建立 JCL SFTP 用戶端。例如：<pre>//JOBNAM JOB ...<br />//**********************************************************************<br />//SFTP EXEC PGM=BPXBATCH,REGION=0M <br />//STDPARM DD * <br />SH cp "//'MAINFRAME.FILE.NAME'" filename.txt; <br />echo 'put filename.txt' > uplcmd; <br />sftp -b uplcmd -i ssh_private_key_file ssh_username@<transfer service ip or DNS>; <br />//SYSPRINT DD SYSOUT=* <br />//STDOUT DD SYSOUT=* <br />//STDENV DD * <br />//STDERR DD SYSOUT=*</pre>如需如何在 z/OS Unix shell 中執行命令的詳細資訊，請參閱 [BPXBATCH 公用程式](https://www.ibm.com/docs/en/zos/2.2.0?topic=ispf-bpxbatch-utility) (IBM 文件）。如需如何在 z/OS 中建立或編輯 JCL 任務的詳細資訊，請參閱[什麼是 ISPF？](https://www.ibm.com/docs/en/zos-basic-skills?topic=interfaces-what-is-ispf)和 [ISPF 編輯器](https://www.ibm.com/docs/en/zos-basic-skills?topic=ispf-editor) (IBM 文件）。 | JCL、大型主機、z/OS Unix shell | 
| 執行 JCL SFTP 用戶端。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/move-mainframe-files-directly-to-amazon-s3-using-transfer-family.html)如需如何檢查批次任務活動的詳細資訊，請參閱 [z/OS SDSF 使用者指南 ](https://www.ibm.com/docs/en/zos/2.4.0?topic=sdsf-zos-users-guide)(IBM 文件）。 | Mainframe、JCL、ISPF | 
| 驗證檔案傳輸。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/move-mainframe-files-directly-to-amazon-s3-using-transfer-family.html) | 一般 AWS | 
| 自動化 JCL SFTP 用戶端。 | 使用任務排程器自動觸發 JCL SFTP 用戶端。您可以使用大型主機任務排程器，例如 [BMC Control-M](https://www.bmcsoftware.pt/it-solutions/control-m.html) 或 [CA 工作負載自動化](https://www.broadcom.com/products/mainframe/workload-automation/ca7)，根據時間和其他批次任務相依性來自動化檔案傳輸的批次任務。 | 任務排程器 | 

## 相關資源
<a name="move-mainframe-files-directly-to-amazon-s3-using-transfer-family-resources"></a>
+ [AWS Transfer 系列的運作方式](https://docs.aws.amazon.com/transfer/latest/userguide/how-aws-transfer-works.html)

# 最佳化 AWS Blu Age 現代化應用程式的效能
<a name="optimize-performance-aws-blu-age-modernized-application"></a>

*Vishal Jaswani、Manish Roy 和 Himanshu Sah，Amazon Web Services*

## 總結
<a name="optimize-performance-aws-blu-age-modernized-application-summary"></a>

使用 AWS Blu Age 進行現代化的大型主機應用程式需要先進行功能和效能相等性測試，才能部署到生產環境。在效能測試中，現代化應用程式的效能可能比傳統系統慢，尤其是在複雜的批次任務中。這種差異是因為大型主機應用程式是單體的，而現代應用程式使用多層架構。此模式提供最佳化技術，以解決透過使用[自動重構搭配 AWS Blu Age ](https://docs.aws.amazon.com/m2/latest/userguide/refactoring-m2.html)進行現代化應用程式的效能差距。

模式使用 AWS Blu Age 現代化架構搭配原生 Java 和資料庫調校功能，來識別和解決效能瓶頸。模式說明如何使用分析和監控來識別 SQL 執行時間、記憶體使用率和 I/O 模式等指標的效能問題。接著說明如何套用目標最佳化，包括資料庫查詢重組、快取和商業邏輯精簡。

改善批次處理時間和系統資源使用率，可協助您符合現代化系統中的大型主機效能等級。此方法在轉換為現代雲端架構期間維持功能等效性。

若要使用此模式，請依照 [Epics](#optimize-performance-aws-blu-age-modernized-application-epics) 區段中的指示設定您的系統並識別效能熱點，並套用[架構](#optimize-performance-aws-blu-age-modernized-application-architecture)區段中詳細說明的最佳化技術。

## 先決條件和限制
<a name="optimize-performance-aws-blu-age-modernized-application-prereqs"></a>

**先決條件**
+  AWS Blu Age 現代化應用程式
+ [JProfiler 授權](https://www.ej-technologies.com/store/jprofiler)
+ 安裝資料庫用戶端和分析工具的管理權限
+ AWS Blu Age [Level 3 認證](https://bluinsights.aws/certification/)
+ 中階了解 AWS Blu Age 架構、產生的程式碼結構和 Java 程式設計

**限制**

下列最佳化功能在此模式範圍之外：
+ 應用程式層之間的網路延遲最佳化
+ 透過 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體類型和儲存最佳化進行基礎設施層級最佳化
+ 並行使用者負載測試和壓力測試

**產品版本**
+ JProfiler 13.0 版或更新版本 （建議最新版本）
+ pgAdmin 8.14 版或更新版本

## Architecture
<a name="optimize-performance-aws-blu-age-modernized-application-architecture"></a>

此模式使用 JProfiler 和 pgAdmin 等工具，為 AWS Blu Age 應用程式設定分析環境。它支援透過 AWS Blu Age 提供的 DAOManager 和 SQLExecutionBuilder APIs進行最佳化。

本節的其餘部分提供詳細資訊和範例，用於識別現代化應用程式的效能熱點和最佳化策略。[Epics](#optimize-performance-aws-blu-age-modernized-application-epics) 區段中的步驟會參考此資訊，以取得進一步指引。

**識別現代化大型主機應用程式中的效能熱點**

在現代化大型主機應用程式中，*效能熱點*是程式碼中會導致顯著變慢或效率不佳的特定區域。這些熱點通常是由大型主機和現代化應用程式之間的架構差異所造成。若要識別這些效能瓶頸並最佳化現代化應用程式的效能，您可以使用三種技術：SQL 記錄、查詢`EXPLAIN`計畫和 JProfiler 分析。

*熱點識別技術：SQL 記錄*

現代 Java 應用程式，包括使用 AWS Blu Age 進行現代化的應用程式，具有記錄 SQL 查詢的內建功能。您可以在 AWS Blu Age 專案中啟用特定記錄器，以追蹤和分析應用程式執行的 SQL 陳述式。此技術對於識別效率不佳的資料庫存取模式特別有用，例如過多的個別查詢或結構不良的資料庫呼叫，可透過批次處理或查詢精簡進行最佳化。

若要在 AWS Blu Age 現代化應用程式中實作 SQL 記錄，請將 `application.properties` 檔案中 `DEBUG` SQL 陳述式的日誌層級設定為 ，以擷取查詢執行詳細資訊：

```
level.org.springframework.beans.factory.support.DefaultListableBeanFactory : WARN
level.com.netfective.bluage.gapwalk.runtime.sort.internal: WARN
level.org.springframework.jdbc.core.StatementCreatorUtils: DEBUG
level.com.netfective.bluage.gapwalk.rt.blu4iv.dao: DEBUG
level.com.fiserv.signature: DEBUG
level.com.netfective.bluage.gapwalk.database.support.central: DEBUG
level.com.netfective.bluage.gapwalk.rt.db.configuration.DatabaseConfiguration: DEBUG
level.com.netfective.bluage.gapwalk.rt.db.DatabaseInteractionLoggerUtils: DEBUG
level.com.netfective.bluage.gapwalk.database.support.AbstractDatabaseSupport: DEBUG
level.com.netfective.bluage.gapwalk.rt: DEBUG
```

使用記錄的資料來識別最佳化目標，以監控高頻率和效能緩慢的查詢。專注於批次程序中的查詢，因為它們通常具有最高的效能影響。

*熱點識別技術：查詢 EXPLAIN 計劃*

此方法使用關聯式資料庫管理系統的查詢規劃功能。您可以使用 `EXPLAIN` PostgreSQL 或 MySQL 或 Oracle `EXPLAIN PLAN`中的 等命令，來檢查資料庫執行指定查詢的方式。這些命令的輸出可提供查詢執行策略的寶貴洞見，包括將使用索引還是執行完整資料表掃描。此資訊對於最佳化查詢效能至關重要，尤其是在適當的索引可以大幅縮短執行時間的情況下。

從應用程式日誌中擷取最常重複的 SQL 查詢，並使用資料庫特有的`EXPLAIN`命令來分析執行緩慢查詢的執行路徑。以下是 PostgreSQL 資料庫的範例。

查詢：

```
SELECT * FROM tenk1 WHERE unique1 < 100;
```

`EXPLAIN` 命令：

```
EXPLAIN SELECT * FROM tenk1 where unique1 < 100;
```

輸出：

```
Bitmap Heap Scan on tenk1 (cost=5.06..224.98 rows=100 width=244) 
Recheck Cond: (unique1 < 100) 
-> Bitmap Index Scan on tenk1_unique1 (cost=0.00..5.04 rows=100 width=0)
Index Cond: (unique1 < 100)
```

您可以解譯`EXPLAIN`輸出，如下所示：
+ 從最內到最外 （從下到上） 操作讀取`EXPLAIN`計劃。
+ 尋找關鍵術語。例如， `Seq Scan` 表示完整資料表掃描，並`Index Scan`顯示索引用量。
+ 檢查成本值：第一個數字是啟動成本，第二個數字是總成本。
+ 請參閱預估輸出資料列數量`rows`的值。

在此範例中，查詢引擎會使用索引掃描來尋找相符的資料列，然後只擷取這些資料列 (`Bitmap Heap Scan`)。這比掃描整個資料表更有效率，即使個別資料列存取的成本較高。

`EXPLAIN` 計劃輸出中的資料表掃描操作表示缺少索引。最佳化需要建立適當的索引。

*熱點識別技術：JProfiler 分析*

JProfiler 是全方位的 Java 分析工具，可透過識別緩慢的資料庫呼叫和 CPU 密集型呼叫，協助您解決效能瓶頸。此工具在識別慢速 SQL 查詢和低效率記憶體使用量方面特別有效。

查詢的範例分析：

```
select evt. com.netfective.bluage.gapwalk.rt.blu4iv.dao.Blu4ivTableManager.queryNonTrasactional
```

JProfiler 熱點檢視提供下列資訊：
+ **時間**欄
  + 顯示總執行持續時間 （例如 329 秒）
  + 顯示應用程式總時間的百分比 （例如 58.7%)
  + 協助識別最耗時的操作
+ **平均時間**欄
  + 顯示每個執行持續時間 （例如 2，692 微秒）
  + 指出個別操作效能
  + 協助找出慢速個別操作
+ **事件**欄
  + 顯示執行計數 （例如 122，387 次）
  + 指出操作頻率
  + 協助識別經常呼叫的方法

針對範例結果：
+ 高頻率：122，387 個執行表示可能進行最佳化
+ 效能問題：平均時間 2，692 微秒表示效率低下
+ 重大影響：總時間的 58.7% 表示重大瓶頸

JProfiler 可以分析應用程式的執行時間行為，以透過靜態程式碼分析或 SQL 記錄顯示可能不明顯的熱點。這些指標可協助您識別需要最佳化的操作，並判斷最有效的最佳化策略。如需 JProfiler 功能的詳細資訊，請參閱 [JProfiler 文件](https://www.ej-technologies.com/resources/jprofiler/help/doc/main/introduction.html)。

結合使用這三種技術 (SQL 記錄、查詢`EXPLAIN`計畫和 JProfiler) 時，您可以全面了解應用程式的效能特性。透過識別和解決最重要的效能熱點，您可以彌補原始大型主機應用程式與現代化雲端系統之間的效能差距。

識別應用程式的效能熱點後，您可以套用最佳化策略，下一節會說明這些策略。

**大型主機現代化最佳化策略**

本節概述最佳化從大型主機系統現代化應用程式的關鍵策略。它著重於三種策略：使用現有的 APIs、實作有效的快取，以及最佳化商業邏輯。

*最佳化策略：使用現有的 APIs*

AWS Blu Age 在 DAO 介面中提供數個強大的 APIs，您可以用來最佳化效能。兩個主要界面 — DAOManager 和 SQLExecutionBuilder — 提供增強應用程式效能的功能。

**DAOManager**

DAOManager 做為現代化應用程式中資料庫操作的主要界面。它提供多種方法來增強資料庫操作和改善應用程式效能，尤其是直接建立、讀取、更新和刪除 (CRUD) 操作和批次處理。
+ **使用 SetMaxResults。**在 DAOManager API 中，您可以使用 **SetMaxResults** 方法來指定單一資料庫操作中要擷取的記錄數目上限。根據預設，DAOManager 一次只會擷取 10 筆記錄，這可能會在處理大型資料集時導致多個資料庫呼叫。當您的應用程式需要處理大量記錄，且目前正在進行多個資料庫呼叫來擷取記錄時，請使用此最佳化。這在您透過大型資料集反覆運算的批次處理案例中特別有用。在下列範例中，左側的程式碼 （最佳化之前） 會使用 10 筆記錄的預設資料擷取值。右側的程式碼 （最佳化後） 會將 **setMaxResults** 設定為一次擷取 100，000 筆記錄。  
![\[使用 SetMaxResults 以避免多個資料庫呼叫的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/beb9623e-e7a8-45ef-adc6-19a249224b05.png)
**注意**  
請仔細選擇較大的批次大小，並檢查物件大小，因為此最佳化會增加記憶體使用量。
+ **將 SetOnGreatorOrEqual 取代為 SetOnEqual。**此最佳化涉及變更您用來設定擷取記錄條件的方法。**SetOnGreatorOrEqual** 方法會擷取大於或等於指定值的記錄，而 **SetOnEqual** 只會擷取完全符合指定值的記錄。

  當您知道需要完全相符，且目前使用 **SetOnEqual** **SetOnGreatorOrEqual**，如下列程式碼範例所示。 **readNextEqual** 此最佳化可減少不必要的資料擷取。  
![\[使用 SetOnEqual 根據完全相符擷取記錄的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/5ce0dac9-f281-4862-a71f-1614493a83f0.png)
+ **使用批次寫入和更新操作。**您可以使用批次操作將多個寫入或更新操作分組為單一資料庫交易。這可減少資料庫呼叫的數量，並可大幅改善涉及多個記錄的操作效能。

  在下列範例中，左側的程式碼會在迴圈中執行寫入操作，這會降低應用程式的效能。您可以使用批次寫入操作來最佳化此程式碼：在`WHILE`迴圈的每個反覆運算期間，您可以將記錄新增至批次，直到批次大小達到預先決定的大小 100。然後，您可以在達到預定批次大小時排清批次，然後將任何剩餘的記錄排清至資料庫。這在您處理需要更新的大型資料集時特別有用。  
![\[將多個操作分組為單一資料庫交易的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/e3bd60d4-06f5-4c1c-9cbd-463f6835a1ba.png)
+ **新增索引。**新增索引是一種資料庫層級最佳化，可大幅改善查詢效能。索引可讓資料庫快速找到具有特定資料欄值的資料列，而無需掃描整個資料表。在子`WHERE`句、`JOIN`條件或`ORDER BY`陳述式中常用的資料欄上使用索引。這對大型資料表或快速資料擷取至關重要時尤其重要。

**SQLExecutionBuilder**

SQLExecutionBuilder 是一種靈活的 API，可用來控制將執行的 SQL `INSERT` 查詢、僅使用 擷取特定資料欄`SELECT`，以及使用動態資料表名稱。在下列範例中，SQLExecutorBuilder 會使用您定義的自訂查詢。

![\[搭配自訂查詢使用 SQLExecutorBuilder 的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/364e9fb1-0cbc-47d0-936d-46fb3b48b608.png)


**在 DAOManager 和 SQLExecutionBuilder 之間進行選擇**

這些 APIs之間的選擇取決於您的特定使用案例：
+ 如果您希望 AWS Blu Age Runtime 產生 SQL 查詢，而不是自行撰寫查詢，請使用 DAOManager。
+ 當您需要寫入 SQL 查詢以利用資料庫特定的功能或寫入最佳的 SQL 查詢時，請選擇 SQLExecutionBuilder。

*最佳化策略：快取*

在現代化應用程式中，實作有效的快取策略可以大幅減少資料庫呼叫並改善回應時間。這有助於彌補大型主機和雲端環境之間的效能差距。

在 AWS Blu Age 應用程式中，簡單的快取實作使用內部資料結構，例如雜湊圖或陣列清單，因此您不需要設定需要成本和程式碼重組的外部快取解決方案。此方法對於經常存取但不常變更的資料特別有效。當您實作快取時，請考慮記憶體限制條件和更新模式，以確保快取的資料保持一致並提供實際的效能優勢。

成功快取的關鍵是識別要快取的正確資料。在下列範例中，左側的程式碼一律會從資料表讀取資料，而當本機雜湊映射沒有指定金鑰的值時，右側的程式碼會從資料表讀取資料。 `cacheMap` 是在程式內容中建立並在程式內容的清除方法中清除的雜湊映射物件。

使用 DAOManager 快取：

![\[使用 DAOManager 快取最佳化的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/4efd3d22-c694-4f7d-a543-2bed341d1651.png)


使用 SQLExecutionBuilder 進行快取：

![\[使用 SQLExecutionBuilder 快取最佳化的範例。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/c8964804-96eb-4e26-b2bf-8742e62b4c33.png)


*最佳化策略：商業邏輯最佳化*

商業邏輯最佳化著重於重組 Blu AWS Age 自動產生的程式碼，以更符合現代架構功能。當產生的程式碼維護與舊版大型主機程式碼相同的邏輯結構時，這會變得必要，這可能不適用於現代系統。目標是改善效能，同時維持與原始應用程式的功能等效性。

此最佳化方法不僅止於簡單的 API 調校和快取策略。它涉及應用程式處理資料和與資料庫互動方式的變更。常見的最佳化包括避免簡單更新不必要的讀取操作、移除備援資料庫呼叫，以及重組資料存取模式，以更符合現代應用程式架構。以下是幾個範例：
+ **直接在資料庫中更新資料。 **使用直接 SQL 更新而非具有迴圈的多個 DAOManager 操作來重組您的業務邏輯。例如，下列程式碼 （左側） 會進行多個資料庫呼叫，並使用過多的記憶體。具體而言，它會在迴圈中使用多個資料庫讀取和寫入操作、個別更新而非批次處理，以及在每次反覆運算時建立不必要的物件。

  下列最佳化程式碼 （右側） 使用單一 Direct SQL 更新操作。具體而言，它使用單一資料庫呼叫，而不是多個呼叫，而且不需要迴圈，因為所有更新都是在單一陳述式中處理。此最佳化可提供更好的效能和資源使用率，並降低複雜性。它可防止 SQL 注入，提供更好的查詢計劃快取，並有助於提高安全性。  
![\[使用直接 SQL 更新而非具有迴圈的 DAOManager 操作來重組程式碼。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/7d0a7879-8db2-4cc5-b41c-ee370b3f22e5.png)
**注意**  
一律使用參數化查詢來防止 SQL 插入，並確保適當的交易管理。
+ **減少備援資料庫呼叫。**備援資料庫呼叫可能會大幅影響應用程式效能，尤其是在迴圈中發生時。簡單但有效的最佳化技術是避免多次重複相同的資料庫查詢。下列程式碼比較示範將`retrieve()`資料庫呼叫移至迴圈之外如何防止重複執行相同的查詢，進而提高效率。  
![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6b42fafd-1535-416d-8abd-1a5f9007ddba/images/da9c15f4-bcf1-4827-b91a-73212fe35cca.png)
+ **使用 SQL 子句減少資料庫呼叫**`JOIN`**。**實作 SQLExecutionBuilder，將對資料庫的呼叫降至最低。SQLExecutionBuilder 提供更多對 SQL 產生的控制，對於 DAOManager 無法有效處理的複雜查詢特別有用。例如，下列程式碼使用多個 DAOManager 呼叫：

  ```
  List<Employee> employees = daoManager.readAll();
  for(Employee emp : employees) {
      Department dept = deptManager.readById(emp.getDeptId());  // Additional call for each employee
      Project proj = projManager.readById(emp.getProjId());     // Another call for each employee
      processEmployeeData(emp, dept, proj);
  }
  ```

  最佳化程式碼在 SQLExecutionBuilder 中使用單一資料庫呼叫：

  ```
  SQLExecutionBuilder builder = new SQLExecutionBuilder();
  builder.append("SELECT e.*, d.name as dept_name, p.name as proj_name");
  builder.append("FROM employee e");
  builder.append("JOIN department d ON e.dept_id = d.id");
  builder.append("JOIN project p ON e.proj_id = p.id");
  builder.append("WHERE e.status = ?", "ACTIVE");
  
  List<Map<String, Object>> results = builder.execute();  // Single database call
  for(Map<String, Object> result : results) {
      processComplexData(result);
  }
  ```

*同時使用最佳化策略*

這三種策略可協同運作：APIs提供有效率的資料存取工具、快取可減少重複資料擷取的需求，而商業邏輯最佳化可確保以最有效的方式使用這些 APIs。這些最佳化的定期監控和調整可確保持續提升效能，同時維持現代化應用程式的可靠性和功能。成功的關鍵在於了解根據您的應用程式特性和效能目標，何時以及如何套用每個策略。

## 工具
<a name="optimize-performance-aws-blu-age-modernized-application-tools"></a>
+ [JProfiler](https://www.ej-technologies.com/jprofiler) 是一種 Java 分析工具，專為開發人員和效能工程師而設計。它可分析 Java 應用程式，並協助識別效能瓶頸、記憶體流失和執行緒問題。JProfiler 提供 CPU、記憶體和執行緒分析，以及資料庫和 Java 虛擬機器 (JVM) 監控，以深入了解應用程式行為。
**注意**  
作為 JProfiler 的替代方案，您可以使用 [Java VisualVM](https://visualvm.github.io/)。這是適用於 Java 應用程式的免費開放原始碼效能分析和監控工具，可提供 CPU 用量、記憶體消耗、執行緒管理和垃圾收集統計資料的即時監控。由於 Java VisualVM 是內建的 JDK 工具，因此對於基本分析需求，比 JProfiler 更具成本效益。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理和開發工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。您可以使用 pgAdmin 來執行各種任務，從撰寫簡單的 SQL 查詢到開發複雜的資料庫。其功能包括強調 SQL 編輯器的語法、伺服器端程式碼編輯器、SQL、殼層和批次任務的排程代理程式，以及支援新手和經驗豐富的 PostgreSQL 使用者的所有 PostgreSQL 功能。

## 最佳實務
<a name="optimize-performance-aws-blu-age-modernized-application-best-practices"></a>

識別效能熱點：
+ 開始最佳化之前，請記錄基準效能指標。
+ 根據業務需求設定明確的效能改善目標。
+ 進行基準測試時，請停用詳細記錄，因為它可能會影響效能。
+ 設定效能測試套件並定期執行。
+ 使用最新版本的 pgAdmin。（舊版不支援`EXPLAIN`查詢計畫。)
+ 針對基準測試，請在最佳化完成後分離 JProfiler，因為它會增加延遲。
+ 針對基準測試，請務必以啟動模式而非偵錯模式執行伺服器，因為偵錯模式會增加延遲。

最佳化策略：
+ 在 `application.yaml` 檔案中設定 **SetMaxResults** 值，根據您的系統規格指定適當大小的批次。
+ 根據資料磁碟區和記憶體限制來設定 **SetMaxResults** 值。
+ 只有在後續呼叫為 時，才將 **SetOnGreatorOrEqual** 變更為 **SetOnEqual**`.readNextEqual()`。
+ 在批次寫入或更新操作中，請分別處理最後一個批次，因為它可能小於設定的批次大小，且寫入或更新操作可能會遺漏。

快取：
+ 在 中引入用於快取的欄位`processImpl`，其會隨著每次執行而變動，應一律在該 的內容中定義`processImpl`。這些欄位也應該使用 `doReset()`或 `cleanUp()`方法清除。
+ 當您實作記憶體內快取時，請調整快取的大小。儲存在記憶體中的非常大型快取可能會佔用所有資源，這可能會影響應用程式的整體效能。

SQLExecutionBuilder：
+ 對於您計劃在 SQLExecutionBuilder 中使用的查詢，請使用金鑰名稱，例如 `PROGRAMNAME_STATEMENTNUMBER`。
+ 當您使用 SQLExecutionBuilder 時，請務必檢查 `Sqlcod` 欄位。此欄位包含一個值，指定查詢是否正確執行或遇到任何錯誤。
+ 使用參數化查詢來防止 SQL 注入。

商業邏輯最佳化：
+ 在重組程式碼時維持功能等效性，並針對相關程式子集執行迴歸測試和資料庫比較。
+ 維護分析快照以進行比較。

## 史詩
<a name="optimize-performance-aws-blu-age-modernized-application-epics"></a>

### 安裝 JProfiler 和 pgAdmin
<a name="install-jprofiler-and-pgadmin"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝和設定 JProfiler。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 應用程式開發人員 | 
| 安裝和設定 pgAdmin。 | 在此步驟中，您會安裝並設定資料庫用戶端來查詢資料庫。此模式使用 PostgreSQL 資料庫和 pgAdmin 做為資料庫用戶端。如果您使用的是另一個資料庫引擎，請遵循對應資料庫用戶端的文件。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 應用程式開發人員 | 

### 識別熱點
<a name="identify-hotspots"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS Blu Age 應用程式中啟用 SQL 查詢記錄。 | 在 AWS Blu Age 應用程式的 `application.properties`檔案中啟用 SQL 查詢記錄的記錄器，如[架構](#optimize-performance-aws-blu-age-modernized-application-architecture)一節所述。 | 應用程式開發人員 | 
| 產生和分析查詢`EXPLAIN`計劃，以識別資料庫效能熱點。 | 如需詳細資訊，請參閱[架構](#optimize-performance-aws-blu-age-modernized-application-architecture)一節。 | 應用程式開發人員 | 
| 建立 JProfiler 快照以分析效能緩慢的測試案例。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 應用程式開發人員 | 
| 分析 JProfiler 快照以識別效能瓶頸。 | 請依照下列步驟分析 JProfiler 快照。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html)如需使用 JProfiler 的詳細資訊，請參閱[架構](#optimize-performance-aws-blu-age-modernized-application-architecture)一節和 [JProfiler 文件](https://www.ej-technologies.com/jprofiler/docs)。 | 應用程式開發人員 | 

### 建立基準
<a name="establish-a-baseline"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 實作最佳化之前，請先建立效能基準。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 應用程式開發人員 | 

### 套用最佳化策略
<a name="apply-optimization-strategies"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 最佳化讀取呼叫。 | 使用 DAOManager **SetMaxResults** 方法最佳化資料擷取。如需此方法的詳細資訊，請參閱[架構](#optimize-performance-aws-blu-age-modernized-application-architecture)一節。 | 應用程式開發人員，DAOManager | 
| 重構商業邏輯，以避免對資料庫進行多次呼叫。 | 使用 SQL `JOIN`子句減少資料庫呼叫。如需詳細資訊和範例，請參閱《 [架構](#optimize-performance-aws-blu-age-modernized-application-architecture)》中的*商業邏輯最佳化*。 | 應用程式開發人員，SQLExecutionBuilder | 
| 重構程式碼以使用快取來降低讀取呼叫的延遲。 | 如需此技術的資訊，請參閱 [架構](#optimize-performance-aws-blu-age-modernized-application-architecture)一節中的*快取*。 | 應用程式開發人員 | 
| 重寫使用多個 DAOManager 操作進行簡單更新操作的無效程式碼。 | 如需直接在資料庫中更新資料的詳細資訊，請參閱 [架構](#optimize-performance-aws-blu-age-modernized-application-architecture)一節中的*商業邏輯最佳化*。 | 應用程式開發人員 | 

### 測試最佳化策略
<a name="test-optimization-strategies"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 反覆驗證每個最佳化變更，同時保持功能等效性。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html)使用基準指標做為參考，可確保準確測量每個最佳化的影響，同時維護系統可靠性。 | 應用程式開發人員 | 

## 疑難排解
<a name="optimize-performance-aws-blu-age-modernized-application-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 當您執行現代應用程式時，您會看到錯誤為 的例外狀況`Query_ID not found`。 | 若要解決此問題：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 
| 您已新增索引，但沒有看到任何效能改善。 | 請依照下列步驟來確保查詢引擎正在使用 索引：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 
| 您遇到out-of-memory例外狀況。 | 驗證程式碼是否釋出資料結構所保留的記憶體。 | 
| 批次寫入操作會導致資料表中的記錄遺失 | 檢閱程式碼，以確保在批次計數不為零時執行額外的寫入操作。 | 
| SQL 記錄不會出現在應用程式日誌中。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/optimize-performance-aws-blu-age-modernized-application.html) | 

## 相關資源
<a name="optimize-performance-aws-blu-age-modernized-application-resources"></a>
+ [使用 AWS Blu Age 自動重構應用程式 ](https://docs.aws.amazon.com/m2/latest/userguide/refactoring-m2.html)(*AWS Mainframe Modernization 使用者指南*)
+ [pgAdmin 文件](https://www.pgadmin.org/docs/)
+ [JProfiler 文件](https://www.ej-technologies.com/jprofiler/docs)

# 使用信任的內容來保護和簡化 AWS 上 Db2 聯合資料庫中的使用者存取
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts"></a>

*Sai Parthasaradhi，Amazon Web Services*

## 總結
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-summary"></a>

許多公司正在將舊版大型主機工作負載遷移至 Amazon Web Services (AWS)。此遷移包括將 z/OS 資料庫的 IBM Db2 轉移至 Amazon Elastic Compute Cloud (Amazon EC2) 上的適用於 Linux、Unix 和 Windows (LUW) 的 Db2。Amazon EC2 從現場部署到 AWS 的分階段遷移期間，使用者可能需要存取 Amazon EC2 上的 IBM Db2 z/OS 和 Db2 LUW 中的資料，直到所有應用程式和資料庫完全遷移至 Db2 LUW。在這種遠端資料存取案例中，使用者身分驗證可能具有挑戰性，因為不同的平台使用不同的身分驗證機制。

此模式涵蓋如何在 Db2 for LUW 上設定聯合伺服器，並將 Db2 for z/OS 設定為遠端資料庫。模式使用信任的內容，將使用者的身分從 Db2 LUW 傳播到 Db2 z/OS，而無需在遠端資料庫上重新驗證。如需受信任內容的詳細資訊，請參閱[其他資訊](#secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-additional)一節。

## 先決條件和限制
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 在 Amazon EC2 執行個體上執行的 Db2 執行個體 Amazon EC2 
+ 在內部部署執行之 z/OS 資料庫的遠端 Db2 
+ 透過 AWS [ Site-to-Site VPN 或 AWS](https://aws.amazon.com/vpn/) [Direct Connect 連線至 AWS](https://aws.amazon.com/directconnect/) 的內部部署網路

## Architecture
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-architecture"></a>

**目標架構**

![\[內部部署大型主機透過內部部署 Db2 伺服器和 VPN 連接到 EC2 上的 Db2 資料庫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9e04f0fe-bae2-412a-93ac-83da50222017/images/0a384695-7907-4fb8-bb7e-d170dcc114af.png)


## 工具
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Site-to-Site VPN](https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html) 可協助您在 AWS 上啟動的執行個體與您自己的遠端網路之間傳遞流量。

**其他工具**
+ [db2cli](https://www.ibm.com/docs/en/db2/11.5?topic=commands-db2cli-db2-interactive-cli) 是 Db2 互動式命令列界面 (CLI) 命令。

## 史詩
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-epics"></a>

### 在 AWS 上執行的 Db2 LUW 資料庫上啟用聯合
<a name="enable-federation-on-the-db2-luw-database-running-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 DB2 LUW 資料庫上啟用聯合。 | 若要在 DB2 LUW 上啟用聯合，請執行下列命令。<pre>update dbm cfg using federated YES</pre> | DBA | 
| 重新啟動資料庫。 | 若要重新啟動資料庫，請執行下列命令。<pre>db2stop force;<br />db2start;</pre> | DBA | 

### 為遠端資料庫編製目錄
<a name="catalog-the-remote-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為遠端 Db2 z/OS 子系統編製目錄。 | 若要在 AWS 上執行的 Db2 LUW 上為遠端 Db2 z/OS 資料庫編製目錄，請使用下列範例命令。 Db2 <pre>catalog TCPIP NODE tcpnode REMOTE mainframehost SERVER mainframeport</pre> | DBA | 
| 為遠端資料庫編製目錄。 | 若要為遠端資料庫編製目錄，請使用下列範例命令。<pre>catalog db dbnam1 as ndbnam1 at node tcpnode</pre> | DBA | 

### 建立遠端伺服器定義
<a name="create-the-remote-server-definition"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 收集遠端 Db2 z/OS 資料庫的使用者憑證。 | 在繼續後續步驟之前，請收集下列資訊：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts.html) | DBA | 
| 建立 DRDA 包裝函式。 | 若要建立 DRDA 包裝函式，請執行下列命令。<pre>CREATE WRAPPER DRDA;</pre> | DBA | 
| 建立伺服器定義。 | 若要建立伺服器定義，請執行下列範例命令。<pre>CREATE SERVER ndbserver<br />TYPE DB2/ZOS VERSION 12<br />WRAPPER DRDA<br />AUTHORIZATION "dbuser1" PASSWORD "dbpasswd" OPTIONS ( DBNAME 'ndbnam1',FED_PROXY_USER 'ZPROXY' );</pre>在此定義中， `FED_PROXY_USER` 指定將用於建立 Db2 z/OS 資料庫信任連線的代理使用者。只有在 Db2 LUW 資料庫中建立遠端伺服器物件時，才需要授權使用者 ID 和密碼。它們稍後不會在執行時間使用。 | DBA | 

### 建立使用者映射
<a name="create-user-mappings"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為代理使用者建立使用者映射。 | 若要為代理使用者建立使用者映射，請執行下列命令。<pre>CREATE USER MAPPING FOR ZPROXY SERVER ndbserver OPTIONS (REMOTE_AUTHID 'ZPROXY', REMOTE_PASSWORD 'zproxy');</pre> | DBA | 
| 在 Db2 LUW 上為每個使用者建立使用者映射。 | 為 AWS 上需要透過代理使用者存取遠端資料的 Db2 LUW 資料庫上的所有使用者建立使用者映射。若要建立使用者映射，請執行下列命令。<pre>CREATE USER MAPPING FOR PERSON1 SERVER ndbserver OPTIONS (REMOTE_AUTHID 'USERZID', USE_TRUSTED_CONTEXT 'Y');</pre>陳述式指定 Db2 LUW (`PERSON1`) 上的使用者可以建立與遠端 Db2 z/OS 資料庫 () 的信任連線`USE_TRUSTED_CONTEXT 'Y'`。透過代理使用者建立連線後，使用者可以使用 Db2 z/OS 使用者 ID () 存取資料`REMOTE_AUTHID 'USERZID'`。 | DBA | 

### 建立信任的內容物件
<a name="create-the-trusted-context-object"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立信任的內容物件。 | 若要在遠端 Db2 z/OS 資料庫上建立信任的內容物件，請使用下列範例命令。<pre>CREATE TRUSTED CONTEXT CTX_LUW_ZOS<br />BASED UPON CONNECTION USING SYSTEM AUTHID ZPROXY<br />ATTRIBUTES (<br />ADDRESS '10.10.10.10'<br />)<br />NO DEFAULT ROLE<br />ENABLE<br />WITH USE FOR PUBLIC WITHOUT AUTHENTICATION;</pre>在此定義中， `CTX_LUW_ZOS`是受信任內容物件的任意名稱。物件包含代理使用者 ID，以及信任連線必須源自的伺服器 IP 地址。在此範例中，AWS 上的 Db2 LUW 資料庫伺服器。您可以使用網域名稱，而不是 IP 地址。子句`WITH USE FOR PUBLIC WITHOUT AUTHENTICATION`指出每個使用者 ID 允許在信任的連線上切換使用者 ID。不需要提供密碼。 | DBA | 

## 相關資源
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-resources"></a>
+ [IBM 資源存取控制設施 (RACF)](https://www.ibm.com/products/resource-access-control-facility)
+ [IBM Db2 LUW 聯合](https://www.ibm.com/docs/en/db2/11.5?topic=federation)
+ [信任的內容](https://www.ibm.com/docs/en/db2-for-zos/13?topic=contexts-trusted)

## 其他資訊
<a name="secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts-additional"></a>

**Db2 信任的內容**

受信任內容是 Db2 資料庫物件，可定義聯合伺服器與遠端資料庫伺服器之間的信任關係。若要定義信任關係，信任的內容會指定信任屬性。信任屬性有三種類型：
+ 發出初始資料庫連線請求的系統授權 ID
+ 進行連線的 IP 地址或網域名稱
+ 資料庫伺服器與資料庫用戶端之間資料通訊的加密設定

當連線請求的所有屬性符合伺服器上定義之任何信任內容物件中指定的屬性時，就會建立信任的連線。信任的連線有兩種類型：隱含和明確。建立隱含信任的連線後，使用者會繼承在該信任的連線定義範圍外無法使用的角色。建立明確信任的連線後，使用者可以在相同實體連線上開啟，無論是否進行身分驗證。此外，可以授予 Db2 使用者角色，這些角色會指定只能在信任連線內使用的權限。此模式使用明確的信任連線。

*此模式中的信任內容*

模式完成後，Db2 LUW 上的 PERSON1 會使用聯合信任內容從 Db2 z/OS 存取遠端資料。如果連線源自於信任內容定義中指定的 IP 地址或網域名稱，則會透過代理使用者建立 PERSON1 的連線。建立連線後，會切換 PERSON1 的對應 Db2 z/OS 使用者 ID，無需重新驗證，而且使用者可以根據為該使用者設定的 Db2 權限來存取資料或物件。

*聯合信任內容的優點*
+ 此方法透過消除使用一般使用者 ID 或應用程式 ID 來維護最低權限原則，這些 ID 需要所有使用者所需權限的超集。
+ 對聯合資料庫和遠端資料庫執行交易的使用者的真實身分始終是已知的，並且可以進行稽核。
+ 效能提升，因為實體連線會在使用者之間重複使用，而不需要重新驗證聯合伺服器。

# 以 CSV 檔案將大規模 Db2 z/OS 資料傳輸至 Amazon S3
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files"></a>

*Bruno Sahinoglu、Abhijit Kshirsagar 和 Ivan Schuster，Amazon Web Services*

## 總結
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-summary"></a>

大型主機仍然是許多企業的記錄系統，其中包含大量資料，包括具有目前記錄的主要資料實體，以及歷史商業交易。它通常是孤立的，且不易被同一企業內的分散式系統存取。隨著雲端技術和大數據民主化的出現，企業有興趣使用大型主機資料中隱藏的洞察來開發新的業務功能。

有了這個目標，企業希望將大型主機 Db2 資料開放至其 Amazon Web Services (AWS) 雲端環境。業務原因有幾個，轉移方法因案例而異。您可能偏好將應用程式直接連接到大型主機，或者您可能偏好近乎即時地複寫資料。如果使用案例是饋送資料倉儲或資料湖，則不再需要擁有up-to-date複本，而且此模式中描述的程序可能就足夠，尤其是如果您想要避免任何第三方產品授權成本。另一個使用案例可能是遷移專案的大型主機資料傳輸。在遷移案例中，需要資料才能執行功能相等性測試。本文章中所述的方法是一種經濟實惠的方式，可將 Db2 資料傳輸到 AWS 雲端環境。

由於 Amazon Simple Storage Service (Amazon S3) 是最整合的 AWS 服務之一，因此您可以從該處存取資料，並使用 Amazon Athena、AWS Lambda 函數或 Amazon QuickSight 等其他 AWS 服務直接收集洞見。您也可以使用 AWS Glue 或 AWS Database Migration Service (AWS DMS) 將資料載入 Amazon Aurora 或 Amazon DynamoDB。考慮到這一點，這說明如何在大型主機上以 ASCII 格式卸載 CSV 檔案中的 Db2 資料，並將檔案傳輸至 Amazon S3。

為此，已開發[大型主機指令碼](https://github.com/aws-samples/unloaddb2-samples)，以協助產生任務控制語言 (JCLs)，以視需要卸載和傳輸任意數量的 Db2 資料表。

## 先決條件和限制
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-prereqs"></a>

**先決條件**
+ IBM z/OS 作業系統使用者，有權執行 Restructured Extended Executor (REXX) 和 JCL 指令碼。
+ 存取 z/OS Unix System Services (USS) 以產生 SSH （安全殼層） 私有和公有金鑰。
+ 可寫入的 S3 儲存貯體。如需詳細資訊，請參閱 Amazon [ S3 文件中的建立您的第一個 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-bucket.html)體。 Amazon S3 
+ 啟用 AWS Transfer 系列 SSH 檔案傳輸通訊協定 (SFTP) 的伺服器，使用做為身分提供者**管理的 Service** 和做為 AWS 儲存服務的 Amazon S3。如需詳細資訊，請參閱 AWS Transfer Family 文件中的[建立啟用 SFTP 的伺服器](https://docs.aws.amazon.com/transfer/latest/userguide/create-server-sftp.html)。

**限制**
+ 此方法不適用於近乎即時或即時的資料同步。
+ 資料只能從 Db2 z/OS 移至 Amazon S3，不能以其他方式移動。

## Architecture
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-architecture"></a>

**來源技術堆疊**
+ 在 z/OS 上執行 Db2 的大型主機

**目標技術堆疊**
+ AWS Transfer 系列
+ Amazon S3
+ Amazon Athena
+ Amazon QuickSight
+ AWS Glue
+ Amazon Relational Database Service (Amazon RDS)
+ Amazon Aurora
+ Amazon Redshift

**來源和目標架構**

下圖顯示以 ASCII CSV 格式產生、擷取和傳輸 Db2 z/OS 資料至 S3 儲存貯體的程序。

![\[Data flow from corporate data center to AWS 雲端, showing mainframe extraction and cloud processing steps.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/66e6fa1a-1c7d-4b7a-8404-9ba85e433b24/images/87b13e0d-0be9-4462-bdbf-67342334416c.png)


1. 系統會選取資料表清單，以便從 Db2 目錄進行資料遷移。

1. 此清單用於使用外部格式的數值和資料欄來推動卸載任務的產生。

1. 然後，資料會使用 AWS Transfer Family 傳輸到 Amazon S3。

1. AWS Glue 擷取、轉換和載入 (ETL) 任務可以轉換資料，並以指定的格式將其載入已處理的儲存貯體，或者 AWS Glue 可以直接將資料饋送至資料庫。

1. Amazon Athena 和 Amazon QuickSight 可用於查詢和轉譯資料以推動分析。

下圖顯示整個程序的邏輯流程。

![\[Flowchart showing JCL process with TABNAME, REXXEXEC, and JCL decks steps, including inputs and outputs.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/66e6fa1a-1c7d-4b7a-8404-9ba85e433b24/images/d72f2572-10c9-43f9-b6c9-7e57c9a69d52.png)


1. 第一個稱為 TABNAME 的 JCL 將使用 Db2 公用程式 DSNTIAUL 來擷取和產生您計劃從 Db2 卸載的資料表清單。若要選擇資料表，您必須手動調整 SQL 輸入以選取和新增篩選條件，以包含一或多個 Db2 結構描述。

1. 第二個 JCL 稱為 REXXEXEC，將使用 JCL 骨架和 REXX 程式來處理 JCL TABNAME 建立的資料表清單，並為每個資料表名稱產生一個 JCL。每個 JCL 都會包含一個卸載資料表的步驟，以及另一個使用 SFTP 通訊協定將檔案傳送至 S3 儲存貯體的步驟。

1. 最後一個步驟包含執行 JCL 以卸載資料表並將檔案傳輸至 AWS。整個程序可以使用內部部署或 AWS 上的排程器來自動化。

## 工具
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-tools"></a>

**AWS 服務**
+ [Amazon Athena](https://docs.aws.amazon.com/athena/latest/ug/what-is.html) 是一種互動式查詢服務，可協助您使用標準 SQL 直接在 Amazon Simple Storage Service (Amazon S3) 中分析資料。
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html) 是全受管的擷取、轉換和載入 (ETL) 服務。它可協助您可靠地分類、清理、擴充和移動資料存放區和資料串流之間的資料。
+ [Amazon QuickSight](https://docs.aws.amazon.com/quicksight/latest/user/welcome.html) 是一種雲端規模的商業智慧 (BI) 服務，可協助您在單一儀表板中視覺化、分析和報告您的資料。
+ [Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html) 是 AWS 雲端中的受管 PB 級資料倉儲服務。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Transfer Family](https://docs.aws.amazon.com/transfer/latest/userguide/what-is-aws-transfer-family.html) 是一種安全傳輸服務，可讓您將檔案傳入和傳出 AWS 儲存服務。

**大型主機工具**
+ [SSH 檔案傳輸通訊協定 (SFTP)](https://www.ssh.com/academy/ssh/sftp-ssh-file-transfer-protocol) 是一種安全的檔案傳輸通訊協定，允許遠端登入 並在伺服器之間傳輸檔案。SSH 透過加密所有流量來提供安全性。
+ [DSNTIAUL](https://www.ibm.com/docs/en/db2-for-zos/11?topic=dpasp-dsntiaul-sample-program) 是由 IBM 提供的範例程式，用於卸載資料。
+ [DSNUTILB](https://www.ibm.com/docs/en/db2-for-zos/11?topic=sharing-recommendations-utilities-in-coexistence) 是由 IBM 提供的公用程式批次程式，用於從 DSNTIAUL 卸載具有不同選項的資料。
+ [z/OS OpenSSH](https://www.ibm.com/docs/en/zos/2.4.0?topic=zbed-zos-openssh) 是在 Unix System Service 上執行的開放原始碼軟體 SSH 連接埠，位於 IBM 作業系統 z/OS 下。SSH 是在 TCP/IP 網路上執行的兩部電腦之間的安全加密連線程式。它提供多個公用程式，包括 ssh-keygen。
+ [REXX （重組延伸執行器）](https://www.ibm.com/docs/en/zos/2.1.0?topic=guide-learning-rexx-language) 指令碼用於使用 Db2 卸載和 SFTP 步驟自動產生 JCL。

**Code**

此模式的程式碼可在 GitHub [unloaddb2](https://github.com/aws-samples/unloaddb2-samples) 儲存庫中使用。

## 最佳實務
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-best-practices"></a>

對於第一次卸載，產生的 JCLs應該卸載整個資料表資料。

第一次完全卸載後，請執行增量卸載，以獲得更好的效能並節省成本。 在範本 JCL 面板中修補 SQL 查詢，以適應卸載程序的任何變更。

您可以手動轉換結構描述，或使用 Lambda 上的指令碼搭配 Db2 SYSPUNCH 做為輸入。對於工業程序，[AWS Schema Conversion Tool (SCT) ](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.DB2zOS.html)是偏好的選項。

最後，使用大型主機型排程器或 AWS 上的排程器搭配大型主機上的代理程式，以協助管理和自動化整個程序。

## 史詩
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-epics"></a>

### 設定 S3 儲存貯體
<a name="set-up-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 如需說明，請參閱[建立您的第一個 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-bucket.html)體。 | 一般 AWS | 

### 設定 Transfer Family 伺服器
<a name="set-up-the-transfer-family-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立啟用 SFTP 的伺服器。 | 若要在 [AWS Transfer Family 主控台](https://console.aws.amazon.com/transfer/)上開啟和建立 SFTP 伺服器，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.html) | 一般 AWS | 
| 建立 Transfer Family 的 IAM 角色。 | 若要為 Transfer Family 建立 AWS Identity and Access Management (IAM) 角色以存取 Amazon S3，請遵循[建立 IAM 角色和政策](https://docs.aws.amazon.com/transfer/latest/userguide/requirements-roles.html)中的指示。 | AWS 管理員 | 
| 新增 Amazon S3 服務受管使用者。 | 若要新增 Amazon S3 服務受管使用者，請遵循 [AWS 文件](https://docs.aws.amazon.com/transfer/latest/userguide/service-managed-users.html#add-s3-user)中的指示，並使用大型主機使用者 ID。 | 一般 AWS | 

### 保護通訊協定
<a name="secure-the-communication-protocol"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 SSH 金鑰。 | 在大型主機 USS 環境中，執行下列命令。<pre>ssh-keygen -t rsa</pre>出現密碼短語提示時，請保留空白。 | 大型主機開發人員 | 
| 將正確的授權層級提供給 SSH 資料夾和金鑰檔案。 | 根據預設，公有和私有金鑰會存放在使用者目錄 中`/u/home/username/.ssh`。您必須將授權 644 提供給金鑰檔案，並將 700 提供給 資料夾。<pre>chmod 644 .ssh/id_rsa<br />chmod 700 .ssh</pre> | 大型主機開發人員 | 
| 將公有金鑰內容複製到您的 Amazon S3 服務受管使用者。 | 若要複製 USS 產生的公有金鑰內容，請開啟 [AWS Transfer Family 主控台](https://console.aws.amazon.com/transfer/)。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.html) | 大型主機開發人員 | 

### 產生 JCLs
<a name="generate-the-jcls"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 產生範圍內的 Db2 資料表清單。 | 提供輸入 SQL 以建立資料遷移範圍的資料表清單。此步驟要求您使用 SQL where 子句指定選取條件，以佇列 Db2 目錄資料表 SYSIBM.SYSTABLES。您可以自訂篩選條件，以包含以特定字首開頭或根據增量卸載時間戳記的特定結構描述或資料表名稱。輸出是在大型主機上的實體序列 (PS) 資料集中擷取。此資料集將做為 JCL 產生下一階段的輸入。在使用 JCL TABNAME 之前 （您可以視需要重新命名它），請進行下列變更：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.html)**Db2 資料表清單擷取任務**<pre><Jobcard><br />//* <br />//* UNLOAD ALL THE TABLE NAMES FOR A PARTICULAR SCHEMA<br />//* <br />//STEP01  EXEC PGM=IEFBR14<br />//* <br />//DD1      DD  DISP=(MOD,DELETE,DELETE),<br />//         UNIT=SYSDA,<br />//         SPACE=(1000,(1,1)),<br />//         DSN=<HLQ1>.DSN81210.TABLIST<br />//* <br />//DD2      DD  DISP=(MOD,DELETE,DELETE),<br />//         UNIT=SYSDA,<br />//         SPACE=(1000,(1,1)),<br />//         DSN=<HLQ1>.DSN81210.SYSPUNCH <br />//* <br />//UNLOAD  EXEC PGM=IKJEFT01,DYNAMNBR=20 <br />//SYSTSPRT DD  SYSOUT=* <br />//STEPLIB  DD  DISP=SHR,DSN=DSNC10.DBCG.SDSNEXIT<br />//         DD  DISP=SHR,DSN=DSNC10.SDSNLOAD<br />//         DD  DISP=SHR,DSN=CEE.SCEERUN <br />//         DD  DISP=SHR,DSN=DSNC10.DBCG.RUNLIB.LOAD <br />//SYSTSIN  DD  *<br />  DSN SYSTEM(DBCG) <br />  RUN  PROGRAM(DSNTIAUL) PLAN(DSNTIB12) PARMS('SQL') - <br />       LIB('DSNC10.DBCG.RUNLIB.LOAD')<br />  END<br />//SYSPRINT DD SYSOUT=*<br />//* <br />//SYSUDUMP DD SYSOUT=*<br />//* <br />//SYSREC00 DD DISP=(NEW,CATLG,DELETE),<br />//            UNIT=SYSDA,SPACE=(32760,(1000,500)),<br />//            DSN=<HLQ1>.DSN81210.TABLIST <br />//* <br />//SYSPUNCH DD DISP=(NEW,CATLG,DELETE), <br />//            UNIT=SYSDA,SPACE=(32760,(1000,500)),<br />//            VOL=SER=SCR03,RECFM=FB,LRECL=120,BLKSIZE=12 <br />//            DSN=<HLQ1>.DSN81210.SYSPUNCH <br />//* <br />//SYSIN    DD * <br />   SELECT CHAR(CREATOR), CHAR(NAME)<br />     FROM SYSIBM.SYSTABLES <br />    WHERE OWNER = '<Schema>' <br />      AND NAME LIKE '<Prefix>%' <br />      AND TYPE = 'T'; <br />/* </pre> | 大型主機開發人員 | 
| 修改 JCL 範本。 | 此模式隨附的 JCL 範本包含一般任務卡和程式庫名稱。不過，大多數大型主機站點都有自己的資料集名稱、程式庫名稱和任務卡命名標準。例如，執行 Db2 任務可能需要特定任務類別。任務項目子系統實作 JES2 和 JES3 可以實施其他變更。標準負載程式庫的第一個限定詞可能與 不同`SYS1`，這是 IBM 預設。因此，在執行範本之前，請自訂範本以考量您的網站特定標準。在骨架 JCL UNLDSKEL 中進行下列變更：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.html)**卸載和 SFTP JCL 骨架**<pre>//&USRPFX.U JOB (DB2UNLOAD),'JOB',CLASS=A,MSGCLASS=A, <br />//         TIME=1440,NOTIFY=&USRPFX<br />//* DELETE DATASETS<br />//STEP01   EXEC PGM=IEFBR14<br />//DD01     DD DISP=(MOD,DELETE,DELETE),<br />//            UNIT=SYSDA,<br />//            SPACE=(TRK,(1,1)),<br />// DSN=&USRPFX..DB2.PUNCH.&JOBNAME<br />//DD02     DD DISP=(MOD,DELETE,DELETE),<br />//            UNIT=SYSDA,<br />//            SPACE=(TRK,(1,1)),<br />// DSN=&USRPFX..DB2.UNLOAD.&JOBNAME<br />//*<br />//* RUNNING DB2 EXTRACTION BATCH JOB FOR AWS DEMO<br />//*<br />//UNLD01   EXEC PGM=DSNUTILB,REGION=0M,<br />// PARM='<DSN>,UNLOAD'<br />//STEPLIB  DD  DISP=SHR,DSN=DSNC10.DBCG.SDSNEXIT<br />//         DD  DISP=SHR,DSN=DSNC10.SDSNLOAD<br />//SYSPRINT DD  SYSOUT=*<br />//UTPRINT  DD  SYSOUT=*<br />//SYSOUT   DD  SYSOUT=*<br />//SYSPUN01 DD  DISP=(NEW,CATLG,DELETE),<br />//             SPACE=(CYL,(1,1),RLSE),<br />// DSN=&USRPFX..DB2.PUNCH.&JOBNAME<br />//SYSREC01 DD  DISP=(NEW,CATLG,DELETE),<br />//             SPACE=(CYL,(10,50),RLSE),<br />// DSN=&USRPFX..DB2.UNLOAD.&JOBNAME<br />//SYSPRINT DD SYSOUT=*<br />//SYSIN    DD *<br />  UNLOAD<br />  DELIMITED COLDEL ','<br />  FROM TABLE &TABNAME<br />  UNLDDN SYSREC01<br />  PUNCHDDN SYSPUN01<br />  SHRLEVEL CHANGE ISOLATION UR;<br /> /*<br />//*<br />//* FTP TO AMAZON S3 BACKED FTP SERVER IF UNLOAD WAS SUCCESSFUL<br />//*<br />//SFTP EXEC PGM=BPXBATCH,COND=(4,LE),REGION=0M<br />//STDPARM DD *<br /> SH cp "//'&USRPFX..DB2.UNLOAD.&JOBNAME'"<br />   &TABNAME..csv;<br /> echo "ascii             " >> uplcmd;<br /> echo "PUT &TABNAME..csv " >>>> uplcmd;<br /> sftp -b uplcmd -i .ssh/id_rsa &FTPUSER.@&FTPSITE;<br /> rm &TABNAME..csv;<br /> //SYSPRINT DD SYSOUT=*<br /> //STDOUT DD SYSOUT=*<br /> //STDENV DD *<br /> //STDERR DD SYSOUT=*                                                </pre>  | 大型主機開發人員 | 
| 產生大量卸載 JCL。 | 此步驟涉及使用 JCL 在 ISPF 環境下執行 REXX 指令碼。提供在第一個步驟上建立的範圍內資料表清單，做為針對`TABLIST DD`名稱產生大量 JCL 的輸入。JCL 會在針對名稱指定的使用者指定分割資料集中，為每個資料表`ISPFILE DD`名稱產生一個新的 JCL。事先配置此程式庫。每個新的 JCL 將有兩個步驟：一個步驟將 Db2 資料表卸載至檔案，一個步驟將檔案傳送至 S3 儲存貯體。在 JCL REXXEXEC 中進行下列變更 （您可以變更名稱）：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.html)**大量 JCL 產生任務**<pre>//RUNREXX JOB (CREATEJCL),'RUNS ISPF TABLIST',CLASS=A,MSGCLASS=A,      <br />//         TIME=1440,NOTIFY=&SYSUID<br />//* Most of the values required can be updated to your site specific<br />//* values using the command 'TSO ISRDDN' in your ISPF session. <br />//* Update all the lines tagged with //update marker to desired<br />//* site specific values. <br />//ISPF EXEC PGM=IKJEFT01,REGION=2048K,DYNAMNBR=25<br />//SYSPROC   DD DISP=SHR,DSN=USER.Z23D.CLIST<br />//SYSEXEC   DD DISP=SHR,DSN=<HLQ1>.TEST.REXXLIB<br />//ISPPLIB   DD DISP=SHR,DSN=ISP.SISPPENU<br />//ISPSLIB   DD DISP=SHR,DSN=ISP.SISPSENU<br />//          DD DISP=SHR,DSN=<HLQ1>.TEST.ISPSLIB<br />//ISPMLIB   DD DSN=ISP.SISPMENU,DISP=SHR<br />//ISPTLIB   DD DDNAME=ISPTABL<br />//          DD DSN=ISP.SISPTENU,DISP=SHR<br />//ISPTABL   DD LIKE=ISP.SISPTENU,UNIT=VIO<br />//ISPPROF   DD LIKE=ISP.SISPTENU,UNIT=VIO<br />//ISPLOG    DD SYSOUT=*,RECFM=VA,LRECL=125<br />//SYSPRINT  DD SYSOUT=*<br />//SYSTSPRT  DD SYSOUT=*<br />//SYSUDUMP  DD SYSOUT=*<br />//SYSDBOUT  DD SYSOUT=*<br />//SYSTSPRT  DD SYSOUT=*<br />//SYSUDUMP  DD SYSOUT=*<br />//SYSDBOUT  DD SYSOUT=*<br />//SYSHELP   DD DSN=SYS1.HELP,DISP=SHR <br />//SYSOUT    DD SYSOUT=*<br />//* Input list of tablenames<br />//TABLIST   DD DISP=SHR,DSN=<HLQ1>.DSN81210.TABLIST<br />//* Output pds<br />//ISPFILE   DD DISP=SHR,DSN=<HLQ1>.TEST.JOBGEN<br />//SYSTSIN   DD *<br />ISPSTART CMD(ZSTEPS <MFUSER> <FTPUSER> <AWS TransferFamily IP>)<br />/*</pre>使用 REXX 指令碼之前，請進行下列變更：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.html)**ZSTEPS REXX 指令碼**<pre>/*REXX - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */<br />/* 10/27/2021 - added new parms to accommodate ftp */<br />Trace "o" <br />    parse arg usrpfx ftpuser ftpsite<br />    Say "Start"<br />    Say "Ftpuser: " ftpuser "Ftpsite:" ftpsite<br />    Say "Reading table name list"<br />    "EXECIO * DISKR TABLIST (STEM LINE. FINIS"<br />    DO I = 1 TO LINE.0<br />      Say I<br />      suffix = I<br />      Say LINE.i<br />      Parse var LINE.i schema table rest<br />      tabname = schema !! "." !! table<br />      Say tabname<br />      tempjob= "LOD" !! RIGHT("0000" !! i, 5) <br />      jobname=tempjob<br />      Say tempjob<br />      ADDRESS ISPEXEC "FTOPEN "<br />      ADDRESS ISPEXEC "FTINCL UNLDSKEL"<br />      /* member will be saved in ISPDSN library allocated in JCL */<br />      ADDRESS ISPEXEC "FTCLOSE NAME("tempjob")"<br />    END<br /><br />    ADDRESS TSO "FREE F(TABLIST) "<br />    ADDRESS TSO "FREE F(ISPFILE) "<br /><br />exit 0</pre> | 大型主機開發人員 | 

### 執行 JCLs
<a name="run-the-jcls"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行 Db2 卸載步驟。 | 在產生 JCL 之後，您將擁有與需要卸載的資料表一樣多JCLs。此案例使用 JCL 產生的範例來解釋結構和最重要的步驟。您不需要執行任何操作。以下資訊僅供參考。如果您打算提交您在上一個步驟中產生的 JCLs，請跳到*提交 LODnnnnn JCLs*任務。使用 JCL 搭配 IBM 提供的 DSNUTILB Db2 公用程式卸載 Db2 資料時，您必須確定卸載的資料不包含壓縮的數值資料。若要達成此目的，請使用 DSNUTILB `DELIMITED` 參數。`DELIMITED` 參數支援以 CSV 格式卸載資料，方法是新增字元做為文字欄位的分隔符號和雙引號，移除 VARCHAR 欄中的填補，並將所有數值欄位轉換為 EXTERNAL FORMAT，包括 DATE 欄位。下列範例顯示所產生 JCL 中的卸載步驟，使用逗號字元做為分隔符號。<pre>                            <br /> UNLOAD<br /> DELIMITED COLDEL ',' <br /> FROM TABLE SCHEMA_NAME.TBNAME<br /> UNLDDN SYSREC01<br /> PUNCHDDN SYSPUN01<br /> SHRLEVEL CHANGE ISOLATION UR;</pre> | Mainframe 開發人員、系統工程師 | 
| 執行 SFTP 步驟。 | 若要從 JCL 使用 SFTP 通訊協定，請使用 BPXBATCH 公用程式。 SFTP 公用程式無法直接存取 MVS 資料集。您可以使用 copy 命令 (`cp`) 將序列檔案複製到 `&USRPFX..DB2.UNLOAD.&JOBNAME` USS 目錄，並在其中變成 `&TABNAME..csv`。使用私有金鑰 (`id_rsa`) 並使用 RACF 使用者 ID 做為使用者名稱來執行`sftp`命令，以連線至 AWS Transfer Family IP 地址。<pre>SH cp "//'&USRPFX..DB2.UNLOAD.&JOBNAME'"<br />   &TABNAME..csv;<br /> echo "ascii             " >> uplcmd;<br /> echo "PUT &TABNAME..csv " >>>> uplcmd;<br /> sftp -b uplcmd -i .ssh/id_rsa &FTPUSER.@&FTP_TF_SITE;<br /> rm &TABNAME..csv; </pre> | Mainframe 開發人員、系統工程師 | 
| 提交 LODnnnnn JCLs。 | 先前的 JCL 已產生所有需要卸載、轉換為 CSV 並傳輸至 S3 儲存貯體的 LODnnnnn nnJCL 資料表。在已產生的所有 JCLs上執行 `submit`命令。 | Mainframe 開發人員、系統工程師 | 

## 相關資源
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-resources"></a>

如需本文件中使用的不同工具和解決方案的詳細資訊，請參閱下列各項：
+ [z/OS OpenSSH 使用者指南](https://www-01.ibm.com/servers/resourcelink/svc00100.nsf/pages/zOSV2R4sc276806/$file/foto100_v2r4.pdf)
+ [Db2 z/OS – UNLOAD 控制陳述式範例](https://www.ibm.com/docs/en/db2-for-zos/11?topic=unload-sample-control-statements)
+ [Db2 z/OS – 卸載分隔檔案](https://www.ibm.com/docs/en/db2-for-zos/11?topic=unload-unloading-delimited-files)
+ [Transfer 系列 – 建立啟用 SFTP 的伺服器](https://docs.aws.amazon.com/transfer/latest/userguide/create-server-sftp.html)
+ [Transfer Family – 使用服務受管使用者](https://docs.aws.amazon.com/transfer/latest/userguide/service-managed-users.html)

## 其他資訊
<a name="transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files-additional"></a>

在 Amazon S3 上取得 Db2 資料後，您有許多方法可以開發新的洞見。由於 Amazon S3 與 AWS 資料分析服務整合，因此您可以在分散式端自由使用或公開這些資料。例如，您可以執行下列動作：
+ 在 [Amazon S3 上建置資料湖](https://aws.amazon.com/products/storage/data-lake-storage/)，並使用query-in-place、分析和機器學習工具擷取寶貴的洞見，而無需移動資料。
+ 透過設定與 AWS Transfer 系列整合的上傳後處理工作流程來啟動 [Lambda 函數](https://aws.amazon.com/lambda/)。
+ 使用 AWS Glue 開發新的微服務來存取 Amazon S3 或[全受管資料庫中](https://aws.amazon.com/free/database/?trk=ps_a134p000007CdNEAA0&trkCampaign=acq_paid_search_brand&sc_channel=PS&sc_campaign=acquisition_FR&sc_publisher=Google&sc_category=Database&sc_country=FR&sc_geo=EMEA&sc_outcome=acq&sc_detail=amazon%20relational%20database%20service&sc_content=Relational%20Database_e&sc_matchtype=e&sc_segment=548727697660&sc_medium=ACQ-P|PS-GO|Brand|Desktop|SU|Database|Solution|FR|EN|Text&s_kwcid=AL!4422!3!548727697660!e!!g!!amazon%20relational%20database%20service&ef_id=CjwKCAjwzt6LBhBeEiwAbPGOgcGbQIl1-QsbHfWTgMZSSHEXzSG377R9ZyK3tCcbnHuT45L230FufxoCeEkQAvD_BwE:G:s&s_kwcid=AL!4422!3!548727697660!e!!g!!amazon%20relational%20database%20service)的資料，AWS Glue 是一種無伺服器資料整合服務，可讓您輕鬆探索、準備和結合資料，以進行分析、機器學習和應用程式開發。 [AWS Glue](https://aws.amazon.com/glue/)

在遷移使用案例中，由於您可以將任何資料從大型主機傳輸到 S3，因此您可以執行下列動作：
+ 淘汰實體基礎設施，並使用 Amazon S3 Glacier 和 S3 Glacier Deep Archive 建立符合成本效益的資料封存策略。 
+ 使用 Amazon S3 和其他 AWS 服務建置可擴展、耐用且安全的備份和還原解決方案，例如 S3 Glacier 和 Amazon Elastic File System (Amazon EFS)，以增強或取代現有的內部部署功能。

# 使用 AWS Transform 自訂將 Easytrieve 轉換為現代語言
<a name="transform-easytrieve-modern-languages"></a>

*Shubham Roy、Subramanyam Malisetty 和 Harshitha Shashidhar，Amazon Web Services*

## 摘要
<a name="transform-easytrieve-modern-languages-summary"></a>

此模式為使用 [AWS Transform 自訂](https://aws.amazon.com/transform/custom/) language-to-language 轉換的大型主機 Broadcom [Easytrieve 報告產生器](https://techdocs.broadcom.com/us/en/ca-mainframe-software/devops/ca-easytrieve-report-generator/11-6.html) (EZT) 工作負載提供更快和較低風險轉換的規範性指引。它解決了現代化常用於批次資料處理和報告產生之利基和專有大型主機 EZT 工作負載的挑戰。此模式會使用您建立的代理式 AI 自動化解決方案，取代依賴專屬工具和罕見大型主機專業知識的昂貴、冗長且容易出錯的遷移方法 AWS Transform。

此模式為 EZT 轉換提供立即可用的自訂轉換定義。此定義使用多個轉換輸入：
+ 使用 為 [AWS Transform 大型主機擷取的](https://aws.amazon.com/transform/mainframe/) EZT 業務規則
+ EZT 程式設計參考文件
+ EZT 原始碼
+ 大型主機輸入和輸出資料集

AWS Transform 自訂 使用這些輸入，以現代目標語言產生功能上同等的應用程式，例如 Java 或 Python。

轉換程序使用智慧型測試執行、自動偵錯和反覆修正功能，來驗證對預期輸出的功能等效性。它還支援持續學習，使自訂轉換定義能夠提高連續轉換的準確性和一致性。使用這種模式，組織可以減少遷移工作量和風險、解決利基大型主機技術債務，並將 上的 EZT 工作負載現代化 AWS ，以提高敏捷性、可靠性、安全性和創新能力。

## 先決條件和限制
<a name="transform-easytrieve-modern-languages-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶 
+ 具有輸入和輸出資料的大型主機 EZT 工作負載 

**限制**

*範圍限制 *
+ **語言支援** – 此特定轉換模式僅支援 EZT-to-Java 轉換。 
+ **超出範圍** – 其他大型主機程式設計語言的轉換需要 AWS Transform 自訂 中新的 自訂轉換定義。

*程序限制 *
+ **驗證相依性** – 如果沒有基準輸出資料，就無法驗證轉換。 
+ **專屬邏輯** – 高度特定、自訂開發的公用程式需要額外的使用者文件和參考資料，AI 代理程式才能正確解譯。

*技術限制 *
+ **服務限制** – 如需 AWS Transform 自訂服務限制和配額，請參閱 [AWS Transform 使用者指南 - 配額](https://docs.aws.amazon.com/transform/latest/userguide/transform-limits.html) 和 [AWS 一般參考 - 轉換配額](https://docs.aws.amazon.com/general/latest/gr/aws-transform.html)。

**產品版本**
+ AWS Transform CLI –  最新版本
+ Node.js – 20 版或更新版本
+ Git –  最新版本
+ 目標環境
  + Java – 第 17 版或更新版本
  + Spring Boot – 3.x 版是重構應用程式的主要目標
  + Maven –  3.6 版或更新版本

## Architecture
<a name="transform-easytrieve-modern-languages-architecture"></a>

**來源技術堆疊**
+ **作業系統** – IBM z/OS
+ **程式設計語言** – Easytrieve、任務控制語言 (JCL)
+ **資料庫** – z/OS 的 IBM DB2、虛擬儲存存取方法 (VSAM)、大型主機平面檔案

**目標技術堆疊**
+ **作業系統** – Amazon Linux
+ **運算** – Amazon Elastic Compute Cloud (Amazon EC2)
+ **程式設計語言** – Java
+ **資料庫** Amazon Relational Database Service (Amazon RDS)

**目標架構**

![\[使用 AWS 轉換自訂將 EZT 轉換為現代程式碼的目標架構圖。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/71f15422-42cb-4c7e-94fa-051a4f130445/images/eb89eed0-dd55-485c-a433-9869162eaad9.png)


**工作流程**

此解決方案使用 AWS Transform 自訂language-to-language遷移轉換模式，透過四步驟自動化工作流程將大型主機 Easytrieve (EZT) 應用程式現代化為 Java。

*步驟 1 –  將舊版程式碼提供給適用於 大型主機 AWS Transform 的 ，以：*
+ 分析程式碼
+ 擷取高階商業邏輯
+ 擷取詳細的商業邏輯。

*步驟 2 –  使用所需的輸入建立資料夾：*
+ 使用 為大型主機擷取 AWS Transform 的 EZT 業務規則 
+ EZT 程式設計參考文件 
+ EZT 原始碼
+ 大型主機輸入和輸出資料集

*步驟 3 – 建立並執行自訂轉換定義*

1. 使用 AWS Transform CLI 以自然語言描述轉換目標。 AWS Transform 自訂會分析 BRE、原始程式碼和 EZT 程式設計指南，以產生自訂轉換定義以供開發人員檢閱和核准。

1. 然後，使用專案原始碼叫用 AWS Transform CLI。 AWS Transform 自訂會建立轉換計劃、在核准時將 EZT 轉換為 Java、產生支援檔案、建置可執行 JAR，以及驗證結束條件。

1. 使用驗證代理程式來測試與大型主機輸出 的功能等效性。自我偵錯工具代理程式會自動修正問題。最終交付項目包括經過驗證的 Java 程式碼和 HTML 驗證報告。

**自動化和擴展**
+ 代理式 AI 多模式執行架構 – AWS Transform 自訂利用代理式 AI 搭配 3 種執行模式 （融合式、互動式、完整自動化） 來自動化複雜的轉換任務，包括程式碼分析、重構、轉換規劃和測試。
+ 自適應學習意見回饋系統 – 平台透過程式碼範例分析、文件剖析和開發人員意見回饋與版本化轉換定義的整合，實作持續學習機制。
+ 並行應用程式處理架構 – 系統可跨可擴展的基礎設施同時進行多個應用程式轉換操作的分散式平行執行。

## 工具
<a name="transform-easytrieve-modern-languages-tools"></a>

**AWS 服務  **
+ [AWS Transform custom](https://docs.aws.amazon.com/transform/latest/userguide/custom.html) 是一種代理式 AI 服務，用於將舊版 EZT 應用程式轉換為現代程式設計語言。 
+ [AWS Transform](https://docs.aws.amazon.com/transform/latest/userguide/what-is-service.html) 使用代理式 AI 來協助您加速傳統工作負載的現代化，例如 .NET、大型主機和 VMware 工作負載。
+ [AWS Transform for mainframe ](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe.html)用於分析 舊版 EZT 應用程式，以擷取內嵌商業邏輯並產生全面的商業規則文件，包括邏輯摘要、縮寫定義和結構化知識庫。這些可做為 AWS Transform 自訂的輸入資料。 
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。Amazon S3 做為用於儲存轉換定義、程式碼儲存庫和處理結果的 AWS Transform 自訂主要儲存服務。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。IAM 提供安全架構，用於 AWS Transform 自訂、管理轉換操作的許可和存取控制。

**其他工具**
+ [AWS Transform CLI](https://docs.aws.amazon.com/transform/latest/userguide/custom-command-reference.html) 是 AWS Transform 自訂的命令列界面，可讓開發人員透過自然語言對話和自動化執行模式定義、執行和管理自訂程式碼轉換。 AWS Transform 自訂支援互動式工作階段 (atx custom def exec) 和自動轉換，以實現程式碼庫的可擴展現代化。
+ [Git](https://git-scm.com/doc) 版本控制系統用於自動修正應用程式期間的分支保護、變更追蹤和復原功能。 
+ [Java](https://www.java.com/en/) 是此模式中使用的程式設計語言和開發環境。 

**程式碼儲存庫**

此模式的程式碼可在使用 GitHub 上的[AWS Transform 自訂的 Easytrieve 轉換為現代語言](https://github.com/aws-samples/sample-mainframe-easytrieve-transform?tab=readme-ov-file#easytrieve-to-modern-languages-transformation-with-aws-transform-custom)中取得。

## 最佳實務
<a name="transform-easytrieve-modern-languages-best-practices"></a>
+ 建立標準化專案結構 – 建立四資料夾結構 (source-code、bre-doc、 input-data、 output-data)、驗證完整性，並在轉換之前記錄內容。
+ 使用基準檔案進行驗證 – 使用生產基準輸入檔案、執行與基準輸出byte-by-byte比較、接受偏差的零容忍度。
+ 使用所有可用的參考文件  – 若要提高轉換的準確性，請提供所有可用的參考文件，例如業務需求和編碼檢查清單。
+ 提供改善品質的輸入  – AWS Transform 自訂會自動從轉換執行中擷取學習 （開發人員意見回饋、程式碼問題），並為其建立知識項目。 在每次成功轉換後檢閱知識項目，並核准您希望在未來執行中使用的項目。這可改善未來轉型的品質。

## 史詩
<a name="transform-easytrieve-modern-languages-epics"></a>

### 產生業務規則擷取 (BRE)
<a name="generate-a-business-rule-extract-bre"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
|  AWS Transform 為大型主機設定 。 | 設定環境和必要 AWS Identity and Access Management (IAM) 許可，以支援大型主機現代化工作流程。如需詳細資訊，請參閱 AWS [文件中的大型主機應用程式的轉換](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html)。 | 應用程式開發人員 | 
| 產生業務規則擷取 (BRE) 文件。 | 從來源 EZT 或 COBOL 程式碼擷取商業邏輯，以產生功能文件。如需如何啟動擷取程序和檢閱輸出的指示，請參閱 AWS Transform 文件中的[擷取商業邏輯](https://docs.aws.amazon.com/transform/latest/userguide/transform-app-mainframe-workflow.html#transform-app-mainframe-workflow-extract-business-logic)。 | 應用程式開發人員 | 

### 設定 AWS Transform 自訂
<a name="set-up-trn-custom"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 佈建 AWS Transform 自訂的基礎設施。 | 部署託管安全轉型環境所需的生產就緒基礎設施。這包括使用轉換 Easytrieve 程式碼所需的工具、IAM 許可和網路設定設定的私有 Amazon EC2 執行個體。若要使用基礎設施做為程式碼 (IaC) 佈建環境，請遵循 [Easytrieve to Modern Languages Transformation with AWS Transform Custom](https://github.com/aws-samples/sample-mainframe-easytrieve-transform) GitHub 儲存庫中的部署說明。 | 應用程式開發人員、AWS 管理員 | 
| 準備用於轉換的輸入資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transform-easytrieve-modern-languages.html) | 應用程式開發人員 | 

###  建立自訂轉換定義
<a name="create-a-custom-transformation-definition"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立轉換定義。 | 請依照下列步驟，使用功能驗證建立 EZT 到 Java 轉換的自訂轉換定義。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transform-easytrieve-modern-languages.html) | 應用程式開發人員 | 
| 發佈轉換定義。 | 在檢閱和驗證轉換定義之後，您可以使用自然語言提示將其發佈到 AWS Transform 自訂登錄檔，並提供定義名稱，例如 *Easytrieve-to-Java-Migration*。 | 應用程式開發人員 | 

### 準備基準資料以進行驗證。
<a name="prepare-baseline-data-for-validation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱轉換驗證摘要。 | 在執行 AWS Transform 自訂轉換之前，請確認 `input-data` 資料夾包含執行大型主機批次任務之前擷取的必要資料檔案。在大型主機批次任務執行之後，請確定 `output-data` 資料夾會擷取產生的檔案。根據執行需求，所有檔案都是使用 EBCDIC 編碼的Sequential/Text/DB2 格式。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transform-easytrieve-modern-languages.html) | 應用程式開發人員 | 
| 執行自訂轉換任務。 | 執行 AWS Transform CLI 命令，選擇非互動式或互動式選項：<pre>:# Non-interactive execution (fully autonomous):<br />atx custom def exec \<br />  --transformation-name "Easytrieve-to-Java-Migration" \<br />  --code-repository-path ~/root/transform-workspace/mainframe-source/source-code \<br />  --build-command "mvn clean install" \<br />  --non-interactive \<br />  --trust-all-tools \<br /><br /># Interactive execution (with human oversight):<br />atx custom def exec \<br />  -n "Easytrieve-to-Java-Migration" \<br />  -p ~/root/transform-workspace/mainframe-source/source-code \<br />  -c "mvn clean install"<br /><br /># Resume interrupted execution:<br />atx -resume<br /># OR<br />atx --conversation-id <conversation-id><br /></pre>AWS Transform 在轉換執行期間， 會透過建置/測試命令自動驗證。 | 應用程式開發人員 | 

### 驗證和交付經過測試的程式碼
<a name="validate-and-deliver-tested-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢閱轉換驗證摘要。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transform-easytrieve-modern-languages.html) | 應用程式開發人員 | 
| 存取驗證報告。 | 輸入這些命令來檢閱詳細的驗證成品：<pre># Full validation report<br />cat ~/.aws/atx/custom/$LATEST_SESSION/artifacts/validation_report.html<br /><br /># Generated code location<br />ls ~/.aws/atx/custom/$LATEST_SESSION/generated/<br /><br /># Execution logs<br />cat ~/.aws/atx/custom/$LATEST_SESSION/logs/execution.log</pre> | 應用程式開發人員 | 
| 啟用知識項目以進行持續學習。 | 將建議的知識項目提升為持久性組態，以改善未來的轉型準確性。轉換後，代理程式會將已識別的模式和映射規則存放在本機工作階段目錄中。若要檢閱並套用這些學到的項目，請在 Amazon EC2 執行個體上執行這些命令：<pre># List all knowledge items for a specific transformation definition<br />atx custom def list-ki -n <transformation-name><br /><br /># Retrieve the details of a specific knowledge item<br />atx custom def get-ki -n <transformation-name> --id <id><br /><br /># Update the status of a knowledge item (ENABLED or DISABLED)<br />atx custom def update-ki-status -n <transformation-name> --id <id> --status ENABLED<br /><br /># Update the knowledge item configuration to enable auto-approval<br />atx custom def update-ki-config -n <transformation-name> --auto-enabled TRUE</pre> | 應用程式開發人員 | 

## 疑難排解
<a name="transform-easytrieve-modern-languages-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| *輸入和輸出路徑組態*輸入檔案未讀取，或輸出檔案未正確寫入。  | 指定存放輸入檔案的完整目錄路徑，並清楚指出輸出應寫入的位置。確保已為這些目錄設定適當的存取許可。 最佳實務包括使用絕對路徑而非相對路徑來避免模棱兩可的情況，並驗證所有指定的路徑都具有適當的讀取/寫入許可。  | 
| *繼續中斷的執行*執行中斷或需要從停止的位置繼續執行 | 您可以在 CLI 命令中提供對話 ID，從您離開的地方繼續執行。在先前執行嘗試的日誌中尋找對話 ID。   | 
| *解決記憶體限制*執行期間發生記憶體不足錯誤。 | 您可以要求 AWS Transform 共用目前的記憶體內 JVM 大小，然後根據此資訊增加記憶體配置。此調整有助於因應更大的處理需求。如果記憶體限制在調整後仍存在，請考慮將大型任務分成較小的批次。  | 
| *解決輸出檔案差異*輸出檔案不符合預期，且 AWS Transform 表示無法進行進一步變更。 | 提供具體的意見回饋和技術原因，說明目前輸出不正確的原因。包含其他技術或商業文件，以支援您的需求。此詳細內容有助於 AWS Transform 修正程式碼，以產生適當的輸出檔案。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transform-easytrieve-modern-languages.html) | 

## 相關資源
<a name="transform-easytrieve-modern-languages-resources"></a>
+ [AWS Transform 自訂文件](https://docs.aws.amazon.com/transform/latest/userguide/custom.html)
+ [Easytrieve 報告產生器 11.6](https://techdocs.broadcom.com/us/en/ca-mainframe-software/devops/ca-easytrieve-report-generator/11-6/getting-started.html)

## 附件
<a name="attachments-71f15422-42cb-4c7e-94fa-051a4f130445"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/71f15422-42cb-4c7e-94fa-051a4f130445/attachments/attachment.zip)

# 更多模式
<a name="mainframe-more-patterns-pattern-list"></a>

**Topics**
+ [使用 Terraform 部署 AWS WAF 解決方案的安全自動化](deploy-the-security-automations-for-aws-waf-solution-by-using-terraform.md)
+ [使用 Precisely Connect 將大型主機資料庫複寫至 AWS](replicate-mainframe-databases-to-aws-by-using-precisely-connect.md)