I am using the Boto 3 python library, and want to connect to AWS CloudFront. I need to specify the correct AWS Profile (AWS Credentials), but looking at the official documentation, I see no way to specify it.
I am initializing the client using the code:
client = boto3.client('cloudfront')
However, this results in it using the default profile to connect. I couldn't find a method where I can specify which profile to use.
This question is related to
python
amazon-web-services
boto3
Just add profile to session configuration before client call.
boto3.session.Session(profile_name='YOUR_PROFILE_NAME').client('cloudwatch')
This section of the boto3 documentation is helpful.
Here's what worked for me:
session = boto3.Session(profile_name='dev')
client = session.client('cloudfront')
Do this to use a profile with name 'dev':
session = boto3.session.Session(profile_name='dev')
s3 = session.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
Source: Stackoverflow.com