Files
doczyai-pipelines/archive/Doczy.AI_Automation/config/aws_conn.py
T

35 lines
992 B
Python
Raw Normal View History

2024-08-21 19:26:08 +05:30
import boto3
from botocore.exceptions import ClientError
import snowflake.connector
def get_files(s3_client, path, client_bucket, batch_id):
2024-09-30 12:21:29 +01:00
batch_objects = s3_client.list_objects_v2(
Bucket=client_bucket, Prefix=path + "/" + batch_id, Delimiter="/"
)
2024-08-21 19:26:08 +05:30
file_list = []
2024-09-30 12:21:29 +01:00
for prefix in batch_objects["CommonPrefixes"]:
file_list.append(prefix["Prefix"][:-1].split("/")[-1])
2024-08-21 19:26:08 +05:30
file_count = len(file_list)
return file_count, file_list
def get_s3_client():
region_name = "us-east-2"
2024-09-30 12:21:29 +01:00
s3_client = boto3.client("s3", region_name=region_name)
2024-08-21 19:26:08 +05:30
return s3_client
def get_snowflake_conn(schema):
2024-09-30 12:21:29 +01:00
secret = "" # get_secret()
2024-08-21 19:26:08 +05:30
secret_dict = eval(secret)
conn = snowflake.connector.connect(
2024-09-30 12:21:29 +01:00
user=secret_dict["user"],
password=secret_dict["password"],
account=secret_dict["account_alias"],
warehouse=secret_dict["warehouse"],
database=secret_dict["database"],
schema=schema,
2024-08-21 19:26:08 +05:30
)
2024-09-30 12:21:29 +01:00
return conn