This repo can be used to deploy a singular simple landing page that allows customers to enter their email and have promotional content emailed to them. This was built for testing and learning purposes and would need some updates and changes to be production-ready.
EX: Enter your email to get a PDF guide with steps on how to complete xyz
- User goes to a website hosted in S3
- User enters email into the text field and hits submit
- The submit button contacts an AWS API
- API triggers a lambda function
- Lambda function sends the S3 object URL to the user's email via SES
The app processes the website requests with Lambda and uses SES to send the email. If you have a new AWS account your account is likely within the SES sandbox. Some of the main limitations of the SES sandbox are:
- You can only send mail to verified email addresses and domains
- You can only send mail from verified email addresses and domains
You can submit a request to move your account out of the SES sandbox however this documentation assumes you are still in the SES sandbox. To get started you will need to verify an address within SES:
- Navigate to SES in the AWS Console
- Click Email Addresses
- Click Verify a New Email Address
- Enter the email address you would like to use as the sending address
- Click Verify This Email Address
- Check your email for a verification email
- Click the link in the email to confirm your email address
The "Resources.YAML" (cfn\Resources.yaml) file deploys the following resources:
- An S3 bucket that is enabled for website hosting
- An S3 bucket with public read access that you will put the promotional content file into
- An HTTP API (including a route, stage, Lambda integration settings and deployment)
- A Lambda function that processes the requests and sends the email
- A Lambda execution role with SES and logging permissions
- Navigate to CloudFormation in the AWS console
- Click create stack and upload the "Resources.YAML" template
- Enter a stack name and add the parameter values
- HttpApiName: This is the name that will be assigned to the HTTP API
- PromotionalDocumentName: Enter the name of your promotional document here. If your file is "Tips_for_securing_your_IT_enviorment.pdf" enter that filename here.
- ReplyEmail: This value is the sending email address. If you plan to send emails from "[email protected]" enter that here. If you completed step 1 you would enter that email here.
- Click next, acknowledge that CloudFormation will create IAM resources and hit deploy
- Wait till the stack deploys and then take note of the output values:
- Get the "PromotionalContentBucketName" value from the CloudFormation output tab
- Upload the promotional document to the S3 bucket:
AWS CLI example:
aws s3 cp C:\Users\User\Documents\projectfolder\FileName.txt s3://BUCKETNAME/FileName.txt
When the user submits their email the website contacts the API that was created with the CloudFormation. Before you upload the index.html website file to S3 you need need to add the API gateway invoke URL to the code.
- Grab the "apiGatewayInvokeURL" value from the CloudFormation output tab
- Add the URL to the javascript script in the index.html file:
The CloudFormation template created an S3 bucket enabled for website hosting. You need to upload the updated index.html file to that bucket.
- Get the "WebsiteBucketName" value from the CloudFormation output tab
- Upload the index.html document to the S3 bucket:
aws s3 cp C:\Users\User\Documents\projectfolder\index.html s3://BUCKETNAME/index.html
With the infrastructure and files in place, you can now test the site.
- Click on the link for the "WebsiteURL" CloudFormation output
- Enter an email and hit submit (If your account is still in the SES sandbox enter the email from step 1)
- Verify that you received the email:
- Empty the 2 S3 buckets:
aws s3 rm s3://BUCKETNAME --recursive
- The bucket that contains the promotional content is publicly available. To prevent people from sharing the link you could make the bucket private and have Lambda generate S3 pre-signed URL's
- There is no record of what emails are entered. You could add logging or potentially send the submitted addresses to a database.