Skip to content

Commit

Permalink
update baseCapacity
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Sep 14, 2024
1 parent 63aca7a commit 3b71877
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
6 changes: 6 additions & 0 deletions API.md

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

17 changes: 15 additions & 2 deletions src/aws-redshiftserverless/workgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export interface WorkgroupProps {
/**
* The base compute capacity of the workgroup in Redshift Processing Units (RPUs).
*
* You can adjust the Base capacity setting from 8 RPUs to 512 RPUs in units of 8.
* Also you can increment or decrement RPUs in units of 32 when setting a base capacity between 512-1024.
*
* @default 128
*
* @see https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-capacity.html
*/
readonly baseCapacity?: number;

Expand Down Expand Up @@ -285,8 +290,16 @@ export class Workgroup extends Resource implements IWorkgroup {
const baseCapacity = this.props.baseCapacity;

if (!Token.isUnresolved(baseCapacity) && baseCapacity !== undefined) {
if (baseCapacity < 8 || baseCapacity > 512 || baseCapacity % 8 !== 0) {
throw new Error(`\`baseCapacity\` must be between 8 and 512 in units of 8, got: ${baseCapacity}.`);
if (baseCapacity < 8 || baseCapacity > 1024) {
throw new Error(`\`baseCapacity\` must be between 8 and 1024, got: ${baseCapacity}.`);
}

if (8 <= baseCapacity && baseCapacity <= 512 && baseCapacity % 8 !== 0) {
throw new Error(`\`baseCapacity\` must be units of 8 between 8 and 512, got: ${baseCapacity}.`);
}

if (512 <= baseCapacity && baseCapacity <= 1024 && baseCapacity % 32 !== 0) {
throw new Error(`\`baseCapacity\` must be units of 32 between 512 and 1024, got: ${baseCapacity}.`);
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions test/aws-redshiftserverless/workgroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,31 @@ describe('Redshift Serverless Workgroup', () => {
});

describe('validateCapacity test', () => {
test.each([0, 520, 15])('throws when baseCapacity is invalid, got %d', baseCapacity => {
test.each([0, 1056])('throws when baseCapacity is out of range, got %d', baseCapacity => {
expect(() => {
new Workgroup(stack, 'Workgroup', {
baseCapacity,
vpc,
});
}).toThrow(`\`baseCapacity\` must be between 8 and 512 in units of 8, got: ${baseCapacity}.`);
}).toThrow(`\`baseCapacity\` must be between 8 and 1024, got: ${baseCapacity}.`);
});

test('throws when baseCapacity is not units of 8 between 8 and 512', () => {
expect(() => {
new Workgroup(stack, 'Workgroup', {
baseCapacity: 15,
vpc,
});
}).toThrow('`baseCapacity` must be units of 8 between 8 and 512, got: 15.');
});

test('throws when baseCapacity is not units of 32 between 512 and 1024', () => {
expect(() => {
new Workgroup(stack, 'Workgroup', {
baseCapacity: 520,
vpc,
});
}).toThrow('`baseCapacity` must be units of 32 between 512 and 1024, got: 520.');
});
});

Expand Down

0 comments on commit 3b71877

Please sign in to comment.