【发布时间】:2019-08-27 00:05:53
【问题描述】:
简单的问题:
我想知道如何使用 minio 作为本地 S3 代理来保存 Airflow 发送的数据,而不是使用 S3 或 GCS。我该怎么做呢?我可以使用 FileToGoogleCloudStorageOperator 吗?
如果不是这条本地存储路线(大型图像而不是数据库行),你会推荐什么?
谢谢!
【问题讨论】:
标签: amazon-s3 google-cloud-storage airflow minio
简单的问题:
我想知道如何使用 minio 作为本地 S3 代理来保存 Airflow 发送的数据,而不是使用 S3 或 GCS。我该怎么做呢?我可以使用 FileToGoogleCloudStorageOperator 吗?
如果不是这条本地存储路线(大型图像而不是数据库行),你会推荐什么?
谢谢!
【问题讨论】:
标签: amazon-s3 google-cloud-storage airflow minio
以similar answer 为基础,这是我在撰写本文时对最新版本的 Airflow (1.10.7) 所做的事情:
首先,使用以下信息创建一个 S3 连接:
Connection Name: '<your connection name>' # e.g. local_minio
Connection Type: S3
Extra: a JSON object with the following properties:
{
"aws_access_key_id":"your_minio_access_key",
"aws_secret_access_key": "your_minio_secret_key",
"host": "http://127.0.0.1:9000"
}
接下来,在您的 DAG 中,使用 S3Hook 创建一个任务来与数据交互。下面是一个示例,您可以根据自己的需要进行调整:
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from airflow.hooks.S3_hook import S3Hook
DEFAULT_ARGS = {
'owner': 'Airflow',
'depends_on_past': False,
'start_date': datetime(2020, 1, 13),
'email': ['airflow@example.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
dag = DAG('create_date_dimension', default_args=DEFAULT_ARGS,
schedule_interval="@once")
def write_text_file(ds, **kwargs):
with open("/tmp/test.txt", "w") as fp:
# Add file generation/processing step here, E.g.:
fp.write(ds)
# Upload generated file to Minio
s3 = S3Hook('local_minio')
s3.load_file("/tmp/test.txt",
key=f"my-test-file.txt",
bucket_name="my-bucket")
# Create a task to call your processing function
t1 = PythonOperator(
task_id='generate_and_upload_to_s3',
provide_context=True,
python_callable=write_text_file,
dag=dag
)
【讨论】: