Skip to content

Instantly share code, notes, and snippets.

@tomasoak
Last active June 15, 2022 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasoak/d2c010d6e479f433dae596e48c33c8cd to your computer and use it in GitHub Desktop.
Save tomasoak/d2c010d6e479f433dae596e48c33c8cd to your computer and use it in GitHub Desktop.
Connect Amazon S3 to PowerBI
"""
Connect Amazon S3 file to PowerBI
"""
# Make sure these packages are installed in your local
# because the script will run in your local default Python
# otherwise: `pip install boto3` etc.
import os
import io
import boto3
import pandas as pd
# Set your keys as environmental variables
my_key = os.environ.get('AWS_ACCESS_KEY_ID')
my_secret = os.environ.get('AWS_SECRET_ACCESS_KEY')
my_bucket_name = 'you-bucket-name'
my_file_path = 'you-csv-file'
session = boto3.Session(aws_access_key_id=my_key, aws_secret_access_key=my_secret)
s3Client = session.client('s3')
file = s3Client.get_object(Bucket=my_bucket_name, Key=my_file_path)
you_file_name = pd.read_csv(io.BytesIO(file['Body'].read()), header=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment