boto3错误:botocore.exceptions.nocredentialserror:无法通过shell脚本找到凭据

发布于 2025-02-08 16:18:56 字数 2358 浏览 1 评论 0原文

当我从CLI(终端)跑步时,它可以通过SSO找到凭据并通过 例如:

2022-06-18 07:38:36,421 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2022-06-18 07:38:36,421 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2022-06-18 07:38:36,421 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: sso
2022-06-18 07:38:36,422 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.8/dist/awscli/botocore/data/endpoints.json
2022-06-18 07:38:36,432 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x7fb797891040>
2022-06-18 07:38:36,433 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.ecr: calling handler <function add_generate_presigned_url at 0x7fb797909820>

当我通过Shell脚本运行相同的命令时,它找不到凭据:

2022-06-18 07:38:53,667 - MainThread - botocore.hooks - DEBUG - Event building-command-table.get-login-password: calling handler <function add_waiters at 0x7fa1820bf9d8>
2022-06-18 07:38:53,667 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2022-06-18 07:38:53,667 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: custom-process
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: config-file
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: ec2-credentials-file
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: boto-config
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: container-role
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: iam-role

这是命令:

aws ecr get-login-password --region xxx --profile xxx | docker login --username AWS --password-stdin xxxxxx.amazonaws.com

我是否缺少配置?

When I run from CLI(terminal) it works, it finds the credentials via sso and passes on
EX:

2022-06-18 07:38:36,421 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2022-06-18 07:38:36,421 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2022-06-18 07:38:36,421 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: sso
2022-06-18 07:38:36,422 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.8/dist/awscli/botocore/data/endpoints.json
2022-06-18 07:38:36,432 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x7fb797891040>
2022-06-18 07:38:36,433 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.ecr: calling handler <function add_generate_presigned_url at 0x7fb797909820>

When I run the same command via a shell script it doesn't find the credentials:

2022-06-18 07:38:53,667 - MainThread - botocore.hooks - DEBUG - Event building-command-table.get-login-password: calling handler <function add_waiters at 0x7fa1820bf9d8>
2022-06-18 07:38:53,667 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2022-06-18 07:38:53,667 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: custom-process
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: config-file
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: ec2-credentials-file
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: boto-config
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: container-role
2022-06-18 07:38:53,668 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: iam-role

This is the command:

aws ecr get-login-password --region xxx --profile xxx | docker login --username AWS --password-stdin xxxxxx.amazonaws.com

Am I missing a configuration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清晰传感 2025-02-15 16:18:56

我已经用鲍泽命令解决了这个问题:

python3 -m pip install --user aws-export-credentials

pip3 install --upgrade awscli

也对我有很大帮助:
https://github.com/aws/aws/aws/aws-cli/issues/4982

I've solved the issue with the bellow commands:

python3 -m pip install --user aws-export-credentials

and

pip3 install --upgrade awscli

This also helped me a lot:
https://github.com/aws/aws-cli/issues/4982

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文