@@ -23,9 +23,10 @@ import * as logs from 'aws-cdk-lib/aws-logs';
23
23
import * as s3 from 'aws-cdk-lib/aws-s3' ;
24
24
import { NagSuppressions } from 'cdk-nag' ;
25
25
import { Construct } from 'constructs' ;
26
+ import { BaseClass , BaseClassProps } from '../../../common/base-class' ;
26
27
import { buildDockerLambdaFunction } from '../../../common/helpers/lambda-builder-helper' ;
27
28
import * as s3_bucket_helper from '../../../common/helpers/s3-bucket-helper' ;
28
- import { version , lambdaMemorySizeLimiter } from '../../../common/helpers/utils' ;
29
+ import { lambdaMemorySizeLimiter } from '../../../common/helpers/utils' ;
29
30
import * as vpc_helper from '../../../common/helpers/vpc-helper' ;
30
31
import { DockerLambdaCustomProps } from '../../../common/props/DockerLambdaCustomProps' ;
31
32
@@ -127,7 +128,7 @@ export interface ContentGenerationAppSyncLambdaProps {
127
128
/**
128
129
* @summary The ContentGenerationAppSyncLambda class.
129
130
*/
130
- export class ContentGenerationAppSyncLambda extends Construct {
131
+ export class ContentGenerationAppSyncLambda extends BaseClass {
131
132
/**
132
133
* Returns the instance of ec2.IVpc used by the construct
133
134
*/
@@ -170,27 +171,16 @@ export class ContentGenerationAppSyncLambda extends Construct {
170
171
constructor ( scope : Construct , id : string , props : ContentGenerationAppSyncLambdaProps ) {
171
172
super ( scope , id ) ;
172
173
173
- // stage
174
- let stage = '-dev' ;
175
- if ( props ?. stage ) {
176
- stage = props . stage ;
177
- }
178
-
179
- // observability
180
- let lambda_tracing = lambda . Tracing . ACTIVE ;
181
- let enable_xray = true ;
182
- let api_log_config = {
183
- fieldLogLevel : appsync . FieldLogLevel . ALL ,
184
- retention : logs . RetentionDays . TEN_YEARS ,
174
+ const baseProps : BaseClassProps = {
175
+ stage : props . stage ,
176
+ enableOperationalMetric : props . enableOperationalMetric ,
177
+ constructorName : this . constructor . name ,
178
+ constructId : id ,
179
+ observability : props . observability ,
185
180
} ;
186
- if ( props . observability == false ) {
187
- enable_xray = false ;
188
- lambda_tracing = lambda . Tracing . DISABLED ;
189
- api_log_config = {
190
- fieldLogLevel : appsync . FieldLogLevel . NONE ,
191
- retention : logs . RetentionDays . TEN_YEARS ,
192
- } ;
193
- }
181
+
182
+ this . updateEnvSuffix ( baseProps ) ;
183
+ this . addObservabilityToConstruct ( baseProps ) ;
194
184
195
185
vpc_helper . CheckVpcProps ( props ) ;
196
186
s3_bucket_helper . CheckS3Props ( {
@@ -211,7 +201,7 @@ export class ContentGenerationAppSyncLambda extends Construct {
211
201
this . securityGroup = new ec2 . SecurityGroup ( this , 'securityGroup' , {
212
202
vpc : this . vpc ,
213
203
allowAllOutbound : true ,
214
- securityGroupName : 'securityGroup' + stage ,
204
+ securityGroupName : 'securityGroup' + this . stage ,
215
205
} ) ;
216
206
}
217
207
@@ -230,7 +220,7 @@ export class ContentGenerationAppSyncLambda extends Construct {
230
220
// bucket for storing server access logging
231
221
const serverAccessLogBucket = new s3 . Bucket (
232
222
this ,
233
- 'serverAccessLogBucket' + stage ,
223
+ 'serverAccessLogBucket' + this . stage ,
234
224
{
235
225
blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
236
226
encryption : s3 . BucketEncryption . S3_MANAGED ,
@@ -250,10 +240,10 @@ export class ContentGenerationAppSyncLambda extends Construct {
250
240
if ( ! props . existingGeneratedAssetsBucketObj ) {
251
241
let tmpBucket : s3 . Bucket ;
252
242
if ( ! props . generatedAssetsBucketProps ) {
253
- tmpBucket = new s3 . Bucket ( this , 'generatedAssetsBucket' + stage , {
243
+ tmpBucket = new s3 . Bucket ( this , 'generatedAssetsBucket' + this . stage , {
254
244
blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
255
245
encryption : s3 . BucketEncryption . S3_MANAGED ,
256
- bucketName : 'generated-asset-bucket' + stage + '-' + Aws . ACCOUNT_ID ,
246
+ bucketName : 'generated-asset-bucket' + this . stage + '-' + Aws . ACCOUNT_ID ,
257
247
serverAccessLogsBucket : serverAccessLogBucket ,
258
248
enforceSSL : true ,
259
249
versioned : true ,
@@ -266,7 +256,7 @@ export class ContentGenerationAppSyncLambda extends Construct {
266
256
} else {
267
257
tmpBucket = new s3 . Bucket (
268
258
this ,
269
- 'generatedAssetsBucket' + stage ,
259
+ 'generatedAssetsBucket' + this . stage ,
270
260
props . generatedAssetsBucketProps ,
271
261
) ;
272
262
}
@@ -284,7 +274,7 @@ export class ContentGenerationAppSyncLambda extends Construct {
284
274
this ,
285
275
'generateImageGraphqlApi' ,
286
276
{
287
- name : 'generateImageGraphqlApi' + stage ,
277
+ name : 'generateImageGraphqlApi' + this . stage ,
288
278
definition : appsync . Definition . fromFile (
289
279
path . join (
290
280
__dirname ,
@@ -302,8 +292,11 @@ export class ContentGenerationAppSyncLambda extends Construct {
302
292
} ,
303
293
] ,
304
294
} ,
305
- xrayEnabled : enable_xray ,
306
- logConfig : api_log_config ,
295
+ xrayEnabled : this . enablexray ,
296
+ logConfig : {
297
+ fieldLogLevel : this . fieldLogLevel ,
298
+ retention : this . retention ,
299
+ } ,
307
300
} ,
308
301
) ;
309
302
@@ -345,9 +338,9 @@ export class ContentGenerationAppSyncLambda extends Construct {
345
338
if ( ! props . existingBusInterface ) {
346
339
this . generatedImageBus = new events . EventBus (
347
340
this ,
348
- 'generateImageEventBus' + stage ,
341
+ 'generateImageEventBus' + this . stage ,
349
342
{
350
- eventBusName : 'generateImageEventBus' + stage ,
343
+ eventBusName : 'generateImageEventBus' + this . stage ,
351
344
} ,
352
345
) ;
353
346
} else {
@@ -356,10 +349,10 @@ export class ContentGenerationAppSyncLambda extends Construct {
356
349
357
350
// create httpdatasource with generate_image_graphql_api
358
351
const event_bridge_datasource = this . graphqlApi . addEventBridgeDataSource (
359
- 'generateImageEventBridgeDataSource' + stage ,
352
+ 'generateImageEventBridgeDataSource' + this . stage ,
360
353
this . generatedImageBus ,
361
354
{
362
- name : 'generateImageEventBridgeDataSource' + stage ,
355
+ name : 'generateImageEventBridgeDataSource' + this . stage ,
363
356
} ,
364
357
) ;
365
358
@@ -488,10 +481,10 @@ export class ContentGenerationAppSyncLambda extends Construct {
488
481
'../../../../lambda/aws-contentgen-appsync-lambda/src' ,
489
482
) ,
490
483
) ,
491
- functionName : 'lambda_generate_image' + stage ,
484
+ functionName : 'lambda_generate_image' + this . stage ,
492
485
description : 'Lambda function for generating image' ,
493
486
vpc : this . vpc ,
494
- tracing : lambda_tracing ,
487
+ tracing : this . lambdaTracing ,
495
488
vpcSubnets : { subnetType : ec2 . SubnetType . PRIVATE_WITH_EGRESS } ,
496
489
securityGroups : [ this . securityGroup ] ,
497
490
memorySize : lambdaMemorySizeLimiter ( this , 1_769 * 4 ) ,
@@ -510,23 +503,16 @@ export class ContentGenerationAppSyncLambda extends Construct {
510
503
} ;
511
504
512
505
const generate_image_function = buildDockerLambdaFunction ( this ,
513
- 'lambda_content_generation' + stage ,
506
+ 'lambda_content_generation' + this . stage ,
514
507
construct_docker_lambda_props ,
515
508
props . customDockerLambdaProps ,
516
509
) ;
517
510
518
511
generate_image_function . currentVersion ;
519
512
520
- const enableOperationalMetric =
521
- props . enableOperationalMetric !== undefined && props . enableOperationalMetric !== null ? props . enableOperationalMetric : true ;
513
+ const lambdaFunctions = [ generate_image_function ] ;
514
+ this . updateConstructTrackingCode ( baseProps , scope , lambdaFunctions ) ;
522
515
523
- if ( enableOperationalMetric ) {
524
- const solutionId = `genai_cdk_${ version } /${ this . constructor . name } /${ id } ` ;
525
- generate_image_function . addEnvironment (
526
- 'AWS_SDK_UA_APP_ID' ,
527
- solutionId ,
528
- ) ;
529
- }
530
516
531
517
// Add GraphQl permissions to the IAM role for the Lambda function
532
518
generate_image_function . addToRolePolicy (
@@ -575,7 +561,7 @@ export class ContentGenerationAppSyncLambda extends Construct {
575
561
) ,
576
562
} ) ;
577
563
578
- const rule = new events . Rule ( this , 'textToImageRule' + stage , {
564
+ const rule = new events . Rule ( this , 'textToImageRule' + this . stage , {
579
565
description : 'Rule to trigger textToImage function' ,
580
566
eventBus : this . generatedImageBus ,
581
567
eventPattern : {
0 commit comments