使用新的 Amazon Glue DynamoDB Export 加速 Amazon DynamoDB 数据访问评论源

Amazon DynamoDB
0
0
{"value":"### **背景介绍**\n**智能湖仓**鼓励数据湖、数据仓库和专用数据存储的集成,从而实现统一治理和轻松数据移动。借助亚马逊云科技上的智能湖仓,您可以将数据存储在数据湖中,并在湖周围使用一系列专门构建的数据服务,从而快速灵活地做出决策。为了实现智能湖仓,可使用 **Amazon Glue** 这项关键服务,它通过数据湖、数据仓库和专门构建的数据存储集成数据。Amazon Glue 简化了数据移动,如由内而外、由外而内或围绕周边移动。功能强大的专用数据存储为 **Amazon DynamoDB**,它已被包括 Amazon.com 在内的数十万家公司广泛使用。将数据从 DynamoDB 移到在 **Amazon Simple Storage Service** (Amazon S3) 之上构建的数据湖非常常见。许多客户使用 Amazon Glue 提取、转换和加载 (ETL) 作业将数据从 DynamoDB 移到 Amazon S3。\n\n智能湖仓:\n[https://aws.amazon.com/cn/big-data/datalakes-and-analytics/modern-data-architecture/](https://aws.amazon.com/cn/big-data/datalakes-and-analytics/modern-data-architecture/)\nAmazon Glue:\n[https://aws.amazon.com/cn/glue/?whats-new-cards.sort-by=item.additionalFields.postDateTime&whats-new-cards.sort-order=desc](https://aws.amazon.com/cn/glue/?whats-new-cards.sort-by=item.additionalFields.postDateTime&whats-new-cards.sort-order=desc)\nAmazon DynamoDB:\n[https://aws.amazon.com/cn/dynamodb/](https://aws.amazon.com/cn/dynamodb/)\nAmazon Simple Storage Service:\n[https://aws.amazon.com/cn/s3/](https://aws.amazon.com/cn/s3/)\n\n![61ad32202eaa750ca4c286f4ad0c6deb.png](https://dev-media.amazoncloud.cn/be4b9556cd134579b10fd93060ce9765_61ad32202eaa750ca4c286f4ad0c6deb.png)\n\n现在,我们很高兴地宣布,全新 Amazon Glue DynamoDB 导出连接器正式发布。它在 **DynamoDB 表导出功能**之上而构建。这是一种可扩展且经济高效的方式,用于在 Amazon Glue ETL 作业中读取大型 DynamoDB 表数据。本文介绍了这个全新导出连接器的好处及其使用案例。以下是使用 Amazon Glue ETL 作业从 DynamoDB 表中读取的典型使用案例:\n\n- 将数据从 DynamoDB 表移到其他数据存储\n- 将数据与其他服务和应用程序集成\n- 保留历史快照以供审计\t\n- 根据 DynamoDB 数据构建 S3 数据湖并分析来自各种服务的数据,例如 **Amazon Athena, Amazon Redshift** 和 **Amazon SageMaker**\n\nDynamoDB 表导出功能:\n[https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)\nAmazon Athena:\n[https://aws.amazon.com/cn/athena/?whats-new-cards.sort-by=item.additionalFields.postDateTime&whats-new-cards.sort-order=desc](https://aws.amazon.com/cn/athena/?whats-new-cards.sort-by=item.additionalFields.postDateTime&whats-new-cards.sort-order=desc)\nAmazon Redshift:\n[https://aws.amazon.com/cn/redshift/](https://aws.amazon.com/cn/redshift/)\nAmazon SageMaker:\n[https://aws.amazon.com/cn/sagemaker/](https://aws.amazon.com/cn/sagemaker/)\n\n### **1. 全新 Amazon Glue DynamoDB 导出连接器**\n\n旧版 Amazon Glue DynamoDB 连接器通过 DynamoDB Scan API 读取 DynamoDB 表。相反,全新 Amazon Glue DynamoDB 导出连接器从快照中读取 DynamoDB 数据,而快照是从 DynamoDB 表中导出的。这种方法具有以下好处:\n\n- 不会占用源 DynamoDB 表的读取容量单位\n- 大型 DynamoDB 表的读取性能一致\n\n特别是对于超过 100 GB 的大型 DynamoDB 表,此新连接器比传统连接器快得多。\n\n要使用这个全新导出连接器,您需要提前为源 DynamoDB 表启用时间点恢复 (PITR)。\n\nDynamoDB Scan API:\n[https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html)\n时间点恢复:\n[https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/PointInTimeRecovery.html](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/PointInTimeRecovery.html)\n\n### **2. 如何在 Amazon Glue Studio Visual Editor 上使用新连接器**\n\nAmazon Glue Studio Visual Editor 是一个图形界面,可以轻松地在 Amazon Glue 中创建、运行和监控 Amazon Glue ETL 作业。Amazon Glue Studio Visual Editor 提供全新 DynamoDB 导出连接器。您可以选择 Amazon DynamoDB 作为源。\n\n![9d200178720a8f3d4c430176b4669536.png](https://dev-media.amazoncloud.cn/42597a3d688643588aab4e1b524311ee_9d200178720a8f3d4c430176b4669536.png)\n\n选择 **Create**(创建)后,您将看到可视 Directed Acyclic Graph (DAG) 。在此处,您可以选择此账户或区域中存在的 DynamoDB 表。这样,您可以在 Amazon Glue Studio 中直接选择 DynamoDB 表(启用了 PITR)作为源。这提供了从任何 DynamoDB 表到 Amazon S3 的一键式导出。您还可以轻松地向 DAG 添加任何数据源和目标或转换。例如,它允许您联接两个不同的 DynamoDB 表,并将结果导出到 Amazon S3,如以下屏幕截图所示。\n\n![94acacd60ddb7ebbe1fc170c23e2a842.png](https://dev-media.amazoncloud.cn/f10bec27e97744b3b02898d8c1dfb12f_94acacd60ddb7ebbe1fc170c23e2a842.png)\n\n以下两个连接选项会自动添加。此位置用于在 DynamoDB 导出阶段存储临时数据。您可以设置 **S3 存储桶生命周期策略**([https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html)),使临时数据过期。\n\n- **dynamodb.s3.bucket** – 用于在 DynamoDB 导出期间存储临时数据的 S3 存储桶\n- **dynamodb.s3.prefix** – 用于在 DynamoDB 导出期间存储临时数据的 S3 前缀\n### **3. 如何在作业脚本代码上使用新连接器**\n\n通过配置以下连接选项,在作业脚本代码中创建 Amazon Glue DynamicFrame 时,可以使用新导出连接器:\n- **dynamodb.export** –(必需)您需要将其设置为 ddb 或 s3\n- **dynamodb.tableArn** –(必需)您的源 DynamoDB 表 ARN\n- **dynamodb.unnestDDBJson** –(可选)如果设置为 true,则执行导出中存在的 DynamoDB JSON 结构的非嵌套转换,默认值为 false\n- **dynamodb.s3.bucket** –(可选)用于在 DynamoDB 导出期间存储临时数据的 S3 存储桶\n- **dynamodb.s3.prefix** –(可选)用于在 DynamoDB 导出期间存储临时数据的 S3 前缀\n\n以下是使用新导出连接器创建 DynamicFrame 的示例 Python 代码:\n```\ndyf = glue_context.create_dynamic_frame.from_options(\nconnection_type=\"dynamodb\",\nconnection_options={\n\"dynamodb.export\": \"ddb\",\n\"dynamodb.tableArn\": \"test_source\",\n\"dynamodb.unnestDDBJson\": True,\n\"dynamodb.s3.bucket\": \"bucket name\",\n\"dynamodb.s3.prefix\": \"bucket prefix\"\n}\n)\n\n```\n与旧连接器不同,新导出连接器不需要与 Amazon Glue 作业并行度相关的配置。现在,当横向扩展 Amazon Glue 作业时,您不再需要更改配置,也不需要任何有关 DynamoDB 表读/写容量及其容量模式(按需或预置)的配置。\n### **4. DynamoDB 表架构处理**\n默认情况下,新导出连接器会读取导出中存在的 DynamoDB JSON 结构中的数据。以下是使用 Amazon Customer Review Dataset ([https://s3.amazonaws.com/amazon-reviews-pds/readme.html](https://s3.amazonaws.com/amazon-reviews-pds/readme.html))的框架的示例架构:\n```\nroot\n|-- Item: struct (nullable = true)\n| |-- product_id: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- review_id: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- total_votes: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- product_title: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- star_rating: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- customer_id: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- marketplace: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- helpful_votes: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- review_headline: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| | |-- NULL: boolean (nullable = true)\n| |-- review_date: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- vine: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- review_body: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| | |-- NULL: boolean (nullable = true)\n| |-- verified_purchase: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- product_category: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- year: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- product_parent: struct (nullable = true)\n| | |-- S: string (nullable = true)\n```\n要在不处理嵌套数据的情况下读取 DynamoDB 项列,可以将 **dynamodb.unnestDDBJson** 设置为 True。以下是相同数据架构下将 **dynamodb.unnestDDBJson** 设置为 True 的示例:\n```\nroot\n|-- product_id: string (nullable = true)\n|-- review_id: string (nullable = true)\n|-- total_votes: string (nullable = true)\n|-- product_title: string (nullable = true)\n|-- star_rating: string (nullable = true)\n|-- customer_id: string (nullable = true)\n|-- marketplace: string (nullable = true)\n|-- helpful_votes: string (nullable = true)\n|-- review_headline: string (nullable = true)\n|-- review_date: string (nullable = true)\n|-- vine: string (nullable = true)\n|-- review_body: string (nullable = true)\n|-- verified_purchase: string (nullable = true)\n|-- product_category: string (nullable = true)\n|-- year: string (nullable = true)\n|-- product_parent: string (nullable = true)\n```\n### **5. 数据新鲜度**\n\n数据新鲜度是衡量原始源中活动表数据的过时程度。在新导出连接器中,选项 dynamodb.export 会影响数据新鲜度。\n\n将 **dynamodb.export** 设置为 ddb 时,Amazon Glue 作业会调用新的导出,然后将放置在 S3 存储桶中的导出读取到 DynamicFrame。它读取活动表的导出,因此,数据可能为最新数据。另一方面,将 **dynamodb.export** 设置为 s3 时,Amazon Glue 作业会跳过调用新导出,直接读取已放置在 S3 存储桶中的导出。它读取过去表的导出,因此数据可能会过时,但您可以减少触发导出的开销。\n\n下表说明了数据新鲜度以及每个选项的优缺点。\n\n![5461cdebab7c24037cda1d89be8dccab.png](https://dev-media.amazoncloud.cn/7dc5a10c885445fca1a6e7bdf59431b2_5461cdebab7c24037cda1d89be8dccab.png)\n\n### **6. 性能**\n以下基准测试显示了旧版 Amazon Glue DynamoDB 连接器和新导出连接器之间的性能改进。比较使用 DynamoDB 表存储 **TPC-DS 基准数据集**([https://www.tpc.org/tpc_documents_current_versions/pdf/tpc-ds_v2.5.0.pdf](https://www.tpc.org/tpc_documents_current_versions/pdf/tpc-ds_v2.5.0.pdf)),范围从 10 MB 到 2 TB 不等。示例 Spark 作业从 DynamoDB 表中读取数据,并计算项计数。所有 Spark 作业都在 Amazon Glue 3.0 G.2X 60 工作线程上运行。\n\n下图比较了旧连接器和新导出连接器之间的 Amazon Glue 作业持续时间。对于小型 DynamoDB 表,旧连接器速度更快。对于超过 80 GB 的大型表,新导出连接器速度更快。换句话说,对于旧连接器运行时间超过 5-10 分钟的作业,建议使用 DynamoDB 导出连接器。此外,该图还显示,新导出连接器的持续时间随着数据大小的增加而缓慢增加,而旧连接器的持续时间则随着数据大小的增加而迅速增加。这意味着新导出连接器特别适用于较大的表。\n\n![12c58650a13c2a2e995c4db69fa9f01f.png](https://dev-media.amazoncloud.cn/d080483bfb544bbc8147e9e17c1b6491_12c58650a13c2a2e995c4db69fa9f01f.png)\n\n### **7. 使用 Amazon Glue Auto Scaling**\nAmazon Glue Auto Scaling 是一项新功能,可自动调整计算资源的大小,从而提高性能,降低成本。您可以通过全新 DynamoDB 导出连接器利用 Amazon Glue Auto Scaling。\n\n如下图所示,使用 Amazon Glue Auto Scaling 时,当源 DynamoDB 表的大小为 100 GB 或更大时,新导出连接器的持续时间将比旧连接器短。在没有 Amazon Glue Auto Scaling 的情况下,它表现出了类似趋势。\n\n![40377ee0b8d02bda407544941df40f47.png](https://dev-media.amazoncloud.cn/bea3a1303a3c40d7946129438f80f468_40377ee0b8d02bda407544941df40f47.png)\n\n您可以获得成本效益,因为在 DynamoDB 导出期间的大部分时间内,只有 Spark 驱动程序处于活动状态(这几乎占了使用基于扫描的旧版连接器的总作业持续时间的 30%)。\n\n### **结论**\nAmazon Glue 是一项与多个数据存储集成的关键服务。在亚马逊云科技,我们不断提高服务性能和成本效益。在本文中,我们宣布推出了全新 Amazon Glue DynamoDB 导出连接器。有了这个新连接器,您可以轻松地将大型 DynamoDB 表的数据与不同数据存储相集成。它可帮您以更低的成本从 Amazon Glue 作业中更快地读取大型表。\n\n新 Amazon Glue DynamoDB 导出连接器现已在所有受支持的 Glue 区域中正式推出。立即开始使用全新 Amazon Glue DynamoDB 导出连接器吧!期待您提供反馈和故事,便于我们了解您如何使用连接器来满足您的需求。\n### **关于作者**\n\n\n**Noritaka Sekiyama**\nAmazon Glue 团队的首席大数据架构师。他负责构建软件工件,帮助客户在云中构建数据湖。\n\n\n**Neil Gupta**\nAmazon Glue 团队的软件开发工程师。他喜欢处理大数据问题和学习更多关于分布式系统的知识。\n\n\n**Andrew Kim**\nAmazon Glue 团队的软件开发工程师。在为具有挑战性的问题构建可扩展、高效的解决方案和使用分布式系统方面,他充满激情。\n\n\n**Savio Dsouza**\nAmazon Glue 团队的软件开发经理。他的团队致力于分布式系统,以高效管理 Amazon 上的数据湖,并优化 Apache Spark 以提高性能和可靠性。\n\n[阅读原文](https://aws.amazon.com/cn/blogs/china/accelerate-amazon-dynamodb-data-access-in-aws-glue-jobs-using-the-new-aws-glue-dynamodb-elt-connector-feed/?sc_channel=sm&sc_campaign=blog&sc_publisher=wechatdev&sc_detail=)","render":"<h3><a id=\"_0\"></a><strong>背景介绍</strong></h3>\n<p><strong>智能湖仓</strong>鼓励数据湖、数据仓库和专用数据存储的集成,从而实现统一治理和轻松数据移动。借助亚马逊云科技上的智能湖仓,您可以将数据存储在数据湖中,并在湖周围使用一系列专门构建的数据服务,从而快速灵活地做出决策。为了实现智能湖仓,可使用 <strong>Amazon Glue</strong> 这项关键服务,它通过数据湖、数据仓库和专门构建的数据存储集成数据。Amazon Glue 简化了数据移动,如由内而外、由外而内或围绕周边移动。功能强大的专用数据存储为 <strong>Amazon DynamoDB</strong>,它已被包括 Amazon.com 在内的数十万家公司广泛使用。将数据从 DynamoDB 移到在 <strong>Amazon Simple Storage Service</strong> (Amazon S3) 之上构建的数据湖非常常见。许多客户使用 Amazon Glue 提取、转换和加载 (ETL) 作业将数据从 DynamoDB 移到 Amazon S3。</p>\n<p>智能湖仓:<br />\n<a href=\"https://aws.amazon.com/cn/big-data/datalakes-and-analytics/modern-data-architecture/\" target=\"_blank\">https://aws.amazon.com/cn/big-data/datalakes-and-analytics/modern-data-architecture/</a><br />\nAmazon Glue:<br />\n<a href=\"https://aws.amazon.com/cn/glue/?whats-new-cards.sort-by=item.additionalFields.postDateTime&amp;whats-new-cards.sort-order=desc\" target=\"_blank\">https://aws.amazon.com/cn/glue/?whats-new-cards.sort-by=item.additionalFields.postDateTime&amp;whats-new-cards.sort-order=desc</a><br />\nAmazon DynamoDB:<br />\n<a href=\"https://aws.amazon.com/cn/dynamodb/\" target=\"_blank\">https://aws.amazon.com/cn/dynamodb/</a><br />\nAmazon Simple Storage Service:<br />\n<a href=\"https://aws.amazon.com/cn/s3/\" target=\"_blank\">https://aws.amazon.com/cn/s3/</a></p>\n<p><img src=\"https://dev-media.amazoncloud.cn/be4b9556cd134579b10fd93060ce9765_61ad32202eaa750ca4c286f4ad0c6deb.png\" alt=\"61ad32202eaa750ca4c286f4ad0c6deb.png\" /></p>\n<p>现在,我们很高兴地宣布,全新 Amazon Glue DynamoDB 导出连接器正式发布。它在 <strong>DynamoDB 表导出功能</strong>之上而构建。这是一种可扩展且经济高效的方式,用于在 Amazon Glue ETL 作业中读取大型 DynamoDB 表数据。本文介绍了这个全新导出连接器的好处及其使用案例。以下是使用 Amazon Glue ETL 作业从 DynamoDB 表中读取的典型使用案例:</p>\n<ul>\n<li>将数据从 DynamoDB 表移到其他数据存储</li>\n<li>将数据与其他服务和应用程序集成</li>\n<li>保留历史快照以供审计</li>\n<li>根据 DynamoDB 数据构建 S3 数据湖并分析来自各种服务的数据,例如 <strong>Amazon Athena, Amazon Redshift</strong> 和 <strong>Amazon SageMaker</strong></li>\n</ul>\n<p>DynamoDB 表导出功能:<br />\n<a href=\"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html\" target=\"_blank\">https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html</a><br />\nAmazon Athena:<br />\n<a href=\"https://aws.amazon.com/cn/athena/?whats-new-cards.sort-by=item.additionalFields.postDateTime&amp;whats-new-cards.sort-order=desc\" target=\"_blank\">https://aws.amazon.com/cn/athena/?whats-new-cards.sort-by=item.additionalFields.postDateTime&amp;whats-new-cards.sort-order=desc</a><br />\nAmazon Redshift:<br />\n<a href=\"https://aws.amazon.com/cn/redshift/\" target=\"_blank\">https://aws.amazon.com/cn/redshift/</a><br />\nAmazon SageMaker:<br />\n<a href=\"https://aws.amazon.com/cn/sagemaker/\" target=\"_blank\">https://aws.amazon.com/cn/sagemaker/</a></p>\n<h3><a id=\"1__Amazon_Glue_DynamoDB__30\"></a><strong>1. 全新 Amazon Glue DynamoDB 导出连接器</strong></h3>\n<p>旧版 Amazon Glue DynamoDB 连接器通过 DynamoDB Scan API 读取 DynamoDB 表。相反,全新 Amazon Glue DynamoDB 导出连接器从快照中读取 DynamoDB 数据,而快照是从 DynamoDB 表中导出的。这种方法具有以下好处:</p>\n<ul>\n<li>不会占用源 DynamoDB 表的读取容量单位</li>\n<li>大型 DynamoDB 表的读取性能一致</li>\n</ul>\n<p>特别是对于超过 100 GB 的大型 DynamoDB 表,此新连接器比传统连接器快得多。</p>\n<p>要使用这个全新导出连接器,您需要提前为源 DynamoDB 表启用时间点恢复 (PITR)。</p>\n<p>DynamoDB Scan API:<br />\n<a href=\"https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html\" target=\"_blank\">https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html</a><br />\n时间点恢复:<br />\n<a href=\"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/PointInTimeRecovery.html\" target=\"_blank\">https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/PointInTimeRecovery.html</a></p>\n<h3><a id=\"2__Amazon_Glue_Studio_Visual_Editor__46\"></a><strong>2. 如何在 Amazon Glue Studio Visual Editor 上使用新连接器</strong></h3>\n<p>Amazon Glue Studio Visual Editor 是一个图形界面,可以轻松地在 Amazon Glue 中创建、运行和监控 Amazon Glue ETL 作业。Amazon Glue Studio Visual Editor 提供全新 DynamoDB 导出连接器。您可以选择 Amazon DynamoDB 作为源。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/42597a3d688643588aab4e1b524311ee_9d200178720a8f3d4c430176b4669536.png\" alt=\"9d200178720a8f3d4c430176b4669536.png\" /></p>\n<p>选择 <strong>Create</strong>(创建)后,您将看到可视 Directed Acyclic Graph (DAG) 。在此处,您可以选择此账户或区域中存在的 DynamoDB 表。这样,您可以在 Amazon Glue Studio 中直接选择 DynamoDB 表(启用了 PITR)作为源。这提供了从任何 DynamoDB 表到 Amazon S3 的一键式导出。您还可以轻松地向 DAG 添加任何数据源和目标或转换。例如,它允许您联接两个不同的 DynamoDB 表,并将结果导出到 Amazon S3,如以下屏幕截图所示。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/f10bec27e97744b3b02898d8c1dfb12f_94acacd60ddb7ebbe1fc170c23e2a842.png\" alt=\"94acacd60ddb7ebbe1fc170c23e2a842.png\" /></p>\n<p>以下两个连接选项会自动添加。此位置用于在 DynamoDB 导出阶段存储临时数据。您可以设置 <strong>S3 存储桶生命周期策略</strong>(<a href=\"https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html\" target=\"_blank\">https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html</a>),使临时数据过期。</p>\n<ul>\n<li><strong>dynamodb.s3.bucket</strong> – 用于在 DynamoDB 导出期间存储临时数据的 S3 存储桶</li>\n<li><strong>dynamodb.s3.prefix</strong> – 用于在 DynamoDB 导出期间存储临时数据的 S3 前缀</li>\n</ul>\n<h3><a id=\"3__60\"></a><strong>3. 如何在作业脚本代码上使用新连接器</strong></h3>\n<p>通过配置以下连接选项,在作业脚本代码中创建 Amazon Glue DynamicFrame 时,可以使用新导出连接器:</p>\n<ul>\n<li><strong>dynamodb.export</strong> –(必需)您需要将其设置为 ddb 或 s3</li>\n<li><strong>dynamodb.tableArn</strong> –(必需)您的源 DynamoDB 表 ARN</li>\n<li><strong>dynamodb.unnestDDBJson</strong> –(可选)如果设置为 true,则执行导出中存在的 DynamoDB JSON 结构的非嵌套转换,默认值为 false</li>\n<li><strong>dynamodb.s3.bucket</strong> –(可选)用于在 DynamoDB 导出期间存储临时数据的 S3 存储桶</li>\n<li><strong>dynamodb.s3.prefix</strong> –(可选)用于在 DynamoDB 导出期间存储临时数据的 S3 前缀</li>\n</ul>\n<p>以下是使用新导出连接器创建 DynamicFrame 的示例 Python 代码:</p>\n<pre><code class=\"lang-\">dyf = glue_context.create_dynamic_frame.from_options(\nconnection_type=&quot;dynamodb&quot;,\nconnection_options={\n&quot;dynamodb.export&quot;: &quot;ddb&quot;,\n&quot;dynamodb.tableArn&quot;: &quot;test_source&quot;,\n&quot;dynamodb.unnestDDBJson&quot;: True,\n&quot;dynamodb.s3.bucket&quot;: &quot;bucket name&quot;,\n&quot;dynamodb.s3.prefix&quot;: &quot;bucket prefix&quot;\n}\n)\n\n</code></pre>\n<p>与旧连接器不同,新导出连接器不需要与 Amazon Glue 作业并行度相关的配置。现在,当横向扩展 Amazon Glue 作业时,您不再需要更改配置,也不需要任何有关 DynamoDB 表读/写容量及其容量模式(按需或预置)的配置。</p>\n<h3><a id=\"4_DynamoDB__84\"></a><strong>4. DynamoDB 表架构处理</strong></h3>\n<p>默认情况下,新导出连接器会读取导出中存在的 DynamoDB JSON 结构中的数据。以下是使用 Amazon Customer Review Dataset (<a href=\"https://s3.amazonaws.com/amazon-reviews-pds/readme.html\" target=\"_blank\">https://s3.amazonaws.com/amazon-reviews-pds/readme.html</a>)的框架的示例架构:</p>\n<pre><code class=\"lang-\">root\n|-- Item: struct (nullable = true)\n| |-- product_id: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- review_id: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- total_votes: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- product_title: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- star_rating: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- customer_id: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- marketplace: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- helpful_votes: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- review_headline: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| | |-- NULL: boolean (nullable = true)\n| |-- review_date: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- vine: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- review_body: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| | |-- NULL: boolean (nullable = true)\n| |-- verified_purchase: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- product_category: struct (nullable = true)\n| | |-- S: string (nullable = true)\n| |-- year: struct (nullable = true)\n| | |-- N: string (nullable = true)\n| |-- product_parent: struct (nullable = true)\n| | |-- S: string (nullable = true)\n</code></pre>\n<p>要在不处理嵌套数据的情况下读取 DynamoDB 项列,可以将 <strong>dynamodb.unnestDDBJson</strong> 设置为 True。以下是相同数据架构下将 <strong>dynamodb.unnestDDBJson</strong> 设置为 True 的示例:</p>\n<pre><code class=\"lang-\">root\n|-- product_id: string (nullable = true)\n|-- review_id: string (nullable = true)\n|-- total_votes: string (nullable = true)\n|-- product_title: string (nullable = true)\n|-- star_rating: string (nullable = true)\n|-- customer_id: string (nullable = true)\n|-- marketplace: string (nullable = true)\n|-- helpful_votes: string (nullable = true)\n|-- review_headline: string (nullable = true)\n|-- review_date: string (nullable = true)\n|-- vine: string (nullable = true)\n|-- review_body: string (nullable = true)\n|-- verified_purchase: string (nullable = true)\n|-- product_category: string (nullable = true)\n|-- year: string (nullable = true)\n|-- product_parent: string (nullable = true)\n</code></pre>\n<h3><a id=\"5__144\"></a><strong>5. 数据新鲜度</strong></h3>\n<p>数据新鲜度是衡量原始源中活动表数据的过时程度。在新导出连接器中,选项 dynamodb.export 会影响数据新鲜度。</p>\n<p>将 <strong>dynamodb.export</strong> 设置为 ddb 时,Amazon Glue 作业会调用新的导出,然后将放置在 S3 存储桶中的导出读取到 DynamicFrame。它读取活动表的导出,因此,数据可能为最新数据。另一方面,将 <strong>dynamodb.export</strong> 设置为 s3 时,Amazon Glue 作业会跳过调用新导出,直接读取已放置在 S3 存储桶中的导出。它读取过去表的导出,因此数据可能会过时,但您可以减少触发导出的开销。</p>\n<p>下表说明了数据新鲜度以及每个选项的优缺点。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/7dc5a10c885445fca1a6e7bdf59431b2_5461cdebab7c24037cda1d89be8dccab.png\" alt=\"5461cdebab7c24037cda1d89be8dccab.png\" /></p>\n<h3><a id=\"6__154\"></a><strong>6. 性能</strong></h3>\n<p>以下基准测试显示了旧版 Amazon Glue DynamoDB 连接器和新导出连接器之间的性能改进。比较使用 DynamoDB 表存储 <strong>TPC-DS 基准数据集</strong>(<a href=\"https://www.tpc.org/tpc_documents_current_versions/pdf/tpc-ds_v2.5.0.pdf\" target=\"_blank\">https://www.tpc.org/tpc_documents_current_versions/pdf/tpc-ds_v2.5.0.pdf</a>),范围从 10 MB 到 2 TB 不等。示例 Spark 作业从 DynamoDB 表中读取数据,并计算项计数。所有 Spark 作业都在 Amazon Glue 3.0 G.2X 60 工作线程上运行。</p>\n<p>下图比较了旧连接器和新导出连接器之间的 Amazon Glue 作业持续时间。对于小型 DynamoDB 表,旧连接器速度更快。对于超过 80 GB 的大型表,新导出连接器速度更快。换句话说,对于旧连接器运行时间超过 5-10 分钟的作业,建议使用 DynamoDB 导出连接器。此外,该图还显示,新导出连接器的持续时间随着数据大小的增加而缓慢增加,而旧连接器的持续时间则随着数据大小的增加而迅速增加。这意味着新导出连接器特别适用于较大的表。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/d080483bfb544bbc8147e9e17c1b6491_12c58650a13c2a2e995c4db69fa9f01f.png\" alt=\"12c58650a13c2a2e995c4db69fa9f01f.png\" /></p>\n<h3><a id=\"7__Amazon_Glue_Auto_Scaling_161\"></a><strong>7. 使用 Amazon Glue Auto Scaling</strong></h3>\n<p>Amazon Glue Auto Scaling 是一项新功能,可自动调整计算资源的大小,从而提高性能,降低成本。您可以通过全新 DynamoDB 导出连接器利用 Amazon Glue Auto Scaling。</p>\n<p>如下图所示,使用 Amazon Glue Auto Scaling 时,当源 DynamoDB 表的大小为 100 GB 或更大时,新导出连接器的持续时间将比旧连接器短。在没有 Amazon Glue Auto Scaling 的情况下,它表现出了类似趋势。</p>\n<p><img src=\"https://dev-media.amazoncloud.cn/bea3a1303a3c40d7946129438f80f468_40377ee0b8d02bda407544941df40f47.png\" alt=\"40377ee0b8d02bda407544941df40f47.png\" /></p>\n<p>您可以获得成本效益,因为在 DynamoDB 导出期间的大部分时间内,只有 Spark 驱动程序处于活动状态(这几乎占了使用基于扫描的旧版连接器的总作业持续时间的 30%)。</p>\n<h3><a id=\"_170\"></a><strong>结论</strong></h3>\n<p>Amazon Glue 是一项与多个数据存储集成的关键服务。在亚马逊云科技,我们不断提高服务性能和成本效益。在本文中,我们宣布推出了全新 Amazon Glue DynamoDB 导出连接器。有了这个新连接器,您可以轻松地将大型 DynamoDB 表的数据与不同数据存储相集成。它可帮您以更低的成本从 Amazon Glue 作业中更快地读取大型表。</p>\n<p>新 Amazon Glue DynamoDB 导出连接器现已在所有受支持的 Glue 区域中正式推出。立即开始使用全新 Amazon Glue DynamoDB 导出连接器吧!期待您提供反馈和故事,便于我们了解您如何使用连接器来满足您的需求。</p>\n<h3><a id=\"_174\"></a><strong>关于作者</strong></h3>\n<p><strong>Noritaka Sekiyama</strong><br />\nAmazon Glue 团队的首席大数据架构师。他负责构建软件工件,帮助客户在云中构建数据湖。</p>\n<p><strong>Neil Gupta</strong><br />\nAmazon Glue 团队的软件开发工程师。他喜欢处理大数据问题和学习更多关于分布式系统的知识。</p>\n<p><strong>Andrew Kim</strong><br />\nAmazon Glue 团队的软件开发工程师。在为具有挑战性的问题构建可扩展、高效的解决方案和使用分布式系统方面,他充满激情。</p>\n<p><strong>Savio Dsouza</strong><br />\nAmazon Glue 团队的软件开发经理。他的团队致力于分布式系统,以高效管理 Amazon 上的数据湖,并优化 Apache Spark 以提高性能和可靠性。</p>\n<p><a href=\"https://aws.amazon.com/cn/blogs/china/accelerate-amazon-dynamodb-data-access-in-aws-glue-jobs-using-the-new-aws-glue-dynamodb-elt-connector-feed/?sc_channel=sm&amp;sc_campaign=blog&amp;sc_publisher=wechatdev&amp;sc_detail=\" target=\"_blank\">阅读原文</a></p>\n"}
0
目录
关闭