The code in this repo allows you to deploy with ease an AWS Serverless infrastructure to handle contact requests in your static website. Before to start make sure you own an email verified in the AWS SES service. How to?
The serverless function is responsible to build and send a message to a specific email, as long as it receives the necessary parameters, otherwise return an error.
Test case:
You are a client, and you fill out and submit a form inside a static website:
- The static website is going to send a request to this serverless function.
- This function will receive the request and will validate all parameters.
- If the request has the correct parameters, then the function is going to build and send a message to the email specified, in the
serverless.json
file, using Amazon SES. Otherwise, the function throws an exception and returns an error message. - Finally, the function returns a response with its respective HTTP status code.
Successful case: a request from postman to the serverless function
Failed case: No message in the request
$ git clone git@github.com:kommitters/serverless-contact-form.git
$ npm i -g serverless
Note: If you're using Linux, you may need to run the command as sudo.
$ serverless config credentials \
--provider aws \
--key xxxxxxxxxxxxxx \
--secret xxxxxxxxxxxxxx
{
"NODE_ENV":"dev",
"EMAIL":"john.doe@mail.com",
"DOMAIN":"*"
}
$ serverless deploy
with CURL:
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"email":"john.doe@email.com","name":"John Doe","message":"Hey!","phone":"12345"}' \
https://{id}.execute-api.{region}.amazonaws.com/{stage}/email/send
With Postman:
Ready to send contact emails from your static website! 💪.
Bug reports and pull requests are welcome on GitHub https://github.com/kommitters/serverless-contact-email. Everyone is welcome to participate in the project. If you are thinking about contributing to the project, please check our Contributing Guide.
See the CHANGELOG for versions details.
See LICENSE for details.
Made with 💙 by kommit