Skip to content

GetTableMetadata (AWS Athena) should pass configured work_group parameter #645

@smuthali

Description

@smuthali

Repository: https://github.com/laughingman7743/PyAthena

Problem

When using PyAthena with a configured work_group, the GetTableMetadata API call does not include the WorkGroup parameter, even though the AWS API supports it. This forces IAM policies to use workgroup/* wildcards instead of specific workgroup ARNs, which is less secure than necessary.

Reproduction

from pyathena import connect

conn = connect(
    work_group='my-workgroup',
    region_name='us-west-2'
)
cursor = conn.cursor()
# This triggers GetTableMetadata without passing WorkGroup
cursor.execute("SELECT * FROM my_catalog.my_database.my_table")

CloudTrail for the GetTableMetadata call shows no workGroup parameter:

  "requestParameters": {
      "catalogName": "s3tablescatalog/my-bucket",
      "databaseName": "my-database",
      "tableName": "my_table"
  }

Expected Behavior

The GetTableMetadata call should include WorkGroup=my-workgroup when a work_group is configured:

  "requestParameters": {
      "catalogName": "s3tablescatalog/my-bucket",
      "databaseName": "my-database",
      "tableName": "my_table",
      "workGroup": "my-workgroup"
  }

Impact

Without the workgroup parameter, IAM policies must allow:
"arn:aws:athena:us-west-2:123456789:workgroup/*"

Instead of the more restrictive:
"arn:aws:athena:us-west-2:123456789:workgroup/my-workgroup"

Suggested Fix

Pass WorkGroup to the get_table_metadata boto3call when self.work_group is configured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions