diff --git a/cdk/lib/cdk-stack.ts b/cdk/lib/cdk-stack.ts index af58db8..926add0 100644 --- a/cdk/lib/cdk-stack.ts +++ b/cdk/lib/cdk-stack.ts @@ -11,6 +11,7 @@ import { Construct } from 'constructs'; import type { DeploymentStage } from './deployment-stage'; import { Dispatcher } from './dispatcher'; +import { Indexer } from './indexer'; import { LambdaDependencies } from './lambda-dependencies'; import { MumbleApi } from './mumble-api'; import { ObjectStore } from './object-store'; @@ -63,7 +64,9 @@ export class CdkStack extends Stack { systemParameters, userTable, }); + const indexer = new Indexer(this, 'Indexer'); const viewer = new Viewer(this, 'Viewer', { + indexer, objectStore, systemParameters, userTable, @@ -134,5 +137,13 @@ export class CdkStack extends Stack { description: 'Path to the OpenAI API key stored in Parameter Store on AWS Systems Manager', value: systemParameters.openAiApiKeyParameter.parameterName, }); + new CfnOutput(this, 'IndexerDatabaseBucketName', { + description: 'Name of the S3 bucket that stores the databases for the indexer', + value: indexer.databaseBucket.bucketName, + }); + new CfnOutput(this, 'SearchSimilarMumblingsFunctionName', { + description: 'Name of the Lambda function that searches similar mumblings', + value: indexer.searchSimilarLambda.functionName, + }); } } diff --git a/cdk/lib/viewer.ts b/cdk/lib/viewer.ts index 94de5c0..479eec5 100644 --- a/cdk/lib/viewer.ts +++ b/cdk/lib/viewer.ts @@ -3,6 +3,7 @@ import { Duration, Fn, aws_lambda as lambda } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import { QwikHandler } from '@codemonger-io/cdk-qwik-bundle'; +import type { Indexer } from './indexer'; import type { ObjectStore } from './object-store'; import type { SystemParameters } from './system-parameters'; import type { UserTable } from './user-table'; @@ -18,6 +19,8 @@ export interface Props { readonly userTable: UserTable; /** Object store. */ readonly objectStore: ObjectStore; + /** Indexer. */ + readonly indexer: Indexer; } /** CDK construct that provisions the viewer app. */ @@ -30,7 +33,7 @@ export class Viewer extends Construct { constructor(scope: Construct, id: string, props: Props) { super(scope, id); - const { objectStore, systemParameters, userTable } = props; + const { indexer, objectStore, systemParameters, userTable } = props; this.handler = new QwikHandler(this, 'ViewerHandler', { entry: path.resolve('./viewer'), @@ -41,6 +44,10 @@ export class Viewer extends Construct { systemParameters.domainNameParameter.parameterName, OBJECT_TABLE_NAME: objectStore.objectTable.tableName, OBJECTS_BUCKET_NAME: objectStore.objectsBucket.bucketName, + OPENAI_API_KEY_PARAMETER_PATH: + systemParameters.openAiApiKeyParameter.parameterName, + SEARCH_SIMILAR_MUMBLINGS_FUNCTION_NAME: + indexer.searchSimilarLambda.functionName, USER_TABLE_NAME: userTable.userTable.tableName, }, memorySize: 256, @@ -51,6 +58,7 @@ export class Viewer extends Construct { }, }, }); + indexer.searchSimilarLambda.grantInvoke(this.handler); objectStore.objectsBucket.grantRead(this.handler); objectStore.objectTable.grantReadData(this.handler); systemParameters.domainNameParameter.grantRead(this.handler);