Last active
June 15, 2022 14:26
-
-
Save tomasoak/d2c010d6e479f433dae596e48c33c8cd to your computer and use it in GitHub Desktop.
Connect Amazon S3 to PowerBI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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