How to check using python boto3 if AWS account is in sandbox mode for SES
I am writing a Lambda Function in Python, which will use AWS SES for sending emails.
However, in my test AWS account, I don't want to send emails to real users.
So I wanted to perform a check like this,
if Account_Status = SANDBOX, then send emails to a pre-verified default recipient. (e.g. an internal company email address )
if Account_Status = PROD, then send emails to the real user email addresses.
But I couldn't find any related boto3 method in ses client, which can give me Account Status.
I tried response = client.get_account_sending_enabled()
but it returns true
even if account is in sandbox..
Solution 1:
You can use the sesv2 api instead which has a flag directly defined in the response of the get_account() function.
client = boto3.client('sesv2')
response = client.get_account()
print(response['ProductionAccessEnabled'])
From the documentation:
ProductionAccessEnabled (boolean) --
Indicates whether or not your account has production access in the current Amazon Web Services Region.
If the value is false , then your account is in the sandbox . When your account is in the sandbox, you can only send email to verified identities. Additionally, the maximum number of emails you can send in a 24-hour period (your sending quota) is 200, and the maximum number of emails you can send per second (your maximum sending rate) is 1.
If the value is true , then your account has production access. When your account has production access, you can send email to any address. The sending quota and maximum sending rate for your account vary based on your specific use case.