ferruzzi commented on code in PR #36722:
URL: https://github.com/apache/airflow/pull/36722#discussion_r1448091836


##########
airflow/providers/amazon/aws/executors/ecs/ecs_executor_config.py:
##########
@@ -60,6 +61,26 @@ def build_task_kwargs() -> dict:
     task_kwargs = _fetch_config_values()
     task_kwargs.update(_fetch_templated_kwargs())
 
+    try:
+        has_launch_type: bool = task_kwargs.get("launch_type") is not None
+        has_capacity_provider: bool = 
task_kwargs.get("capacity_provider_strategy") is not None
+
+        if has_capacity_provider and has_launch_type:
+            raise ValueError(
+                "capacity_provider_strategy and launch_type are mutually 
exclusive, you can not provide both."
+            )
+        elif not (has_capacity_provider or has_launch_type):
+            # Default API behavior if neither is provided is to fall back on 
the default capacity
+            # provider if it exists. Since it is not a required value, check 
if there is one
+            # before using it, and if there is not then use the FARGATE 
launch_type as
+            # the final fallback.
+            cluster = 
EcsHook().conn.describe_clusters(clusters=[task_kwargs["cluster"]])["clusters"][0]
+            if not cluster.get("defaultCapacityProviderStrategy"):
+                task_kwargs["launch_type"] = "FARGATE"
+
+    except KeyError:
+        pass

Review Comment:
   Making that a get() just changes the issue to a potential IndexError on the 
[0] at the end of the same line, but I can try to scope the try/catch a bit 
tighter like you mentioned.



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