mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Add AWS boto3 error code exception function is_boto3_error_code (#41202)
* Add aws/core.py function to check for specific AWS error codes * Use sys.exc_info to get exception object if it isn't passed in * Allow catching exceptions with is_boto3_error_code * Replace from_code with is_boto3_error_code * Return a type that will never be raised to support stricter type comparisons in Python 3+ * Use is_boto3_error_code in aws_eks_cluster * Add duplicate-except to ignores when using is_boto3_error_code * Add is_boto3_error_code to module development guideline docs
This commit is contained in:
parent
269f404121
commit
40d2df0ef3
12 changed files with 84 additions and 41 deletions
|
@ -340,7 +340,7 @@ instances:
|
|||
sample: sg-abcd1234
|
||||
'''
|
||||
|
||||
from ansible.module_utils.aws.core import AnsibleAWSModule
|
||||
from ansible.module_utils.aws.core import AnsibleAWSModule, is_boto3_error_code
|
||||
from ansible.module_utils.ec2 import ansible_dict_to_boto3_filter_list, boto3_tag_list_to_ansible_dict, AWSRetry, camel_dict_to_snake_dict
|
||||
|
||||
|
||||
|
@ -363,9 +363,9 @@ def instance_facts(module, conn):
|
|||
paginator = conn.get_paginator('describe_db_instances')
|
||||
try:
|
||||
results = paginator.paginate(**params).build_full_result()['DBInstances']
|
||||
except conn.exceptions.from_code('DBInstanceNotFound'):
|
||||
except is_boto3_error_code('DBInstanceNotFound'):
|
||||
results = []
|
||||
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
|
||||
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
|
||||
module.fail_json_aws(e, "Couldn't get instance information")
|
||||
|
||||
for instance in results:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue