Skip to content
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

Update Boto3 API calls in ECSOperator #16050

Merged
merged 8 commits into from
Jun 23, 2021
Merged

Update Boto3 API calls in ECSOperator #16050

merged 8 commits into from
Jun 23, 2021

Conversation

scottypate
Copy link
Contributor

This PR corrects two errors that can occur when utilizing the parameter reattach=True. These two errors are detailed below.

  1. The describe_task_definition() function requires a named keyword argument instead of a positional argument. The current error generated is...
[2021-05-25 14:33:24,145] {{taskinstance.py:1455}} ERROR - describe_task_definition() only accepts keyword arguments.
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1112, in _run_raw_task
    self._prepare_and_execute_task_with_callbacks(context, task)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1285, in _prepare_and_execute_task_with_callbacks
    result = self._execute_task(context, task_copy)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1310, in _execute_task
    result = task_copy.execute(context=context)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/providers/amazon/aws/operators/ecs.py", line 193, in execute
    self._try_reattach_task()
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/providers/amazon/aws/operators/ecs.py", line 244, in _try_reattach_task
    task_def_resp = self.client.describe_task_definition(self.task_definition)
  File "/home/airflow/.local/lib/python3.8/site-packages/botocore/client.py", line 354, in _api_call
    raise TypeError(
TypeError: describe_task_definition() only accepts keyword arguments.
  1. The list_tasks() function cannot provide both launch_type and family as a filter criteria. The current error generated is...
[2021-05-25 12:32:18,441] {{taskinstance.py:1455}} ERROR - An error occurred (InvalidParameterException) when calling the ListTasks operation: cannot specify filters 'launchType' and 'family' at the same time
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1112, in _run_raw_task
    self._prepare_and_execute_task_with_callbacks(context, task)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1285, in _prepare_and_execute_task_with_callbacks
    result = self._execute_task(context, task_copy)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 1310, in _execute_task
    result = task_copy.execute(context=context)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/providers/amazon/aws/operators/ecs.py", line 193, in execute
    self._try_reattach_task()
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/providers/amazon/aws/operators/ecs.py", line 247, in _try_reattach_task
    list_tasks_resp = self.client.list_tasks(
  File "/home/airflow/.local/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/botocore/client.py", line 676, in _make_api_call
    raise error_class(parsed_response, operation_name)

When creating a task definition with the same family name but changing the launch_type, then it creates a new revision of the task with the same family name. I removed this launch_type parameter from this function. The ECS task will be running the latest version of the task definition and I don't think it would be possible to be running the same family of task definition on multiple launch_type strategies.

@boring-cyborg boring-cyborg bot added area:providers provider:amazon-aws AWS/Amazon - related issues labels May 25, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented May 25, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@scottypate
Copy link
Contributor Author

👋 @darwinyip, since you added the reattach option to this operator I wonder if you would look at this PR and see if it makes sense to you.

Copy link
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a straight_forward fix.

@potiuk potiuk closed this Jun 13, 2021
@potiuk potiuk reopened this Jun 13, 2021
@potiuk
Copy link
Member

potiuk commented Jun 13, 2021

Reopened to rebuild it.

@eladkal
Copy link
Contributor

eladkal commented Jun 14, 2021

@scottypate can you rebase? it will most likely solve the CI build issue

ecs_task_family = task_def_resp['taskDefinition']['family']

list_tasks_resp = self.client.list_tasks(
cluster=self.cluster, launchType=self.launch_type, desiredStatus='RUNNING', family=ecs_task_family
cluster=self.cluster, desiredStatus='RUNNING', family=ecs_task_family
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you decide which of the two arguments to drop?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the op explained it in the PR description. I think it makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, must have missed that!

@potiuk potiuk merged commit 2ab2cbf into apache:main Jun 23, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 23, 2021

Awesome work, congrats on your first merged pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants