AWS: update reference to auto-retrying ResourceNotFound (#72314)

AWS Dev Guidelines: update reference to auto-retrying ResourceNotFound

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Mark Chappell 2021-04-28 06:29:12 +02:00 committed by GitHub
parent 877e5b3dfe
commit c387b318a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -386,27 +386,18 @@ The combination of these two approaches is then:
module.fail_json_aws(e, msg="Could not describe some resource") module.fail_json_aws(e, msg="Could not describe some resource")
If the underlying ``describe_some_resources`` API call throws a ``ResourceNotFound`` Prior to Ansible 2.10 if the underlying ``describe_some_resources`` API call threw
exception, ``AWSRetry`` takes this as a cue to retry until it's not thrown (this a ``ResourceNotFound`` exception, ``AWSRetry`` would take this as a cue to retry until
is so that when creating a resource, we can just retry until it exists). it is not thrown (this is so that when creating a resource, we can just retry until it
exists). This default was changed and it is now necessary to explicitly request
To handle authorization failures or parameter validation errors in this behaviour. This can be done by using the ``catch_extra_error_codes``
``describe_some_resource_with_backoff``, where we just want to return ``None`` if argument on the decorator.
the resource doesn't exist and not retry, we need:
.. code-block:: python .. code-block:: python
@AWSRetry.exponential_backoff(retries=5, delay=5) @AWSRetry.exponential_backoff(retries=5, delay=5, catch_extra_error_codes=['ResourceNotFound'])
def describe_some_resource_with_backoff(client, **kwargs): def describe_some_resource_retry_missing(client, **kwargs):
try: return client.describe_some_resource(ResourceName=kwargs['name'])['Resources']
return client.describe_some_resource(ResourceName=kwargs['name'])['Resources']
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'ResourceNotFound':
return None
else:
raise
except BotoCoreError as e:
raise
def describe_some_resource(client, module): def describe_some_resource(client, module):
name = module.params.get['name'] name = module.params.get['name']