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(cdk): Added SecondsBeforeTimeout, TimeOutAction #27183 #27489

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
99f2fcc
init
Oct 7, 2023
f9969e8
ok it works
Oct 7, 2023
dfbe2b1
chore(deps): Bump tj-actions/changed-files from 39.2.0 to 39.2.1 (#27…
dependabot[bot] Oct 9, 2023
07c164f
chore(deps): Bump stefanzweifel/git-auto-commit-action from 4 to 5 (#…
dependabot[bot] Oct 9, 2023
a4270e4
feat: update AWS Service Spec (#27464)
aws-cdk-automation Oct 9, 2023
2149428
chore(synthetics): delete alpha module (#27441)
kaizencc Oct 9, 2023
157baf7
feat(init-templates): update init templates to use the current LTS ve…
TheRealAmazonKendra Oct 9, 2023
e3e2069
chore(issue-label-assign): aws-scheduler and aws-scheduler-targets (#…
kaizencc Oct 9, 2023
663ff79
revert: "chore(synthetics): delete alpha module" (#27470)
kaizencc Oct 9, 2023
ab8f38a
chore(synthetics): deprecate aws-synthetics-alpha (#27471)
kaizencc Oct 10, 2023
6c4849f
fix(glue-alpha): prefix validation logic is incorrect (#27472)
mikewrighton Oct 10, 2023
e82b498
feat(lambda-python-alpha): add without-urls option for poetry (#27442)
msambol Oct 10, 2023
71f2304
fix(integ-tests): cannot make two or more identical assertions (#27380)
misterjoshua Oct 10, 2023
7f79214
fix(assertions): cannot use HTTP apis that do not return JSON (#27463)
rix0rrr Oct 10, 2023
2c98644
feat(stepfunctions-tasks): add `ExecutionParameters` to `AthenaStartQ…
nakedible-p Oct 11, 2023
e2d5cb5
Merge branch 'aws:main' into PR-Timeout
edxlang Oct 11, 2023
5eff589
adding snapshot, I believe.
Oct 11, 2023
a6a4318
Merge branch 'main' into PR-Timeout
edxlang Oct 11, 2023
af1ff21
added integ test and i think snapshot
Oct 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ const noCopyTagsCluster = new rds.ServerlessCluster(stack, 'Serverless Database
});
noCopyTagsCluster.connections.allowDefaultPortFromAnyIpv4('Open to the world');

const slc = new rds.ServerlessCluster(stack, 'Serverless Database', {
engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
vpc,
scaling: {
secondsBeforeTimeout: cdk.Duration.seconds(300),
timeoutAction: String('RollbackCapacityChange'),
},
});
slc.connections.allowDefaultPortFromAnyIpv4('Severless Cluster with timeout');

app.synth();
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,8 @@ const cluster = new rds.ServerlessCluster(this, 'AnotherCluster', {
autoPause: Duration.minutes(10), // default is to pause after 5 minutes of idle time
minCapacity: rds.AuroraCapacityUnit.ACU_8, // default is 2 Aurora capacity units (ACUs)
maxCapacity: rds.AuroraCapacityUnit.ACU_32, // default is 16 Aurora capacity units (ACUs)
secondsBeforeTimeout: Duration.seconds(300), // default is 300 seconds
timeoutAction: string("RollbackCapacityChange") // default is RollbackCapacityChange
}
});
```
Expand Down
33 changes: 33 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/serverless-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ export interface ServerlessScalingOptions {
* @default - automatic pause enabled after 5 minutes
*/
readonly autoPause?: Duration;

/**
* The amount of time, in seconds, that Aurora Serverless v1 tries to find a scaling point to perform seamless scaling before enforcing the timeout action.
* @default - automatic timeout after
*/
readonly secondsBeforeTimeout? : Duration;

/**
* The action to take when the timeout is reached, either ForceApplyCapacityChange or RollbackCapacityChange.
* ForceApplyCapacityChange sets the capacity to the specified value as soon as possible.
* RollbackCapacityChange, the default, ignores the capacity change if a scaling point isn't found in the timeout period.
* @default - RollbackCapacityChange
*/
readonly timeoutAction? : string;
}

/**
Expand Down Expand Up @@ -441,9 +455,24 @@ abstract class ServerlessClusterNew extends ServerlessClusterBase {
});
}

// valid timeout
private timeoutValidation(timeout: number | undefined, timeoutAction?: string | undefined): void {
if (timeout && (timeout < 60 || timeout > 600)) {
throw Error('seconds before timeout must be between 60 and 600 seconds.');
}

if (timeoutAction && (timeoutAction !== 'ForceApplyCapacityChange' && timeoutAction !== 'RollbackCapacityChange')) {
throw Error('timeout action must be ForceApplyCapacityChange or RollbackCapacityChange.');
}
}

private renderScalingConfiguration(options: ServerlessScalingOptions): CfnDBCluster.ScalingConfigurationProperty {
const minCapacity = options.minCapacity;
const maxCapacity = options.maxCapacity;
const timeout = options.secondsBeforeTimeout?.toSeconds();
const timeoutAction = options.timeoutAction;

this.timeoutValidation(timeout, timeoutAction);

if (minCapacity && maxCapacity && minCapacity > maxCapacity) {
throw new Error('maximum capacity must be greater than or equal to minimum capacity.');
Expand All @@ -458,6 +487,10 @@ abstract class ServerlessClusterNew extends ServerlessClusterBase {
autoPause: (secondsToAutoPause === 0) ? false : true,
minCapacity: options.minCapacity,
maxCapacity: options.maxCapacity,

secondsBeforeTimeout: (timeout === 300) ? undefined : timeout,
timeoutAction: options.timeoutAction,

secondsUntilAutoPause: (secondsToAutoPause === 0) ? undefined : secondsToAutoPause,
};
}
Expand Down
36 changes: 36 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/serverless-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ describe('serverless cluster', () => {
minCapacity: AuroraCapacityUnit.ACU_1,
maxCapacity: AuroraCapacityUnit.ACU_128,
autoPause: cdk.Duration.minutes(10),
secondsBeforeTimeout: cdk.Duration.seconds(0),
timeoutAction: String('RollbackCapacityChange'),
},
});

Expand All @@ -472,6 +474,8 @@ describe('serverless cluster', () => {
MaxCapacity: 128,
MinCapacity: 1,
SecondsUntilAutoPause: 600,
SecondsBeforeTimeout: 0,
TimeoutAction: 'RollbackCapacityChange',
},
});
});
Expand Down Expand Up @@ -536,6 +540,37 @@ describe('serverless cluster', () => {
});
});

test('throws when invalid seconds before time out is specified', () => {
// GIVEN
const stack = testStack();
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true });

expect(() =>
new ServerlessCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA_MYSQL,
vpc,
scaling: {
secondsBeforeTimeout: cdk.Duration.seconds(650),
},
})).toThrow(/seconds before timeout must be between 60 and 600 seconds./);
});

test('throws when invalid time out action set', () => {
// GIVEN
const stack = testStack();
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true });

// WHEN
expect(() =>
new ServerlessCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA_MYSQL,
vpc,
scaling: {
timeoutAction: String('helloworld'),
},
})).toThrow(/timeout action must be ForceApplyCapacityChange or RollbackCapacityChange./);
});

test('throws when invalid auto pause time is specified', () => {
// GIVEN
const stack = testStack();
Expand Down Expand Up @@ -942,3 +977,4 @@ function testStack(app?: cdk.App, id?: string): cdk.Stack {
stack.node.setContext('availability-zones:12345:us-test-1', ['us-test-1a', 'us-test-1b']);
return stack;
}

Loading