The README you provided is already quite detailed and provides a good overview of the project. However, adding an API Methods section with example JSON payloads would indeed be beneficial for users who want to interact with the API. Here's a revised version of the README with the suggested changes:
This repository contains the source code for the JSCOM Contact Services, a serverless application that handles contact form submissions. The application is built using AWS services, including API Gateway, Lambda, DynamoDB, and SQS, and is managed using Terraform.
The application consists of three AWS Lambda functions, an API Gateway, two DynamoDB tables, and two SQS queues.
The architecture follows this flow:
- Contact form submissions are sent to the API Gateway.
- The API Gateway triggers the
contact-listener
Lambda function. - The
contact-listener
Lambda function validates the incoming message and forwards it to thecontact-message-queue
. - The
contact-filter
Lambda function is triggered by the new message in thecontact-message-queue
. It checks if the sender is blocked. If not, the message is forwarded to thecontact-notify-queue
. - The
contact-notifier
Lambda function is triggered by the new message in thecontact-notify-queue
and sends an email to the admin.
All Lambda functions are written in Python.
-
contact-listener
: This function receives contact form submissions from the API Gateway, performs simple validation, and forwards the messages to thecontact-message-queue
. Source Code -
contact-filter
: This function filters blocked contact messages from thecontact-message-queue
. It checks theblocked_contacts
DynamoDB table to see if the sender is blocked. Valid messages are forwarded to thecontact-notify-queue
. Source Code -
contact-notifier
: This function receives messages from thecontact-notify-queue
, formats them, and sends them to the admin email. Source Code
-
all-contact-messages
: This table stores all contact messages. It has the following attributes:id
,timestamp
,sender_name
,sender_email
,message_body
, andis_blocked
. It also has global secondary indexes onsender_name
,sender_email
,is_blocked
, andmessage_body
. -
blocked_contacts
: This table tracks blocked contacts. It has the following attributes:id
,ip_address
,user_agent
, andis_blocked
. It also has global secondary indexes onip_address
,user_agent
,is_blocked
, and a composite index onip_address
anduser_agent
.
-
contact-message-queue
: This queue holds messages received from thecontact-listener
Lambda function. -
contact-notify-queue
: This queue holds messages that have been filtered by thecontact-filter
Lambda function and are ready to be sent to the admin email by thecontact-notifier
Lambda function.
The API Gateway exposes the following endpoint:
POST https://api.johnsosoka.com/v1/contact
: Submits a new contact form message. The request body should be a JSON object with the following structure:
{
"sender_name": "John Doe",
"sender_email": "[email protected]",
"message_body": "Hello, this is a test message."
}
The application is deployed using Terraform. The Terraform configuration files are located in the terraform
directory. The Terraform state is managed remotely in an S3 bucket.
To deploy the application, navigate to the terraform
directory and run the following commands:
terraform init
terraform apply