我在使用boto3时遇到了错误。

0

【以下的问题经过翻译处理】 我正在使用以下脚本获取ec2实例列表,但遇到了问题[1]。我能够使用相同的凭据与session.get_available_regions(service)和session.client('sts'),但是在session.resource('ec2', region_name=region)中无法使用。我已经验证了机器上的时钟,并进行了同步。

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
profile picture
EXPERTO
preguntada hace 10 meses50 visualizaciones
1 Respuesta
0

【以下的回答经过翻译处理】 从以下错误信息可以看出,您的access key/secret access key/region是无效的。请 确认是否正确。您可能需要重新生成新的访问密钥/秘密访问密钥。

  • botocore.exceptions.ClientError: An error occurred (AuthFailure) when calling the DescribeInstances operation: AWS was not able to validate the provided access credentials
profile picture
EXPERTO
respondido hace 10 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas