You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/07/29 13:59:28 UTC

[GitHub] [airflow] josh-fell commented on a diff in pull request #25345: Convert Local to S3 example DAG to System Test (AIP-47)

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


##########
tests/system/providers/amazon/aws/example_local_to_s3.py:
##########
@@ -0,0 +1,101 @@
+# 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.
+import os
+from datetime import datetime
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.providers.amazon.aws.operators.s3 import S3CreateBucketOperator, S3DeleteBucketOperator
+from airflow.providers.amazon.aws.transfers.local_to_s3 import LocalFilesystemToS3Operator
+from airflow.utils.trigger_rule import TriggerRule
+from tests.system.providers.amazon.aws.utils import SystemTestContextBuilder
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+
+DAG_ID = 'example_local_to_s3'
+TEMP_FILE_PATH = '/tmp/sample-txt.txt'
+SAMPLE_TEXT = 'This is some sample text.'
+
+
+@task
+def create_temp_file():
+    file = open(TEMP_FILE_PATH, 'w')
+    file.write(SAMPLE_TEXT)
+
+
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def delete_temp_file():
+    if os.path.exists(TEMP_FILE_PATH):
+        os.remove(TEMP_FILE_PATH)
+
+
+with DAG(
+    dag_id=DAG_ID,
+    schedule_interval='@once',
+    start_date=datetime(2021, 1, 1),  # Override to match your needs
+    tags=['example'],
+    catchup=False,
+) as dag:
+    test_context = sys_test_context_task()
+    env_id = test_context['ENV_ID']
+
+    s3_bucket_name = f'{env_id}-bucket'
+    s3_key = f'{env_id}/files/my-temp-file.txt'
+
+    create_s3_bucket = S3CreateBucketOperator(task_id='create-s3-bucket', bucket_name=s3_bucket_name)
+    # [START howto_transfer_local_to_s3]

Review Comment:
   These `START/END` markers in example DAGs are used in the Airflow docs as reference to code snippets. Since the example DAG moved, you'll need to update the [corresponding doc](https://github.com/apache/airflow/blob/main/docs/apache-airflow-providers-amazon/operators/transfer/local_to_s3.rst) to have this code reference point to the new file location of the markers.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org