Skip to content

Serverless service for sending emails from a contact form using AWS Lambda and AWS Simple Email Service.

Notifications You must be signed in to change notification settings

petruborta/contact-form-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CONTACT FORM API

Serverless service for sending emails from a contact form.

Table of contents

Technologies

Setup

  • 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 of region (line 11) with your own region

  • Create secrets.json and use two of your emails for MAIN_EMAIL and SECONDARY_EMAIL or a single one for both

    NOTICE: The emails must be verified with AWS SES

    You can change NODE_ENV's value to production and DOMAIN'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

Status

Project is: finished

Inspiration

Followed this tutorial to implement a serverless contact form

Contact

Created by @petruborta - feel free to contact me!

About

Serverless service for sending emails from a contact form using AWS Lambda and AWS Simple Email Service.

Topics

Resources

Stars

Watchers

Forks