Skip to content
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
10 changes: 7 additions & 3 deletions packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ const secret = new rds.DatabaseSecret(stack, 'AuroraSecret', {
username: 'clusteradmin',
});

// Create the DB cluster, provide all values needed to customise the database.
const cluster = new rds.DatabaseCluster(stack, 'AuroraCluster', {
engine: rds.DatabaseClusterEngine.auroraMysql({ version: rds.AuroraMysqlEngineVersion.VER_2_07_1 }),
// The VPC to place the cluster in
const vpc = new ec2.Vpc(stack, 'AuroraVpc');

// Create the serverless cluster, provide all values needed to customise the database.
const cluster = new rds.ServerlessCluster(stack, 'AuroraCluster', {
engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
vpc,
credentials: { username: 'clusteradmin' },
clusterIdentifier: 'db-endpoint-test',
defaultDatabaseName: 'demos',
Expand Down
12 changes: 6 additions & 6 deletions packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ITable } from '@aws-cdk/aws-dynamodb';
import { Grant, IGrantable, IPrincipal, IRole, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import { IFunction } from '@aws-cdk/aws-lambda';
import { IDatabaseCluster } from '@aws-cdk/aws-rds';
import { IServerlessCluster } from '@aws-cdk/aws-rds';
import { ISecret } from '@aws-cdk/aws-secretsmanager';
import { IResolvable, Lazy, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -303,9 +303,9 @@ export class LambdaDataSource extends BackedDataSource {
*/
export interface RdsDataSourceProps extends BackedDataSourceProps {
/**
* The database cluster to call to interact with this data source
* The serverless cluster to call to interact with this data source
*/
readonly databaseCluster: IDatabaseCluster;
readonly serverlessCluster: IServerlessCluster;
/**
* The secret containing the credentials for the database
*/
Expand All @@ -327,12 +327,12 @@ export class RdsDataSource extends BackedDataSource {
type: 'RELATIONAL_DATABASE',
relationalDatabaseConfig: {
rdsHttpEndpointConfig: {
awsRegion: props.databaseCluster.stack.region,
awsRegion: props.serverlessCluster.stack.region,
dbClusterIdentifier: Lazy.string({
produce: () => {
return Stack.of(this).formatArn({
service: 'rds',
resource: `cluster:${props.databaseCluster.clusterIdentifier}`,
resource: `cluster:${props.serverlessCluster.clusterIdentifier}`,
});
},
}),
Expand All @@ -344,7 +344,7 @@ export class RdsDataSource extends BackedDataSource {
});
const clusterArn = Stack.of(this).formatArn({
service: 'rds',
resource: `cluster:${props.databaseCluster.clusterIdentifier}`,
resource: `cluster:${props.serverlessCluster.clusterIdentifier}`,
});
props.secretStore.grantRead(this);

Expand Down
16 changes: 8 additions & 8 deletions packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ITable } from '@aws-cdk/aws-dynamodb';
import { IFunction } from '@aws-cdk/aws-lambda';
import { IDatabaseCluster } from '@aws-cdk/aws-rds';
import { IServerlessCluster } from '@aws-cdk/aws-rds';
import { ISecret } from '@aws-cdk/aws-secretsmanager';
import { CfnResource, IResource, Resource } from '@aws-cdk/core';
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, RdsDataSource, AwsIamConfig } from './data-source';
Expand Down Expand Up @@ -97,14 +97,14 @@ export interface IGraphqlApi extends IResource {
* add a new Rds data source to this API
*
* @param id The data source's id
* @param databaseCluster The database cluster to interact with this data source
* @param secretStore The secret store that contains the username and password for the database cluster
* @param serverlessCluster The serverless cluster to interact with this data source
* @param secretStore The secret store that contains the username and password for the serverless cluster
* @param databaseName The optional name of the database to use within the cluster
* @param options The optional configuration for this data source
*/
addRdsDataSource(
id: string,
databaseCluster: IDatabaseCluster,
serverlessCluster: IServerlessCluster,
secretStore: ISecret,
databaseName?: string,
options?: DataSourceOptions
Expand Down Expand Up @@ -206,14 +206,14 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
/**
* add a new Rds data source to this API
* @param id The data source's id
* @param databaseCluster The database cluster to interact with this data source
* @param secretStore The secret store that contains the username and password for the database cluster
* @param serverlessCluster The serverless cluster to interact with this data source
* @param secretStore The secret store that contains the username and password for the serverless cluster
* @param databaseName The optional name of the database to use within the cluster
* @param options The optional configuration for this data source
*/
public addRdsDataSource(
id: string,
databaseCluster: IDatabaseCluster,
serverlessCluster: IServerlessCluster,
secretStore: ISecret,
databaseName?: string,
options?: DataSourceOptions,
Expand All @@ -222,7 +222,7 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
api: this,
name: options?.name,
description: options?.description,
databaseCluster,
serverlessCluster,
secretStore,
databaseName,
});
Expand Down
30 changes: 12 additions & 18 deletions packages/@aws-cdk/aws-appsync/test/appsync-rds.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@aws-cdk/assert/jest';
import * as path from 'path';
import { Vpc, SecurityGroup, SubnetType, InstanceType, InstanceClass, InstanceSize } from '@aws-cdk/aws-ec2';
import { DatabaseSecret, DatabaseCluster, DatabaseClusterEngine, AuroraMysqlEngineVersion } from '@aws-cdk/aws-rds';
import { Vpc, SecurityGroup, SubnetType } from '@aws-cdk/aws-ec2';
import { DatabaseSecret, DatabaseClusterEngine, AuroraMysqlEngineVersion, ServerlessCluster } from '@aws-cdk/aws-rds';
import * as cdk from '@aws-cdk/core';
import * as appsync from '../lib';

Expand All @@ -21,7 +21,7 @@ beforeEach(() => {
describe('Rds Data Source configuration', () => {
// GIVEN
let secret: DatabaseSecret;
let cluster: DatabaseCluster;
let cluster: ServerlessCluster;
beforeEach(() => {
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2 });
const securityGroup = new SecurityGroup(stack, 'AuroraSecurityGroup', {
Expand All @@ -31,16 +31,13 @@ describe('Rds Data Source configuration', () => {
secret = new DatabaseSecret(stack, 'AuroraSecret', {
username: 'clusteradmin',
});
cluster = new DatabaseCluster(stack, 'AuroraCluster', {
cluster = new ServerlessCluster(stack, 'AuroraCluster', {
engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_2_07_1 }),
credentials: { username: 'clusteradmin' },
clusterIdentifier: 'db-endpoint-test',
instanceProps: {
instanceType: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.SMALL),
vpcSubnets: { subnetType: SubnetType.PRIVATE },
vpc,
securityGroups: [securityGroup],
},
vpc,
vpcSubnets: { subnetType: SubnetType.PRIVATE },
securityGroups: [securityGroup],
defaultDatabaseName: 'Animals',
});
});
Expand Down Expand Up @@ -205,7 +202,7 @@ describe('Rds Data Source configuration', () => {
describe('adding rds data source from imported api', () => {
// GIVEN
let secret: DatabaseSecret;
let cluster: DatabaseCluster;
let cluster: ServerlessCluster;
beforeEach(() => {
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2 });
const securityGroup = new SecurityGroup(stack, 'AuroraSecurityGroup', {
Expand All @@ -215,16 +212,13 @@ describe('adding rds data source from imported api', () => {
secret = new DatabaseSecret(stack, 'AuroraSecret', {
username: 'clusteradmin',
});
cluster = new DatabaseCluster(stack, 'AuroraCluster', {
cluster = new ServerlessCluster(stack, 'AuroraCluster', {
engine: DatabaseClusterEngine.auroraMysql({ version: AuroraMysqlEngineVersion.VER_2_07_1 }),
credentials: { username: 'clusteradmin' },
clusterIdentifier: 'db-endpoint-test',
instanceProps: {
instanceType: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.SMALL),
vpcSubnets: { subnetType: SubnetType.PRIVATE },
vpc,
securityGroups: [securityGroup],
},
vpc,
vpcSubnets: { subnetType: SubnetType.PRIVATE },
securityGroups: [securityGroup],
defaultDatabaseName: 'Animals',
});
});
Expand Down