Skip to content

Latest commit

 

History

History
128 lines (75 loc) · 7.81 KB

File metadata and controls

128 lines (75 loc) · 7.81 KB

Mailgun Webhook AWS Lambda DyanamoDB and SNS Notification Service

Table of Contents

Summary of Features

Execution / Deployment via AWS CodeFormation (Auto-creation of AWS Resources)

To create the necessary AWS resources, this repo implements infracstructure by code via CloudFormation.

You need to have AWS CLI and Yarn installed in your system to execute the script file.

Run the following:

chmod u+x create-cf-stacks.sh
./create-cf-stacks.sh

This script will automate the creation of the required AWS resources (S3, Lambda, API Gateway, DynamoDB, SNS, CodeBuild, IAM Roles, etc).

Screen Shot 2022-11-17 at 10 58 59 AM

Once executed the terminal will prompt you for the Github Auth Token, Mailgun Webhook Signing Key and Email to be used for subscription.

Details about the Github Token and Mailgun Signing key will be discussed here.

You can customize the AWS resources by updating the variables section of create-sf-stacks.sh Screen Shot 2022-11-16 at 11 23 57 PM

How to Test

After executing the create-cf-stacks.sh scripts you can test the application by sending a mailgun webhook. To do this follow the following steps:

Confrim SNS Subscription

Go to the email you provided and confirm subscription to SNS Topic. Screen Shot 2022-11-17 at 8 32 55 AM Screen Shot 2022-11-17 at 8 33 18 AM

Copy AWS API Gateway URL for mailgunwebhook.

Go to your AWS API Gateway Page and click on MailGunWebhook API.

Go to Stages > / > /mailgunwebhook > POST and copy the Invoke URL. Screen Shot 2022-11-17 at 8 44 48 AM

Test Using Mailgun.com

Go and login to Mailgun.com.

Once logged in go to Sending > Webhooks on the right navigation panel.

Paste the copied API Gateway URL and click Test webhook. Screen Shot 2022-11-17 at 8 53 32 AM

Once tested you will receive a response coming from our AWS Lambda Function.

Features

Mailgun Webhook Processing

Once a the webhook is received by our Gateway API and processed by our Lambda this app will do the following:

Saving of sent Mailgun webhook in DynamoDB.

Screen Shot 2022-11-17 at 9 02 35 AM

Sending of AWS SNS Notification to subscribed email/s

Screen Shot 2022-11-17 at 9 04 17 AM

Automatic CloudFormation Deploy of Application Stacks (Automatic AWS allocation of resources).

The create-cf-stacks.sh script will automatically create all the required AWS resources when executed. No more time consuming creation/integration of AWS resources via CLI or Online Console.

Screen Shot 2022-11-17 at 9 09 07 AM Screen Shot 2022-11-17 at 9 15 49 AM

Auto-update of AWS Lambda Function

Our deployment is integrated to this Github repo's main branch via AWS CodeBuild. Any PR merged to the main branch of this repo will trigger a build/update of our AWS Lambda. See buildspec.yml. Screen Shot 2022-11-17 at 9 22 16 AM Screen Shot 2022-11-17 at 9 24 35 AM

Acquiring Github Auth Token and Mail Gun Webhook Signing Key

Github Auth Token

The Github Token will be used for connecting your AWS account to Github account for CodeBuild configurations. CodeBuild will track Github repo's main branch to update the AWS Lambda function.

Go to New Personal Access Tokens (Classic) Page.

Replicate the following configuration shown on the images.

Screen Shot 2022-11-17 at 10 40 10 AM

Screen Shot 2022-11-17 at 10 40 28 AM

Then Generate token and copy the token for create-cf-stacks.sh prompt.

Mailgun Webhook Sigining Key

The Mailgun webhook signing key is used to verify that the hooks received by AWS Lambda via API gateway are coming from the Mailgun account of the user.

To get Mailgun webhook signing key go and login to Mailgun.com.

Once logged in go to Sending > Webhooks on the right navigation panel.

On this page you will see the HTTP webhook signing key. Copy this for the create-cf-stacks.sh prompt. Screen Shot 2022-11-17 at 10 30 51 AM