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 Oct 13, 2023
1 parent 6e207a1 commit 1584010
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions plugins/modules/iam_server_certificate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@

try:
import boto3
import botocore
import botocore.exceptions
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info


def get_server_certs(iam, name=None):
Expand Down Expand Up @@ -151,10 +150,9 @@ def main():
date='2021-12-01', collection_name='community.aws')

try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
iam = boto3_conn(module, conn_type='client', resource='iam', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except botocore.exceptions.ClientError as e:
module.fail_json(msg="Boto3 Client Error - " + str(e.msg))
iam = module.client('iam')
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg='Failed to connect to AWS')

cert_name = module.params.get('name')
results = get_server_certs(iam, cert_name)
Expand Down

0 comments on commit 1584010

Please sign in to comment.