diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index a1530a8c8c..c983c3eb87 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -1642,12 +1642,15 @@ def main(): module.fail_json(msg='boto required for this module') try: - _, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) if module.params.get('region') or not module.params.get('ec2_url'): ec2 = ec2_connect(module) elif module.params.get('ec2_url'): ec2 = connect_ec2_endpoint(ec2_url, **aws_connect_kwargs) + if 'region' not in aws_connect_kwargs: + aws_connect_kwargs['region'] = ec2.region + vpc = connect_vpc(**aws_connect_kwargs) except boto.exception.NoAuthHandlerFound as e: module.fail_json(msg="Failed to get connection: %s" % e.message, exception=traceback.format_exc())