MWAA ECSOperator "No task found" but succeeds

615 Views Asked by At

I have an ECSOperator task in MWAA.

When I trigger the task, it succeeds immediately. However, the task should take time to complete, so I do not believe it is actually starting.

When I go to inspect the task run, I get the error "No tasks found".

enter image description here

The task definition looks like this:

from datetime import datetime
from airflow import DAG
from airflow.providers.amazon.aws.operators.ecs import ECSOperator

dag = DAG(
  "my_dag",
  description = "",
  start_date = datetime.fromisoformat("2022-03-28"),
  catchup = False,
)

my_task = ECSOperator(
  task_id = "my_task",
  cluster = "my-cluster",
  task_definition = "my-task",
  launch_type = "FARGATE",
  aws_conn_id = "aws_ecs",
  overrides = {},
  network_configuration = {
    "awsvpcConfiguration": {
      "securityGroups": [ "sg-aaaa" ],
      "subnets": [ "subnet-bbbb" ],
    },
  },
  awslogs_group = "/ecs/my-task",
)

my_task

What am I missing here?

1

There are 1 best solutions below

0
On BEST ANSWER

If task executed it should have a log. I think your issue is that the task you defined is not assigned to any DAG object thus you see No task found error (empty DAG)

You should add dag=dag:

my_task = ECSOperator(
  task_id = "my_task",
  ...,
  dag=dag
)

or use context manager to avoid such issue:

with DAG(
    dag_id="my_dag",
   ...
) as dag:
    my_task = ECSOperator(
      task_id = "my_task",
      ...,
    
    )

If you are using Airflow 2 you can also use dag decorator.