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 = 'xxxx@xxx.xx'
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',
'xxxx@xxx.xx',
[email])
send_mail('subject',
'msg',
'xxxx@xxx.xx',
['toemail@gmail.com'])
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.
This AWS blog post may sort things out for you.
Essentially AWS now allows you to connect to SES through a VPC endpoint, which means you no longer need to use an internet gateway or NAT device.
You'll have to edit your security group's inbound rules by adding rules for both SMTP and SMTPS. Once you've done that, you create an endpoint, attach the edited security group, and it should work from there once the endpoint becomes available.