Building a Contact Form with API Gateway and SES

Length: 00:14:05

Lesson Summary:

This lesson demonstrates a web page with a typical contact form. Using API Gateway and a Lambda function as a backend for this form, we will send the form post contents via email using SES, and also write the contact data to DynamoDB.

Source code for this lesson

https://github.com/linuxacademy/content-lambda-boto3/tree/master/WebApps/Contact-Form

DynamoDB

Create a table named Contact with a primary partition key named id:

aws dynamodb create-table --table-name Contact \
  --attribute-definitions AttributeName=id,AttributeType=S \
  --key-schema AttributeName=id,KeyType=HASH \
  --billing-mode=PAY_PER_REQUEST

Lambda function

Create a function named ContactEmail.

API Gateway

Create an API named ContactEmailAPI.

Create Method

  1. Select POST and check the check mark.

    • Integration Type: Lambda Function
    • Use Lambda Proxy Integration: Checked (stores request data in event)
    • Lambda region: Same region as Lambda function
    • Lambda function: ContactEmail

Enable CORS

  1. Select the POST method
  2. Under Actions, select Enable CORS
  3. Leave the default options and click on Enable CORS and replace existing CORS headers
  4. Click Yes, replace existing values

Deploy API

  1. Under Actions, select Deploy API

    • Deployment stage: [New stage]
    • Stage name: prod
  2. Note the Invoke URL and update form.js.

Test locally

cd Contact-Form
python3 -m http.server

Navigate to http://localhost:8000


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More