I am using AWS Glue and you cannot read/write multiple dynamic frame without using an iteration. I made this code below but am struggling on 2 things:
- Is "tableName" i.e. the filtered list of tables correct (all the tables I want to iterate on start with client_historical_*).
- I am stuck on how to dynamically populate the Redshift table name using the mapping below.
Redshift mappings:
client_historical_ks --> table_01_a
client_historical_kg --> table_01_b
client_historical_kt --> table_01_c
client_historical_kf --> table_01_d
Code:
client = boto3.client('glue',region_name='us-east-1')
databaseName = 'incomingdata'
tables = client.get_tables(DatabaseName = databaseName)
tableList = tables['TableList']
for table in tableList:
start_prefix = client_historical_
tableName = list(filter(lambda x: x.startswith(start_prefix), table['Name']))
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "incomingdata", table_name = tableName, transformation_ctx = "datasource0")
datasink4 = glueContext.write_dynamic_frame.from_jdbc_conf(frame = datasource0, catalog_connection = "Redshift", connection_options = {"dbtable": "nameoftablehere", "database": "metadata"}, redshift_tmp_dir = args["TempDir"], transformation_ctx = "datasink4")