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
  • Loading branch information
tremble authored and jillr committed Aug 26, 2020
1 parent 4cdfe56 commit a67dfc8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions plugins/modules/ec2_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,15 @@

try:
import boto3
import botocore
from botocore.exceptions import ClientError
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 ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict
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 get_aws_connection_info


def list_ec2_instances(connection, module):
Expand Down Expand Up @@ -550,12 +549,10 @@ def main():
if module._name == 'ec2_instance_facts':
module.deprecate("The 'ec2_instance_facts' module has been renamed to 'ec2_instance_info'", date='2021-12-01', collection_name='community.aws')

region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)

if region:
connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params)
else:
module.fail_json(msg="region must be specified")
try:
connection = module.client('ec2')
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg='Failed to connect to AWS')

list_ec2_instances(connection, module)

Expand Down

0 comments on commit a67dfc8

Please sign in to comment.