Skip to content

Commit fbc290d

Browse files
author
Dinesh Sajwan
committed
feat(baseclass): updated description format
1 parent 14b9687 commit fbc290d

File tree

11 files changed

+68
-22
lines changed

11 files changed

+68
-22
lines changed

src/common/base-class/base-class.ts

+26-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as appsync from 'aws-cdk-lib/aws-appsync';
1515
import * as lambda from 'aws-cdk-lib/aws-lambda';
1616
import * as logs from 'aws-cdk-lib/aws-logs';
1717
import { Construct } from 'constructs';
18+
import { ConstructName } from './construct-name-enum';
1819
import { version } from '../helpers/utils';
1920

2021

@@ -43,7 +44,7 @@ export interface BaseClassProps {
4344
* name of the construct.
4445
*
4546
*/
46-
readonly constructorName: string;
47+
readonly constructName: ConstructName;
4748

4849
/**
4950
* construct id.
@@ -62,8 +63,17 @@ export interface BaseClassProps {
6263

6364
export class BaseClass extends Construct {
6465

65-
static constructIdsStr: string='';
66-
static constructNamesStr: string='';
66+
protected static usageMetricMap : Record<string, number> ={
67+
[ConstructName.AWSRAGAPPSYNCSTEPFNOPENSEARCH]: 0,
68+
[ConstructName.AWSQAAPPSYNCOPENSEARCH]: 0,
69+
[ConstructName.AWSSUMMARIZATIONAPPSYNCSTEPFN]: 0,
70+
[ConstructName.AWSMODELDEPLOYMENTSAGEMAKER]: 0,
71+
[ConstructName.CUSTOMSAGEMAKERENDPOINT]: 0,
72+
[ConstructName.HUGGINGFACESAGEMAKERENDPOINT]: 0,
73+
[ConstructName.JUMPSTARTSAGEMAKERENDPOINT]: 0,
74+
[ConstructName.AWSCONTENTGENAPPSYNCLAMBDA]: 0,
75+
};
76+
6777

6878
/**
6979
* construct usage metric , added in template description
@@ -123,7 +133,7 @@ export class BaseClass extends Construct {
123133
*/
124134
protected updateConstructUsageMetricCode(props: BaseClassProps, scope: Construct, lambdaFunctions: lambda.DockerImageFunction[],
125135
) {
126-
const solutionId = `genai_cdk_${version}/${props.constructorName}/${props.constructId}`;
136+
const solutionId = `genai_cdk_${version}/${props.constructName}/${props.constructId}`;
127137

128138
const enableOperationalMetric =
129139
props.enableOperationalMetric !== undefined &&
@@ -138,14 +148,19 @@ export class BaseClass extends Construct {
138148
);
139149
}
140150
}
141-
// ADD unique key in template description
142-
// format (usage metric id:usbxxxx) (version:1.xx) (construct name:awsappsyncXX1,awsappsyncXX2,awsappsyncXX3) (construct id:awsappsyncxxxx1,awsappsyncxxx2,awsappsyncxxx3)
143-
BaseClass.constructIdsStr=BaseClass.constructIdsStr+', '+props.constructId;
144-
BaseClass.constructNamesStr=BaseClass.constructNamesStr+', '+props.constructorName;
145-
151+
152+
if (props && BaseClass.usageMetricMap.hasOwnProperty(props.constructName)) {
153+
BaseClass.usageMetricMap[props.constructName]=BaseClass.usageMetricMap[props.constructName]+1;
154+
}
155+
else{
156+
throw Error('construct name is not present in usageMetricMap ')
157+
}
158+
159+
const usageMetricMapSerialized = JSON.stringify(BaseClass.usageMetricMap);
160+
161+
146162
Stack.of(scope).templateOptions.description =
147-
`(usage id :${this.constructUsageMetric})(version:${version}) (construct name:::${ BaseClass.constructIdsStr}) (construct id:::${ BaseClass.constructNamesStr})`;
148-
163+
`(usage id :${this.constructUsageMetric})(version:${version}) (constructs :::${ usageMetricMapSerialized}) `;
149164

