- Newest
- Most votes
- Most comments
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
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
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated a year 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" "