From 84f3ec2f6aadf63c75ed53ebe5114f3d9e8720ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Tue, 18 Apr 2023 14:02:50 -0400 Subject: [PATCH] StatusMessage is not always defined in the progress_event With MemoryDB, `StatusMessage` is not always defined and this trigger an exception within the existing exception handling block. With this change we fallback on `OperationStatus` if `StatusMessage` is missing. If none of them are available, we will get a `None` instead of an exception. According to the documentation the presence of these two keys is not guarantee. They are both identified as optional (`Required: No`). See: https://docs.aws.amazon.com/cloudcontrolapi/latest/APIReference/API_ProgressEvent.html --- .../fragments/avoid_KeyError_exception_during_wait.yaml | 3 +++ plugins/module_utils/core.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/avoid_KeyError_exception_during_wait.yaml diff --git a/changelogs/fragments/avoid_KeyError_exception_during_wait.yaml b/changelogs/fragments/avoid_KeyError_exception_during_wait.yaml new file mode 100644 index 00000000..24a2c2ea --- /dev/null +++ b/changelogs/fragments/avoid_KeyError_exception_during_wait.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- "Address a situation where the creation of a resource with ``wait: true`` was causing an exception in case of timeout (https://github.com/ansible-collections/amazon.cloud/pull/60)." diff --git a/plugins/module_utils/core.py b/plugins/module_utils/core.py index 2cb4e7b3..e9894f5e 100644 --- a/plugins/module_utils/core.py +++ b/plugins/module_utils/core.py @@ -105,8 +105,10 @@ def wait_until_resource_request_success(self, request_token: str): WaiterConfig=self._waiter_config, ) except botocore.exceptions.WaiterError as e: + progress_event = e.last_response["ProgressEvent"] + message = progress_event.get("StatusMessage") or progress_event.get("OperationStatus") self.module.fail_json_aws( - e.last_response["ProgressEvent"]["StatusMessage"], + message, msg="Resource request failed to reach successful state", ) except (