Skip to content

Commit

Permalink
fix(rds): do not allow aurora engines when using DatabaseInstance
Browse files Browse the repository at this point in the history
Aurora instances can only be created inside a cluster and should use the
`DatabaseCluster` construct.

Closes aws#5345
  • Loading branch information
jogold committed Dec 11, 2019
1 parent 88df1eb commit 409a958
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
constructor(scope: Construct, id: string, props: DatabaseInstanceSourceProps) {
super(scope, id, props);

if (/aurora/.test(props.engine.name)) {
throw new Error('Aurora instances can only be created inside a cluster. Please use `DatabaseCluster`.');
}

this.secretRotationApplication = props.engine.secretRotationApplication;

this.sourceCfnProps = {
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ export = {
}
}));

test.done();
},

'throws with aurora engines'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');

// THEN
test.throws(() => new rds.DatabaseInstance(stack, 'Instance', {
engine: rds.DatabaseInstanceEngine.AURORA_POSTGRESQL,
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.SMALL),
masterUsername: 'admin',
vpc,
}), /Aurora instances can only be created inside a cluster. Please use `DatabaseCluster`./);

test.done();
}
};

0 comments on commit 409a958

Please sign in to comment.