为什么当我运行命令时...
aws --profile default sts get-caller-identity
它有效,我得到了预期的结果。但是当我尝试跑步时...
aws sts get-caller-identity
失败并显示错误“调用 GetCallerIdentity 操作时发生错误 (ExpiredToken):请求中包含的安全令牌已过期”
我已正确配置 aws sso 并已成功授予我的计算机权限。我确保我的用户或系统环境变量中没有设置 AWS 环境变量(没有以“AWS_”为前缀的环境变量)
好的,感谢 jarmods 对我的问题的评论,我能够通过使用命令生成的日志来隔离问题:
aws sts get-caller-identity --debug 2>&1 | Select-String
“botocore.credentials”输出:
2024-03-28 13:00:11,472 - MainThread - botocore.credentials - 调试 - 通过以下方式查找凭据:env 2024-03-28 13:00:11,472 - MainThread - botocore.credentials - 信息 - 在环境变量中找到凭据。
所以我运行了命令:
Remove-Item -Path Env:\AWS_ACCESS_KEY_ID
Remove-Item -Path Env:\AWS_SECRET_ACCESS_KEY
并重新运行上面的命令,这给了我输出:
2024-03-28 13:04:14,393 - MainThread - botocore.credentials - 调试 - 通过以下方式查找凭据:env 2024-03-28 13:04:14,393 - MainThread - botocore.credentials - 调试 - 通过以下方式查找凭据:假设角色 2024-03-28 13:04:14,393 - MainThread - botocore.credentials - 调试 - 通过以下方式查找凭据:assume-role-with-web-identity 2024-03-28 13:04:14,393 - MainThread - botocore.credentials - 调试 - 通过以下方式查找凭据:sso 2024-03-28 13:04:14,541 - MainThread - botocore.credentials - DEBUG - 从缓存检索角色的凭据。 2024-03-28 13:04:14,541 - MainThread - botocore.credentials - 调试 - 检索到的凭据将在以下时间过期:2024-03-28 20:56:29+00:00
现在当我运行命令时
aws sts get-caller-identity
它按预期工作