我的库需要连接到任意AWS-IoT帐户,因此我在实例化AWS客户端时传递了所需的凭据:
client = boto3.client('iot',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,...)
根据boto3文档(摘录如下),以这种方式传递的凭据应覆盖所有其他凭据。但是,此调用会从Boto3生成以下日志消息:
"Found credentials in shared credentials file: ~/.aws/credentials"
我真的不希望boto3获取用户可能在他们的系统上配置的任何凭据 - 我希望它只使用我传递给boto3.client()的那些凭据。任何想法如何确保这一点?
boto3 docs摘录:
The order in which Boto3 searches for credentials is:
1. Passing credentials as parameters in the boto.client() method
2. Passing credentials as parameters when creating a Session object
3. Environment variables
4. Shared credential file (~/.aws/credentials)
5. AWS config file (~/.aws/config)
6. Assume Role provider
7. Boto2 config file (/etc/boto.cfg and ~/.boto)
8. Instance metadata service on an Amazon EC2 instance that has an IAM role configured.
根据我的测试,当将aws_access_key_id
和aws_secret_access_key
参数传递给boto3.client(..)
时,即使它们不正确并且不从文件加载任何其他凭据,它也会接受它们。发送API调用时,它会返回NoCredentialsError
异常。
但是,当上述参数未通过ieboto3.client('iot')
并且系统中存在默认配置文件时,我可以看到“在共享凭证文件中找到凭据:〜/ .aws / credentials”。
这意味着,只要您明确提供凭据参数,就应该保护您免受在错误帐户上执行的调用。