-
Notifications
You must be signed in to change notification settings - Fork 15.9k
AWS ECS Executor #34381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWS ECS Executor #34381
Changes from 39 commits
9ff62d8
226e6ff
aca382a
5e02868
22274ea
ca2b7e1
62b14cc
b7457c0
575387c
20a0c7c
a5eef70
455296a
3bbc42a
99b5d7c
466bcc7
7847c85
dca2837
08089ea
d0cdc26
3e6a854
94be3b6
50e5404
dd700bb
7d02806
23db81f
6dc7144
de69f17
4b8365e
5d6d233
5b02b5b
16a1b82
3a8895f
2ced018
c56c096
3766091
3c1d54e
2d7d1fd
4c553af
29ff7eb
603367a
162b13b
2a3119f
3de720f
5fb00f0
d2d8db3
dcca29e
6c8cb37
0e3b9ea
008695b
40f0458
7abbb97
d507073
e25b084
5d42a93
8945379
b939730
a8cdf1a
bcaf9de
59e1f6f
e5409c5
bdfd8be
5e44514
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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. | ||
|
|
||
| --- | ||
|
|
||
| aws_ecs_executor: | ||
| description: | | ||
| This section only applies if you are using the AwsEcsExecutor in | ||
| Airflow's ``[core]`` configuration. | ||
| For more information on any of these execution parameters, see the link below: | ||
| https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs/client/run_task.html | ||
| For boto3 credential management, see | ||
| https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html | ||
| options: | ||
| conn_id: | ||
| description: | | ||
| The Airflow connection (i.e. credentials) used by the ECS executor to make API calls to AWS ECS. | ||
| version_added: "2.8" | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type: string | ||
| example: "aws_default" | ||
| default: "aws_default" | ||
|
||
| region: | ||
ferruzzi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: | | ||
| The name of the AWS Region where Amazon ECS is configured. Required. | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| version_added: "2.8" | ||
| type: string | ||
| example: "us-east-1" | ||
| default: ~ | ||
| assign_public_ip: | ||
| description: | | ||
| Whether to assign a public IP address to the containers launched by the ECS executor. | ||
| For more info see url to Boto3 docs above. | ||
| version_added: "2.8" | ||
| type: boolean | ||
| example: "True" | ||
| default: "False" | ||
| cluster: | ||
| description: | | ||
| Name of the Amazon ECS Cluster. Required. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: "ecs_executor_cluster" | ||
| default: ~ | ||
| container_name: | ||
| description: | | ||
| Name of the container that will be used to execute Airflow tasks via the ECS executor. | ||
| The container should be specified in the ECS Task Definition and will receive an airflow | ||
| CLI command as an additional parameter to its entrypoint. For more info see url to Boto3 | ||
| docs above. Required. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: "ecs_executor_container" | ||
| default: ~ | ||
| launch_type: | ||
| description: | | ||
| Launch type can either be 'FARGATE' OR 'EC2'. For more info see url to | ||
| Boto3 docs above. | ||
| If the launch type is EC2, the executor will attempt to place tasks on | ||
| empty EC2 instances. If there are no EC2 instances available, no task | ||
| is placed and this function will be called again in the next heart-beat. | ||
| If the launch type is FARGATE, this will run the tasks on new AWS Fargate | ||
| instances. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: "FARGATE" | ||
| default: "FARGATE" | ||
| platform_version: | ||
| description: | | ||
| The platform version the task uses. A platform version is only specified | ||
| for tasks hosted on Fargate. If one isn't specified, the LATEST platform | ||
| version is used. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: "1.4.0" | ||
| default: "LATEST" | ||
| security_groups: | ||
| description: | | ||
| The comma-seperated IDs of the security groups associated with the task. If you | ||
| don't specify a security group, the default security group for the VPC is used. | ||
| There's a limit of 5 security groups. For more info see url to Boto3 docs above. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: "sg-XXXX,sg-YYYY" | ||
| default: ~ | ||
| subnets: | ||
| description: | | ||
| The comma-separated IDs of the subnets associated with the task or service. | ||
| There's a limit of 16 subnets. For more info see url to Boto3 docs above. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: "subnet-XXXXXXXX,subnet-YYYYYYYY" | ||
| default: ~ | ||
| task_definition: | ||
| description: | | ||
| The family and revision (family:revision) or full ARN of the task definition | ||
| to run. If a revision isn't specified, the latest ACTIVE revision is used. | ||
| For more info see url to Boto3 docs above. | ||
| version_added: "2.8" | ||
| type: string | ||
| example: executor_task_definition:LATEST | ||
| default: ~ | ||
| max_run_task_attempts: | ||
| description: | | ||
| The maximum number of times the Ecs Executor should attempt to run a task. | ||
| version_added: "2.8" | ||
| type: int | ||
| example: "3" | ||
| default: "3" | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| run_task_kwargs: | ||
| description: | | ||
| A JSON string containing arguments to provide the ECS `run_task` API (see url above). | ||
| version_added: "2.8" | ||
| type: string | ||
| example: '{"tags": {"key": "schema", "value": "1.0"}}' | ||
| default: ~ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # hadolint ignore=DL3007 | ||
| FROM apache/airflow:latest | ||
o-nikolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| USER root | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends unzip \ | ||
| # The below helps to keep the image size down | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
| RUN unzip awscliv2.zip && ./aws/install | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Add a script to run the aws s3 sync command when the container is run | ||
| COPY <<"EOF" /entrypoint.sh | ||
| #!/bin/bash | ||
|
|
||
| echo "Downloading DAGs from S3 bucket" | ||
| aws s3 sync "$S3_URL" "$CONTAINER_DAG_PATH" | ||
|
|
||
| exec "$@" | ||
| EOF | ||
|
|
||
| RUN chmod +x /entrypoint.sh | ||
|
|
||
| USER airflow | ||
|
|
||
| ## Installing Python Dependencies | ||
| # Python dependencies can be installed by providing a requirements.txt. | ||
| # If the file is in a different location, use the requirements_path build argument to specify | ||
| # the file path. | ||
| ARG requirements_path=./requirements.txt | ||
| ENV REQUIREMENTS_PATH=$requirements_path | ||
o-nikolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Uncomment the two lines below to copy the requirements.txt file to the container, and | ||
| # install the dependencies. | ||
| # COPY --chown=airflow:root $REQUIREMENTS_PATH /opt/airflow/requirements.txt | ||
| # RUN pip install --no-cache-dir -r /opt/airflow/requirements.txt | ||
|
|
||
|
|
||
| ## AWS Authentication | ||
| # The image requires access to AWS services. This Dockerfile supports 2 ways to authenticate with AWS. | ||
| # The first is using build arguments where you can provide the AWS credentials as arguments | ||
| # passed when building the image. The other option is to copy the ~/.aws folder to the container, | ||
| # and authenticate using the credentials in that folder. | ||
| # If you would like to use an alternative method of authentication, feel free to make the | ||
| # necessary changes to this file. | ||
|
|
||
| # Use these arguments to provide AWS authentication information | ||
| ARG aws_access_key_id | ||
| ARG aws_secret_access_key | ||
| ARG aws_default_region | ||
| ARG aws_session_token | ||
|
|
||
| ENV AWS_ACCESS_KEY_ID=$aws_access_key_id | ||
o-nikolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ENV AWS_SECRET_ACCESS_KEY=$aws_secret_access_key | ||
| ENV AWS_DEFAULT_REGION=$aws_default_region | ||
| ENV AWS_SESSION_TOKEN=$aws_session_token | ||
|
|
||
| # Uncomment the line below to authenticate to AWS using the ~/.aws folder | ||
| # Keep in mind the docker build context when placing .aws folder | ||
| # COPY --chown=airflow:root ./.aws /home/airflow/.aws | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Loading DAGs | ||
| # This Dockerfile supports 2 ways to load DAGs onto the container. | ||
| # One is to upload all the DAGs onto an S3 bucket, and then | ||
| # download them onto the container. The other is to copy a local folder with | ||
| # the DAGs onto the container. | ||
| # If you would like to use an alternative method of loading DAGs, feel free to make the | ||
| # necessary changes to this file. | ||
|
|
||
| ARG host_dag_path=./dags | ||
| ENV HOST_DAG_PATH=$host_dag_path | ||
| # Set host_dag_path to the path of the DAGs on the host | ||
| # COPY --chown=airflow:root $HOST_DAG_PATH $CONTAINER_DAG_PATH | ||
|
|
||
|
|
||
| # If using S3 bucket as source of DAGs, uncommenting the next ENTRYPOINT command will overwrite this one. | ||
| ENTRYPOINT [] | ||
|
|
||
| # Use these arguments to load DAGs onto the container from S3 | ||
| ARG s3_url | ||
| ENV S3_URL=$s3_url | ||
| ARG container_dag_path=/opt/airflow/dags | ||
| ENV CONTAINER_DAG_PATH=$container_dag_path | ||
| # Uncomment the line if using S3 bucket as the source of DAGs | ||
| # ENTRYPOINT ["/entrypoint.sh"] | ||
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
o-nikolas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New mechanism to enable task log output to show up in task logs for containerized executors. A previous mechanism existed for K8s only (a source of executor coupling!) a new one was added, but K8s was not migrated as part of this PR to keep the size down. More changes in settings.py and logging_mixin.py below