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

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.

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();
24 changes: 23 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 - 14 hours
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default value is described at Advanced delivery options/Maximum delivery duration section.

Setting a custom maximum delivery limit (shorter than the SES default of 14 hours),

badmintoncryer marked this conversation as resolved.
Show resolved Hide resolved
*/
readonly maxDeliveryDuration?: Duration;
}

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

if (props.maxDeliveryDuration && !Token.isUnresolved(props.maxDeliveryDuration)) {
if (props.maxDeliveryDuration.toMilliseconds() < Duration.seconds(1).toMilliseconds()) {
throw new Error(`The maximum delivery duration must be greater than or equal to 5 minutes (300 seconds), got: ${props.maxDeliveryDuration.toMilliseconds()} milliseconds.`);
badmintoncryer marked this conversation as resolved.
Show resolved Hide resolved
}
if (props.maxDeliveryDuration.toSeconds() < Duration.minutes(5).toSeconds()) {
throw new Error(`The maximum delivery duration must be greater than or equal to 5 minutes (300 seconds), got: ${props.maxDeliveryDuration.toSeconds()} seconds.`);
}
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
30 changes: 29 additions & 1 deletion packages/aws-cdk-lib/aws-ses/test/configuration-set.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Template, Match } from '../../assertions';
import { Stack } from '../../core';
import { Duration, Stack } from '../../core';
import { ConfigurationSet, ConfigurationSetTlsPolicy, DedicatedIpPool, SuppressionReasons } from '../lib';

let stack: Stack;
Expand All @@ -21,6 +21,7 @@ test('configuration set with options', () => {
suppressionReasons: SuppressionReasons.COMPLAINTS_ONLY,
tlsPolicy: ConfigurationSetTlsPolicy.REQUIRE,
dedicatedIpPool: new DedicatedIpPool(stack, 'Pool'),
maxDeliveryDuration: Duration.seconds(300),
});

Template.fromStack(stack).hasResourceProperties('AWS::SES::ConfigurationSet', {
Expand All @@ -29,6 +30,7 @@ test('configuration set with options', () => {
Ref: 'PoolD3F588B8',
},
TlsPolicy: 'REQUIRE',
MaxDeliverySeconds: 300,
},
SuppressionOptions: {
SuppressedReasons: [
Expand Down Expand Up @@ -89,3 +91,29 @@ test('configuration set with vdmOptions not configured', () => {
VdmOptions: Match.absent(),
});
});

describe('maxDeliveryDuration', () => {
test('invalid duration less than 1 second', () => {
expect(() => {
new ConfigurationSet(stack, 'ConfigurationSet', {
maxDeliveryDuration: Duration.millis(999),
});
}).toThrow('The maximum delivery duration must be greater than or equal to 5 minutes (300 seconds), got: 999 milliseconds.');
});

test('invalid duration less than 5 minutes and greater than 1 second', () => {
expect(() => {
new ConfigurationSet(stack, 'ConfigurationSet', {
maxDeliveryDuration: Duration.minutes(4),
});
}).toThrow('The maximum delivery duration must be greater than or equal to 5 minutes (300 seconds), got: 240 seconds.');
});

test('invalid duration greater than 14 hours', () => {
expect(() => {
new ConfigurationSet(stack, 'ConfigurationSet', {
maxDeliveryDuration: Duration.hours(14).plus(Duration.seconds(1)),
});
}).toThrow('The maximum delivery duration must be less than or equal to 14 hours (50400 seconds), got: 50401 seconds.');
});
});
Loading