Hi,
I’m currently writing an EMR module for ansible at $WORK (sorry no plan for now to open source it) and I’m trying to use boto3, and I have to admit I’m confused with logic behind boto3_conn().
I have to use a role to access our environment so I must use sts_assume_role to gain privileges. Unfortunately, my “security_token” is set to None since rev 27398131cf31eb7ca834a30ea2d8a871a937a377 (https://github.com/ansible/ansible/commit/27398131cf31eb7ca834a30ea2d8a871a937a377)
Here’s the non working pseudo-code (copy’n’paste from ECS ones)
class EMRClusterManager:
“”" Handles EMR clusters"“”
def init(self, module):
self.module = module
try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
if not region:
module.fail_json(msg=“Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file”)
self.emr = boto3_conn(module, conn_type=‘client’, resource=‘emr’, region=region, endpoint=ec2_url, **aws_connect_kwargs)
XXX doesn’t catch error IRL
except boto.exception.NoAuthHandlerFound, e:
self.module.fail_json(msg="Can’t authorize connection - "+str(e))
def main()
argument_spec = ec2_argument_spec()
argument_spec.update( [SNIP] )
module = AnsibleModule(argument_spec=argument_spec)
emr = EMRClusterManager(module)
[SNIP]
it fails with : “The security token included in the request is invalid.” error message.
IMHO, the culpit is here (https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/ec2.py#L45)
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[‘aws_session_token’] is already set via get_aws_connection_info() line 151
if HAS_BOTO3 and 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
removing the last line fix the problem (params[‘aws_session_token’] = params.pop(‘security_token’, None))
Since I’m not very familiar with ansible core, I wonder if I missed something.
Thanks for your help
clem