使用 Boto3 通过 SSO 登录 AWS(无需预先配置凭证文件)

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

我正在尝试创建一个程序包/应用程序,当提供正确的 SSO 凭证时,该程序包/应用程序可以登录到 AWS S3 存储桶。

此问题的答案如何在通过 SSO 凭证连接时使用 AWS Python SDK 假设凭证文件。但是,我希望能够在任何 PC 上运行我的应用程序,只要运行它的人拥有使用 Start URL 注册的 AWS 帐户即可。

我通常需要如何设置它:

aws configure sso
# Run through the configuration steps here

然后做

import boto3
boto3.setup_default_session(profile_name='sso_profile')
client = boto3.client('s3')

在新机器上,aws cli 将不可用,我想通过 boto3 完成所有操作。

2ps 的回答如何在通过 SSO 凭证连接时使用 AWS Python SDK 让我走得很远,但我不知道任何给定用户的“account_id”是什么。

amazon-web-services boto3 aws-sdk
1个回答
0
投票

但是我不知道任何给定用户的“account_id”是什么。

~.aws/config 中不需要

account_id

您可以将其作为用户的输入。

[?] Please enter account ID:
 > 

或者您可以使用 sso list-account 列出用户 SSO 中存在的帐户。

[?] Please select the account to use:
  Prd [123456789] <
  Acc [987654321]
  Dev [786234823] 

由于用户每个 AWS 账户可以拥有多个角色,因此如果有多个角色,您可以使用

list-account-roles
并让用户选择要用于他们输入的账户的角色。

© www.soinside.com 2019 - 2024. All rights reserved.