Simple email sender running on Lambda. It sends emails via AWS SES. It comes in handy when you would add a contact form to your static website.
- Apex - http://apex.run/
- An email address verified with AWS SES
Init your project
git clone [email protected]:craftzdog/send-email-lambda.git
cd send-email-lambda
apex init
> Project nane: send-email
Edit your project.json
file based on project.json.example
like:
{
"name": "send-email",
"description": "Simple email transmitter",
"memory": 128,
"timeout": 5,
"environment": {},
"runtime": "nodejs6.10",
"role": "<YOUR_IAM_ROLE>"
}
Edit functions/submit/function.json
as you like:
{
"environment": {
"SES_REGION": "us-west-2",
"FROM_NAME": "Craftzdog Contact Form",
"FROM_EMAIL": "<YOUR_AUTOMATED_EMAIL_SENDER>",
"TO_EMAIL": "<EMAIL_TO_RECEIVE>"
}
}
SES_REGION
: The AWS region for the SESFROM_NAME
: Sender name like "Contact Form"FROM_EMAIL
: The email address you would receive from. e.g., [email protected]TO_EMAIL
: Your personal email address to receive emails.
Add following policy to your lambda's IAM role (ex. send-email_lambda_function
) that allows the lambda function to use SES.sendEmail with policy name send-email_submit
:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1504526549000",
"Effect": "Allow",
"Action": [
"ses:SendEmail"
],
"Resource": [
"*"
]
}
]
}
At the project top directory:
apex deploy
You can run the lambda function manually with below command:
echo -n '{ "subject": "hello", "body": "world" }' | apex invoke submit
And you will get an email to the configured address.
Configure your API Gateway like this:
And deploy the API.
See the swagger YAML file as an example.
It accepts JSON data with 2 fields:
subject
: The message subjectbody
: The message body
MIT, Copyright 2017 by Takuya Matsuyama <[email protected]>