1

my python code is not working on Lambda which actully works well when I run it from my local python environment. Whenever I try to create SES object on Lambda function, I get this error:

Response:
{
  "errorMessage": "Unable to import module 'lambda_function'"
}

Here's my code:

def lambda_handler(event, context):

    connection = boto.ses.connect_to_region('us-east-1')


    return connection.send_email(
            from_addr,
            subject,
            None,
            to,
            format= format,
            text_body=text,
            html_body=html
        )   

Is it something related to boto.ses not being supported over lambda and I have to use boto3 instead??

This lambda function contains multiple part and at the end I have to create SES object to send mail to my client, but when I try to do that I'm getting this error

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Satyashil Deshpande
  • 186
  • 2
  • 4
  • 17
  • Possible duplicate of ["errorMessage": "Unable to import module 'lambda\_function'](https://stackoverflow.com/questions/50814024/errormessage-unable-to-import-module-lambda-function) – NoorJafri Jan 04 '19 at 10:09
  • it's not about the name of function or handler because rest of my code works well on lambda , just when i include SES related code then only i'm facing it – Satyashil Deshpande Jan 04 '19 at 10:16
  • Everything works smoothly without SES? The answer above can be used for initial diagnostics. Let's dig deeper then. – NoorJafri Jan 04 '19 at 11:12

1 Answers1

1

These days, it is highly recommended to use boto3.

The syntax is:

import boto3

connection = boto3.client('ses', region_name='us-east-1')

response = client.send_email(
    Source='string',
    Destination={
        'ToAddresses': [
            'string',
        ],
        'CcAddresses': [
            'string',
        ],
        'BccAddresses': [
            'string',
        ]
    },
    Message={
        'Subject': {
            'Data': 'string',
            'Charset': 'string'
        },
        'Body': {
            'Text': {
                'Data': 'string',
                'Charset': 'string'
            },
            'Html': {
                'Data': 'string',
                'Charset': 'string'
            }
        }
    },
    ReplyToAddresses=[
        'string',
    ],
    ReturnPath='string',
    SourceArn='string',
    ReturnPathArn='string',
    Tags=[
        {
            'Name': 'string',
            'Value': 'string'
        },
    ],
    ConfigurationSetName='string'
)

See: SES — Boto 3 Docs documentation

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Thanks John, boto3 works well but my question was about boto.ses which i guess is not supported over Lambda. I used above code from AWS doc's which worked well for me :) – Satyashil Deshpande Jan 07 '19 at 05:52