From b1fc9163d515c5c2df0db62a5f7ba281e0cb31d0 Mon Sep 17 00:00:00 2001 From: Eli Acherkan <69798096+eacherkan-aternity@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:08:52 +0300 Subject: [PATCH] ecs_taskdefinition: use `aws_retry` to avoid throttling exception (#2124) SUMMARY Fixes #2123 by adding aws_retry=True to the API calls. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ecs_taskdefinition ADDITIONAL INFORMATION We observed that ecs_taskdefinition intermittently causes a ThrottlingException when running on a task definition with a large number of revisions. Looking at the code, it appears that describe_task_definitions loops over the revisions without using the retry mechanism. This PR attempts to solve the problem by adding aws_retry=True to the API calls. Due to the nature of the problem (intermittent throttling by AWS), I couldn't devise automated tests that validate the fix. Reviewed-by: Alina Buzachis Reviewed-by: Mark Chappell Reviewed-by: Eli Acherkan (cherry picked from commit 97131eca035974f41ad17357ef9bef8a0a61f675) --- .../fragments/2124-add-retry-to-ecs_taskdefinition.yml | 2 ++ plugins/modules/ecs_taskdefinition.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/2124-add-retry-to-ecs_taskdefinition.yml diff --git a/changelogs/fragments/2124-add-retry-to-ecs_taskdefinition.yml b/changelogs/fragments/2124-add-retry-to-ecs_taskdefinition.yml new file mode 100644 index 00000000000..cd03aab2d41 --- /dev/null +++ b/changelogs/fragments/2124-add-retry-to-ecs_taskdefinition.yml @@ -0,0 +1,2 @@ +bugfixes: + - ecs_taskdefinition - avoid throttling exceptions on task definitions with a large number of revisions by using the retry mechanism (https://github.com/ansible-collections/community.aws/issues/2123). diff --git a/plugins/modules/ecs_taskdefinition.py b/plugins/modules/ecs_taskdefinition.py index 25a786e4f4c..9f8871def49 100644 --- a/plugins/modules/ecs_taskdefinition.py +++ b/plugins/modules/ecs_taskdefinition.py @@ -916,7 +916,7 @@ def fetch(): if data["nextToken"]: params["nextToken"] = data["nextToken"] - result = self.ecs.list_task_definitions(**params) + result = self.ecs.list_task_definitions(aws_retry=True, **params) data["taskDefinitionArns"] += result["taskDefinitionArns"] data["nextToken"] = result.get("nextToken", None) return data["nextToken"] is not None @@ -929,7 +929,7 @@ def fetch(): return list( sorted( [ - self.ecs.describe_task_definition(taskDefinition=arn)["taskDefinition"] + self.ecs.describe_task_definition(aws_retry=True, taskDefinition=arn)["taskDefinition"] for arn in data["taskDefinitionArns"] ], key=lambda td: td["revision"], @@ -937,7 +937,7 @@ def fetch(): ) def deregister_task(self, taskArn): - response = self.ecs.deregister_task_definition(taskDefinition=taskArn) + response = self.ecs.deregister_task_definition(aws_retry=True, taskDefinition=taskArn) return response["taskDefinition"]