Skip to content

Instantly share code, notes, and snippets.

@valerybriz
Forked from dan-hook/rename_table.py
Last active June 1, 2020 23:03
Show Gist options
  • Save valerybriz/69e18576ace09844bd337e96c887ef1a to your computer and use it in GitHub Desktop.
Save valerybriz/69e18576ace09844bd337e96c887ef1a to your computer and use it in GitHub Desktop.
"Rename" an AWS Glue table by creating a new table
import boto3
from settings import AWS_PROFILE
database_name = "test"
new_database_name = "newdb"
table_name = "table_name"
new_table_name = "new_table_name"
session = boto3.session.Session(profile_name=AWS_PROFILE)
client = session.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")
table_input.pop("DatabaseName")
table_input.pop("IsRegisteredWithLakeFormation")
create_response = client.create_table(DatabaseName=new_database_name, TableInput=table_input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment