

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

# 在 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)<br />**授予 IAM 角色的存取權**<br />若要提供 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)中，檢閱**圖形檢查器**中的工作流程執行。執行執行狀態會以顏色編碼來表示執行狀態。例如，藍色表示**進行中**，綠色表示**成功**，紅色表示**失敗**。您也可以檢閱**執行事件歷史記錄**區段中的資料表，以取得執行事件的詳細資訊。<br />如需圖形工作流程執行的範例，請參閱此模式*額外資訊*區段中的 *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/\_bulk 【status：200 request：0.100s】 | 
|  | 2022-08-10T15：53：33.172 年 5 月 00 日 | 大量寫入成功：100 個文件 | 