Skip to content

Commit

Permalink
Merge branch 'master' into bundled_assets_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Nov 19, 2021
2 parents bf075f8 + 9b2158b commit e97b4cb
Show file tree
Hide file tree
Showing 13 changed files with 680 additions and 59 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.8",
"jest-junit": "^13.0.0",
"jsii-diff": "^1.44.2",
"jsii-pacmak": "^1.44.2",
"jsii-reflect": "^1.44.2",
"jsii-rosetta": "^1.44.2",
"jsii-diff": "^1.45.0",
"jsii-pacmak": "^1.45.0",
"jsii-reflect": "^1.45.0",
"jsii-rosetta": "^1.45.0",
"lerna": "^4.0.0",
"patch-package": "^6.4.7",
"standard-version": "^9.3.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ urllib3==1.25.11
# Requests used by this lambda
requests==2.23.0
# Pillow 6.x so that python 2.7 and 3.x can both use this fixture
pillow==6.2.2
pillow==8.3.2
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ new rds.DatabaseInstanceReadReplica(this, 'ReadReplica', {
});
```

Automatic backups of read replica instances are only supported for MySQL and MariaDB. By default,
automatic backups are disabled for read replicas and can only be enabled (using `backupRetention`)
if also enabled on the source instance.

Creating a "production" Oracle database instance with option and parameter groups:

[example of setting up a production oracle instance](test/integ.instance.lit.ts)
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/instance-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export interface IInstanceEngine extends IEngine {
/** The application used by this engine to perform rotation for a multi-user scenario. */
readonly multiUserRotationApplication: secretsmanager.SecretRotationApplication;

/**
* Whether this engine supports automatic backups of a read replica instance.
*
* @default false
*/
readonly supportsReadReplicaBackups?: boolean;

/**
* Method called when the engine is used to create a new instance.
*/
Expand All @@ -123,6 +130,7 @@ abstract class InstanceEngineBase implements IInstanceEngine {
public readonly singleUserRotationApplication: secretsmanager.SecretRotationApplication;
public readonly multiUserRotationApplication: secretsmanager.SecretRotationApplication;
public readonly engineFamily?: string;
public readonly supportsReadReplicaBackups?: boolean;

private readonly features?: InstanceEngineFeatures;

Expand Down Expand Up @@ -320,6 +328,8 @@ export interface MariaDbInstanceEngineProps {
}

class MariaDbInstanceEngine extends InstanceEngineBase {
public readonly supportsReadReplicaBackups = true;

constructor(version?: MariaDbEngineVersion) {
super({
engineType: 'mariadb',
Expand Down Expand Up @@ -533,6 +543,8 @@ export interface MySqlInstanceEngineProps {
}

class MySqlInstanceEngine extends InstanceEngineBase {
public readonly supportsReadReplicaBackups = true;

constructor(version?: MysqlEngineVersion) {
super({
engineType: 'mysql',
Expand Down
8 changes: 7 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export interface DatabaseInstanceNewProps {
* When creating a read replica, you must enable automatic backups on the source
* database instance by setting the backup retention to a value other than zero.
*
* @default Duration.days(1)
* @default - Duration.days(1) for source instances, disabled for read replicas
*/
readonly backupRetention?: Duration;

Expand Down Expand Up @@ -1143,6 +1143,12 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
constructor(scope: Construct, id: string, props: DatabaseInstanceReadReplicaProps) {
super(scope, id, props);

if (props.sourceDatabaseInstance.engine
&& !props.sourceDatabaseInstance.engine.supportsReadReplicaBackups
&& props.backupRetention) {
throw new Error(`Cannot set 'backupRetention', as engine '${engineDescription(props.sourceDatabaseInstance.engine)}' does not support automatic backups for read replicas`);
}

const instance = new CfnDBInstance(this, 'Resource', {
...this.newCfnProps,
// this must be ARN, not ID, because of https://github.com/terraform-providers/terraform-provider-aws/issues/528#issuecomment-391169012
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-rds/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,26 @@ describe('instance', () => {
});
});

test('throws with backupRetention on a read replica if engine does not support it', () => {
// GIVEN
const instanceType = ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL);
const backupRetention = cdk.Duration.days(5);
const source = new rds.DatabaseInstance(stack, 'Source', {
engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_13 }),
backupRetention,
instanceType,
vpc,
});

expect(() => {
new rds.DatabaseInstanceReadReplica(stack, 'Replica', {
sourceDatabaseInstance: source,
backupRetention,
instanceType,
vpc,
});
}).toThrow(/Cannot set 'backupRetention', as engine 'postgres-13' does not support automatic backups for read replicas/);
});
});

test.each([
Expand Down
Loading

0 comments on commit e97b4cb

Please sign in to comment.