diff --git a/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml b/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml index 7ffe218892b..8953b2390a1 100644 --- a/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml +++ b/changelogs/fragments/1650-fix-invalidinstanceid-notfound.yml @@ -1,3 +1,3 @@ --- bugfixes: - - ec2_instance - retry API call if we get ``InvalidGroup.NotFound`` error (https://github.com/ansible-collections/amazon.aws/pull/1650). + - ec2_instance - retry API call if we get ``InvalidInstanceID.NotFound`` error (https://github.com/ansible-collections/amazon.aws/pull/1650). diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index d1f86b54f45..0b468333e6d 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -1950,7 +1950,12 @@ def ensure_present(existing_matches, desired_module_state, current_count=None): for ins in instances: # Wait for instances to exist (don't check state) try: - client.describe_instance_status(InstanceIds=[ins["InstanceId"]], IncludeAllInstances=True) + AWSRetry.jittered_backoff( + catch_extra_error_codes=["InvalidInstanceID.NotFound"], + )(client.describe_instance_status)( + InstanceIds=[ins["InstanceId"]], + IncludeAllInstances=True, + ) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: module.fail_json_aws(e, msg="Failed to fetch status of new EC2 instance") changes = diff_instance_and_params(ins, module.params, skip=["UserData", "EbsOptimized"])