@@ -21,8 +21,15 @@ import { NagSuppressions } from 'cdk-nag';
21
21
import { Construct } from 'constructs' ;
22
22
import { buildCustomResourceProvider } from '../../common/helpers/custom-resource-provider-helper' ;
23
23
import { generatePhysicalNameV2 } from '../../common/helpers/utils' ;
24
- import { AddAwsServiceEndpoint , buildVpc , ServiceEndpointTypeEnum } from '../../common/helpers/vpc-helper' ;
25
-
24
+ import {
25
+ AddAwsServiceEndpoint ,
26
+ buildVpc ,
27
+ ServiceEndpointTypeEnum ,
28
+ } from '../../common/helpers/vpc-helper' ;
29
+
30
+ /******************************************************************************
31
+ * ENUMS
32
+ *****************************************************************************/
26
33
/**
27
34
* List of supported versions of PostgreSQL for Aurora cluster.
28
35
*/
@@ -43,6 +50,9 @@ export const SupportedPostgreSQLVersions = {
43
50
export type SupportedPostgreSQLVersions =
44
51
( typeof SupportedPostgreSQLVersions ) [ keyof typeof SupportedPostgreSQLVersions ] ;
45
52
53
+ /******************************************************************************
54
+ * COMMON
55
+ *****************************************************************************/
46
56
/**
47
57
* Base properties for an Aurora Vector Store.
48
58
*/
@@ -141,11 +151,11 @@ export interface ExistingAmazonAuroraVectorStoreProps extends BaseAuroraVectorSt
141
151
readonly secret : secretsmanager . ISecret ;
142
152
143
153
/**
144
- * The id of the security group associated with the RDS Aurora instance.
154
+ * The Security group associated with the RDS Aurora instance.
145
155
* This security group allows access to the Aurora Vector Store from Lambda's
146
156
* custom resource running pgVector SQL commands.
147
157
*/
148
- readonly auroraSecurityGroupId : string ;
158
+ readonly auroraSecurityGroup : ec2 . ISecurityGroup ;
149
159
}
150
160
151
161
/**
@@ -181,7 +191,7 @@ export interface DatabaseClusterResources {
181
191
/**
182
192
* The security group associated with the Aurora cluster.
183
193
*/
184
- readonly auroraSecurityGroup : ec2 . SecurityGroup ;
194
+ readonly auroraSecurityGroup : ec2 . ISecurityGroup ;
185
195
}
186
196
187
197
/**
@@ -242,7 +252,8 @@ abstract class BaseAmazonAuroraVectorStore extends Construct {
242
252
* Setup databaseName based on if it is provided in the props or not
243
253
* and based on whether it is an existing Aurora Vector Store or not.
244
254
*/
245
- this . databaseName = 'clusterIdentifier' in props ? props . databaseName : props . databaseName ?? 'bedrock_vector_db' ;
255
+ this . databaseName =
256
+ 'clusterIdentifier' in props ? props . databaseName : props . databaseName ?? 'bedrock_vector_db' ;
246
257
247
258
this . schemaName = props . schemaName ?? 'bedrock_integration' ;
248
259
this . vectorField = props . vectorField ?? 'embedding' ;
@@ -324,14 +335,9 @@ abstract class BaseAmazonAuroraVectorStore extends Construct {
324
335
vpc : ec2 . IVpc ,
325
336
secret : secretsmanager . ISecret ,
326
337
clusterIdentifier : string ,
327
- auroraSecurityGroupId : string ,
338
+ auroraSecurityGroup : ec2 . ISecurityGroup ,
328
339
) : DatabaseClusterResources {
329
340
const resourceArn = this . generateResourceArn ( clusterIdentifier ) ;
330
- const auroraSecurityGroup = ec2 . SecurityGroup . fromLookupById (
331
- this ,
332
- 'ExistingSG' ,
333
- auroraSecurityGroupId ,
334
- ) as ec2 . SecurityGroup ;
335
341
336
342
return {
337
343
vpc,
@@ -351,8 +357,8 @@ abstract class BaseAmazonAuroraVectorStore extends Construct {
351
357
}
352
358
353
359
protected addIngressRuleToAuroraSecurityGroup (
354
- lambdaSecurityGroup : ec2 . SecurityGroup ,
355
- auroraSecurityGroup : ec2 . SecurityGroup ,
360
+ lambdaSecurityGroup : ec2 . ISecurityGroup ,
361
+ auroraSecurityGroup : ec2 . ISecurityGroup ,
356
362
) {
357
363
auroraSecurityGroup . addIngressRule (
358
364
lambdaSecurityGroup ,
@@ -424,12 +430,17 @@ export class ExistingAmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore
424
430
props . vpc ,
425
431
props . secret ,
426
432
props . clusterIdentifier ,
427
- props . auroraSecurityGroupId ,
433
+ props . auroraSecurityGroup ,
428
434
) ;
429
435
430
- const auroraPgCRPolicy = this . createAuroraPgCRPolicy ( databaseClusterResources . clusterIdentifier ) ;
436
+ const auroraPgCRPolicy = this . createAuroraPgCRPolicy (
437
+ databaseClusterResources . clusterIdentifier ,
438
+ ) ;
431
439
const lambdaSecurityGroup = this . createLambdaSecurityGroup ( databaseClusterResources . vpc ) ;
432
- this . addIngressRuleToAuroraSecurityGroup ( lambdaSecurityGroup , databaseClusterResources . auroraSecurityGroup ) ;
440
+ this . addIngressRuleToAuroraSecurityGroup (
441
+ lambdaSecurityGroup ,
442
+ databaseClusterResources . auroraSecurityGroup ,
443
+ ) ;
433
444
434
445
this . resourceArn = this . generateResourceArn ( databaseClusterResources . clusterIdentifier ) ;
435
446
this . credentialsSecretArn = databaseClusterResources . secret . secretArn ;
@@ -450,8 +461,7 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
450
461
* You need to provide your existing Aurora Vector Store properties
451
462
* such as `databaseName`, `clusterIdentifier`, `vpc` where database is deployed,
452
463
* `secret` containing username and password for authentication to database,
453
- * and `auroraSecurityGroupId` with the value of a security group id that was
454
- * used for the database.
464
+ * and `auroraSecurityGroup` with the ecurity group that was used for the database.
455
465
*
456
466
* @param scope - The scope in which to define the construct.
457
467
* @param id - The ID of the construct.
@@ -489,9 +499,14 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
489
499
props . vpc ,
490
500
props . clusterId ,
491
501
) ;
492
- const auroraPgCRPolicy = this . createAuroraPgCRPolicy ( databaseClusterResources . clusterIdentifier ) ;
502
+ const auroraPgCRPolicy = this . createAuroraPgCRPolicy (
503
+ databaseClusterResources . clusterIdentifier ,
504
+ ) ;
493
505
const lambdaSecurityGroup = this . createLambdaSecurityGroup ( databaseClusterResources . vpc ) ;
494
- this . addIngressRuleToAuroraSecurityGroup ( lambdaSecurityGroup , databaseClusterResources . auroraSecurityGroup ) ;
506
+ this . addIngressRuleToAuroraSecurityGroup (
507
+ lambdaSecurityGroup ,
508
+ databaseClusterResources . auroraSecurityGroup ,
509
+ ) ;
495
510
496
511
this . resourceArn = databaseClusterResources . resourceArn ;
497
512
this . credentialsSecretArn = databaseClusterResources . secret . secretArn ;
@@ -502,7 +517,11 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
502
517
ServiceEndpointTypeEnum . BEDROCK_RUNTIME ,
503
518
] ) ;
504
519
505
- const auroraPgVector = this . setupCustomResource ( databaseClusterResources , lambdaSecurityGroup , auroraPgCRPolicy ) ;
520
+ const auroraPgVector = this . setupCustomResource (
521
+ databaseClusterResources ,
522
+ lambdaSecurityGroup ,
523
+ auroraPgCRPolicy ,
524
+ ) ;
506
525
507
526
auroraPgVector . node . addDependency ( databaseClusterResources . auroraCluster ! ) ;
508
527
}
@@ -531,7 +550,13 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
531
550
version : postgreSQLVersion ,
532
551
} ) ,
533
552
credentials : rds . Credentials . fromGeneratedSecret ( 'postgres' ) ,
534
- clusterIdentifier : clusterIdentifier ?? generatePhysicalNameV2 ( this , 'aurora-serverless' , { maxLength : 63 , lower : true , separator : '-' } ) ,
553
+ clusterIdentifier :
554
+ clusterIdentifier ??
555
+ generatePhysicalNameV2 ( this , 'aurora-serverless' , {
556
+ maxLength : 63 ,
557
+ lower : true ,
558
+ separator : '-' ,
559
+ } ) ,
535
560
defaultDatabaseName : this . databaseName ,
536
561
vpc,
537
562
vpcSubnets : { subnetType : ec2 . SubnetType . PRIVATE_ISOLATED } ,
@@ -541,7 +566,9 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
541
566
serverlessV2MinCapacity : 0.5 ,
542
567
serverlessV2MaxCapacity : 4 ,
543
568
writer : rds . ClusterInstance . serverlessV2 ( 'AuroraServerlessWriter' ) ,
544
- readers : [ rds . ClusterInstance . serverlessV2 ( 'AuroraServerlessReader' , { scaleWithWriter : true } ) ] ,
569
+ readers : [
570
+ rds . ClusterInstance . serverlessV2 ( 'AuroraServerlessReader' , { scaleWithWriter : true } ) ,
571
+ ] ,
545
572
removalPolicy : cdk . RemovalPolicy . DESTROY ,
546
573
} ) ;
547
574
const resourceArn = cdk . Stack . of ( this ) . formatArn ( {
0 commit comments