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: add parameters and parameter groups support [CLK-260856] #64

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions API.md

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

54 changes: 46 additions & 8 deletions src/aurora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,35 @@ export interface AuroraProps {
* @default {subnetType:aws_ec2.SubnetType.PRIVATE_WITH_EGRESS} - all private subnets
*/
readonly vpcSubnets?: aws_ec2.SubnetSelection;

/**
* Additional parameters to pass to the database engine
*
* You can only specify parameterGroup or parameters but not both.
*
* @default - No parameter group.
*/
readonly parameterGroup?: aws_rds.IParameterGroup;

/**
* The parameters in the DBClusterParameterGroup to create automatically
*
* You can only specify parameterGroup or parameters but not both.
* You need to use a versioned engine to auto-generate a DBClusterParameterGroup.
*
* @default - defaultParameters
*
* const defaultParameters = {
* // While these are mentioned in the docs, applying them doesn't work.
* 'rds.logical_replication': '1', // found in the cluster parameters.
* // wal_level: 'logical', // not found in cluster parameters, but implicitly set by rds.logical_replication
* max_replication_slots: '10', // Arbitrary, must be > 1
* max_wal_senders: '10', // Arbitrary, must be > 1
* wal_sender_timeout: '0', // Never time out. Risky, but recommended.
* };
*
*/
readonly parameters?: { [key: string]: string };
}

/**
Expand Down Expand Up @@ -267,6 +296,21 @@ export class Aurora extends Construct {
];
}

/*
If both parameterGroup and parameters are not specified, the defaultParameters is used.
The behaviour is for backward compatibility so existing clusters don't show diffs when using upgraded libary.
Maybe better to move it to a upstream library.
*/
const defaultParameters = {
// While these are mentioned in the docs, applying them doesn't work.
'rds.logical_replication': '1', // found in the cluster parameters.
// wal_level: 'logical', // not found in cluster parameters, but implicitly set by rds.logical_replication
max_replication_slots: '10', // Arbitrary, must be > 1
max_wal_senders: '10', // Arbitrary, must be > 1
wal_sender_timeout: '0', // Never time out. Risky, but recommended.
};
const parameters = props.parameterGroup || props.parameters ? props.parameters : defaultParameters;

this.cluster = new aws_rds.DatabaseCluster(this, 'Database', {
backup: {
retention: props.retention ?? Duration.days(1),
Expand All @@ -293,14 +337,8 @@ export class Aurora extends Construct {
vpcSubnets,
},
instances: props.instances,
parameters: {
// While these are mentioned in the docs, applying them doesn't work.
'rds.logical_replication': '1', // found in the cluster parameters.
// wal_level: 'logical', // not found in cluster parameters, but implicitly set by rds.logical_replication
max_replication_slots: '10', // Arbitrary, must be > 1
max_wal_senders: '10', // Arbitrary, must be > 1
wal_sender_timeout: '0', // Never time out. Risky, but recommended.
},
parameterGroup: props.parameterGroup,
parameters: parameters,
removalPolicy: props.removalPolicy,
storageEncryptionKey: encryptionKey,
});
Expand Down
26 changes: 25 additions & 1 deletion test/aurora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {
} from 'aws-cdk-lib/aws-ec2';
import { CfnKey, IKey, Key } from 'aws-cdk-lib/aws-kms';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { AuroraPostgresEngineVersion, PerformanceInsightRetention } from 'aws-cdk-lib/aws-rds';
import {
AuroraPostgresEngineVersion,
DatabaseClusterEngine,
ParameterGroup,
PerformanceInsightRetention,
} from 'aws-cdk-lib/aws-rds';
import { Namer } from 'multi-convention-namer';

import { Aurora, AuroraProps } from '../src';
Expand Down Expand Up @@ -315,5 +320,24 @@ describe('Aurora', () => {
}),
);
});
it('parameterGroup', () => {
const version = AuroraPostgresEngineVersion.VER_12_8;
const parameterGroup = new ParameterGroup(stack, 'ParameterGroup', {
engine: DatabaseClusterEngine.auroraPostgres({
version,
}),
parameters: { test: 'rds' },
});
createAurora({ ...defaultAuroraProps, parameterGroup: parameterGroup });
template.hasResourceProperties('AWS::RDS::DBClusterParameterGroup', {
Parameters: { test: 'rds' },
});
});
it('parameters', () => {
createAurora({ ...defaultAuroraProps, parameters: { test: 'rds' } });
template.hasResourceProperties('AWS::RDS::DBClusterParameterGroup', {
Parameters: { test: 'rds' },
});
});
});
});