@@ -5,6 +5,8 @@ import { AcceleratorConfig } from '@aws-accelerator/common-config/src';
55import { AccountStacks , AccountStack } from '../../common/account-stacks' ;
66import { JsonOutputValue } from '../../common/json-output' ;
77import { ArtifactName , CfnArtifactOutput } from './outputs' ;
8+ import { createRoleName } from '@aws-accelerator/cdk-accelerator/src/core/accelerator-name-generator' ;
9+ import { S3CopyFiles } from '@aws-accelerator/custom-resource-s3-copy-files' ;
810
911export interface ArtifactsStep1Props {
1012 accountStacks : AccountStacks ;
@@ -18,8 +20,14 @@ export async function step1(props: ArtifactsStep1Props) {
1820 const masterAccountKey = config . getMandatoryAccountKey ( 'master' ) ;
1921 const masterAccountStack = accountStacks . getOrCreateAccountStack ( masterAccountKey ) ;
2022
23+ // Get the location of the original central bucket
24+ const centralConfigBucketName = config [ 'global-options' ] [ 'central-bucket' ] ;
25+ const centralConfigBucket = s3 . Bucket . fromBucketAttributes ( masterAccountStack , 'CentralBucket' , {
26+ bucketName : centralConfigBucketName ,
27+ } ) ;
28+
2129 // upload SCP Artifacts
22- uploadArtifacts ( {
30+ const scpUpload = uploadArtifacts ( {
2331 accountStack : masterAccountStack ,
2432 artifactName : 'SCP' ,
2533 artifactFolderName : 'SCPs' ,
@@ -29,7 +37,7 @@ export async function step1(props: ArtifactsStep1Props) {
2937 } ) ;
3038
3139 // upload IAM-Policies Artifacts
32- uploadArtifacts ( {
40+ const iamUpload = uploadArtifacts ( {
3341 accountStack : masterAccountStack ,
3442 artifactName : 'IamPolicy' ,
3543 artifactFolderName : 'iam-policies' ,
@@ -39,7 +47,7 @@ export async function step1(props: ArtifactsStep1Props) {
3947 } ) ;
4048
4149 // upload RDGW Artifacts
42- uploadArtifacts ( {
50+ const rdgwUpload = uploadArtifacts ( {
4351 accountStack : masterAccountStack ,
4452 artifactName : 'Rdgw' ,
4553 artifactFolderName : 'scripts' ,
@@ -49,7 +57,7 @@ export async function step1(props: ArtifactsStep1Props) {
4957 } ) ;
5058
5159 // upload Rsyslog Artifacts
52- uploadArtifacts ( {
60+ const rsyslogUpload = uploadArtifacts ( {
5361 accountStack : masterAccountStack ,
5462 artifactName : 'Rsyslog' ,
5563 artifactFolderName : 'rsyslog' ,
@@ -59,7 +67,7 @@ export async function step1(props: ArtifactsStep1Props) {
5967 } ) ;
6068
6169 // upload SSM-Document Artifacts
62- uploadArtifacts ( {
70+ const ssmUpload = uploadArtifacts ( {
6371 accountStack : masterAccountStack ,
6472 artifactName : 'SsmDocument' ,
6573 artifactFolderName : 'ssm-documents' ,
@@ -68,6 +76,21 @@ export async function step1(props: ArtifactsStep1Props) {
6876 destinationKeyPrefix : 'ssm-documents' ,
6977 keepExistingFiles : true ,
7078 } ) ;
79+
80+ // Copy files from source to destination
81+ const copyFiles = new S3CopyFiles ( masterAccountStack , 'CopyFiles' , {
82+ roleName : createRoleName ( 'S3CopyFiles' ) ,
83+ sourceBucket : centralConfigBucket ,
84+ destinationBucket : centralBucket ,
85+ deleteSourceObjects : false ,
86+ deleteSourceBucket : false ,
87+ forceUpdate : true ,
88+ } ) ;
89+ copyFiles . node . addDependency ( ssmUpload ) ;
90+ copyFiles . node . addDependency ( rsyslogUpload ) ;
91+ copyFiles . node . addDependency ( rdgwUpload ) ;
92+ copyFiles . node . addDependency ( iamUpload ) ;
93+ copyFiles . node . addDependency ( scpUpload ) ;
7194}
7295
7396function uploadArtifacts ( props : {
@@ -78,7 +101,7 @@ function uploadArtifacts(props: {
78101 centralBucket : s3 . IBucket ;
79102 destinationKeyPrefix ?: string ;
80103 keepExistingFiles ?: boolean ;
81- } ) {
104+ } ) : s3deployment . BucketDeployment {
82105 const {
83106 accountStack,
84107 artifactName,
@@ -102,15 +125,16 @@ function uploadArtifacts(props: {
102125 artifactFolderName ,
103126 ) ;
104127
105- // TODO Leave existing files in the folder
106- // TODO Do not override existing files
107- // See https://github.com/aws/aws-cdk/issues/953
108- new s3deployment . BucketDeployment ( accountStack , `${ artifactName } ArtifactsDeployment${ accountKey } ` , {
109- sources : [ s3deployment . Source . asset ( artifactsFolderPath ) ] ,
110- destinationBucket : centralBucket ,
111- destinationKeyPrefix,
112- prune : ! keepExistingFiles ,
113- } ) ;
128+ const s3Deployment = new s3deployment . BucketDeployment (
129+ accountStack ,
130+ `${ artifactName } ArtifactsDeployment${ accountKey } ` ,
131+ {
132+ sources : [ s3deployment . Source . asset ( artifactsFolderPath ) ] ,
133+ destinationBucket : centralBucket ,
134+ destinationKeyPrefix,
135+ prune : ! keepExistingFiles ,
136+ } ,
137+ ) ;
114138
115139 // outputs to store reference artifacts s3 bucket information
116140 new JsonOutputValue ( accountStack , `${ artifactName } ArtifactsOutput${ accountKey } ` , {
@@ -130,4 +154,5 @@ function uploadArtifacts(props: {
130154 bucketName : centralBucket . bucketName ,
131155 keyPrefix : artifactKeyPrefix ,
132156 } ) ;
157+ return s3Deployment ;
133158}
0 commit comments