josh-fell commented on code in PR #31585:
URL: https://github.com/apache/airflow/pull/31585#discussion_r1282591556


##########
airflow/providers/microsoft/azure/transfers/s3_to_azure_blob.py:
##########
@@ -0,0 +1,91 @@
+#
+# 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 tempfile
+from typing import TYPE_CHECKING
+
+from airflow.models import BaseOperator
+from airflow.providers.amazon.aws.hooks.s3 import S3Hook
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class S3ToAzureBlobOperator(BaseOperator):
+    """
+    This operator enables the transferring of files from an S3 Bucket to Azure 
Blob Storage container.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:S3ToAzureBlobOperator`
+
+    :param aws_conn_id: reference to a specific AWS connection
+    :param wasb_conn_id: Reference to the wasb connection.
+    :param s3_bucket: The targeted s3 bucket. This is the S3 bucket from
+        where the file is downloaded.
+    :param s3_key: The targeted s3 key. This is the specified file path for
+        downloading the file from S3.
+    :param blob_name: Name of the blob
+    :param container_name: Name of the container
+    :param create_container: Attempt to create the target container prior to 
uploading the blob. This is
+            useful if the target container may not exist yet. Defaults to 
False.
+    """
+
+    def __init__(
+        self,
+        *,
+        aws_conn_id="aws_default",
+        wasb_conn_id="wasb_default",
+        s3_bucket,
+        s3_key,

Review Comment:
   ```suggestion
           s3_bucket: str,
           s3_key: str,
   ```



##########
docs/apache-airflow-providers-microsoft-azure/operators/s3_to_azure_blob.rst:
##########
@@ -0,0 +1,61 @@
+
+ .. 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.
+
+AWS S3 to Azure Blob Storage Transfer Operator

Review Comment:
   Agreed. @RachitSharma2001 would you mind updating the doc path?



##########
airflow/providers/microsoft/azure/transfers/s3_to_azure_blob.py:
##########
@@ -0,0 +1,91 @@
+#
+# 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 tempfile
+from typing import TYPE_CHECKING
+
+from airflow.models import BaseOperator
+from airflow.providers.amazon.aws.hooks.s3 import S3Hook
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class S3ToAzureBlobOperator(BaseOperator):

Review Comment:
   Any thoughts on what could be template fields for this operator? Maybe 
`s3_bucket`, `s3_key`, `container_name`, and `blob_name`? Might be beneficial 
with some use cases especially those where these args are outputs of previous 
tasks.



##########
airflow/providers/microsoft/azure/transfers/s3_to_azure_blob.py:
##########
@@ -0,0 +1,91 @@
+#
+# 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 tempfile
+from typing import TYPE_CHECKING
+
+from airflow.models import BaseOperator
+from airflow.providers.amazon.aws.hooks.s3 import S3Hook
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class S3ToAzureBlobOperator(BaseOperator):
+    """
+    This operator enables the transferring of files from an S3 Bucket to Azure 
Blob Storage container.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:S3ToAzureBlobOperator`
+
+    :param aws_conn_id: reference to a specific AWS connection
+    :param wasb_conn_id: Reference to the wasb connection.
+    :param s3_bucket: The targeted s3 bucket. This is the S3 bucket from
+        where the file is downloaded.
+    :param s3_key: The targeted s3 key. This is the specified file path for
+        downloading the file from S3.
+    :param blob_name: Name of the blob
+    :param container_name: Name of the container
+    :param create_container: Attempt to create the target container prior to 
uploading the blob. This is
+            useful if the target container may not exist yet. Defaults to 
False.
+    """
+
+    def __init__(
+        self,
+        *,
+        aws_conn_id="aws_default",
+        wasb_conn_id="wasb_default",
+        s3_bucket,
+        s3_key,
+        blob_name: str,
+        container_name: str,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.aws_conn_id = aws_conn_id
+        self.wasb_conn_id = wasb_conn_id
+        self.s3_bucket = s3_bucket
+        self.s3_key = s3_key
+        self.blob_name = blob_name
+        self.container_name = container_name
+        self.create_container = create_container
+
+    def execute(self, context: Context) -> None:
+        s3_hook = S3Hook(self.aws_conn_id)
+        s3_client = s3_hook.get_conn()
+        azure_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
+        with tempfile.NamedTemporaryFile() as temp_file:
+            self.log.info("Downloading data from S3 bucket %s at key %s", 
self.s3_bucket, self.s3_key)
+            s3_client.download_file(self.s3_bucket, self.s3_key, 
temp_file.name)
+            self.log.info("Uploading data to blob %s", self.blob_name)
+            azure_hook.load_file(
+                file_path=temp_file.name,
+                container_name=self.container_name,
+                blob_name=self.blob_name,

Review Comment:
   What do you think about making `blob_name` an optional arg? Basically if 
`blob_name` is not provided then use `s3_key`. It's quite possible users would 
want to simply copy from one storage service to another and keep the same 
naming.



##########
tests/system/providers/microsoft/azure/example_s3_to_azure_blob.py:
##########
@@ -0,0 +1,106 @@
+#
+# 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 datetime import datetime
+
+from airflow import DAG
+from airflow.providers.amazon.aws.operators.s3 import (
+    S3CreateBucketOperator,
+    S3CreateObjectOperator,
+    S3DeleteBucketOperator,
+    S3DeleteObjectsOperator,
+)
+from airflow.providers.microsoft.azure.transfers.s3_to_azure_blob import 
S3ToAzureBlobOperator
+from airflow.utils.trigger_rule import TriggerRule
+from tests.system.providers.amazon.aws.utils import SystemTestContextBuilder
+
+BLOB_NAME = os.environ.get("AZURE_BLOB_NAME", "file.txt")
+AZURE_CONTAINER_NAME = os.environ.get("AZURE_CONTAINER_NAME", "airflow")
+DAG_ID = "example_s3_to_azure_blob"
+PREFIX_NAME = os.environ.get("AZURE_PREFIX_NAME", "20230421")
+
+sys_test_context_task = SystemTestContextBuilder().build()
+SAMPLE_DATA = "some data"
+
+with DAG(
+    DAG_ID,
+    schedule="@once",
+    start_date=datetime(2021, 1, 1),  # Override to match your needs
+    default_args={"container_name": AZURE_CONTAINER_NAME, "blob_name": 
BLOB_NAME, "prefix": PREFIX_NAME},
+) as dag:

Review Comment:
   ```suggestion
   ):
   ```
   No longer required as of Airflow 2.4



-- 
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]

Reply via email to