当我尝试使用 AWS Command Line Interface(AWS CLI)访问我的 Amazon Simple Storage Service(Amazon S3)存储桶时,收到错误消息。如何解决此问题?
解决方法
"Unable to locate credentials" 错误表示 Amazon S3 找不到用于对 AWS API 调用进行身份验证的凭证。要解决此问题,请确保在 AWS CLI 中正确配置了 AWS 凭证。
**注意:**如果运行 AWS CLI 命令时仍然收到错误,请确保您使用的是最新的 AWS CLI 版本。
要检查 AWS CLI 是否配置了凭证,请运行以下命令:
$ aws configure list
如果在配置文件中配置了凭证,则该命令将返回类似于以下内容的响应:
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************ABCD config_file ~/.aws/config
secret_key ****************ABCD config_file ~/.aws/config
region us-west-2 env AWS_DEFAULT_REGION
如果您的凭证是使用环境变量配置的,则该命令将返回类似于以下内容的响应:
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************N36N env
secret_key ****************cxxy env
region <not set> None None
如果在实例配置文件中配置了凭证,则该命令将返回类似于以下内容的响应:
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************YVEQ iam-role
secret_key ****************2a9N iam-role
region <not set> None None
如果命令返回以下输出,则不会设置任何凭据:
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key <not set> None None
secret_key <not set> None None
region <not set> None None
查看响应以检查凭证是否丢失或者存储的凭证是否不正确。要更新您的证书,请使用 AWS CLI、环境变量或将实例配置文件附加到 EC2 实例。
更新凭证后,请运行 Amazon S3 AWS CLI 命令(例如 aws s3 ls)测试 AWS CLI。
相关信息
配置和凭证文件设置