0

Has anyone been successful in connecting PowerBI to AWS S3? Is it possible? Please provide any helpful insight as to how to accomplish this.

I have seen a couple posts about an AWS S3 API. I have no familiarity to APIs so I don't know where to begin. I have also tried using the Web connector in PowerBI Desktop thinking that's where I should begin...

TechNewbie
  • 164
  • 2
  • 15

1 Answers1

0

In Power BI, from Get Data you can select Python script and then use the boto3, an example function to download a .csv file from s3 is given below:

import io
import boto3
import pandas as pd

ACCESS_KEY_ID = 'your key id here'
SECRET_ACCESS_KEY = 'your access key here'

s3 = boto3.client('s3', aws_access_key_id = ACCESS_KEY_ID, aws_secret_access_key = SECRET_ACCESS_KEY)
   
def read_csv_file_from_s3(s3_url):

    assert s3_url.startswith('s3://'), 'Url does not starts with s3://'
    bucket_name, key_name = s3_url[5:].split('/', 1)
    response = s3.get_object(Bucket=bucket_name, Key=key_name)

    return pd.read_csv(io.BytesIO(response['Body'].read()))

s3_url = 's3://yourbucket/example.csv'
df = read_csv_file_from_s3(s3_url)

df will appear in data section in Power BI. Also some other examples of using boto3 for importing data to Power BI are given here and here.

Note: You can check and change the python interpreter Power BI is using from Options -> Global -> Python Scripting and install the required libraries/modules accordingly.

  • I followed this suggestion to use Python script, however the gateway doesn't support python script connectors, so my solution ran aground. – Dr Jeff Sinclair Apr 13 '22 at 02:33