在Amazon Glue 和Amazon Redshift ft 之间移动 - Amazon Glue
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

在Amazon Glue 和Amazon Redshift ft 之间移动

在 Amazon Redshift edshift Spark 连接器Amazon

在 ETL 脚本中使用Amazon Redshift ft Spark 连接器是通过DynamicFrame 类来执行的。使用 Spark 连接器需要在创建或写入您的文件时设置某些配置选项DynamicFrame

使用Amazon Glue Spark 连接器使用Amazon Redshift ft 所需的密钥
描述

url

Glue Spark 连接器用来连接的支持亚马逊 RedshifAmazon t 的 JDBC 的网址。您可以从 Amazon Redshift 控制台显示屏上的 Amazon Redshift 工作组配置复制此 URL,该址应始终采用该格式jdbc:redshift://host:port/redshift-database-name

dbtable

用于连接Amazon Redshift 表的名称。

redshiftTmpDir [可选]

用于存储Amazon Glue Spark 连接器在作业运行期间使用的临时数据的目录。默认值为args["TempDir"],该值使用 Amazon Redshift。

aws_iam_role

用于连接Amazon Redshift Redshift 的使用,由 ARN 指定。阅读本主题的示例,了解如何根据您的Amazon账户 ID 和 IAM 角色名称构造此 ARN。

用户 [可选]

用于连接Amazon Redshift 用户名和密码。用于连接Amazon Redshift 即使您提供了这些参数,您仍然需要关联的 IAM 角色才能访问连接器使用的其他资源。

密码 [可选]

注意

从中写入 Amazon Redshift 表时,如果DynamicFrame架构(列名及其数据类型)与 Amazon Redshift 表架构不匹配,则可能会添加其他列。DynamicFrame这种行为是故意的,目的是让 DynamicFrame对象可以灵活地将各种数据类型写入 Amazon Redshift。

有关Amazon Spark 连接器 Amazon Redshift 数据类型的信息,请参阅适用于 Apache Spark 的 Amazon Redshift 集成

示例代码段

以下示例代码段演示了如何使用(加载数据)和create_dynamic_frame_from_options(写入数据)配置、加载和write_dynamic_frame_from_jdbc_conf 写入连接到 Amazon Redshift 的DynamicFrame对象。有关 JDBC 端点的连接属性的信息可以在上找到Amazon Glue JDBC 连接属性

例 配置和使用Amazon Redshift ft 作为 ETL 任务的数据源

以下代码段可用于为您的Amazon Glue ETL 脚本加载或存储来自 Amazon Redshift 的数据。按照描述替换代码段中的注释值,以连接到您的 Amazon Redshift 数据存储。

redshift_connection_options = { # JDBC URL to Amazon Redshift Workgroup, available from the Amazon Redshift console "url": "jdbc:redshift://host:port/redshift-database-name", # `table-name`: Amazon Redshift table to load data from, in the JDBC schema.table-name or table-name format "dbtable": "table-name", "redshiftTmpDir": args["TempDir"], # `account-id`: Your Amazon account ID # `role-name`: Name of the IAM role configured for COPY, UNLOAD, and CREATE LIBRARY permissions on the table "aws_iam_role": "arn:aws:iam::account-id:role/role-name" } # In the following, glueContext is your Glue Context for the ETL job. # To load from Amazon Redshift load_rs_dynamicframe = glueContext.create_dynamic_frame_from_options("redshift", redshift_connection_options) # To write data to Amazon Redshift glueContext.write_dynamic_frame_from_jdbc_conf( # `frame-to-write`: The `DynamicFrame` object to write to Amazon Redshift frame = frame-to-write, # `connection-name`: The catalog connection to use. catalog_connection = connection-name, connection_options = redshift_connection_options, redshift_tmp_dir = args["TempDir"] )