feluelle commented on a change in pull request #8888:
URL: https://github.com/apache/airflow/pull/8888#discussion_r427792951



##########
File path: airflow/providers/amazon/aws/example_dags/example_ecs_fargate.py
##########
@@ -64,8 +65,8 @@
     },
     network_configuration={
         "awsvpcConfiguration": {
-            "securityGroups": ["sg-123abc"],
-            "subnets": ["subnet-123456ab"],
+            "securityGroups": [os.environ.get("SECURITY_GROUP_ID")],  # or 
simply ["sg-123abc"],
+            "subnets": [os.environ.get("SUBNET_ID")],  # or simply 
["subnet-123456ab"],

Review comment:
       You can pass fall-back values to `.get`
   ```suggestion
               "securityGroups": [os.environ.get("SECURITY_GROUP_ID", 
"sg-123abc")],
               "subnets": [os.environ.get("SUBNET_ID", "subnet-123456ab")],
   ```

##########
File path: tests/providers/amazon/aws/operators/test_ecs_system.py
##########
@@ -0,0 +1,140 @@
+#
+# 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 pytest
+
+from tests.test_utils.amazon_system_helpers import AmazonSystemTest, 
AWS_DAG_FOLDER
+
+
[email protected]("amazon")
+class ECSSystemTest(AmazonSystemTest):
+    """
+    ECS System Test to run and test example ECS dags
+
+    Required variables.env file content (from your account):
+        # Auto-export all variables
+        set -a
+
+        # aws parameters
+        REGION_NAME="eu-west-1"
+        REGISTRY_ID="123456789012"
+        REPOSITORY_NAME="foobar/hello-world"
+        SUBNET_ID="subnet-068e9654a3c357a"
+        SECURITY_GROUP_ID="sg-054dc69874a651"
+        EXECUTION_ROLE_ARN="arn:aws:iam::123456789012:role/FooBarRole"
+
+        # remove all created/existing resources flag
+        # comment out to keep resources or use empty string
+        # REMOVE_RESOURCES="True"
+    """
+
+    # should be same as in the example dag
+    aws_conn_id = "aws_ecs"
+    cluster = "c"
+    task_definition = "hello-world"
+    container = "hello-world-container"
+    awslogs_group = "/ecs/hello-world"
+    awslogs_stream_prefix = "prefix_b/hello-world-container"
+
+    local_image_tag = "hello"
+    local_image_context_path = 
"/opt/airflow/tests/providers/amazon/aws/images/ecs_test_image/"
+
+    def setUp(self):
+        print("setUp")
+        super().setUp()
+        self.create_connection(
+            aws_conn_id=self.aws_conn_id,
+            region=self._region_name(),
+        )
+
+        # create repository in ecr if it does not exist
+        repository_exists, repository_uri = self.is_ecr_repository_exists(
+            aws_conn_id=self.aws_conn_id,
+            repository_name=self._repository_name(),
+            registry_id=self._registry_id(),
+        )
+        print(f"repository_exists: {repository_exists}")
+        if not repository_exists:
+            repository_uri = self.create_ecr_repository(
+                aws_conn_id=self.aws_conn_id,
+                repository_name=self._repository_name(),
+            )
+            print(f"repository_uri: {repository_uri}")
+        full_image_name = f"{repository_uri}:latest"
+
+        # prepare (build, tag, push) image
+        self.authenticate_client_to_ecr(
+            region=self._region_name(),
+        )
+        self.build_image(
+            tag=self.local_image_tag,
+            path=self.local_image_context_path,
+        )
+        self.tag_image(
+            source=f"{self.local_image_tag}:latest",
+            target=full_image_name,
+        )
+        self.push_image(
+            tag=full_image_name,
+        )

Review comment:
       +1 for public images. 
   
   I think having the ecs system test specializing only on running the existing 
image from an existing ecr repo is enough to test for. Creating the image or 
creating the ecr repo should not be part of it (my opinion).

##########
File path: tests/test_utils/amazon_system_helpers.py
##########
@@ -60,6 +84,25 @@ def execute_with_ctx(cls, cmd: List[str]):
         with provide_aws_context():
             executor.execute_cmd(cmd=cmd)
 
+    @staticmethod
+    def create_connection(aws_conn_id: str,
+                          region: str = "eu-west-1") -> None:

Review comment:
       ```suggestion
                             region: str) -> None:
   ```
   Can we let the user decide that? If necessary I would add it as variable 
(setable via env) to the example dag.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to