Serverless service for sending emails from a contact form.
-
Install serverless framework (run command as
sudo
if you're using Linux)$ npm i -g serverless
-
Create an AWS IAM user or use credentials of an existing one
-
Set credentials so that Serverless knows what account to connect to when you run any terminal command
$ serverless config credentials \
--provider aws \
--key YOUR_ACCESS_KEY_ID \
--secret YOUR_SECRET_ACCESS_KEY
-
Create a service
$ serverless create --template aws-nodejs --path /path/to/your/contact-form-api
-
Clone this repository to your local machine and replace the files
$ git clone https://github.com/petruborta/contact-form-api.git
-
In
serverless.yml
, replace the value ofregion
(line 11) with your own region -
Create
secrets.json
and use two of your emails forMAIN_EMAIL
andSECONDARY_EMAIL
or a single one for bothNOTICE: The emails must be verified with AWS SES
You can change
NODE_ENV
's value to production andDOMAIN
's value to your actual domain, once it's ready for production
{
"NODE_ENV": "dev",
"MAIN_EMAIL": "YOUR_MAIN_EMAIL",
"SECONDARY_EMAIL": "YOUR_SECONDARY_EMAIL",
"DOMAIN": "*"
}
-
Deploy the API to AWS Lambda
$ serverless deploy
The endpoint will be logged to the console once it's deployed
-
Test the API
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"email":"[email protected]","name":"John Doe","subject":"Test email","message":"Hello!"}' \
https://{id}.execute-api.{region}.amazonaws.com/{stage}/email/send
Project is: finished
Followed this tutorial to implement a serverless contact form
Created by @petruborta - feel free to contact me!