

# DynamicFrameWriter クラス
<a name="aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer"></a>



##   方法
<a name="aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-_methods"></a>
+ [\$1\$1init\$1\$1](#aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-__init__)
+ [from\$1options](#aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-from_options)
+ [from\$1catalog](#aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-from_catalog)
+ [from\$1jdbc\$1conf](#aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-from_jdbc_conf)

## \$1\$1init\$1\$1
<a name="aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-__init__"></a>

**`__init__(glue_context)`**
+ `glue_context` - 使用する [GlueContext クラス](aws-glue-api-crawler-pyspark-extensions-glue-context.md)。

## from\$1options
<a name="aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-from_options"></a>

**`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 の接続タイプとオプション](aws-glue-programming-etl-connect.md)」を参照してください。
+ `format` – 形式の仕様 (オプション)。これは、Amazon Simple Storage Service (Amazon S3)、または複数の形式をサポートする AWS Glue 接続で使用されます。サポートされる形式については、[AWS Glue for Spark での入出力のデータ形式に関するオプション](aws-glue-programming-etl-format.md) を参照してください。
+ `format_options` – 指定された形式についてのオプション。サポートされる形式については、[AWS Glue for Spark での入出力のデータ形式に関するオプション](aws-glue-programming-etl-format.md) を参照してください。
+ `transformation_ctx` - 使用する変換コンテキスト (オプション)。

## from\$1catalog
<a name="aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-from_catalog"></a>

**`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 で自動的に `DeleteObjectsOnCancel` APIを呼び出します。詳細については、*AWS Lake Formation Developer Guide* の「[DeleteObjectsOnCancel](https://docs.aws.amazon.com/lake-formation/latest/dg/aws-lake-formation-api-transactions-api.html#aws-lake-formation-api-transactions-api-DeleteObjectsOnCancel)」を参照してください。  
**Example 例: 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\$1jdbc\$1conf
<a name="aws-glue-api-crawler-pyspark-extensions-dynamic-frame-writer-from_jdbc_conf"></a>

**`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\$1dynamic\$1frame の例
<a name="pyspark-WriteDynamicFrame-examples"></a>

この例では、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')
```