import boto3 import csv from io import StringIO import string import secrets def read_csv_from_s3(bucket_name, filepath): s3 = boto3.client('s3') # Get the object from s3 s3_object = s3.get_object(Bucket=bucket_name, Key=filepath) # Read the CSV body from the s3 object body = s3_object['Body'].read() # Use StringIO to create a file-like object from the string csv_data = StringIO(body.decode('utf-8')) # Use csv library to read it into a list of dictionaries reader = csv.DictReader(csv_data) data = list(reader) return data def generate_api_key(): # Define the characters that will be used to generate the api key characters = string.ascii_letters + string.digits # Generate a 40 character long api key api_key = ''.join(secrets.choice(characters) for _ in range(40)) return api_key