Reputation: 759
I want to access Amazon’s SES(Simple Email Service) using the boto3 library and a user profile. The code I want to execute is listed below which does not work. It gives me an error “botocore.exceptions.NoCredentialsError: Unable to locate credentials”, I am currently able to access S3 services with no issue so I know my profile is setup correctly, but I cannot find code to access the SES service using a profile. I need some pointers how to get the code to work.
SES code that NOT work
import boto3
session = boto3.session.Session(profile_name='myprofile')
client = boto3.client('ses','us-east-1')
response = client.list_verified_email_addresses()
S3 code which currently works with a profile
import boto3
session = boto3.session.Session(profile_name='myprofile')
s3 = session.resource('s3')
Reference: http://boto3.readthedocs.org/en/latest/reference/services/ses.html
Upvotes: 0
Views: 1239
Reputation: 52413
In your SES code, you are not using the session that you created with your profile. But in S3 code, you use the session. When you call boto3.client()
, it knows nothing about your profile. Try this:
session = boto3.Session(profile_name='myprofile')
client = session.client('ses','us-east-1')
response = client.list_verified_email_addresses()
Upvotes: 5