Skip to content

Instantly share code, notes, and snippets.

@dan-hook
Created June 6, 2018 14:32
Show Gist options
  • Save dan-hook/843ac18047906e506f447becc4231a61 to your computer and use it in GitHub Desktop.
Save dan-hook/843ac18047906e506f447becc4231a61 to your computer and use it in GitHub Desktop.
"Rename" an AWS Glue table by creating a new table
import boto3
database_name = "databse"
table_name = "prefix-dir_name"
new_table_name = "more_awesome_name"
client = boto3.client("glue")
response = client.get_table(DatabaseName=database_name, Name=table_name)
table_input = response["Table"]
table_input["Name"] = new_table_name
# Delete keys that cause create_table to fail
table_input.pop("CreatedBy")
table_input.pop("CreateTime")
table_input.pop("UpdateTime")
create_response = client.create_table(DatabaseName=database_name, TableInput=table_input)
@dilraj45
Copy link

dilraj45 commented Sep 9, 2020

What if the Glue table is partitioned? Table replica might not behave as expected if the partition information is not copied over.

@fjavieralba
Copy link

What if the Glue table is partitioned? Table replica might not behave as expected if the partition information is not copied over.

If the table is partitioned you need to load partitions afterwards.

You can do it using boto3.

Here is an example: https://gist.github.com/ramondeklein/fb016893c500685c976dd1e89a0b5873

@msropp
Copy link

msropp commented Dec 14, 2022

That gist listed above by @fjavieralba works really well!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment