据我了解,您只需将查询发送到 AWS Athena 服务,在所有聚合步骤完成后,您只需检索结果csv
文件来自 Athena 保存结果的 S3 存储桶,因此您最终会得到 1000 个文件(每个作业一个)。但问题是并发 Athena 查询的数量,而不是总执行时间。
您是否考虑过使用阿帕奇气流 https://airflow.apache.org/用于编排和安排您的查询。我认为气流是 Lambda 和 Step Functions 组合的替代方案,但它是完全免费的。它很容易在本地和远程计算机上进行设置,具有用于任务监控的 CLI 和 GUI,抽象出所有调度和重试逻辑。气流甚至有hooks https://airflow.apache.org/_api/airflow/contrib/hooks/aws_hook/index.html与 AWS 服务交互。天啊,它甚至还有一个专职操作员 https://airflow.apache.org/_api/airflow/contrib/operators/aws_athena_operator/index.html用于向 Athena 发送查询,因此发送查询非常简单:
from airflow.models import DAG
from airflow.contrib.operators.aws_athena_operator import AWSAthenaOperator
from datetime import datetime
with DAG(dag_id='simple_athena_query',
schedule_interval=None,
start_date=datetime(2019, 5, 21)) as dag:
run_query = AWSAthenaOperator(
task_id='run_query',
query='SELECT * FROM UNNEST(SEQUENCE(0, 100))',
output_location='s3://my-bucket/my-path/',
database='my_database'
)
我将它用于类似类型的每日/每周任务(使用 CTAS 语句处理数据),这些任务超出了并发查询数量的限制。
有大量博客文章和文档可以帮助您入门。例如:
-
中柱 https://medium.com/slido-dev-blog/automate-executing-aws-athena-queries-and-moving-the-results-around-s3-with-airflow-dd3603dc611d:自动执行 AWS Athena 查询并使用 Airflow 在 S3 中移动结果。
- Airflow 安装完整指南,link 1 https://medium.com/@srivathsankr7/apache-airflow-a-practical-guide-5164ff19d18b and link 2 http://site.clairvoyantsoft.com/installing-and-configuring-apache-airflow/
您甚至可以设置与 Slack 集成 https://medium.com/datareply/integrating-slack-alerts-in-airflow-c9dcd155105用于在查询以成功或失败状态终止时发送通知。
但是,那主要缺点 https://stackoverflow.com/questions/57145967/aws-athena-concurrency-limits-number-of-submitted-queries-vs-number-of-running我面临的是,只有 4-5 个查询同时实际执行,而其他所有查询都处于空闲状态。