使用 aws configure sso 时收到“没有可供您使用的 AWS 账户”

问题描述 投票:0回答:1

我在 AWS IAM Identity Center 中设置了一个用户。当我运行 aws configure sso 时,我输入会话名称、起始 url、区域和注册范围(默认为 sso:account:access,所以我只使用它),然后使用我的用户登录名登录浏览器,然后登录成功,我收到“没有可供您使用的 AWS 账户。”

我注意到登录后,会在 /Users/[user]/.aws/sso/cache 处创建一个文件

我正在尝试进行身份验证,以便可以使用“aws ecr get-login-password”将 docker 文件推送到 aws 容器注册表。

更新: 观看此视频了解了如何在 IAM Identity Center 中管理账户: https://www.youtube.com/watch?v=_KhrGFV_Npw

现在我可以从命令行使用“aws configure sso”成功登录。

但是,登录后,当我尝试运行此命令将容器推送到 AWS 容器注册表时: “aws ecr get-login-password --region us-east-1 | docker login --用户名 AWS --password-stdin [id].dkr.ecr.us-east-1.amazonaws.com”

我收到此错误: 无法找到凭据。您可以通过运行“aws configure”来配置凭据。

amazon-web-services docker-registry amazon-ecr
1个回答
0
投票

当您设置 aws cli sso 配置文件时

aws configure sso
,它会询问您以下详细信息:

▶ aws configure sso
SSO session name (Recommended): mysso
SSO start URL [None]: <start_url>
SSO region [None]: <aws_region>
SSO registration scopes [sso:account:access]: <>

Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
https://device.sso.eu-central-1.amazonaws.com/
Then enter the code: xxxxxxxx

登录后,会询问要使用的帐户和角色:

There are # AWS accounts available to you.
<Select account>
Using the account ID 1234567890
The only role available to you is: AdministratorAccess
Using the role name "AdministratorAccess"

CLI default client Region [<aws_region>]:
CLI default output format [json]:
CLI profile name [AdministratorAccess-123456789]:

它会告诉您如何使用创建的配置文件:

To use this profile, specify the profile name using --profile, as shown:
aws s3 ls --profile AdministratorAccess-123456789

所以在你的情况下:

# .aws/config

[sso-session my-sso] 
sso_start_url = xxxxxxxx.awsapps.com/start 
sso_region = us-east-1 
sso_registration_scopes = sso:account:access

[profile AdministratorAccess-xxxxxxxxx] 
sso_session = my-sso 
sso_account_id = xxxxxxxxx 
sso_role_name = AdministratorAccess 

您需要使用

--profile AdministratorAccess-xxxxxxxxx

运行 aws 命令
aws ecr get-login-password --region us-east-1 --profile AdministratorAccess-xxxxxxxxx | docker login --username AWS --password-stdin [id].dkr.ecr.us-east-1.amazonaws.com
© www.soinside.com 2019 - 2024. All rights reserved.