DynamicFrameWriter クラス
方法
__init__
__init__(glue_context)
glue_context- 使用する GlueContext クラス。
from_options
from_options(frame, connection_type, connection_options={},
format=None, format_options={}, transformation_ctx="")
指定された接続と形式を使用して DynamicFrame を書き込みます。
frame- 書き込むDynamicFrame。connection_type- 接続タイプ。有効な値には、s3、mysql、postgresql、redshift、sqlserver、およびoracleがあります。connection_options- 接続オプション (パスやデータベーステーブルなど) (オプション)。s3のconnection_typeでは、Amazon S3 パスが定義されています。connection_options = {"path": "s3://aws-glue-target/temp"}JDBC 接続の場合、いくつかのプロパティを定義する必要があります。データベース名は URL の一部である必要があることに注意してください。オプションで接続オプションに含めることができます。
警告
スクリプトにパスワードを保存することはお勧めしません。AWS Secrets Manager または AWS Glue データカタログから取得する場合には、
boto3を使用することを検討してください。connection_options = {"url": "jdbc-url/database", "user": "username", "password":passwordVariable,"dbtable": "table-name", "redshiftTmpDir": "s3-tempdir-path"}dbtableプロパティは JDBC テーブルの名前です。データベース内でスキーマをサポートする JDBC データストアの場合、schema.table-nameを指定します。スキーマを指定しない場合、デフォルトの「パブリック」スキーマが使用されます。詳しくは、「AWS Glue for Spark での ETL の接続タイプとオプション」を参照してください。
format– 形式の仕様 (オプション)。これは、Amazon Simple Storage Service (Amazon S3)、または複数の形式をサポートする AWS Glue 接続で使用されます。サポートされる形式については、「AWS Glue for Spark での入出力のデータ形式に関するオプション」を参照してください。format_options– 指定された形式についてのオプション。サポートされる形式については、「AWS Glue for Spark での入出力のデータ形式に関するオプション」を参照してください。transformation_ctx- 使用する変換コンテキスト (オプション)。
from_catalog
from_catalog(frame, name_space, table_name, redshift_tmp_dir="", transformation_ctx="")
指定されたカタログデータベースとテーブル名を使用して DynamicFrame を書き込みます。
frame- 書き込むDynamicFrame。name_space– 使用するデータベース。table_name- 使用するtable_name。redshift_tmp_dir- 使用する Amazon Redshift の一時ディレクトリ (オプション)。transformation_ctx- 使用する変換コンテキスト (オプション)。-
additional_options– AWS Glue で使用する追加のオプション。Lake Formation governed table に書き込むには、以下の追加オプションを使用することができます。
-
transactionId— (文字列) governed table への書き込みを行うトランザクション ID。このトランザクションをコミットまたは中断することはできません。書き込みが失敗します。 -
callDeleteObjectsOnCancel- (プール値、オプション)true(デフォルト) に設定すると、オブジェクトが Amazon S3 に書き込まれた後、AWS Glue で自動的にDeleteObjectsOnCancelAPIを呼び出します。詳細については、AWS Lake Formation Developer Guide の「DeleteObjectsOnCancel」を参照してください。
例: Lake Formation の governed table への書き込み
txId = glueContext.start_transaction(read_only=False) glueContext.write_dynamic_frame.from_catalog( frame=dyf, database = db, table_name = tbl, transformation_ctx = "datasource0", additional_options={"transactionId":txId}) ... glueContext.commit_transaction(txId) -
from_jdbc_conf
from_jdbc_conf(frame, catalog_connection, connection_options={}, redshift_tmp_dir = "", transformation_ctx="")
指定された JDBC 接続情報を使用して DynamicFrame を書き込みます。
frame- 書き込むDynamicFrame。catalog_connection- 使用するカタログ接続。connection_options- 接続オプション (パスやデータベーステーブルなど) (オプション)。redshift_tmp_dir- 使用する Amazon Redshift の一時ディレクトリ (オプション)。transformation_ctx- 使用する変換コンテキスト (オプション)。
write_dynamic_frame の例
この例では、POSIX パス引数を持つ S3 のconnection_type を connection_options で使用して、ローカルストレージへの書き込みを許可し、出力をローカルに書き込みます。
glueContext.write_dynamic_frame.from_options(\ frame = dyf_splitFields,\ connection_options = {'path': '/home/glue/GlueLocalOutput/'},\ connection_type = 's3',\ format = 'json')