Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ses): maximum delivery time for emails #32102

Merged
merged 10 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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(),
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved
}),
name: this.physicalName,
reputationOptions: undefinedIfNoKeys({
Expand Down
Loading