

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在 Amazon Web Services Cloud 中构建高级大型机文件查看器
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud"></a>

*Boopathy GOPALSAMY 和 Jeremiah O'Connor，Amazon Web Services*

## Summary
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-summary"></a>

此模式提供代码示例和步骤，帮助您构建高级工具，以使用 AWS 无服务器服务浏览和查看大型机固定格式文件。该模式提供了如何将大型机输入文件转换为用于浏览和搜索的 Amazon S OpenSearch ervice 文档的示例。文件查看器工具可以帮助您实现以下目标：
+ 保持相同的大型机文件结构和布局以保持您的 AWS 目标迁移环境中的一致性（例如，在将文件传输给外部方的批处理应用程序中，您可为文件保持相同的布局）
+ 在大型机迁移过程中加快开发和测试速度
+ 支持迁移后的维护活动

## 先决条件和限制
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-prereqs"></a>

**先决条件**
+ 一个活跃的 AWS 账户
+ 具有可由您的旧平台访问的子网的虚拟私有云（VPC）
+ 
**注意**  
输入文件及其相应的面向业务的通用语言 (COBOL) 字帖 (: 有关输入文件和 COBOL 字帖的示例，请参阅存储库中的。[gfs-mainframe-solutions](https://github.com/aws-samples/gfs-mainframe-patterns.git) GitHub 有关 COBOL 字帖的更多信息，请参阅 IBM 网站上的《[适用于 z/OS 6.3 的企业 CO](https://publibfp.boulder.ibm.com/epubs/pdf/igy6pg30.pdf) BOL 编程指南》。）

**限制**
+ 副本解析限制为不超过两个嵌套级别（出现）

## 架构
<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
+ 亚马逊 OpenSearch 服务
+ Amazon Simple Storage Service（Amazon S3）
+ AWS Lambda
+ AWS Step Functions

**目标架构**

下图显示了解析大型机输入文件并将其转换为 OpenSearch 服务文档以供浏览和搜索的过程。

![解析大型机输入文件并将其转换为服务的过程。 OpenSearch](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/36d72b00-d163-455f-9e59-e2c872e7c28a/images/cce68438-bcf2-48c1-b86b-01242235ec76.png)


下图显示了如下工作流：

1. 管理员用户或应用程序将输入文件推送到一个 S3 存储桶，并将 COBOL copybook 推送到另一个 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 服务。

1. 用户访问带有 S OpenSearch ervice 的 OpenSearch 仪表板以各种表和列格式检索数据，然后对索引数据运行查询。

## 工具
<a name="build-an-advanced-mainframe-file-viewer-in-the-aws-cloud-tools"></a>

**Amazon Web Services**
+ [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 实现核心逻辑，例如解析文件、转换数据以及将数据加载到 S OpenSearch ervice 中以进行交互式文件访问。
+ [Amazon S OpenSearch er](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/what-is.html) vice 是一项托管服务，可帮助您在 AWS 云中部署、运营和扩展 OpenSearch 服务集群。在这种模式中，您可以使用 S OpenSearch ervice 为转换后的文件编制索引，并为用户提供交互式搜索功能。
+ [Amazon Simple Storage Service（Amazon S3）](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)是一项基于云的对象存储服务，可帮助您存储、保护和检索任意数量的数据。
+ [AWS 命令行界面（AWS CLI）](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)是一种开源工具，它可帮助您通过命令行 Shell 中的命令与 Amazon Web Services 交互。
+ [AWS Identity and Access Management (AWS IAM) ](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)通过控制验证和授权使用您 AWS 资源的用户，帮助您安全地管理对您 AWS 资源的访问。
+ [AWS Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) 是一项无服务器编排服务，可帮助您搭配使用 Lambda 函数和其他 Amazon Web Services 来构建业务关键型应用程序。在这种模式中，您可使用 Step Functions 编排 Lambda 函数。

**其他工具**
+ [GitHub](https://github.com/)是一项代码托管服务，提供协作工具和版本控制。
+ [Python](https://www.python.org/) 是高级编程语言。

**代码**

此模式的代码可在 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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 S3 存储桶。 | [创建 S3 存储桶](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_cn/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_cn/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_cn/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_cn/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 常规 AWS | 
| 创建 OpenSearch 服务集群。 | **创建集群**[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/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_cn/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_cn/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html) | 常规 AWS | 

### 部署并运行
<a name="deploy-and-run"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 将输入文件和副本上传到 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_cn/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_cn/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_cn/prescriptive-guidance/latest/patterns/build-an-advanced-mainframe-file-viewer-in-the-aws-cloud.html)有关成功传送日志的示例，请参阅此模式的 “*其他信息*” 部分中的*CloudWatch 传送日*志。 | 常规 AWS | 
| 在 OpenSearch 仪表板中验证格式化后的文件并执行文件操作。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/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 文档）
+ 在@@ [亚马逊 OpenSearch 服务中使用 OpenSearch 控制面板](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_cn/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-05:00 | 处理文档数量：100 |  | 
| --- |--- |--- |
|  | 2022-08-10T15:53:33.171-05:00 | [信息] 2022-08-10T20：53:33.171 Z a1b2c3d4-5678-90ab-cdef-: 443/\_Bulk [状态:200 请求:0.100s] EXAMPLE11111 https://search-essearch-3h4uqclifeqaj2vg4mphe7ffle.us-east-2.es.amazonaws.com | 
|  | 2022-08-10T15:53:33.172-05:00 | 批量写入成功：100 个文档 | 