Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AWS profile when accessing Glue, S3 #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions dbt/adapters/athena/impl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from uuid import uuid4
import agate
import re
import boto3
import boto3.session
from botocore.exceptions import ClientError
from typing import Optional

Expand Down Expand Up @@ -50,10 +50,11 @@ def clean_up_partitions(
):
# Look up Glue partitions & clean up
conn = self.connections.get_thread_connection()
client = conn.handle
creds = conn.credentials
session = boto3.session.Session(region_name=creds.region_name, profile_name=creds.aws_profile_name)

glue_client = boto3.client('glue', region_name=client.region_name)
s3_resource = boto3.resource('s3', region_name=client.region_name)
glue_client = session.client('glue')
s3_resource = session.resource('s3')
partitions = glue_client.get_partitions(
# CatalogId='123456789012', # Need to make this configurable if it is different from default AWS Account ID
DatabaseName=database_name,
Expand All @@ -76,8 +77,10 @@ def clean_up_table(
):
# Look up Glue partitions & clean up
conn = self.connections.get_thread_connection()
client = conn.handle
glue_client = boto3.client('glue', region_name=client.region_name)
creds = conn.credentials
session = boto3.session.Session(region_name=creds.region_name, profile_name=creds.aws_profile_name)

glue_client = session.client('glue')
try:
table = glue_client.get_table(
DatabaseName=database_name,
Expand All @@ -95,7 +98,7 @@ def clean_up_table(
if m is not None:
bucket_name = m.group(1)
prefix = m.group(2)
s3_resource = boto3.resource('s3', region_name=client.region_name)
s3_resource = session.resource('s3')
s3_bucket = s3_resource.Bucket(bucket_name)
s3_bucket.objects.filter(Prefix=prefix).delete()

Expand Down