Skip to content

Athena Boto3 start_query_execution returns CATALOG_NOT_FOUND / Table not found for Amazon S3 Tables (Iceberg) but runs perfectly in Console Editor

0

Context: I am trying to query an Amazon S3 Table (managed Iceberg tables feature) using Amazon Athena in the us-east-1 region. The S3 Table resides in a table bucket named my-s3-table-bucket-test1 under the namespace test_db, with the table named tbl_sales.

The Problem: When I open the Athena Web Console Query Editor and run a simple count query using the 3-part naming convention, it works perfectly and returns the row count immediately. However, when I submit the exact same query string programmatics-wise via an AWS Lambda function using the Python boto3 SDK (start_query_execution), it consistently fails with a catalog routing error.

Boto3 Python Implementation: The Lambda function client is explicitly initialized in us-east-1 and points to the primary workgroup (matching my console configuration). The QueryExecutionContext block is omitted to let the SQL text handle 100% of the routing:

import boto3
athena_client = boto3.client("athena", region_name="us-east-1")

params = {
    "QueryString": 'SELECT COUNT(*) FROM "s3tablescatalog/my-s3-table-bucket-test1"."test_db"."tbl_sales"',
    "WorkGroup": "primary",
    "ResultConfiguration": {
        "OutputLocation": "s3://aws-athena-query-results-6944813*****-us-east-1/logs/"
    }
}
response = athena_client.start_query_execution(**params)

The Error Log from Boto3 Execution: Athena generates a Query Execution ID successfully, but the state immediately transitions to FAILED with this error message: Reason: CATALOG_NOT_FOUND: line 1:22: Catalog 's3tablescatalog/my-s3-table-bucket-test1' does not exist

(Note: If I try to pass the catalog path inside the QueryExecutionContext block via Catalog and Database properties instead of the SQL string, it returns a similar failure)

What has been verified:

  1. Region & Workgroup: Lambda, Athena Workgroup, and the S3 Table Bucket are all strictly verified to be inside us-east-1. Both paths use the primary workgroup.
  2. IAM Policy: The Lambda function's IAM Execution Role has full administrative permissions for testing, explicitly including athena:, s3:, glue:, and s3tables: actions targeting the S3 Table Bucket ARN.
  3. Lake Formation: This catalog integration is set to use purely IAM access control—Lake Formation default permissions are not blocking it. Why is the programmatic Athena execution driver unable to parse or recognize the custom S3 Tables catalog path ("s3tablescatalog/my-s3-table-bucket-test1") when it is sent via the API, and what is the proper formatting syntax to make Boto3 align with the Web Console's background session routing?

Any thoughts and experiences, appreciated. Thanks.

asked a month ago140 views

2 Answers
0

The issue you're encountering stems from how the S3 Tables catalog needs to be specified when using the Boto3 API versus the Athena Console. When working with S3 Tables through the API, you need to explicitly pass the catalog information in the QueryExecutionContext parameter rather than relying solely on the three-part naming convention in the SQL string.

For S3 Tables queries via Boto3, the proper approach is to specify the catalog in the QueryExecutionContext using the format 's3tablescatalog/your-bucket-name' for the Catalog field and your namespace for the Database field. Here's the corrected implementation:

import boto3
athena_client = boto3.client('athena', region_name='us-east-1')

params = {
    'QueryString': 'SELECT COUNT(*) FROM tbl_sales',
    'QueryExecutionContext': {
        'Catalog': 's3tablescatalog/my-s3-table-bucket-test1',
        'Database': 'test_db'
    },
    'WorkGroup': 'primary',
    'ResultConfiguration': {
        'OutputLocation': 's3://aws-athena-query-results-6944813*****-us-east-1/logs/'
    }
}
response = athena_client.start_query_execution(**params)

Notice that when you provide the catalog and database in the QueryExecutionContext, you should use the simple table name in your SQL query rather than the fully qualified three-part name. The API requires this explicit context specification to properly route the query to the S3 Tables catalog.

The Athena Console likely handles the three-part naming convention differently in its backend, automatically parsing and routing it to the appropriate catalog. However, the start_query_execution API expects the catalog routing information to be provided through the QueryExecutionContext parameter structure.

If you previously tried passing the catalog in QueryExecutionContext and received an error, ensure you're using the exact format 's3tablescatalog/bucket-name' without any additional prefixes or modifications, and that your namespace name matches exactly what was created in your S3 table bucket.
Sources
Register S3 table bucket catalogs and query Tables from Athena - Amazon Athena
start_query_execution - Boto3 1.42.43 documentation
start_query_execution - Boto3 1.42.50 documentation
start_query_execution - botocore 1.42.50 documentation

answered a month ago

EXPERT

reviewed a month ago

  • even that gives same error. I am sure, there is some limitation via lambda python s3 table catalogs are not visible. Because same code runs from AWS CLI works well and given the result.

    "Response: { "errorMessage": "Athena query execution failed: CATALOG_NOT_FOUND: line 1:22: Catalog 's3tablescatalog/my-s3-table-bucket-test1' does not exist", "errorType": "Exception", "requestId": "43189948-8955-48c8-86b1-f349d0c5ff46" "

0

Hello.

Please use the following AWS CLI command to check the differences between the query executed from the Management Console and the one executed from Lambda.
There is a possibility that an error is occurring due to some kind of discrepancy.
https://docs.aws.amazon.com/cli/latest/reference/athena/get-query-execution.html

aws athena get-query-execution \
  --query-execution-id <successful-console-query-id> \
  --region us-east-1
EXPERT

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.