#2180·Zappa

Unable to send emails via SES on django app hosted through Zappa(lambda)

Author: shrinidhinhegdeCreated Nov 1, 2020Updated Aug 4, 2023

so i have hosted my site on lambda using zappa. and i am using django-amazon-ses to send email after submitting a form.

settings.py

AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID", "my access key")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY", "my secret key")
DEFAULT_FROM_EMAIL = '[email protected]'
EMAIL_BACKEND = 'django_amazon_ses.EmailBackend'
AWS_SES_REGION = 'ap-south-1'
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-south-1.amazonaws.com'

view

@csrf_exempt
def formSubmit(request):
    if request.method == 'POST':
        var = json.loads(request.body)
        name = var['name1']
        email = var['email1']
        company = var['company1']
        description = var['description1']
        send_mail('subject',
                  'msg',
                  '[email protected]',
                  [email])
        send_mail('subject',
                  'msg',
                  '[email protected]',
                  ['[email protected]'])
    return JsonResponse({'result': 'done'})

now this works fine on my local host but, when i try to do it online, it shows the following error on submitting.

ClientError at /submit/
An error occurred (InvalidClientTokenId) when calling the SendRawEmail operation: The security token included in the request is invalid.

At first, i thought it is because i havent configued a vpc with the lambda function, but then it showed me the same error after i configured a public/private vpc wizard.

not sure what am i doing wrong. any help would be appreciated.