

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

# 使用 和 Terraform 現代化 AWS Transform 和部署大型主機應用程式
<a name="modernize-mainframe-app-transform-terraform"></a>

*Mason Cahill、Qandi Jhandi、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/)。 | 一般 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/)