Blog

How to set the active Receipt Rule Set in SES using CloudFormation

25 Nov, 2019
Xebia Background Header Wave

In AWS CloudFormation there is no way to set the active receipt rule set of the AWS Simple Email Service. As we strive for 100% reproducibility, we created a custom resource to
do just that.

How do I set the active receipt rule set in CloudFormation?

After you have defined the receipt rule set with the standard CloudFormation resources, just add a CloudFormation resource of type Custom::ActiveReceiptRuleSet:

Resources:
  ActiveReceiptRuleSet:
    Type: Custom::ActiveReceiptRuleSet
    Properties:
      RuleSetName: !Ref 'ReceiptRuleSet'
      Region: !Ref 'AWS::Region'
      ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:binxio-cfn-ses-provider'

  ReceiptRuleSet:
    Type: AWS::SES::ConfigurationSet
    Properties: 
      Name: default

This will activate the specified receipt rule set.

## Installation
To install this custom resource provider, type:
```sh
git clone https://github.com/binxio/cfn-ses-provider.git
cd cfn-ses-provider
aws cloudformation deploy \
    --capabilities CAPABILITY_IAM \
    --stack-name cfn-ses-provider \
    --template-file ./cloudformation/cfn-resource-provider.yaml 

This CloudFormation template will use our pre-packaged provider from s3://binxio-public-$(aws configure get region)/lambdas/cfn-ses-provider-0.6.4.zip.

Conclusion

Although there is a CloudFormation resource to define a receipt rule set, there is no way to indicate which one should be active. With this SES custom provider you can. This ensures that your complete environment can be defined using CloudFormation and is fully reproducible without manual interventions.

To configure your SES domain identity, check out How to deploy AWS SES Domain Identities and DKIM records using CloudFormation.

If you have any questions, do not hesitate to contact me.

Mark van Holsteijn
Mark van Holsteijn is a senior software systems architect at Xebia Cloud-native solutions. He is passionate about removing waste in the software delivery process and keeping things clear and simple.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts