Merge pull request #13053 from Etherdaemon/fix_13010_boto3_aws_profile

Fixes #13010 by updating boto3 methods
pull/13184/head
Brian Coca 9 years ago
commit db27541a0e

@ -41,20 +41,25 @@ except:
def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params): def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
profile = params.pop('profile_name', None)
params['aws_session_token'] = params.pop('security_token', None)
params['verify'] = params.pop('validate_certs', None)
if conn_type not in ['both', 'resource', 'client']: if conn_type not in ['both', 'resource', 'client']:
module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call') module.fail_json(msg='There is an issue in the code of the module. You must specify either both, resource or client to the conn_type parameter in the boto3_conn function call')
if conn_type == 'resource': if conn_type == 'resource':
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params) resource = boto3.session.Session(profile_name=profile).resource(resource, region_name=region, endpoint_url=endpoint, **params)
return resource return resource
elif conn_type == 'client': elif conn_type == 'client':
client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params) client = boto3.session.Session(profile_name=profile).client(resource, region_name=region, endpoint_url=endpoint, **params)
return client return client
else: else:
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params) resource = boto3.session.Session(profile_name=profile).resource(resource, region_name=region, endpoint_url=endpoint, **params)
client = boto3.session.Session().client(resource, region_name=region, endpoint_url=endpoint, **params) client = boto3.session.Session(profile_name=profile).client(resource, region_name=region, endpoint_url=endpoint, **params)
return client, resource return client, resource
def aws_common_argument_spec(): def aws_common_argument_spec():
return dict( return dict(
ec2_url=dict(), ec2_url=dict(),
@ -153,7 +158,6 @@ def get_aws_connection_info(module, boto3=False):
if profile_name: if profile_name:
boto_params['profile_name'] = profile_name boto_params['profile_name'] = profile_name
else: else:
boto_params = dict(aws_access_key_id=access_key, boto_params = dict(aws_access_key_id=access_key,
aws_secret_access_key=secret_key, aws_secret_access_key=secret_key,

Loading…
Cancel
Save