API Gateway + AWS Lambda + AWS SES
The email function use the AWS SDK for Node.js to send an email using AWS Simple Email Service.
Usefull for:
- Marketing websites
- Product landing pages
- Micro-sites
- Team homepages
- Setup your AWS Credentials
- Install Serverless.js
npm install -g serverless
- Clone the project:
git clone git@github.com:ceccode/serverless-contact-service.git
- Install dependencies
npm install
- In your serverless.yml file set environment var:
environment:
EMAIL_SENDER: 'you-sender-address'
EMAIL_RECEIVER: 'you-receiver-address'
EMAIL_OBJECT: 'Referral Form'
This project use Amazon SES to send emails. For testing, it restricts the email addresses that can “send” and “receive” messages to ones that have been “verified”. Go to the SES page of the Console, choose Email Addresses > Verify New Email Address.
- Ad an usage plan to your api-key, see how here
Find the api-key name in your serverless.yml file:
apiKeys:
- contack-key
npm run deploy
[POST] /contact
Headers
{
"Content-Type": "application/json",
"x-api-key": "spnbH7eO7Rgj1Kv6tJ7v9jKwvY6sPyL27eV8nYqb",
}
Body:
{
"name": "Mario Rossi",
"email": "mario.rossi@example.it",
"message": "My message"
}
Run all tests
npm test
Coverage
npm run test-travis