Skip to content

Commit

Permalink
Cleanup: Bulk Migration from boto3_conn to module.client() (ansible-c…
Browse files Browse the repository at this point in the history
…ollections#188)

* Migrate from boto3_conn to module.client
* Simplify error handling when creating connections
* Simplify Region handling
* Remove unused imports
* Changelog

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@6bdf00d
  • Loading branch information
tremble authored and alinabuzachis committed Sep 22, 2022
1 parent c8d6542 commit d19a217
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions plugins/modules/rds_param_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@
from ansible.module_utils._text import to_native

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list
Expand Down Expand Up @@ -328,16 +326,10 @@ def main():
required_if=[['state', 'present', ['description', 'engine']]],
)

# Retrieve any AWS settings from the environment.
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)

if not region:
module.fail_json(msg="Region must be present")

try:
conn = boto3_conn(module, conn_type='client', resource='rds', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except botocore.exceptions.NoCredentialsError as e:
module.fail_json(msg="Couldn't connect to AWS: %s" % str(e))
conn = module.client('rds')
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg='Failed to connect to AWS')

state = module.params.get('state')
if state == 'present':
Expand Down

0 comments on commit d19a217

Please sign in to comment.