Connection function for boto3

Boto3 conn
pull/11591/head
Jonathan Davila 10 years ago
parent 2664de55fb
commit 6ea772931f

@ -46,6 +46,19 @@ AWS_REGIONS = [
'us-gov-west-1',
]
def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None, **params):
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')
resource = boto3.session.Session().resource(resource, region_name=region, endpoint_url=endpoint, **params)
client = resource.meta.client
if conn_type == 'resource':
return resource
elif conn_type == 'client':
return client
else:
return client, resource
def aws_common_argument_spec():
return dict(
@ -72,7 +85,7 @@ def boto_supports_profile_name():
return hasattr(boto.ec2.EC2Connection, 'profile_name')
def get_aws_connection_info(module):
def get_aws_connection_info(module, boto3=False):
# Check module args for credentials, then check environment vars
# access_key
@ -131,6 +144,18 @@ def get_aws_connection_info(module):
# in case security_token came in as empty string
security_token = None
if boto3:
boto_params = dict(aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=security_token)
if validate_certs:
boto_params['verify'] = validate_certs
if profile_name:
boto_params['profile_name'] = profile_name
else:
boto_params = dict(aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
security_token=security_token)

Loading…
Cancel
Save