@codification/cdk-sns-email-forms
v0.1.1
Published
A cdk construct to simplify emailing form submissions using SNS.
Downloads
20
Maintainers
Readme
SNS Email Forms
Construct that handles verifying, formatting and sending form submissions using AWS SNS.
Architecture
Form data, in the form of a JSON payload, is POSTed.
The POST triggers the EmailFormHandler lambda function via Api Gateway.
Validation is performed.
i. The format of the payload is verified.
ii. The reCaptcha token, if enabled, is verified.
iii. Finally, the JSON schema specified by the payload is loaded from S3 and used to verify the form fields are valid.
If validation fails, an error is returned.
If validation succeeds, the message is formated using the Mustache template specified by the payload.
The formatted message is sent to the email address specified in the RecipientEmailAddress parameter via SNS.
Installation Steps
Create an AWS account if you do not already have one and login
Go to the app's page on the Serverless Application Repository.
Provide the required app parameters (see below for steps to create Google reCaptcha parameters)
Click "Deploy"
Parameters
In addition to the Etsy API key parameter, the app also requires some of the following parameters:
Stage (optional) - The Api Gateway stage to use. Default: prod.
RecipientEmailAddress (required) - The email address that the processed messages should ultimately be sent to.
TemplateBucketName (required) - The S3 bucket that will be created and used to store validation schemas and templates.
RecaptchaEnabled (optional) - Indicates if reCaptcha will be used to prevent abuse. RecaptchaSecretKey is required if this parameter is set to true. Default: false.
RecaptchaSecretKey (optional) - The secret key provided by Google. Please see details below. Default: empty.
CorsEnabled (optional) - Indicates if CORS headers will be returned. Default: false.
CorsOrigins (optional) - If CorsEnabled is
true
, this is a comma delimited list of approved origins. The incoming origin is matched against the list and is returned if present. Default: *.CorsHeaders (optional) - If CorsEnabled is
true
, this is a comma delimited list of approved headers. Default: *.
Adjusting the Logging Level
After deploying the application, the logging level can be adjusted by:
Accessing your AWS Console
Click on Services in the header and then select Compute > Lambda
Find the SNS Email lambda function in the list and click it.
On the first screen, Configuration, scroll down to Environment variables
Click Edit in the upper right corner
Click Add environement variable at the bottom of the list
Enter LOGGING_LEVEL as the key and one of the following values:
- ALL - TRACE - DEBUG - INFO - WARN - ERROR
Click Save
Please note that you may have to wait for a new instance of the lambda to be created for your changes to take effect.
Enabling Google reCaptcha
In order to enable reCaptcha functionality, you will first need a secret key. The following steps walk you through registering your site with Google reCaptcha.
Go to the Google reCaptcha site and click Admin console in the upper right hand corner.
i. Note: If you do not have a Google account, you will need to make one.
Register the app that contains forms you want to protect with reCaptcha:
i. Click the "+".
ii. Enter a "Label" for the application.
iii. Select "reCaptcha v2" for the "reCaptcha type". Currently, only v2 is supported.
iv. Under "Domains", enter all the domains that your app will operate under.
v. Enter you email address under "Owners".
vi. Accept the Terms of Service and click "Submit".
Get the keys:
i. After registering your application you will be provided with a site key and a secret key.
The site key will be used in the widget on your client side form.
Use the secret key as the value for the RecaptchaSecretKey parameter.