【问题标题】:How to use all the credentials from .aws to execute Boto3 script?如何使用 .aws 中的所有凭据执行 Boto3 脚本?
【发布时间】:2020-02-10 19:51:11
【问题描述】:

我有一个可以使用的 boto3 脚本。当我从 .aws 凭据文件中指定配置文件名称时,它工作正常。但是,我想在我的 .aws 凭据文件中存在的所有配置文件中运行脚本。而且,我有超过 20 个个人资料。如何自动配置 boto3 以继续获取配置文件并返回输出?

#Listing the validity of SSL certs in RDS
import boto3
from pprint import pprint

rds = boto3.client('rds')

sslcert = rds.describe_certificates()

for cert in sslcert['Certificates']:
    print('Valid till', cert['ValidTill'])

【问题讨论】:

  • 没有内置功能可以做到这一点。您需要提取配置文件列表,然后遍历每个配置文件,创建一个使用该特定配置文件的新 boto3 客户端。

标签: python-3.x amazon-web-services boto3 amazon-rds


【解决方案1】:

看起来有一个功能可以列出本地 .aws/credentials 文件中的所有配置文件。

for profile in boto3.session.Session().available_profiles:
    print(profile)

【讨论】:

    猜你喜欢
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多