@@ -21,8 +21,15 @@ import { NagSuppressions } from 'cdk-nag';
2121import { Construct } from 'constructs' ;
2222import { buildCustomResourceProvider } from '../../common/helpers/custom-resource-provider-helper' ;
2323import { 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+ *****************************************************************************/
2633/**
2734 * List of supported versions of PostgreSQL for Aurora cluster.
2835 */
@@ -43,6 +50,9 @@ export const SupportedPostgreSQLVersions = {
4350export type SupportedPostgreSQLVersions =
4451 ( typeof SupportedPostgreSQLVersions ) [ keyof typeof SupportedPostgreSQLVersions ] ;
4552
53+ /******************************************************************************
54+ * COMMON
55+ *****************************************************************************/
4656/**
4757 * Base properties for an Aurora Vector Store.
4858 */
@@ -141,11 +151,11 @@ export interface ExistingAmazonAuroraVectorStoreProps extends BaseAuroraVectorSt
141151 readonly secret : secretsmanager . ISecret ;
142152
143153 /**
144- * The id of the security group associated with the RDS Aurora instance.
154+ * The Security group associated with the RDS Aurora instance.
145155 * This security group allows access to the Aurora Vector Store from Lambda's
146156 * custom resource running pgVector SQL commands.
147157 */
148- readonly auroraSecurityGroupId : string ;
158+ readonly auroraSecurityGroup : ec2 . ISecurityGroup ;
149159}
150160
151161/**
@@ -181,7 +191,7 @@ export interface DatabaseClusterResources {
181191 /**
182192 * The security group associated with the Aurora cluster.
183193 */
184- readonly auroraSecurityGroup : ec2 . SecurityGroup ;
194+ readonly auroraSecurityGroup : ec2 . ISecurityGroup ;
185195}
186196
187197/**
@@ -242,7 +252,8 @@ abstract class BaseAmazonAuroraVectorStore extends Construct {
242252 * Setup databaseName based on if it is provided in the props or not
243253 * and based on whether it is an existing Aurora Vector Store or not.
244254 */
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' ;
246257
247258 this . schemaName = props . schemaName ?? 'bedrock_integration' ;
248259 this . vectorField = props . vectorField ?? 'embedding' ;
@@ -324,14 +335,9 @@ abstract class BaseAmazonAuroraVectorStore extends Construct {
324335 vpc : ec2 . IVpc ,
325336 secret : secretsmanager . ISecret ,
326337 clusterIdentifier : string ,
327- auroraSecurityGroupId : string ,
338+ auroraSecurityGroup : ec2 . ISecurityGroup ,
328339 ) : DatabaseClusterResources {
329340 const resourceArn = this . generateResourceArn ( clusterIdentifier ) ;
330- const auroraSecurityGroup = ec2 . SecurityGroup . fromLookupById (
331- this ,
332- 'ExistingSG' ,
333- auroraSecurityGroupId ,
334- ) as ec2 . SecurityGroup ;
335341
336342 return {
337343 vpc,
@@ -351,8 +357,8 @@ abstract class BaseAmazonAuroraVectorStore extends Construct {
351357 }
352358
353359 protected addIngressRuleToAuroraSecurityGroup (
354- lambdaSecurityGroup : ec2 . SecurityGroup ,
355- auroraSecurityGroup : ec2 . SecurityGroup ,
360+ lambdaSecurityGroup : ec2 . ISecurityGroup ,
361+ auroraSecurityGroup : ec2 . ISecurityGroup ,
356362 ) {
357363 auroraSecurityGroup . addIngressRule (
358364 lambdaSecurityGroup ,
@@ -424,12 +430,17 @@ export class ExistingAmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore
424430 props . vpc ,
425431 props . secret ,
426432 props . clusterIdentifier ,
427- props . auroraSecurityGroupId ,
433+ props . auroraSecurityGroup ,
428434 ) ;
429435
430- const auroraPgCRPolicy = this . createAuroraPgCRPolicy ( databaseClusterResources . clusterIdentifier ) ;
436+ const auroraPgCRPolicy = this . createAuroraPgCRPolicy (
437+ databaseClusterResources . clusterIdentifier ,
438+ ) ;
431439 const lambdaSecurityGroup = this . createLambdaSecurityGroup ( databaseClusterResources . vpc ) ;
432- this . addIngressRuleToAuroraSecurityGroup ( lambdaSecurityGroup , databaseClusterResources . auroraSecurityGroup ) ;
440+ this . addIngressRuleToAuroraSecurityGroup (
441+ lambdaSecurityGroup ,
442+ databaseClusterResources . auroraSecurityGroup ,
443+ ) ;
433444
434445 this . resourceArn = this . generateResourceArn ( databaseClusterResources . clusterIdentifier ) ;
435446 this . credentialsSecretArn = databaseClusterResources . secret . secretArn ;
@@ -450,8 +461,7 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
450461 * You need to provide your existing Aurora Vector Store properties
451462 * such as `databaseName`, `clusterIdentifier`, `vpc` where database is deployed,
452463 * `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.
455465 *
456466 * @param scope - The scope in which to define the construct.
457467 * @param id - The ID of the construct.
@@ -489,9 +499,14 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
489499 props . vpc ,
490500 props . clusterId ,
491501 ) ;
492- const auroraPgCRPolicy = this . createAuroraPgCRPolicy ( databaseClusterResources . clusterIdentifier ) ;
502+ const auroraPgCRPolicy = this . createAuroraPgCRPolicy (
503+ databaseClusterResources . clusterIdentifier ,
504+ ) ;
493505 const lambdaSecurityGroup = this . createLambdaSecurityGroup ( databaseClusterResources . vpc ) ;
494- this . addIngressRuleToAuroraSecurityGroup ( lambdaSecurityGroup , databaseClusterResources . auroraSecurityGroup ) ;
506+ this . addIngressRuleToAuroraSecurityGroup (
507+ lambdaSecurityGroup ,
508+ databaseClusterResources . auroraSecurityGroup ,
509+ ) ;
495510
496511 this . resourceArn = databaseClusterResources . resourceArn ;
497512 this . credentialsSecretArn = databaseClusterResources . secret . secretArn ;
@@ -502,7 +517,11 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
502517 ServiceEndpointTypeEnum . BEDROCK_RUNTIME ,
503518 ] ) ;
504519
505- const auroraPgVector = this . setupCustomResource ( databaseClusterResources , lambdaSecurityGroup , auroraPgCRPolicy ) ;
520+ const auroraPgVector = this . setupCustomResource (
521+ databaseClusterResources ,
522+ lambdaSecurityGroup ,
523+ auroraPgCRPolicy ,
524+ ) ;
506525
507526 auroraPgVector . node . addDependency ( databaseClusterResources . auroraCluster ! ) ;
508527 }
@@ -531,7 +550,13 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
531550 version : postgreSQLVersion ,
532551 } ) ,
533552 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+ } ) ,
535560 defaultDatabaseName : this . databaseName ,
536561 vpc,
537562 vpcSubnets : { subnetType : ec2 . SubnetType . PRIVATE_ISOLATED } ,
@@ -541,7 +566,9 @@ export class AmazonAuroraVectorStore extends BaseAmazonAuroraVectorStore {
541566 serverlessV2MinCapacity : 0.5 ,
542567 serverlessV2MaxCapacity : 4 ,
543568 writer : rds . ClusterInstance . serverlessV2 ( 'AuroraServerlessWriter' ) ,
544- readers : [ rds . ClusterInstance . serverlessV2 ( 'AuroraServerlessReader' , { scaleWithWriter : true } ) ] ,
569+ readers : [
570+ rds . ClusterInstance . serverlessV2 ( 'AuroraServerlessReader' , { scaleWithWriter : true } ) ,
571+ ] ,
545572 removalPolicy : cdk . RemovalPolicy . DESTROY ,
546573 } ) ;
547574 const resourceArn = cdk . Stack . of ( this ) . formatArn ( {
0 commit comments