11
11
* and limitations under the License.
12
12
*/
13
13
import * as path from 'path' ;
14
- import { Duration , Aws , Stack } from 'aws-cdk-lib' ;
14
+ import { Duration , Aws } from 'aws-cdk-lib' ;
15
15
import * as appsync from 'aws-cdk-lib/aws-appsync' ;
16
16
import * as cognito from 'aws-cdk-lib/aws-cognito' ;
17
17
import * as ec2 from 'aws-cdk-lib/aws-ec2' ;
@@ -31,7 +31,7 @@ import { ConstructName } from '../../../common/base-class/construct-name-enum';
31
31
import * as eventBridge from '../../../common/helpers/eventbridge-helper' ;
32
32
import { buildDockerLambdaFunction } from '../../../common/helpers/lambda-builder-helper' ;
33
33
import * as s3BucketHelper from '../../../common/helpers/s3-bucket-helper' ;
34
- import { generatePhysicalName , lambdaMemorySizeLimiter } from '../../../common/helpers/utils' ;
34
+ import { lambdaMemorySizeLimiter , generatePhysicalNameV2 } from '../../../common/helpers/utils' ;
35
35
import { DockerLambdaCustomProps } from '../../../common/props/DockerLambdaCustomProps' ;
36
36
37
37
export interface SummarizationAppsyncStepfnProps {
@@ -197,6 +197,16 @@ export class SummarizationAppsyncStepfn extends BaseClass {
197
197
*/
198
198
public readonly graphqlApi : appsync . IGraphqlApi ;
199
199
200
+ /**
201
+ * Graphql Api Id value
202
+ */
203
+ public readonly graphqlApiId : string ;
204
+
205
+ /**
206
+ * Graphql Url value
207
+ */
208
+ public readonly graphqlUrl : string ;
209
+
200
210
/**
201
211
* Returns the instance of ec2.IVpc used by the construct
202
212
*/
@@ -313,8 +323,10 @@ export class SummarizationAppsyncStepfn extends BaseClass {
313
323
this . inputAssetBucket = new s3 . Bucket ( this ,
314
324
'inputAssetsSummaryBucket' + this . stage , props . bucketInputsAssetsProps ) ;
315
325
} else {
316
- const bucketName = 'input-assets-summary-bucket' + this . stage + '-' + Aws . ACCOUNT_ID ;
317
- this . inputAssetBucket = new s3 . Bucket ( this , 'inputAssetsSummaryBucket' + this . stage ,
326
+ const bucketName = generatePhysicalNameV2 ( this ,
327
+ 'input-assets-bucket' + this . stage ,
328
+ { maxLength : 63 , lower : true } ) ;
329
+ this . inputAssetBucket = new s3 . Bucket ( this , bucketName ,
318
330
{
319
331
blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
320
332
encryption : s3 . BucketEncryption . S3_MANAGED ,
@@ -340,9 +352,11 @@ export class SummarizationAppsyncStepfn extends BaseClass {
340
352
this . processedAssetBucket = new s3 . Bucket ( this ,
341
353
'processedAssetsSummaryBucket' + this . stage , props . bucketProcessedAssetsProps ) ;
342
354
} else {
343
- const bucketName = 'processed-assets-summary-bucket' + this . stage + '-' + Aws . ACCOUNT_ID ;
355
+ const bucketName = generatePhysicalNameV2 ( this ,
356
+ 'processed-assets-bucket' + this . stage ,
357
+ { maxLength : 63 , lower : true } ) ;
344
358
345
- this . processedAssetBucket = new s3 . Bucket ( this , 'processedAssetsSummaryBucket' + this . stage ,
359
+ this . processedAssetBucket = new s3 . Bucket ( this , bucketName ,
346
360
{
347
361
blockPublicAccess : s3 . BlockPublicAccess . BLOCK_ALL ,
348
362
encryption : s3 . BucketEncryption . S3_MANAGED ,
@@ -376,10 +390,12 @@ export class SummarizationAppsyncStepfn extends BaseClass {
376
390
] ,
377
391
} ;
378
392
379
- const apiName = props . summaryApiName || 'summaryApi' ;
393
+ const apiName = props . summaryApiName || generatePhysicalNameV2 ( this ,
394
+ 'summaryApi' + this . stage ,
395
+ { maxLength : 32 , lower : true } ) ;
380
396
381
397
// graphql api for summary. client invoke this api with given schema and cognito user pool auth.
382
- const summarizationGraphqlApi = new appsync . GraphqlApi ( this , 'summarizationGraphqlApi' + this . stage ,
398
+ const summarizationGraphqlApi = new appsync . GraphqlApi ( this , apiName ,
383
399
{
384
400
name : apiName + this . stage ,
385
401
logConfig : {
@@ -393,6 +409,8 @@ export class SummarizationAppsyncStepfn extends BaseClass {
393
409
xrayEnabled : this . enablexray ,
394
410
} ) ;
395
411
this . graphqlApi = summarizationGraphqlApi ;
412
+ this . graphqlApiId = summarizationGraphqlApi . apiId ;
413
+ this . graphqlUrl = summarizationGraphqlApi . graphqlUrl ;
396
414
397
415
// If the user provides a mergedApi endpoint, the lambda
398
416
// functions will use this endpoint to send their status updates
@@ -473,7 +491,9 @@ export class SummarizationAppsyncStepfn extends BaseClass {
473
491
474
492
const construct_input_validation_lambda_props = {
475
493
code : lambda . DockerImageCode . fromImageAsset ( path . join ( __dirname , '../../../../lambda/aws-summarization-appsync-stepfn/input_validator' ) ) ,
476
- functionName : 'summary_input_validator' + this . stage ,
494
+ functionName : generatePhysicalNameV2 ( this ,
495
+ 'summary_input_validator' + this . stage ,
496
+ { maxLength : 63 , lower : true } ) ,
477
497
description : 'Lambda function to validate input for summary api' ,
478
498
vpc : this . vpc ,
479
499
tracing : this . lambdaTracing ,
@@ -669,8 +689,11 @@ export class SummarizationAppsyncStepfn extends BaseClass {
669
689
true ,
670
690
) ;
671
691
692
+ const functionName = generatePhysicalNameV2 ( this ,
693
+ 'summary_generator' + this . stage ,
694
+ { maxLength : 32 , lower : true } ) ;
672
695
const construct_generate_summary_lambda_props = {
673
- functionName : 'summary_generator' + this . stage ,
696
+ functionName : functionName ,
674
697
description : 'Lambda function to generate the summary' ,
675
698
code : lambda . DockerImageCode . fromImageAsset ( path . join ( __dirname , '../../../../lambda/aws-summarization-appsync-stepfn/summary_generator' ) ) ,
676
699
vpc : this . vpc ,
@@ -689,7 +712,7 @@ export class SummarizationAppsyncStepfn extends BaseClass {
689
712
690
713
// Lambda function used to generate the summary in the step function
691
714
const generateSummarylambda = buildDockerLambdaFunction ( this ,
692
- 'generateSummarylambda' + this . stage ,
715
+ functionName ,
693
716
construct_generate_summary_lambda_props ,
694
717
props . customSummaryGeneratorDockerLambdaProps ,
695
718
) ;
@@ -729,7 +752,7 @@ export class SummarizationAppsyncStepfn extends BaseClass {
729
752
resultPath : '$.validation_result' ,
730
753
} ) ;
731
754
732
- const documentReaderTask = new sfnTask . LambdaInvoke ( this , 'Read document and check summary in cache ' , {
755
+ const documentReaderTask = new sfnTask . LambdaInvoke ( this , 'Read document. ' , {
733
756
lambdaFunction : documentReaderLambda ,
734
757
resultPath : '$.document_result' ,
735
758
} ) ;
@@ -741,7 +764,9 @@ export class SummarizationAppsyncStepfn extends BaseClass {
741
764
} ) ;
742
765
743
766
const dlq : sqs . Queue = new sqs . Queue ( this , 'dlq' , {
744
- queueName : 'summarydlq' + this . stage ,
767
+ queueName : generatePhysicalNameV2 ( this ,
768
+ 'summarydlq' + this . stage ,
769
+ { maxLength : 32 , lower : true } ) ,
745
770
retentionPeriod : Duration . days ( 7 ) ,
746
771
enforceSSL : true ,
747
772
} ) ;
@@ -783,12 +808,9 @@ export class SummarizationAppsyncStepfn extends BaseClass {
783
808
const maxLogGroupNameLength = 255 ;
784
809
const logGroupPrefix = '/aws/vendedlogs/states/constructs/' ;
785
810
const maxGeneratedNameLength = maxLogGroupNameLength - logGroupPrefix . length ;
786
- const nameParts : string [ ] = [
787
- Stack . of ( scope ) . stackName , // Name of the stack
788
- scope . node . id , // Construct ID
789
- 'StateMachineLogSummarization' , // Literal string for log group name portion
790
- ] ;
791
- const logGroupName = generatePhysicalName ( logGroupPrefix , nameParts , maxGeneratedNameLength ) ;
811
+
812
+ const logGroupName = generatePhysicalNameV2 ( this , logGroupPrefix ,
813
+ { maxLength : maxGeneratedNameLength , lower : true } ) ;
792
814
const summarizationLogGroup = new logs . LogGroup ( this , 'summarizationLogGroup' , {
793
815
logGroupName : logGroupName ,
794
816
} ) ;
0 commit comments