Boto3 intermittent NoAuthHandlerFound errors

自古美人都是妖i 提交于 2021-01-29 11:21:28

问题


When trying to connect to an AWS service via Boto3, I occasionally get the following error:

NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV3Handler'] Check your credentials

This is running on an EC2 instance with an IAM Role configured. This error happens rarely.


回答1:


IAM roles provide credentials via the AWS metadata service. Boto3 will connect to this service to get credentials, but this connection can time out. By default, Boto3 will not retry connections to the metadata service, but this can be changed by setting the environment variable AWS_METADATA_SERVICE_NUM_ATTEMPTS to a number higher than 1.

See the docs:

AWS_METADATA_SERVICE_NUM_ATTEMPTS

When attempting to retrieve credentials on an EC2 instance that has been configured with an IAM role, boto3 will only make one attempt to retrieve credentials from the instance metadata service before giving up. If you know your code will be running on an EC2 instance, you can increase this value to make boto3 retry multiple times before giving up.



来源:https://stackoverflow.com/questions/59312799/boto3-intermittent-noauthhandlerfound-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!