如果 AWS 帐户处于 SES 的沙盒模式,如何使用 python boto3 检查

How to check using python boto3 if AWS account is in sandbox mode for SES

我正在 Python 中编写 Lambda 函数,它将使用 AWS SES 发送电子邮件。

但是,在我的测试 AWS 账户中,我不想向真实用户发送电子邮件。

所以我想执行这样的检查,

if Account_Status = SANDBOX,然后将电子邮件发送给预先验证的默认收件人。 (例如公司内部电子邮件地址)

如果 Account_Status = PROD,则将电子邮件发送到真实用户的电子邮件地址。

但是我在ses客户端找不到相关的boto3方法,可以给我Account Status

我试过 response = client.get_account_sending_enabled() 但它 returns true 即使帐户在沙盒中..

您可以使用 sesv2 api,它在 get_account() 函数的响应中直接定义了一个标志。

client = boto3.client('sesv2')
response = client.get_account()
print(response['ProductionAccessEnabled'])

来自文档:

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.