ismailsimsek commented on code in PR #46621: URL: https://github.com/apache/airflow/pull/46621#discussion_r2104645626
########## providers/amazon/src/airflow/providers/amazon/aws/bundles/s3.py: ########## @@ -0,0 +1,214 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import os +from pathlib import Path + +import structlog + +log = structlog.get_logger(__name__) + +from airflow.dag_processing.bundles.base import BaseDagBundle +from airflow.exceptions import AirflowException +from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook +from airflow.providers.amazon.aws.hooks.s3 import S3Hook + + +class S3DagBundle(BaseDagBundle): + """ + S3 DAG bundle - exposes a directory in S3 as a DAG bundle. + + This allows Airflow to load DAGs directly from an S3 bucket. + + :param aws_conn_id: Airflow connection ID for AWS. Defaults to AwsBaseHook.default_conn_name. + :param bucket_name: The name of the S3 bucket containing the DAG files. + :param prefix: Optional subdirectory within the S3 bucket where the DAGs are stored. + If None, DAGs are assumed to be at the root of the bucket (Optional). + """ + + supports_versioning = False + + def __init__( + self, + *, + aws_conn_id: str = AwsBaseHook.default_conn_name, + bucket_name: str, + prefix: str = "", + **kwargs, + ) -> None: + super().__init__(**kwargs) + self.aws_conn_id = aws_conn_id + self.bucket_name = bucket_name + self.prefix = prefix + # Local path where S3 DAGs are downloaded. + self.s3_dags_root_dir: Path = self.base_dir.joinpath("s3") + # Local path where S3 DAGs are downloaded for current config. + self.s3_dags_dir: Path = self.s3_dags_root_dir.joinpath(self.name) + + self._log = log.bind( + bundle_name=self.name, + version=self.version, + bucket_name=self.bucket_name, + prefix=self.prefix, + aws_conn_id=self.aws_conn_id, + ) + + try: + self.s3_hook: S3Hook = S3Hook(aws_conn_id=self.aws_conn_id) # Initialize S3 hook. Review Comment: Changed to lazy init property -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
