Shubham Shekhar
Shubham Shekhar

Reputation: 189

How to use all the credentials from .aws to execute Boto3 script?

I have a boto3 script ready to use. It is working fine when I specify a profile name from my .aws credentials file. But, I want to run the script in all the profiles which are present in my .aws credentials file. And, I have like more than 20 profiles. How do I automatically configure boto3 to keep fetching the profiles one by one and return the output ?

#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'])

Upvotes: 0

Views: 911

Answers (1)

Shubham Shekhar
Shubham Shekhar

Reputation: 189

Looks like there is a function to list out all the profiles in your local .aws/credentials file.

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

Upvotes: 2

Related Questions