I'm not exactly sure why you want to write your data with .txt
extension, but then in your file you specify format="csv"
. If you meant as a generic text file, csv is what you want to use.
Glue DynamicFrameWriter supports custom format options, here's what you need to add to your code (also see docs here):
glue_context.write_dynamic_frame.from_options(
frame=frame,
connection_type='s3',
connection_options={
'path': outpath,
},
format='csv',
format_options={
'separator': "|"
# ...other kwargs
}
)
Please note that DynamicFrameWriter won't allow to specify a name for your file, and will also create multiple outputs based on the amount of partitions created during execution.
If you want just a single output file, you have to do:
df = df.repartition(1)
before writing to s3.