150165
};
151166
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5+
* with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
10+
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
export enum ConstructName {
14+
AWSRAGAPPSYNCSTEPFNOPENSEARCH='C1',
15+
AWSQAAPPSYNCOPENSEARCH='C2',
16+
AWSSUMMARIZATIONAPPSYNCSTEPFN='C3',
17+
AWSMODELDEPLOYMENTSAGEMAKER='C4',
18+
CUSTOMSAGEMAKERENDPOINT='C5',
19+
HUGGINGFACESAGEMAKERENDPOINT='C6',
20+
JUMPSTARTSAGEMAKERENDPOINT='C7',
21+
AWSCONTENTGENAPPSYNCLAMBDA='C8'
22+
23+
}

src/common/base-class/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
1111
* and limitations under the License.
1212
*/
13-
export * from './base-class';
13+
export * from './base-class';
14+
export * from './construct-name-enum';

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export { version } from './common/helpers/utils';
2424
export * from './common/props/DockerLambdaCustomProps';
2525
export * from './common/props/LangchainProps';
2626
export * from './common/props/AdapterProps';
27-
export * from './common/base-class';
27+
export * from './common/base-class/base-class';
28+
export * from './common/base-class/construct-name-enum';

src/patterns/gen-ai/aws-contentgen-appsync-lambda/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as logs from 'aws-cdk-lib/aws-logs';
2323
import * as s3 from 'aws-cdk-lib/aws-s3';
2424
import { NagSuppressions } from 'cdk-nag';
2525
import { Construct } from 'constructs';
26-
import { BaseClass, BaseClassProps } from '../../../common/base-class';
26+
import { BaseClass, BaseClassProps, ConstructName } from '../../../common/base-class';
2727
import { buildDockerLambdaFunction } from '../../../common/helpers/lambda-builder-helper';
2828
import * as s3_bucket_helper from '../../../common/helpers/s3-bucket-helper';
2929
import { lambdaMemorySizeLimiter } from '../../../common/helpers/utils';
@@ -174,7 +174,7 @@ export class ContentGenerationAppSyncLambda extends BaseClass {
174174
const baseProps: BaseClassProps={
175175
stage: props.stage,
176176
enableOperationalMetric: props.enableOperationalMetric,
177-
constructorName: this.constructor.name,
177+
constructName: ConstructName.AWSCONTENTGENAPPSYNCLAMBDA,
178178
constructId: id,
179179
observability: props.observability,
180180
};

src/patterns/gen-ai/aws-model-deployment-sagemaker/custom-sagemaker-endpoint.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Construct } from 'constructs';
1717
import { ContainerImage } from './container-image';
1818
import { SageMakerEndpointBase } from './sagemaker-endpoint-base';
1919
import { SageMakerInstanceType } from './sagemaker-instance-type';
20+
import { ConstructName } from '../../../common/base-class';
2021
import { BaseClassProps } from '../../../common/base-class/base-class';
2122

2223
export interface CustomSageMakerEndpointProps {
@@ -57,7 +58,7 @@ export class CustomSageMakerEndpoint extends SageMakerEndpointBase implements ia
5758

5859
const baseProps: BaseClassProps={
5960
enableOperationalMetric: props.enableOperationalMetric,
60-
constructorName: this.constructor.name,
61+
constructName: ConstructName.CUSTOMSAGEMAKERENDPOINT,
6162
constructId: id,
6263
};
6364

src/patterns/gen-ai/aws-model-deployment-sagemaker/huggingface-sagemaker-endpoint.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Construct } from 'constructs';
1717
import { ContainerImage } from './container-image';
1818
import { SageMakerEndpointBase } from './sagemaker-endpoint-base';
1919
import { SageMakerInstanceType } from './sagemaker-instance-type';
20+
import { ConstructName } from '../../../common/base-class';
2021
import { BaseClassProps } from '../../../common/base-class/base-class';
2122

