@@ -4,6 +4,7 @@ import * as iam from '@aws-cdk/aws-iam';
44import * as lambda from '@aws-cdk/aws-lambda' ;
55import * as s3assets from '@aws-cdk/aws-s3-assets' ;
66import * as secrets from '@aws-cdk/aws-secretsmanager' ;
7+ import * as dynamodb from '@aws-cdk/aws-dynamodb' ;
78import * as sfn from '@aws-cdk/aws-stepfunctions' ;
89import * as tasks from '@aws-cdk/aws-stepfunctions-tasks' ;
910import { CdkDeployProject , PrebuiltCdkDeployProject } from '@aws-accelerator/cdk-accelerator/src/codebuild' ;
@@ -19,6 +20,7 @@ import { CreateStackTask } from './tasks/create-stack-task';
1920import { RunAcrossAccountsTask } from './tasks/run-across-accounts-task' ;
2021import * as fs from 'fs' ;
2122import * as sns from '@aws-cdk/aws-sns' ;
23+ import { StoreOutputsTask } from './tasks/store-outputs-task' ;
2224
2325export namespace InitialSetup {
2426 export interface CommonProps {
@@ -84,6 +86,18 @@ export namespace InitialSetup {
8486 } ) ;
8587 setSecretValue ( organizationsSecret , '[]' ) ;
8688
89+ const outputsTable = new dynamodb . Table ( this , 'Outputs' , {
90+ tableName : createName ( {
91+ name : 'Outputs' ,
92+ suffixLength : 0 ,
93+ } ) ,
94+ partitionKey : {
95+ name : 'id' ,
96+ type : dynamodb . AttributeType . STRING ,
97+ } ,
98+ encryption : dynamodb . TableEncryption . DEFAULT ,
99+ } ) ;
100+
87101 // This is the maximum time before a build times out
88102 // The role used by the build should allow this session duration
89103 const buildTimeout = cdk . Duration . hours ( 4 ) ;
@@ -469,9 +483,7 @@ export namespace InitialSetup {
469483 'configCommitId.$' : '$.configCommitId' ,
470484 'organizationalUnits.$' : '$.organizationalUnits' ,
471485 'accounts.$' : '$.accounts' ,
472- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
473- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
474- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
486+ outputTableName : outputsTable . tableName ,
475487 } ,
476488 resultPath : 'DISCARD' ,
477489 } ) ;
@@ -527,12 +539,8 @@ export namespace InitialSetup {
527539 ACCELERATOR_PIPELINE_ROLE_NAME : pipelineRole . roleName ,
528540 ACCELERATOR_STATE_MACHINE_NAME : props . stateMachineName ,
529541 CONFIG_BRANCH_NAME : props . configBranchName ,
542+ STACK_OUTPUT_TABLE_NAME : outputsTable . tableName ,
530543 } ;
531- if ( loadOutputs ) {
532- environment [ 'STACK_OUTPUT_BUCKET_NAME.$' ] = '$.storeOutput.outputBucketName' ;
533- environment [ 'STACK_OUTPUT_BUCKET_KEY.$' ] = '$.storeOutput.outputBucketKey' ;
534- environment [ 'STACK_OUTPUT_VERSION.$' ] = '$.storeOutput.outputVersion' ;
535- }
536544 const deployTask = new sfn . Task ( this , `Deploy Phase ${ phase } ` , {
537545 // tslint:disable-next-line: deprecation
538546 task : new tasks . StartExecution ( codeBuildStateMachine , {
@@ -547,21 +555,32 @@ export namespace InitialSetup {
547555 return deployTask ;
548556 } ;
549557
550- const createStoreOutputTask = ( phase : number ) =>
551- new CodeTask ( this , `Store Phase ${ phase } Output` , {
552- functionProps : {
553- code : lambdaCode ,
554- handler : 'index.storeStackOutputStep' ,
555- role : pipelineRole ,
556- } ,
557- functionPayload : {
558- acceleratorPrefix : props . acceleratorPrefix ,
559- assumeRoleName : props . stateMachineExecutionRole ,
560- 'accounts.$' : '$.accounts' ,
561- 'regions.$' : '$.regions' ,
562- } ,
563- resultPath : '$.storeOutput' ,
558+ const storeOutputsStateMachine = new sfn . StateMachine ( this , `${ props . acceleratorPrefix } StoreOutputs_sm` , {
559+ stateMachineName : `${ props . acceleratorPrefix } StoreOutputs_sm` ,
560+ definition : new StoreOutputsTask ( this , 'StoreOutputs' , {
561+ lambdaCode,
562+ role : pipelineRole ,
563+ } ) ,
564+ } ) ;
565+
566+ const createStoreOutputTask = ( phase : number ) => {
567+ const storeOutputsTask = new sfn . Task ( this , `Store Phase ${ phase } Outputs` , {
568+ // tslint:disable-next-line: deprecation
569+ task : new tasks . StartExecution ( storeOutputsStateMachine , {
570+ integrationPattern : sfn . ServiceIntegrationPattern . SYNC ,
571+ input : {
572+ 'accounts.$' : '$.accounts' ,
573+ 'regions.$' : '$.regions' ,
574+ acceleratorPrefix : props . acceleratorPrefix ,
575+ assumeRoleName : props . stateMachineExecutionRole ,
576+ outputsTable : outputsTable . tableName ,
577+ phaseNumber : phase ,
578+ } ,
579+ } ) ,
580+ resultPath : 'DISCARD' ,
564581 } ) ;
582+ return storeOutputsTask ;
583+ } ;
565584
566585 // TODO Create separate state machine for deployment
567586 const deployPhaseRolesTask = createDeploymentTask ( - 1 , false ) ;
@@ -587,9 +606,7 @@ export namespace InitialSetup {
587606 lambdaPath : 'index.createConfigRecorder' ,
588607 name : 'Create Config Recorder' ,
589608 functionPayload : {
590- 'stackOutputBucketName.$' : '$.stackOutputBucketName' ,
591- 'stackOutputBucketKey.$' : '$.stackOutputBucketKey' ,
592- 'stackOutputVersion.$' : '$.stackOutputVersion' ,
609+ outputTableName : outputsTable . tableName ,
593610 } ,
594611 } ) ,
595612 } ) ;
@@ -604,9 +621,7 @@ export namespace InitialSetup {
604621 'configFilePath.$' : '$.configFilePath' ,
605622 'configCommitId.$' : '$.configCommitId' ,
606623 'baseline.$' : '$.baseline' ,
607- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
608- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
609- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
624+ outputTableName : outputsTable . tableName ,
610625 acceleratorPrefix : props . acceleratorPrefix ,
611626 } ,
612627 } ) ,
@@ -626,9 +641,7 @@ export namespace InitialSetup {
626641 'configRepositoryName.$' : '$.configRepositoryName' ,
627642 'configFilePath.$' : '$.configFilePath' ,
628643 'configCommitId.$' : '$.configCommitId' ,
629- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
630- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
631- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
644+ outputTableName : outputsTable . tableName ,
632645 } ,
633646 resultPath : 'DISCARD' ,
634647 } ) ;
@@ -648,9 +661,7 @@ export namespace InitialSetup {
648661 'configRepositoryName.$' : '$.configRepositoryName' ,
649662 'configFilePath.$' : '$.configFilePath' ,
650663 'configCommitId.$' : '$.configCommitId' ,
651- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
652- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
653- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
664+ outputTableName : outputsTable . tableName ,
654665 rdgwScripts,
655666 } ,
656667 resultPath : 'DISCARD' ,
@@ -668,9 +679,7 @@ export namespace InitialSetup {
668679 'configRepositoryName.$' : '$.configRepositoryName' ,
669680 'configFilePath.$' : '$.configFilePath' ,
670681 'configCommitId.$' : '$.configCommitId' ,
671- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
672- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
673- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
682+ outputTableName : outputsTable . tableName ,
674683 } ,
675684 resultPath : 'DISCARD' ,
676685 } ) ;
@@ -683,9 +692,7 @@ export namespace InitialSetup {
683692 } ,
684693 functionPayload : {
685694 assumeRoleName : props . stateMachineExecutionRole ,
686- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
687- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
688- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
695+ outputTableName : outputsTable . tableName ,
689696 } ,
690697 resultPath : 'DISCARD' ,
691698 } ) ;
@@ -702,9 +709,7 @@ export namespace InitialSetup {
702709 'configRepositoryName.$' : '$.configRepositoryName' ,
703710 'configFilePath.$' : '$.configFilePath' ,
704711 'configCommitId.$' : '$.configCommitId' ,
705- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
706- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
707- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
712+ outputTableName : outputsTable . tableName ,
708713 } ,
709714 resultPath : 'DISCARD' ,
710715 } ) ;
@@ -728,9 +733,7 @@ export namespace InitialSetup {
728733 'configRepositoryName.$' : '$.configRepositoryName' ,
729734 'configFilePath.$' : '$.configFilePath' ,
730735 'configCommitId.$' : '$.configCommitId' ,
731- 'stackOutputBucketName.$' : '$.storeOutput.outputBucketName' ,
732- 'stackOutputBucketKey.$' : '$.storeOutput.outputBucketKey' ,
733- 'stackOutputVersion.$' : '$.storeOutput.outputVersion' ,
736+ outputTableName : outputsTable . tableName ,
734737 } ,
735738 } ) ,
736739 resultPath : 'DISCARD' ,
0 commit comments