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..
CodePudding user response:
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.
CodePudding user response:
You can use the get_send_quota method.
It returns the sending limits for the Amazon SES account. For SES Sandbox mode the limits are:
- A maximum of 200 messages per 24-hour period.
- A maximum of 1 message per second.
The structure response for get_send_quota is:
{
'Max24HourSend': Number,
'MaxSendRate': Number,
'SentLast24Hours': Number
}
These are some response examples:
SANDBOX
{
"Max24HourSend": 200.0,
"MaxSendRate": 1.0,
"SentLast24Hours": 51.0
}
PRODUCTION
{
"Max24HourSend": 50000.0,
"MaxSendRate": 14.0,
"SentLast24Hours": 2250.0
}
So you can validate if Max24HourSend <= 200 and MaxSendRate == 1 then the account is in Sandbox mode.
