AWS Quicksight是一种用于数据分析和可视化的云服务。在AWS Quicksight中,表格被称为数据集(dataset)。以下是一个解决方法,展示如何获取并展示前10张表格的代码示例:
以下是一个使用Python和Boto3(AWS SDK for Python)的示例代码:
import boto3
# Connect to AWS Quicksight
quicksight = boto3.client('quicksight', region_name='us-west-2')
# List all datasets
response = quicksight.list_data_sets()
# Sort datasets by name
datasets = response['DataSetSummaries']
datasets.sort(key=lambda x: x['Name'])
# Get the first 10 datasets
top_10_datasets = datasets[:10]
# For each dataset, create a new dataset object and ingest data
for dataset in top_10_datasets:
dataset_arn = dataset['Arn']
# Create a new dataset object
create_dataset_response = quicksight.create_data_set(
AwsAccountId='123456789012',
DataSetId=dataset['DataSetId'],
Name=dataset['Name'],
PhysicalTableMap={},
LogicalTableMap={}
)
# Ingest data into the dataset
create_ingestion_response = quicksight.create_ingestion(
AwsAccountId='123456789012',
DataSetId=dataset['DataSetId'],
IngestionId='12345678-1234-1234-1234-123456789012',
IngestionMode='SPICE',
S3Source={
'DataSourceArn': 'arn:aws:s3:::bucket-name',
'UploadSettings': {
'Format': 'CSV',
'StartFromRow': 1,
'ContainsHeader': True
}
}
)
# Create a data source object
create_datasource_response = quicksight.create_data_source(
AwsAccountId='123456789012',
DataSourceId=dataset['DataSetId'],
Name=dataset['Name'],
Type='SPICE',
DataSourceParameters={
'SPICEParameters': {
'DataSetArn': dataset_arn
}
}
)
# Create an analysis object
create_analysis_response = quicksight.create_analysis(
AwsAccountId='123456789012',
AnalysisId=dataset['DataSetId'],
Name=dataset['Name'],
SourceEntity={
'SourceTemplate': {
'DataSetReferences': [
{
'DataSetPlaceholder': 'placeholder',
'DataSetArn': dataset_arn
}
],
'Arn': 'arn:aws:quicksight:us-west-2:123456789012:template/template-id'
}
}
)
# Create a dashboard object
create_dashboard_response = quicksight.create_dashboard(
AwsAccountId='123456789012',
DashboardId=dataset['DataSetId'],
Name=dataset['Name'],
SourceEntity={
'SourceTemplate': {
'DataSetReferences': [
{
'DataSetPlaceholder': 'placeholder',
'DataSetArn': dataset_arn
}
],
'Arn': 'arn:aws:quicksight:us-west-2:123456789012:template/template-id'
}
}
)
请注意,上述代码示例是一个简化的版本,仅用于演示目的。根据实际需求,您可能需要对代码进行修改和优化。另外,请确保您已正确配置AWS凭证和权限,并将代码中的占位符值(如账户ID、ARN、桶名称等)替换为您自己的值。
上一篇:AWS Quicksight能否记住每个用户的控制/筛选设置?
下一篇:AWS QuickSight嵌入CLI错误 - aws: error: argument command: 无效的选择,有效的选择有: