Skip to content

Commit

Permalink
feat(rds): add clusterArn property to IServerlessCluster (aws#10741)
Browse files Browse the repository at this point in the history
This PR adds a property `clusterArn` to `IServerlessCluster`. This simplifies the usage of the Data API which requires passing the ARN of the cluster in Data API calls.

closes aws#10736


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
asterikx authored Oct 6, 2020
1 parent 8006459 commit 1559fe9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/@aws-cdk/aws-rds/lib/serverless-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import { Resource, Duration, Token, Annotations, RemovalPolicy, IResource } from '@aws-cdk/core';
import { Resource, Duration, Token, Annotations, RemovalPolicy, IResource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IClusterEngine } from './cluster-engine';
import { DatabaseSecret } from './database-secret';
Expand All @@ -23,6 +23,11 @@ export interface IServerlessCluster extends IResource, ec2.IConnectable, secrets
*/
readonly clusterIdentifier: string;

/**
* The ARN of the cluster
*/
readonly clusterArn: string;

/**
* The endpoint to use for read/write operations
* @attribute EndpointAddress,EndpointPort
Expand Down Expand Up @@ -282,6 +287,18 @@ abstract class ServerlessClusterBase extends Resource implements IServerlessClus
*/
public abstract readonly connections: ec2.Connections;

/**
* The ARN of the cluster
*/
public get clusterArn(): string {
return Stack.of(this).formatArn({
service: 'rds',
resource: 'cluster',
sep: ':',
resourceName: this.clusterIdentifier,
});
}

/**
* Renders the secret attachment target specifications.
*/
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.serverless-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,37 @@ export = {

test.done();
},

'check that clusterArn property works'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true });
const cluster = new ServerlessCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA_MYSQL,
vpc,
});
const exportName = 'DbCluterArn';

// WHEN
new cdk.CfnOutput(stack, exportName, {
exportName,
value: cluster.clusterArn,
});

// THEN
test.deepEqual(stack.resolve(cluster.clusterArn), {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':rds:us-test-1:12345:cluster:',
{ Ref: 'DatabaseB269D8BB' },
],
],
});
test.done();
},
};

function testStack() {
Expand Down

0 comments on commit 1559fe9

Please sign in to comment.