https://github.com/cbschuld/aws-lambda-ses-forwarder-cdk
An AWS SES Email Forwarder in TypeScript wrapped up in the AWS CDK
https://github.com/cbschuld/aws-lambda-ses-forwarder-cdk
Last synced: 3 months ago
JSON representation
An AWS SES Email Forwarder in TypeScript wrapped up in the AWS CDK
- Host: GitHub
- URL: https://github.com/cbschuld/aws-lambda-ses-forwarder-cdk
- Owner: cbschuld
- Created: 2022-06-25T15:04:48.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-22T22:26:23.000Z (over 2 years ago)
- Last Synced: 2025-01-25T11:26:08.610Z (5 months ago)
- Language: TypeScript
- Size: 119 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SES Forwarding via CDK ✉️
The SES forwarding system allows you to have domain receive email via AWS SES and forward to another email account.
## Special Thanks
Special thanks to [Joe Turgeon](https://github.com/arithmetric) for doing the original lift here. This is an adapted version of his [SES Email Fowarder](https://github.com/arithmetric/aws-lambda-ses-forwarder) modified to TypeScript and then bootstrapped with the AWS CDK.
## Using for your domain
Actions to get SES Forwarding correctly on your domain:
- The first step is to make sure you have the [AWS CDK installed](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)
- Clone or download this project
- Copy `src/config.sample.json` to `src/config.json` and update the file with parameters relative to your installation. _(the same parameter's as [Joe Turgeon](https://github.com/arithmetric) solution)_
- Deploy using the CDK _(see below for examples)_
- Enable the Ruleset _(the CDK does not allow this... read below how to do this quickly)(if this changes in the future I'll automate this)_## config.json
Expected keys/values:
- **fromEmail**: Forwarded emails will come from this verified address
- **subjectPrefix**: Forwarded emails subject will contain this prefix
- **emailBucket**: S3 bucket name where SES stores emails.
- **rejectSpam**: Do not FWD email on which AWS detected as SPAM
- **emailKeyPrefix**: S3 key name prefix where SES stores email. Include the trailing slash.
- **allowPlusSign**: Enables support for plus sign suffixes on email addresses. If set to `true`, the username/mailbox part of an email address is parsed to remove anything after a plus sign. For example, an email sent to `[email protected]` would be treated as if it was sent to `[email protected]`.
- **forwardMapping**: Object where the key is the lowercase email address from which to forward and the value is an array of email addresses to which to send the message.To match all email addresses on a domain, use a key without the name part of an email address before the "at" symbol (i.e. `@example.com`).
To match a mailbox name on all domains, use a key without the "at" symbol and domain part of an email address (i.e. `info`).
To match all email addresses matching no other mapping, use "@" as a key.
## CDK Deploy
Deploy via the CDK using the CDK's cli. You will need to know your **AWS account ID**, the **region** you want to deploy the solution on and your receiving **domain**. You may need to add a named profile _(if you use them)_ or set your AWS keys up in the environment ([see the **Prerequisites** section of the CDK page](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html))
```sh
npm install
npm run build
# if you have not does a CDK bootstrap; run the following:
cdk bootstrap -c account=1234567890 -c domain=mydomain.com -c region=us-west-2
cdk deploy -c account=1234567890 -c domain=mydomain.com -c region=us-west-2```
## Enable the Ruleset
You cannot activate an SES Ruleset from the CDK 👎 so...
To Enable:
```sh
RULESET=`aws cloudformation list-exports --query "Exports[?Name=='SESRuleSetName'].Value" --no-paginate --output text` \
&& \
aws ses set-active-receipt-rule-set --rule-set-name $RULESET
```Or disable all of the Rulesets💥:
```sh
aws ses set-active-receipt-rule-set
```## Rough downside of SES Forwarding
SES becomes the "real" sender of the email. If you smash SPAM on an email send to your account you will be hitting SPAM on yourself. Be smart and careful with your sending rating over at AWS SES.
## CDK Clean up
If you deploy the CDK in the wrong region and you want to clean it up you cannot simply do it. Thus, if you run `cdk bootstrap` in the wrong region there is no clean way to back out of it. The fastest way to clean it up is via:
```sh
aws cloudformation delete-stack --stack-name CDKToolkit
aws s3 ls | grep -i cdk
aws s3 rb --force s3://cdk-XXXX-assets-XXXXX-REGION
```## Credits
Based on the work of [Joe Turgeon](https://github.com/arithmetric/aws-lambda-ses-forwarder) [@eleven41 and @mwhouser](https://github.com/eleven41/aws-lambda-send-ses-email)