I am using the following script to get the list of ec2 instances but running into [1]. I am able to use the same creds with session.get_available_regions(service) and session.client('sts') but it doesn't work with session.resource('ec2', region_name=region). I've verified the clock on the machine and it is synced. I would appreciate any help!
session = boto3.Session(
aws_access_key_id=key,
aws_secret_access_key=secret,
)
ec2_instance = session.resource('ec2', region_name=region)
for instance in ec2_instance.instances.all():
print(instance)
[1]
Failed to run listener function (error: An error occurred (AuthFailure) when calling the DescribeInstances operation: AWS was not able to validate the provided access credentials)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/ops/listener/thread_runner.py", line 120, in run_ack_function_asynchronously
listener.run_ack_function(request=request, response=response)
File "/usr/local/lib/python3.10/dist-packages/ops/listener/custom_listener.py", line 50, in run_ack_function
return self.ack_function(
File "/home/ops/codeserver/awsops.py", line 439, in get_ec2_instances
for instance in ec2_instance.instances.all():
File "/usr/local/lib/python3.10/dist-packages/boto3/resources/collection.py", line 81, in __iter__
for page in self.pages():
File "/usr/local/lib/python3.10/dist-packages/boto3/resources/collection.py", line 171, in pages
for page in pages:
File "/usr/local/lib/python3.10/dist-packages/botocore/paginate.py", line 269, in __iter__
response = self._make_request(current_kwargs)
File "/usr/local/lib/python3.10/dist-packages/botocore/paginate.py", line 357, in _make_request
return self._method(**current_kwargs)
File "/usr/local/lib/python3.10/dist-packages/botocore/client.py", line 530, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.10/dist-packages/botocore/client.py", line 960, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AuthFailure) when calling the DescribeInstances operation: AWS was not able to validate the provided access credentials
I am able to use the same creds with session.get_available_regions(service) and session.client('sts') but it doesn't work with session.resource('ec2', region_name=region)
The APIs you listed may work without any authenication. Let us explore further in two directions.
https://aws.amazon.com/cli/