求助:如何将AWS成本使用报告集成至Tableau实现可视化
AWS成本使用报告对接Athena及Tableau步骤
一、将S3中的成本报告接入Athena
- 确认S3成本报告格式:AWS成本使用报告通常以CSV或Parquet格式存储,检查存储路径是否按时间分区(如
year=YYYY/month=MM/day=DD),分区结构能提升Athena查询效率。 - 创建Athena数据库:在Athena控制台执行SQL语句创建专属数据库:
CREATE DATABASE IF NOT EXISTS aws_cost_db; - 创建外部表映射S3数据:根据你的成本报告字段编写DDL,示例如下(需替换S3路径及匹配实际字段):
注意:如果是Parquet格式,需替换SERDE为CREATE EXTERNAL TABLE IF NOT EXISTS aws_cost_db.cost_usage_report ( `identity_line_item_id` string, `identity_time_interval` string, `bill_invoice_id` string, `bill_billing_period_start_date` string, `line_item_usage_account_id` string, `line_item_line_item_type` string, `line_item_product_code` string, `line_item_usage_type` string, `line_item_usage_amount` double, `line_item_blended_cost` double, `line_item_unblended_cost` double, `product_product_name` string, `product_region` string ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' WITH SERDEPROPERTIES ( 'serialization.format' = ',', 'field.delim' = ',', 'skip.header.line.count' = '1' ) LOCATION 's3://your-cost-report-bucket/path/to/reports/' TBLPROPERTIES ('has_encrypted_data'='false');org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe,并去掉表头配置。 - 验证数据查询:执行以下语句确认能正常读取S3数据:
SELECT * FROM aws_cost_db.cost_usage_report LIMIT 10;
二、Athena对接Tableau实现可视化
- 打开Tableau,点击「连接」→「更多」→「Amazon Athena」
- 配置连接参数:输入Athena所在的AWS区域,选择身份验证方式(IAM用户凭证或IAM角色,需确保对应权限)
- 选择数据源:连接成功后,在左侧面板选择创建好的
aws_cost_db数据库,以及cost_usage_report表 - 构建可视化:将所需字段(如
product_product_name、line_item_unblended_cost、bill_billing_period_start_date)拖入工作表,按需创建柱状图、折线图、热力图等成本分析视图。
关键注意事项
- 数据更新:AWS成本报告每日自动同步到S3,Athena会自动读取新数据;若报告结构变更,需执行
MSCK REPAIR TABLE aws_cost_db.cost_usage_report;同步表结构。 - 性能优化:优先使用Parquet格式的成本报告,配合时间分区查询,能大幅减少Athena扫描的数据量,提升查询速度。
- 权限配置:确保Athena执行角色拥有S3成本报告桶的读取权限,Tableau使用的IAM凭证拥有Athena查询权限及S3读取权限。
内容的提问来源于stack exchange,提问作者Pinky
相关产品推荐
相关产品推荐

