I am configuring credentials on an EC2 instance by assigning an IAM role and having boto3 fetch the credentials via instance metadata.
But the first use of a ec2.client call fails because the credentials were not found.
ec2_client = boto3.client('ec2', region_name="us-east-1")
regions = ec2_client.describe_regions( <--- fails
RegionNames=[
s
]
)
Stacktrace
2018-10-30 17:20:03,437 ha_csr: set_route_table:290 ERROR Exception: Unable to locate credentials
Traceback (most recent call last):
File "/home/guestshell/.local/lib/python2.7/site-packages/csr_cloud/ha_csr.py", line 264, in set_route_table
routes = route_table.routes
File "/home/guestshell/.local/lib/python2.7/site-packages/boto3/resources/factory.py", line 431, in get_reference
self.load()
File "/home/guestshell/.local/lib/python2.7/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, kwargs)
File "/home/guestshell/.local/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in call
response = getattr(parent.meta.client, operation_name)(params)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/client.py", line 320, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/client.py", line 610, in _make_api_call
operation_model, request_dict)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 132, in _send_request
request = self.create_request(request_dict, operation_model)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 116, in create_request
operation_name=operation_model.name)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, kwargs)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/hooks.py", line 211, in _emit
response = handler(kwargs)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/signers.py", line 90, in handler
return self.sign(operation_name, request)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/signers.py", line 157, in sign
auth.add_auth(request)
File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/auth.py", line 357, in add_auth
raise NoCredentialsError
NoCredentialsError: Unable to locate credentials
It appears I have a race condition here.
This is my first call into the boot package. And it appears this first call is what triggers boto to initialize and try to find the instance credentials. In the meantime, the describe_regions call is executed, but fails because the credentials are not yet known.
Is there a way for me to kick boto to perform its initialization before calling functions to do useful work?
I am configuring credentials on an EC2 instance by assigning an IAM role and having boto3 fetch the credentials via instance metadata. But the first use of a ec2.client call fails because the credentials were not found. ec2_client = boto3.client('ec2', region_name="us-east-1") regions = ec2_client.describe_regions( <--- fails RegionNames=[ s ] )
Stacktrace
2018-10-30 17:20:03,437 ha_csr: set_route_table:290 ERROR Exception: Unable to locate credentials Traceback (most recent call last): File "/home/guestshell/.local/lib/python2.7/site-packages/csr_cloud/ha_csr.py", line 264, in set_route_table routes = route_table.routes File "/home/guestshell/.local/lib/python2.7/site-packages/boto3/resources/factory.py", line 431, in get_reference self.load() File "/home/guestshell/.local/lib/python2.7/site-packages/boto3/resources/factory.py", line 505, in do_action response = action(self, *args, kwargs) File "/home/guestshell/.local/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in call response = getattr(parent.meta.client, operation_name)(params) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/client.py", line 320, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/client.py", line 610, in _make_api_call operation_model, request_dict) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 102, in make_request return self._send_request(request_dict, operation_model) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 132, in _send_request request = self.create_request(request_dict, operation_model) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/endpoint.py", line 116, in create_request operation_name=operation_model.name) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/hooks.py", line 356, in emit return self._emitter.emit(aliased_event_name, kwargs) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/hooks.py", line 228, in emit return self._emit(event_name, kwargs) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/hooks.py", line 211, in _emit response = handler(kwargs) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/signers.py", line 90, in handler return self.sign(operation_name, request) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/signers.py", line 157, in sign auth.add_auth(request) File "/home/guestshell/.local/lib/python2.7/site-packages/botocore/auth.py", line 357, in add_auth raise NoCredentialsError NoCredentialsError: Unable to locate credentials
Versions
pip freeze boto3==1.9.35 botocore==1.12.35 csr-aws-ha==0.0.1 csr-aws-utils==0.0.47 csr-ha==0.0.22 docutils==0.14 futures==3.2.0 iniparse==0.4 ipaddress==1.0.22 jmespath==0.9.3 pycurl==7.19.0 pygpgme==0.3 pyliblzma==0.5.3 python-dateutil==2.7.5 pyxattr==0.5.1 s3transfer==0.1.13 six==1.11.0 urlgrabber==3.10 urllib3==1.24 yum-metadata-parser==1.1.4
It appears I have a race condition here. This is my first call into the boot package. And it appears this first call is what triggers boto to initialize and try to find the instance credentials. In the meantime, the describe_regions call is executed, but fails because the credentials are not yet known.
Is there a way for me to kick boto to perform its initialization before calling functions to do useful work?