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
14 changes: 11 additions & 3 deletions packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Grant, IGrantable, IPrincipal, IRole, Role, ServicePrincipal } from '@a
import { IFunction } from '@aws-cdk/aws-lambda';
import { IDatabaseCluster } from '@aws-cdk/aws-rds';
import { ISecret } from '@aws-cdk/aws-secretsmanager';
import { IResolvable, Stack } from '@aws-cdk/core';
import { IResolvable, Lazy, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { BaseAppsyncFunctionProps, AppsyncFunction } from './appsync-function';
import { CfnDataSource } from './appsync.generated';
Expand Down Expand Up @@ -318,17 +318,25 @@ export class RdsDataSource extends BackedDataSource {
relationalDatabaseConfig: {
rdsHttpEndpointConfig: {
awsRegion: props.databaseCluster.stack.region,
dbClusterIdentifier: props.databaseCluster.clusterIdentifier,
dbClusterIdentifier: Lazy.string({
produce: () => {
return Stack.of(this).formatArn({
service: 'rds',
resource: `cluster:${props.databaseCluster.clusterIdentifier}`,
});
},
}),
awsSecretStoreArn: props.secretStore.secretArn,
},
relationalDatabaseSourceType: 'RDS_HTTP_ENDPOINT',
},
});
props.secretStore.grantRead(this);
const clusterArn = Stack.of(this).formatArn({
service: 'rds',
resource: `cluster:${props.databaseCluster.clusterIdentifier}`,
});
props.secretStore.grantRead(this);

// Change to grant with RDS grant becomes implemented
Grant.addToPrincipal({
grantee: this,
Expand Down
26 changes: 26 additions & 0 deletions packages/@aws-cdk/aws-appsync/test/appsync-rds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ describe('Rds Data Source configuration', () => {
});
});

test('rds cluster arn saved to RdsHttpEndpointConfig', () => {
// WHEN
api.addRdsDataSource('ds', cluster, secret);

// THEN
expect(stack).toHaveResourceLike('AWS::AppSync::DataSource', {
Type: 'RELATIONAL_DATABASE',
RelationalDatabaseConfig: {
RdsHttpEndpointConfig: {
AwsRegion: { Ref: 'AWS::Region' },
AwsSecretStoreArn: { Ref: 'AuroraSecret41E6E877' },
DbClusterIdentifier: {
'Fn::Join': ['', ['arn:',
{ Ref: 'AWS::Partition' },
':rds:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':cluster:',
{ Ref: 'AuroraCluster23D869C0' }]],
},
},
},
});
});

test('default configuration produces name identical to the id', () => {
// WHEN
api.addRdsDataSource('ds', cluster, secret);
Expand Down