How to get the details of a user-defined function in a database from AWS Glue Data catalog using Boto3

Let's see how a user can get the details of a specified function definition from AWS Glue Data Catalog using the Boto3 library.

Problem Statement

Use boto3 library in Python to get the details of a user-defined function named insert_employee_record in database employee from AWS Glue Data Catalog.

Approach

  • Step 1: Import boto3 and botocore exceptions to handle exceptions.

  • Step 2: database_name and function_name are the required parameters. It fetches the definition of a given function in a specified database.

  • Step 3: Create an AWS session using boto3. Make sure region_name is mentioned in the default profile or pass it explicitly.

  • Step 4: Create an AWS client for glue.

  • Step 5: Call get_user_defined_function method with DatabaseName and FunctionName parameters.

  • Step 6: Handle exceptions if the function is not found or other errors occur.

Syntax

client.get_user_defined_function(
    DatabaseName='string',
    FunctionName='string'
)

Example

The following code fetches the definition of a user-defined function from AWS Glue Data Catalog ?

import boto3
from botocore.exceptions import ClientError

def get_function_definition(database_name, function_name):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    try:
        response = glue_client.get_user_defined_function(
            DatabaseName=database_name, 
            FunctionName=function_name
        )
        return response
    except ClientError as e:
        raise Exception("boto3 client error in get_function_definition: " + str(e))
    except Exception as e:
        raise Exception("Unexpected error in get_function_definition: " + str(e))

# Get function details
result = get_function_definition('employee', 'insert_employee_record')
print(result)

Output

{
    'UserDefinedFunction': {
        'FunctionName': 'insert_employee_record',
        'DatabaseName': 'employee',
        'ClassName': 'InsertEmployee',
        'OwnerName': 'admin',
        'OwnerType': 'USER',
        'CreateTime': datetime.datetime(2021, 3, 15, 10, 30, 45),
        'ResourceUris': [
            {
                'ResourceType': 'JAR',
                'Uri': 's3://my-bucket/employee-functions.jar'
            }
        ]
    },
    'ResponseMetadata': {
        'RequestId': 'abcd1234-5678-90ef-ghij-klmnopqrstuv',
        'HTTPStatusCode': 200
    }
}

Key Points

  • The get_user_defined_function method returns detailed information about a specific user-defined function.

  • Both DatabaseName and FunctionName are required parameters.

  • The response includes function metadata like class name, owner, creation time, and resource URIs.

  • Proper exception handling is essential for AWS API calls to handle missing functions or permission issues.

Conclusion

Use get_user_defined_function from Boto3 Glue client to retrieve detailed information about user-defined functions in AWS Glue Data Catalog. Always include proper exception handling for robust AWS API interactions.

Updated on: 2026-03-25T18:40:46+05:30

404 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements