Querying discovered Amazon Redshift objects from applications and AI agents - Amazon Redshift
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Amazon Redshift will no longer support the use of Python UDFs after June 30, 2026. We will start enforcing it in phases. For more information on the details of Python end of life and migration options, see the blog post that was published on June 30, 2025.

Querying discovered Amazon Redshift objects from applications and AI agents

An application or an AI agent can go from an asset in the AWS Glue Data Catalog to a query on the table or view that it describes. After the prerequisites are in place, every step is an API call.

An asset tells you that a table or a view exists, and where. It doesn't hold the data. To read the data, query the provisioned cluster or serverless namespace that holds the object.

An application or an AI agent takes the following steps:

  1. Find the asset in the AWS Glue Data Catalog. For more information, see Semantic search for AWS Glue Data Catalog in the AWS Glue Developer Guide.

  2. Read the location of the object from the asset.

  3. Find the provisioned cluster, or the workgroup of the serverless namespace, that holds the object.

  4. Run the query.

Prerequisites

The principal that runs these steps needs the following:

  • Permission to read assets in AWS Glue. For more information, see Discovering assets in AWS Glue Data Catalog in the AWS Glue Developer Guide.

  • Permission to find the cluster or the workgroup: redshift:DescribeClusters for provisioned clusters, or redshift-serverless:ListNamespaces and redshift-serverless:ListWorkgroups for serverless namespaces.

  • Permission to run the query with the Amazon Redshift Data API: redshift-data:ExecuteStatement, redshift-data:DescribeStatement, and redshift-data:GetStatementResult, plus permission to get database credentials. For more information, see Choosing database authentication credentials when calling the Amazon Redshift Data API.

  • Privileges on the table or the view in the database.

Reading the location of the object from the asset

The asset of a table or a view gives you the following. For the names of the fields, see Amazon Redshift asset types and fields in the AWS Glue Data Catalog.

  • The namespace Amazon Resource Name (ARN) of the provisioned cluster or serverless namespace that holds the object.

  • The name of the database.

  • The name of the schema.

  • The name of the table or the view, and its columns.

The namespace ARN stays the same when you rename a cluster or a workgroup. The service in the ARN tells you whether a provisioned cluster or a serverless namespace holds the object:

  • A provisioned cluster – arn:aws:redshift:us-east-1:123456789012:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

  • A serverless namespace – arn:aws:redshift-serverless:us-east-1:123456789012:namespace/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222

Finding the cluster or the workgroup

For a provisioned cluster, use the describe-clusters command to list the clusters in the account and Region of the ARN, and select the one with that namespace ARN. The following example returns the cluster identifier and the status of the cluster:

aws redshift describe-clusters \ --query "Clusters[?ClusterNamespaceArn=='arn:aws:redshift:us-east-1:123456789012:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111'].[ClusterIdentifier,ClusterStatus]" \ --output text

If the cluster is paused, resume it before you run the query.

For a serverless namespace, use the list-namespaces command to find the namespace with that ARN, and then the list-workgroups command to find the workgroup that is associated with it. The following example returns the name of the namespace, and then the name of the workgroup:

aws redshift-serverless list-namespaces \ --query "namespaces[?namespaceArn=='arn:aws:redshift-serverless:us-east-1:123456789012:namespace/a1b2c3d4-5678-90ab-cdef-EXAMPLE22222'].namespaceName" \ --output text aws redshift-serverless list-workgroups \ --query "workgroups[?namespaceName=='my-namespace'].workgroupName" \ --output text

If the second command returns nothing, the namespace has no workgroup, and you can't query its objects until you create one.

Running the query

You can run the query with the Amazon Redshift Data API, which needs no driver and no network path to the cluster or the workgroup. Use the database name from the asset, and qualify the table or the view with the schema name from the asset.

The following example runs a query on a provisioned cluster:

aws redshift-data execute-statement \ --cluster-identifier my-redshift-cluster \ --database sales_db \ --sql 'SELECT * FROM "retail"."orders" LIMIT 10'

The following example runs the same query on the workgroup of a serverless namespace:

aws redshift-data execute-statement \ --workgroup-name my-workgroup \ --database sales_db \ --sql 'SELECT * FROM "retail"."orders" LIMIT 10'

The command returns the identifier of the statement. The following example uses it to check whether the statement has finished, and then to fetch the result:

aws redshift-data describe-statement --id statement-id aws redshift-data get-statement-result --id statement-id

For more information, see Using the Amazon Redshift Data API.

You can also connect with a JDBC, ODBC, or Python driver. For more information, see Connecting to an Amazon Redshift data warehouse using SQL client tools.

Considerations

The following considerations apply when you query an object that you find in the AWS Glue Data Catalog:

  • Recent changes – An asset might not show a recent change yet, because the AWS Glue Data Catalog is eventually consistent with the provisioned cluster or serverless namespace. If a query fails because the object doesn't exist, the object might have been dropped or renamed. Read the asset again and retry.

  • Names – Use the names as they appear in the asset. Enclose a name in double quotation marks if it isn't a standard identifier. For more information, see Names and identifiers in the Amazon Redshift Database Developer Guide.

  • Late-binding views without columns – If the asset of a late-binding view has no columns, you can still query the view. For more information, see Late-binding views and materialized views.