Skip to content

Commit

Permalink
feat(neptune): add copyTagsToSnapshot property to the DatabaseCluster…
Browse files Browse the repository at this point in the history
… Construct (#30092)

### Issue # (if applicable)

Closes #30087 

### Reason for this change
As described in the issue.



### Description of changes
Add copyTagsToSnapshot property to the DatabaseCluster Construct.


### Description of how you validated changes
Add both unit tests and integ tests.


### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mazyu36 committed May 27, 2024
1 parent 6301a9a commit ba8edb3
Show file tree
Hide file tree
Showing 12 changed files with 2,021 additions and 7 deletions.
22 changes: 17 additions & 5 deletions packages/@aws-cdk/aws-neptune-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as neptune from '@aws-cdk/aws-neptune-alpha';

## Starting a Neptune Database

To set up a Neptune database, define a `DatabaseCluster`. You must always launch a database in a VPC.
To set up a Neptune database, define a `DatabaseCluster`. You must always launch a database in a VPC.

```ts
const cluster = new neptune.DatabaseCluster(this, 'Database', {
Expand Down Expand Up @@ -126,9 +126,9 @@ const replica1 = new neptune.DatabaseInstance(this, 'Instance', {

## Automatic minor version upgrades

By setting `autoMinorVersionUpgrade` to true, Neptune will automatically update
the engine of the entire cluster to the latest minor version after a stabilization
window of 2 to 3 weeks.
By setting `autoMinorVersionUpgrade` to true, Neptune will automatically update
the engine of the entire cluster to the latest minor version after a stabilization
window of 2 to 3 weeks.

```ts
new neptune.DatabaseCluster(this, 'Cluster', {
Expand Down Expand Up @@ -184,9 +184,21 @@ instance.metric('SparqlRequestsPerSec') // instance-level SparqlErrors metric

For more details on the available metrics, refer to https://docs.aws.amazon.com/neptune/latest/userguide/cw-metrics.html

## Copy tags to snapshot

By setting `copyTagsToSnapshot` to true, all tags of the cluster are copied to the snapshots when they are created.

```ts
const cluster = new neptune.DatabaseCluster(this, 'Database', {
vpc,
instanceType: neptune.InstanceType.R5_LARGE,
copyTagsToSnapshot: true // whether to save the cluster tags when creating the snapshot.
});
```

## Neptune Serverless

You can configure a Neptune Serverless cluster using the dedicated instance type along with the
You can configure a Neptune Serverless cluster using the dedicated instance type along with the
`serverlessScalingConfiguration` property.

> Visit [Using Amazon Neptune Serverless](https://docs.aws.amazon.com/neptune/latest/userguide/neptune-serverless-using.html) for more details.
Expand Down
13 changes: 11 additions & 2 deletions packages/@aws-cdk/aws-neptune-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class EngineVersion {
* Constructor for specifying a custom engine version
* @param version the engine version of Neptune
*/
public constructor(public readonly version: string) {}
public constructor(public readonly version: string) { }
}

/**
Expand All @@ -109,7 +109,7 @@ export class LogType {
* Constructor for specifying a custom log type
* @param value the log type
*/
public constructor(public readonly value: string) {}
public constructor(public readonly value: string) { }
}

export interface ServerlessScalingConfiguration {
Expand Down Expand Up @@ -325,6 +325,13 @@ export interface DatabaseClusterProps {
* @default - required if instanceType is db.serverless
*/
readonly serverlessScalingConfiguration?: ServerlessScalingConfiguration;

/**
* Whether to copy tags to the snapshot when a snapshot is created.
*
* @default - false
*/
readonly copyTagsToSnapshot?: boolean;
}

/**
Expand Down Expand Up @@ -620,6 +627,8 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
enableCloudwatchLogsExports: props.cloudwatchLogsExports?.map(logType => logType.value),
storageEncrypted,
serverlessScalingConfiguration: props.serverlessScalingConfiguration,
// Tags
copyTagsToSnapshot: props.copyTagsToSnapshot,
});

cluster.applyRemovalPolicy(props.removalPolicy, {
Expand Down
34 changes: 34 additions & 0 deletions packages/@aws-cdk/aws-neptune-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,40 @@ describe('DatabaseCluster', () => {
RetentionInDays: 30,
});
});

test('copyTagsToSnapshot is not set by default', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
vpc,
instanceType: InstanceType.R5_LARGE,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBCluster', {
CopyTagsToSnapshot: Match.absent(),
});
});

test.each([false, true])('cluster with copyTagsToSnapshot set', (value) => {
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
vpc,
instanceType: InstanceType.R5_LARGE,
copyTagsToSnapshot: value,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBCluster', {
CopyTagsToSnapshot: value,
});
});
});

function testStack() {
Expand Down

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

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

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

Loading

0 comments on commit ba8edb3

Please sign in to comment.