Skip to content

Commit

Permalink
feat(cdk): link Viewer and Indexer
Browse files Browse the repository at this point in the history
- `CdkStack` provisions `Indexer` and links `Viewer` and `Indexer`.

issue codemonger-io#28
  • Loading branch information
kikuomax committed Oct 15, 2023
1 parent d693605 commit 409a730
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cdk/lib/cdk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
}
}
10 changes: 9 additions & 1 deletion cdk/lib/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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. */
Expand All @@ -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'),
Expand All @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 409a730

Please sign in to comment.