2223
export interface HuggingFaceSageMakerEndpointProps {
@@ -55,7 +56,7 @@ export class HuggingFaceSageMakerEndpoint extends SageMakerEndpointBase implemen
5556

5657
const baseProps: BaseClassProps={
5758
enableOperationalMetric: props.enableOperationalMetric,
58-
constructorName: this.constructor.name,
59+
constructName: ConstructName.HUGGINGFACESAGEMAKERENDPOINT,
5960
constructId: id,
6061
};
6162

src/patterns/gen-ai/aws-model-deployment-sagemaker/jumpstart-sagemaker-endpoint.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { JumpStartConstants } from './private/jumpstart-constants';
2020
import { SageMakerEndpointBase } from './sagemaker-endpoint-base';
2121
import { SageMakerInstanceType } from './sagemaker-instance-type';
2222
import { BaseClassProps } from '../../../common/base-class/base-class';
23+
import { ConstructName } from '../../../common/base-class/construct-name-enum';
2324

2425
export interface JumpStartSageMakerEndpointProps {
2526
readonly model: JumpStartModel;
@@ -61,7 +62,7 @@ export class JumpStartSageMakerEndpoint extends SageMakerEndpointBase {
6162

6263
const baseProps: BaseClassProps={
6364
enableOperationalMetric: props.enableOperationalMetric,
64-
constructorName: this.constructor.name,
65+
constructName: ConstructName.JUMPSTARTSAGEMAKERENDPOINT,
6566
constructId: id,
6667
};
6768

src/patterns/gen-ai/aws-qa-appsync-opensearch/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as s3 from 'aws-cdk-lib/aws-s3';
2626
import * as secret from 'aws-cdk-lib/aws-secretsmanager';
2727
import { NagSuppressions } from 'cdk-nag';
2828
import { Construct } from 'constructs';
29-
import { BaseClass, BaseClassProps } from '../../../common/base-class';
29+
import { BaseClass, BaseClassProps, ConstructName } from '../../../common/base-class';
3030
import { buildDockerLambdaFunction } from '../../../common/helpers/lambda-builder-helper';
3131
import * as opensearch_helper from '../../../common/helpers/opensearch-helper';
3232
import * as s3_bucket_helper from '../../../common/helpers/s3-bucket-helper';
@@ -204,7 +204,7 @@ export class QaAppsyncOpensearch extends BaseClass {
204204
const baseProps: BaseClassProps={
205205
stage: props.stage,
206206
enableOperationalMetric: props.enableOperationalMetric,
207-
constructorName: this.constructor.name,
207+
constructName: ConstructName.AWSQAAPPSYNCOPENSEARCH,
208208
constructId: id,
209209
observability: props.observability,
210210
};

src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import * as stepfn_task from 'aws-cdk-lib/aws-stepfunctions-tasks';
2929
import { NagSuppressions } from 'cdk-nag';
3030
import { Construct } from 'constructs';
3131
import { BaseClass, BaseClassProps } from '../../../common/base-class';
32+
import { ConstructName } from '../../../common/base-class/construct-name-enum';
3233
import { buildDockerLambdaFunction } from '../../../common/helpers/lambda-builder-helper';
3334
import * as opensearch_helper from '../../../common/helpers/opensearch-helper';
3435
import * as s3_bucket_helper from '../../../common/helpers/s3-bucket-helper';
@@ -243,10 +244,11 @@ export class RagAppsyncStepfnOpensearch extends BaseClass {
243244
constructor(scope: Construct, id: string, props: RagAppsyncStepfnOpensearchProps) {
244245
super(scope, id);
245246

247+
246248
const baseProps: BaseClassProps={
247249
stage: props.stage,
248250
enableOperationalMetric: props.enableOperationalMetric,
249-
constructorName: this.constructor.name,
251+
constructName: ConstructName.AWSRAGAPPSYNCSTEPFNOPENSEARCH,
250252
constructId: id,
251253
observability: props.observability,
252254
};

src/patterns/gen-ai/aws-summarization-appsync-stepfn/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import * as sfnTask from 'aws-cdk-lib/aws-stepfunctions-tasks';
2828
import { NagSuppressions } from 'cdk-nag';
2929
import { Construct } from 'constructs';
3030
import { BaseClass, BaseClassProps } from '../../../common/base-class/base-class';
31+
import { ConstructName } from '../../../common/base-class/construct-name-enum';
3132
import * as eventBridge from '../../../common/helpers/eventbridge-helper';
3233
import { buildDockerLambdaFunction } from '../../../common/helpers/lambda-builder-helper';
3334
import * as redisHelper from '../../../common/helpers/redis-helper';
@@ -268,7 +269,7 @@ export class SummarizationAppsyncStepfn extends BaseClass {
268269
const baseProps: BaseClassProps={
269270
stage: props.stage,
270271
enableOperationalMetric: props.enableOperationalMetric,
271-
constructorName: this.constructor.name,
272+
constructName: ConstructName.AWSSUMMARIZATIONAPPSYNCSTEPFN,
272273
constructId: id,
273274
observability: props.observability,
274275
};

0 commit comments

Comments
 (0)