Skip to content

Commit

Permalink
Added credentials to client
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Mar 4, 2025
1 parent a6b7768 commit 6bc5bbf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cumulus_library/databases/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ def __init__(self, region: str, work_group: str, profile: str, schema_name: str)
self.profile = profile
self.schema_name = schema_name
self.connection = None
self.connect_kwargs = {}

def init_errors(self): # pragma: no cover
return ["COLUMN_NOT_FOUND", "TABLE_NOT_FOUND"]

def connect(self):
# the profile may not be required, provided the above three AWS env vars
# are set. If both are present, the env vars take precedence
connect_kwargs = {}
if self.profile is not None:
connect_kwargs["profile_name"] = self.profile
self.connect_kwargs["profile_name"] = self.profile
for aws_env_name in [
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_SESSION_TOKEN",
]:
if aws_env_val := os.environ.get(aws_env_name):
connect_kwargs[aws_env_name.lower()] = aws_env_val
self.connect_kwargs[aws_env_name.lower()] = aws_env_val

self.connection = pyathena.connect(
region_name=self.region,
work_group=self.work_group,
schema_name=self.schema_name,
**connect_kwargs,
**self.connect_kwargs,
)

def cursor(self) -> AthenaCursor:
Expand Down Expand Up @@ -148,7 +148,10 @@ def _clean_bucket_path(self, client, bucket, res):
def export_table_as_parquet(
self, table_name: str, file_name: str, location: pathlib.Path, *args, **kwargs
) -> bool:
s3_client = boto3.client("s3")
session = boto3.session.Session(
**self.connect_kwargs,
)
s3_client = session.client("s3")
workgroup = self.connection._client.get_work_group(WorkGroup=self.work_group)
wg_conf = workgroup["WorkGroup"]["Configuration"]["ResultConfiguration"]
s3_path = wg_conf["OutputLocation"]
Expand Down

0 comments on commit 6bc5bbf

Please sign in to comment.