Module Contents Exception)[source]
Check if exception is related to ECS resource quota (CPU, MEM).

Bases: airflow.typing_compat.Protocol

A structured Protocol for boto3.client('ecs'). This is used for type hints on ECSOperator.client().

run_task(self, **kwargs)[source]

get_waiter(self, x: str)[source]

describe_tasks(self, cluster: str, tasks)[source]

stop_task(self, cluster, task, reason: str)[source]

describe_task_definition(self, taskDefinition: str)[source]

list_tasks(self, cluster: str, launchType: str, desiredStatus: str, family: str)[source]

class*, aws_conn_id: Optional[str] = 'aws_default', region_name: Optional[str] = None, log_group: str, log_stream_name: str, fetch_interval: timedelta, logger: Logger)[source]

Bases: threading.Thread

Fetches Cloudwatch log events with specific interval as a thread and sends the log events to the info channel of the provided logger.

get_last_log_messages(self, number_messages)[source]
class*, task_definition: str, cluster: str, overrides: dict, aws_conn_id: Optional[str] = None, region_name: Optional[str] = None, launch_type: str = 'EC2', capacity_provider_strategy: Optional[list] = None, group: Optional[str] = None, placement_constraints: Optional[list] = None, placement_strategy: Optional[list] = None, platform_version: Optional[str] = None, network_configuration: Optional[dict] = None, tags: Optional[dict] = None, awslogs_group: Optional[str] = None, awslogs_region: Optional[str] = None, awslogs_stream_prefix: Optional[str] = None, awslogs_fetch_interval: timedelta = timedelta(seconds=30), propagate_tags: Optional[str] = None, quota_retry: Optional[dict] = None, reattach: bool = False, number_logs_exception: int = 10, **kwargs)[source]

Bases: airflow.models.BaseOperator

Execute a task on AWS ECS (Elastic Container Service)

See also

For more information on how to use this operator, take a look at the guide: ECS Operator

  • task_definition (str) -- the task definition name on Elastic Container Service

  • cluster (str) -- the cluster name on Elastic Container Service

  • overrides (dict) -- the same parameter that boto3 will receive (templated):

  • aws_conn_id (str) -- connection id of AWS credentials / region name. If None, credential boto3 strategy will be used (

  • region_name (str) -- region name to use in AWS Hook. Override the region_name in connection (if provided)

  • launch_type (str) -- the launch type on which to run your task ('EC2' or 'FARGATE')

  • capacity_provider_strategy (list) -- the capacity provider strategy to use for the task. When capacity_provider_strategy is specified, the launch_type parameter is omitted. If no capacity_provider_strategy or launch_type is specified, the default capacity provider strategy for the cluster is used.

  • group (str) -- the name of the task group associated with the task

  • placement_constraints (list) -- an array of placement constraint objects to use for the task

  • placement_strategy (list) -- an array of placement strategy objects to use for the task

  • platform_version (str) -- the platform version on which your task is running

  • network_configuration (dict) -- the network configuration for the task

  • tags (dict) -- a dictionary of tags in the form of {'tagKey': 'tagValue'}.

  • awslogs_group (str) -- the CloudWatch group where your ECS container logs are stored. Only required if you want logs to be shown in the Airflow UI after your job has finished.

  • awslogs_region (str) -- the region in which your CloudWatch logs are stored. If None, this is the same as the region_name parameter. If that is also None, this is the default AWS region based on your connection settings.

  • awslogs_stream_prefix (str) -- the stream prefix that is used for the CloudWatch logs. This is usually based on some custom name combined with the name of the container. Only required if you want logs to be shown in the Airflow UI after your job has finished.

  • awslogs_fetch_interval (timedelta) -- the interval that the ECS task log fetcher should wait in between each Cloudwatch logs fetches.

  • quota_retry (dict) -- Config if and how to retry the launch of a new ECS task, to handle transient errors.

  • reattach (bool) -- If set to True, will check if the task previously launched by the task_instance is already running. If so, the operator will attach to it instead of starting a new task. This is to avoid relaunching a new task when the connection drops between Airflow and ECS while the task is running (when the Airflow worker is restarted for example).

  • number_logs_exception (int) -- Number of lines from the last Cloudwatch logs to return in the AirflowException if an ECS task is stopped (to receive Airflow alerts with the logs of what failed in the code running in ECS).

ui_color = #f0ede4[source]
template_fields = ['overrides'][source]
REATTACH_XCOM_KEY = ecs_task_arn[source]
REATTACH_XCOM_TASK_ID_TEMPLATE = {task_id}_task_arn[source]
execute(self, context, session=None)[source]

Create and return an AwsHook.


Was this entry helpful?