I'm trying to send an email message using AWS SES with Python 3.7 lambda function.
When I'm trying to test the function and see if it sends the email message, I get a message that the task timed out.
It reaches to the code part where it sends the message, but the message isn't being sent at any time, and the task just got timeout.
This is the code that I'm using to send the message:
from __future__ import print_function
import boto3
import json
import decimal
from datetime import datetime
from boto3.dynamodb.conditions import Key, Attr
from botocore.exceptions import ClientError
ses = boto3.client(
'ses',
region_name = 'us-east-1',
endpoint_url = 'https://email.us-east-1.amazonaws.com'
)
try:
response = ses.send_email(
Destination = {
'ToAddresses': [
email
],
},
Message = {
'Body': {
'Html': {
'Charset': CHARSET,
'Data': BODY_HTML
},
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT
}
},
Source = SENDER
)
except ClientError as e:
print(e)
else:
print('Email sent! Message ID:'),
print(response['MessageId'])
All of the above variables are hardcoded in the code, and definitely has value (I have printed it to the console to ensure it).
It looks like your endpoint_url = 'https://dynamodb.us-east-1.amazonaws.com'
is pointing to DynamoDB which doesn' seem valid in an SES client. Try removing that:
ses = boto3.client(
'ses',
region_name = 'us-east-1',
)