Skip to content

Commit

Permalink
feat(cdk): add OpenAI API key param
Browse files Browse the repository at this point in the history
- `SystemParameters` introduces a new parameter
  `openAiApiKeyParameter` that stores the OpenAI API key.
- `ViewerHandler` is granted access to the OpenAI API key parameter.
- `CdkStack` outputs the parameter path of the OpenAI API key as
  `OpenAiApiKeyParameterPath`.

issue codemonger-io#26
  • Loading branch information
kikuomax committed Oct 11, 2023
1 parent d44d88a commit 97e2a6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cdk/lib/cdk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,9 @@ export class CdkStack extends Stack {
description: 'Path to the domain name stored in Parameter Store on AWS Systems Manager',
value: systemParameters.domainNameParameter.parameterName,
});
new CfnOutput(this, 'OpenAiApiKeyParameterPath', {
description: 'Path to the OpenAI API key stored in Parameter Store on AWS Systems Manager',
value: systemParameters.openAiApiKeyParameter.parameterName,
});
}
}
5 changes: 5 additions & 0 deletions cdk/lib/system-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class SystemParameters extends Construct {
readonly parameterPathPrefix: string;
/** Parameter for the domain name. */
readonly domainNameParameter: GhostStringParameter;
/** Parameter for the OpenAI API key. */
readonly openAiApiKeyParameter: GhostStringParameter;

constructor(scope: Construct, id: string) {
super(scope, id);
Expand All @@ -18,5 +20,8 @@ export class SystemParameters extends Construct {
this.domainNameParameter = new GhostStringParameter(this, {
parameterName: `${this.parameterPathPrefix}DOMAIN_NAME`,
});
this.openAiApiKeyParameter = new GhostStringParameter(this, {
parameterName: `${this.parameterPathPrefix}OPENAI_API_KEY`,
});
}
}
1 change: 1 addition & 0 deletions cdk/lib/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class Viewer extends Construct {
objectStore.objectsBucket.grantRead(this.handler);
objectStore.objectTable.grantReadData(this.handler);
systemParameters.domainNameParameter.grantRead(this.handler);
systemParameters.openAiApiKeyParameter.grantRead(this.handler);
userTable.userTable.grantReadData(this.handler);

this.functionUrl = this.handler.addFunctionUrl({
Expand Down

0 comments on commit 97e2a6e

Please sign in to comment.