可以通过以下步骤完成:
pip install boto3 pandas
import boto3
import pandas as pd
session = boto3.Session(
aws_access_key_id='YOUR_ACCESS_KEY',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='YOUR_REGION'
)
请将YOUR_ACCESS_KEY、YOUR_SECRET_KEY和YOUR_REGION替换为您自己的AWS访问密钥和区域。
quicksight_client = session.client('quicksight')
response = quicksight_client.describe_dashboard(
AwsAccountId='YOUR_ACCOUNT_ID',
DashboardId='YOUR_DASHBOARD_ID'
)
请将YOUR_ACCOUNT_ID和YOUR_DASHBOARD_ID替换为您自己的AWS账号ID和仪表板ID。
dataset_id = response['Dashboard']['Version']['DataSetArns'][0].split('/')[-1]
response = quicksight_client.get_data_set(
AwsAccountId='YOUR_ACCOUNT_ID',
DataSetId=dataset_id
)
data_source_id = response['DataSet']['PhysicalTableMap']['string']['RelationalTable']['DataSourceArn'].split('/')[-1]
response = quicksight_client.get_data_source(
AwsAccountId='YOUR_ACCOUNT_ID',
DataSourceId=data_source_id
)
connection_info = response['DataSource']['DataSourceParameters']['AuroraParameters']['SecretArn']
secretsmanager_client = session.client('secretsmanager')
response = secretsmanager_client.get_secret_value(
SecretId=connection_info
)
connection_string = response['SecretString']
connection = pd.connect(connection_string)
query = 'SELECT * FROM YOUR_TABLE'
df = pd.read_sql(query, connection)
请将YOUR_TABLE替换为您自己的表名,根据需要修改SQL查询。
df.to_csv('output.csv', index=False)
将数据保存为名为output.csv的CSV文件。
以上步骤是使用Python从Quicksight仪表板提取CSV的完整流程。请注意,这只是一个示例,具体的实现可能因为您的具体情况而有所不同。
领取专属 10元无门槛券
手把手带您无忧上云