How to use Boto3 to get the specified version table definition of a database from AWS Glue Data Catalog?

AWS Glue Data Catalog stores metadata about your data sources, and you can retrieve specific versions of table definitions using Boto3. This is useful when you need to access historical schema information or track changes over time.

Problem Statement

Use the Boto3 library in Python to retrieve a specific version of a table definition from AWS Glue Data Catalog. For example, retrieve version 2 of the 'security' table from the 'QA-test' database.

Required Parameters

The get_table_version function requires three mandatory parameters ?

  • DatabaseName − The name of the database containing the table
  • TableName − The name of the table
  • VersionId − The version number as a string (e.g., "2")

Implementation

Here's how to retrieve a specific table version using Boto3 ?

import boto3
from botocore.exceptions import ClientError

def get_table_version_details(database_name, table_name, version_id):
    """
    Retrieves table definition for a specified version from AWS Glue Data Catalog
    """
    session = boto3.session.Session()
    glue_client = session.client('glue')
    
    try:
        response = glue_client.get_table_version(
            DatabaseName=database_name, 
            TableName=table_name, 
            VersionId=version_id
        )
        return response
    except ClientError as e:
        raise Exception(f"boto3 client error in get_table_version_details: {e}")
    except Exception as e:
        raise Exception(f"Unexpected error in get_table_version_details: {e}")

# Example usage
result = get_table_version_details('QA-test', 'security', '2')
print(result)

Key Points

  • The VersionId parameter must be passed as a string, not an integer
  • Ensure your AWS credentials are properly configured in your default profile
  • The function returns comprehensive metadata including schema, storage location, and table properties
  • Handle both ClientError for AWS-specific errors and generic exceptions

Response Structure

The response contains a TableVersion object with detailed information about ?

  • Table metadata − Name, database, owner, creation/update times
  • Schema definition − Column names and data types
  • Storage details − S3 location, file format, compression settings
  • Version information − The specific version ID requested

Conclusion

Use get_table_version to retrieve specific versions of table definitions from AWS Glue Data Catalog. This enables version tracking and historical schema analysis for your data sources.

Updated on: 2026-03-25T18:20:18+05:30

363 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements