import os from dotenv import load_dotenv import boto3 # Load environment variables from .env load_dotenv() # Get AWS credentials and bucket name from environment variables aws_access_key = os.getenv('AWS_ACCESS_KEY_ID') aws_secret_key = os.getenv('AWS_SECRET_ACCESS_KEY') bucket_name = os.getenv('AWS_BUCKET_NAME') def getFile(file_key): # Initialize S3 client s3 = boto3.client('s3', aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) # Download the file from S3 try: print("Fetching file:", file_key) # s3.download_file(bucket_name, file_key, 'downloaded_file.xml') response = s3.get_object(Bucket=bucket_name, Key=file_key) file_content = response['Body'].read().decode('utf-8') return file_content except Exception as e: print(f"Error downloading file: {e}")