Skip to content

Commit 45cf387

Browse files
authored
fix(aws-appsync): use serverlessCluster on rdsDataSource (#13206)
Resolves: #12567 BREAKING CHANGE: RdsDataSource now takes a ServerlessCluster instead of a DatabaseCluster ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 745fc22 commit 45cf387

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

packages/@aws-cdk/aws-appsync/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ const secret = new rds.DatabaseSecret(stack, 'AuroraSecret', {
107107
username: 'clusteradmin',
108108
});
109109

110-
// Create the DB cluster, provide all values needed to customise the database.
111-
const cluster = new rds.DatabaseCluster(stack, 'AuroraCluster', {
112-
engine: rds.DatabaseClusterEngine.auroraMysql({ version: rds.AuroraMysqlEngineVersion.VER_2_07_1 }),
110+
// The VPC to place the cluster in
111+
const vpc = new ec2.Vpc(stack, 'AuroraVpc');
112+
113+
// Create the serverless cluster, provide all values needed to customise the database.
114+
const cluster = new rds.ServerlessCluster(stack, 'AuroraCluster', {
115+
engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
116+
vpc,
113117
credentials: { username: 'clusteradmin' },
114118
clusterIdentifier: 'db-endpoint-test',
115119
defaultDatabaseName: 'demos',

packages/@aws-cdk/aws-appsync/lib/data-source.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ITable } from '@aws-cdk/aws-dynamodb';
22
import { Grant, IGrantable, IPrincipal, IRole, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
33
import { IFunction } from '@aws-cdk/aws-lambda';
4-
import { IDatabaseCluster } from '@aws-cdk/aws-rds';
4+
import { IServerlessCluster } from '@aws-cdk/aws-rds';
55
import { ISecret } from '@aws-cdk/aws-secretsmanager';
66
import { IResolvable, Lazy, Stack } from '@aws-cdk/core';
77
import { Construct } from 'constructs';
@@ -303,9 +303,9 @@ export class LambdaDataSource extends BackedDataSource {
303303
*/
304304
export interface RdsDataSourceProps extends BackedDataSourceProps {
305305
/**
306-
* The database cluster to call to interact with this data source
306+
* The serverless cluster to call to interact with this data source
307307
*/
308-
readonly databaseCluster: IDatabaseCluster;
308+
readonly serverlessCluster: IServerlessCluster;
309309
/**
310310
* The secret containing the credentials for the database
311311
*/
@@ -327,12 +327,12 @@ export class RdsDataSource extends BackedDataSource {
327327
type: 'RELATIONAL_DATABASE',
328328
relationalDatabaseConfig: {
329329
rdsHttpEndpointConfig: {
330-
awsRegion: props.databaseCluster.stack.region,
330+
awsRegion: props.serverlessCluster.stack.region,
331331
dbClusterIdentifier: Lazy.string({
332332
produce: () => {
333333
return Stack.of(this).formatArn({
334334
service: 'rds',
335-
resource: `cluster:${props.databaseCluster.clusterIdentifier}`,
335+
resource: `cluster:${props.serverlessCluster.clusterIdentifier}`,
336336
});
337337
},
338338
}),
@@ -344,7 +344,7 @@ export class RdsDataSource extends BackedDataSource {
344344
});
345345
const clusterArn = Stack.of(this).formatArn({
346346
service: 'rds',
347-
resource: `cluster:${props.databaseCluster.clusterIdentifier}`,
347+
resource: `cluster:${props.serverlessCluster.clusterIdentifier}`,
348348
});
349349
props.secretStore.grantRead(this);
350350

packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ITable } from '@aws-cdk/aws-dynamodb';
22
import { IFunction } from '@aws-cdk/aws-lambda';
3-
import { IDatabaseCluster } from '@aws-cdk/aws-rds';
3+
import { IServerlessCluster } from '@aws-cdk/aws-rds';
44
import { ISecret } from '@aws-cdk/aws-secretsmanager';
55
import { CfnResource, IResource, Resource } from '@aws-cdk/core';
66
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, RdsDataSource, AwsIamConfig } from './data-source';
@@ -97,14 +97,14 @@ export interface IGraphqlApi extends IResource {
9797
* add a new Rds data source to this API
9898
*
9999
* @param id The data source's id
100-
* @param databaseCluster The database cluster to interact with this data source
101-
* @param secretStore The secret store that contains the username and password for the database cluster
100+
* @param serverlessCluster The serverless cluster to interact with this data source
101+
* @param secretStore The secret store that contains the username and password for the serverless cluster
102102
* @param databaseName The optional name of the database to use within the cluster
103103
* @param options The optional configuration for this data source
104104
*/
105105
addRdsDataSource(
106106
id: string,
107-
databaseCluster: IDatabaseCluster,
107+
serverlessCluster: IServerlessCluster,
108108
secretStore: ISecret,
109109
databaseName?: string,
110110
options?: DataSourceOptions
@@ -206,14 +206,14 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
206206
/**
207207
* add a new Rds data source to this API
208208
* @param id The data source's id
209-
* @param databaseCluster The database cluster to interact with this data source
210-
* @param secretStore The secret store that contains the username and password for the database cluster
209+
* @param serverlessCluster The serverless cluster to interact with this data source
210+
* @param secretStore The secret store that contains the username and password for the serverless cluster
211211
* @param databaseName The optional name of the database to use within the cluster
212212
* @param options The optional configuration for this data source
213213
*/
214214
public addRdsDataSource(
215215
id: string,
216-
databaseCluster: IDatabaseCluster,
216+
serverlessCluster: IServerlessCluster,
217217
secretStore: ISecret,
218218
databaseName?: string,
219219
options?: DataSourceOptions,
@@ -222,7 +222,7 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
222222
api: this,
223223
name: options?.name,
224224
description: options?.description,
225-
databaseCluster,
225+
serverlessCluster,
226226
secretStore,
227227
databaseName,
228228
});

packages/@aws-cdk/aws-appsync/test/appsync-rds.test.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '@aws-cdk/assert/jest';
22
import * as path from 'path';
3-
import { Vpc, SecurityGroup, SubnetType, InstanceType, InstanceClass, InstanceSize } from '@aws-cdk/aws-ec2';
4-
import { DatabaseSecret, DatabaseCluster, DatabaseClusterEngine, AuroraMysqlEngineVersion } from '@aws-cdk/aws-rds';
3+
import { Vpc, SecurityGroup, SubnetType } from '@aws-cdk/aws-ec2';
4+
import { DatabaseSecret, DatabaseClusterEngine, AuroraMysqlEngineVersion, ServerlessCluster } from '@aws-cdk/aws-rds';
55
import * as cdk from '@aws-cdk/core';
66
import * as appsync from '../lib';
77

@@ -21,7 +21,7 @@ beforeEach(() => {
2121
describe('Rds Data Source configuration', () => {
2222
// GIVEN
2323
let secret: DatabaseSecret;
24-
let cluster: DatabaseCluster;
24+
let cluster: ServerlessCluster;
2525
beforeEach(() => {
2626
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2 });
2727
const securityGroup = new SecurityGroup(stack, 'AuroraSecurityGroup', {
@@ -31,16 +31,13 @@ describe('Rds Data Source configuration', () => {
3131
secret = new DatabaseSecret(stack, 'AuroraSecret', {
3232
username: 'clusteradmin',
3333
});
34-
cluster = new DatabaseCluster(stack, 'AuroraCluster', {
34+
cluster = new ServerlessCluster(stack, 'AuroraCluster', {
3535
engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_2_07_1 }),
3636
credentials: { username: 'clusteradmin' },
3737
clusterIdentifier: 'db-endpoint-test',
38-
instanceProps: {
39-
instanceType: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.SMALL),
40-
vpcSubnets: { subnetType: SubnetType.PRIVATE },
41-
vpc,
42-
securityGroups: [securityGroup],
43-
},
38+
vpc,
39+
vpcSubnets: { subnetType: SubnetType.PRIVATE },
40+
securityGroups: [securityGroup],
4441
defaultDatabaseName: 'Animals',
4542
});
4643
});
@@ -205,7 +202,7 @@ describe('Rds Data Source configuration', () => {
205202
describe('adding rds data source from imported api', () => {
206203
// GIVEN
207204
let secret: DatabaseSecret;
208-
let cluster: DatabaseCluster;
205+
let cluster: ServerlessCluster;
209206
beforeEach(() => {
210207
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2 });
211208
const securityGroup = new SecurityGroup(stack, 'AuroraSecurityGroup', {
@@ -215,16 +212,13 @@ describe('adding rds data source from imported api', () => {
215212
secret = new DatabaseSecret(stack, 'AuroraSecret', {
216213
username: 'clusteradmin',
217214
});
218-
cluster = new DatabaseCluster(stack, 'AuroraCluster', {
215+
cluster = new ServerlessCluster(stack, 'AuroraCluster', {
219216
engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_2_07_1 }),
220217
credentials: { username: 'clusteradmin' },
221218
clusterIdentifier: 'db-endpoint-test',
222-
instanceProps: {
223-
instanceType: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.SMALL),
224-
vpcSubnets: { subnetType: SubnetType.PRIVATE },
225-
vpc,
226-
securityGroups: [securityGroup],
227-
},
219+
vpc,
220+
vpcSubnets: { subnetType: SubnetType.PRIVATE },
221+
securityGroups: [securityGroup],
228222
defaultDatabaseName: 'Animals',
229223
});
230224
});

0 commit comments

Comments
 (0)