Skip to content

Commit

Permalink
feat(ses): maximum delivery time for emails (#32102)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)

None

### Reason for this change

Amazon Simple Email Service (SES) offers a [new delivery option that allows us to set a custom maximum delivery time for our emails at Oct 15, 2024](https://aws.amazon.com/about-aws/whats-new/2024/10/amazon-ses-configurability-maximum-delivery-time-emails/?nc1=h_ls)

Cfn documentation: <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ses-configurationset-deliveryoptions.html#cfn-ses-configurationset-deliveryoptions-maxdeliveryseconds>

### Description of changes

Add `maxDeliveryDuration` to `ConfigurationSetProps`.

### Description of how you validated changes

Add both unit and integ tests.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
badmintoncryer authored Nov 18, 2024
1 parent 6820c62 commit 771eeff
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 52 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"Resources": {
"ConfigurationSet3DD38186": {
"Type": "AWS::SES::ConfigurationSet"
"Type": "AWS::SES::ConfigurationSet",
"Properties": {
"DeliveryOptions": {
"MaxDeliverySeconds": 600
}
}
},
"ConfigurationSetSns63B38980": {
"Type": "AWS::SES::ConfigurationSetEventDestination",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { App, Duration, Stack, StackProps } from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import { Construct } from 'constructs';
import * as ses from 'aws-cdk-lib/aws-ses';
Expand All @@ -8,7 +8,9 @@ class TestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const configurationSet = new ses.ConfigurationSet(this, 'ConfigurationSet');
const configurationSet = new ses.ConfigurationSet(this, 'ConfigurationSet', {
maxDeliveryDuration: Duration.minutes(10),
});

const topic = new sns.Topic(this, 'Topic');

Expand All @@ -32,5 +34,3 @@ const app = new App();
new integ.IntegTest(app, 'ConfigurationSetInteg', {
testCases: [new TestStack(app, 'cdk-ses-configuration-set-integ')],
});

app.synth();
6 changes: 6 additions & 0 deletions packages/aws-cdk-lib/aws-ses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,19 @@ set to an email, all of the rules in that configuration set are applied to the e
Use the `ConfigurationSet` construct to create a configuration set:

```ts
import { Duration } from 'aws-cdk-lib';

declare const myPool: ses.IDedicatedIpPool;

new ses.ConfigurationSet(this, 'ConfigurationSet', {
customTrackingRedirectDomain: 'track.cdk.dev',
suppressionReasons: ses.SuppressionReasons.COMPLAINTS_ONLY,
tlsPolicy: ses.ConfigurationSetTlsPolicy.REQUIRE,
dedicatedIpPool: myPool,
// Specify maximum delivery time
// This configuration can be useful in such cases as time-sensitive emails (like those containing a one-time-password),
// transactional emails, and email that you want to ensure isn't delivered during non-business hours.
maxDeliveryDuration: Duration.minutes(10),
});
```

Expand Down
21 changes: 20 additions & 1 deletion packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfigurationSetEventDestination, ConfigurationSetEventDestinationOptio
import { IDedicatedIpPool } from './dedicated-ip-pool';
import { undefinedIfNoKeys } from './private/utils';
import { CfnConfigurationSet } from './ses.generated';
import { IResource, Resource } from '../../core';
import { Duration, IResource, Resource, Token } from '../../core';

/**
* A configuration set
Expand Down Expand Up @@ -80,6 +80,15 @@ export interface ConfigurationSetProps {
* @default - VDM options not configured at the configuration set level. In this case, use account level settings. (To set the account level settings using CDK, use the `VdmAttributes` Construct.)
*/
readonly vdmOptions?: VdmOptions;

/**
* The maximum amount of time that Amazon SES API v2 will attempt delivery of email.
*
* This value must be greater than or equal to 5 minutes and less than or equal to 14 hours.
*
* @default undefined - SES defaults to 14 hours
*/
readonly maxDeliveryDuration?: Duration;
}

/**
Expand Down Expand Up @@ -158,10 +167,20 @@ export class ConfigurationSet extends Resource implements IConfigurationSet {
physicalName: props.configurationSetName,
});

if (props.maxDeliveryDuration && !Token.isUnresolved(props.maxDeliveryDuration)) {
if (props.maxDeliveryDuration.toMilliseconds() < Duration.minutes(5).toMilliseconds()) {
throw new Error(`The maximum delivery duration must be greater than or equal to 5 minutes (300_000 milliseconds), got: ${props.maxDeliveryDuration.toMilliseconds()} milliseconds.`);
}
if (props.maxDeliveryDuration.toSeconds() > Duration.hours(14).toSeconds()) {
throw new Error(`The maximum delivery duration must be less than or equal to 14 hours (50400 seconds), got: ${props.maxDeliveryDuration.toSeconds()} seconds.`);
}
}

const configurationSet = new CfnConfigurationSet(this, 'Resource', {
deliveryOptions: undefinedIfNoKeys({
sendingPoolName: props.dedicatedIpPool?.dedicatedIpPoolName,
tlsPolicy: props.tlsPolicy,
maxDeliverySeconds: props.maxDeliveryDuration?.toSeconds(),
}),
name: this.physicalName,
reputationOptions: undefinedIfNoKeys({
Expand Down
Loading

0 comments on commit 771eeff

Please sign in to comment.