Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task timed out when trying to use SES SendEmail operation

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).

like image 381
Ido Naveh Avatar asked Oct 15 '25 13:10

Ido Naveh


2 Answers

I'm having the same issue (but with nodejs). I found these answers that may help you, looks like a networking issue of aws. https://forums.aws.amazon.com/thread.jspa?threadID=232508 https://github.com/aws/aws-sdk-js/issues/1451

Edit: The easiest solution for me in a similar situation was to use SNS to invoke another lambda that is not inside a VPC. The second lambda is used to call the SES service. You can create an endpoint for SNS and connect it to the VPC.

like image 156
Gilad S Avatar answered Oct 18 '25 08:10

Gilad S


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',
)
like image 36
Tomanow Avatar answered Oct 18 '25 09:10

Tomanow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!