@@ -33,12 +33,13 @@ fs.readdirSync(global_s3_assets).forEach(file => {
3333 const fn = template . Resources [ f ] ;
3434 if ( fn . Properties . Code . hasOwnProperty ( 'S3Bucket' ) ) {
3535 // Set the S3 key reference
36- let artifactHash = Object . assign ( fn . Properties . Code . S3Bucket . Ref ) ;
37- // artifactHash = artifactHash.replace('AssetParameters', '');
38- let start = artifactHash . indexOf ( 'AssetParameters' ) + 15
39- artifactHash = artifactHash . substring ( start , artifactHash . indexOf ( 'S3Bucket' ) ) ;
40- const assetPath = `asset${ artifactHash } ` ;
41- fn . Properties . Code . S3Key = `%%SOLUTION_NAME%%/%%VERSION%%/${ assetPath } .zip` ;
36+ let s3Key = Object . assign ( fn . Properties . Code . S3Key ) ;
37+ // https://github.com/aws/aws-cdk/issues/10608
38+ if ( ! s3Key . endsWith ( '.zip' ) ) {
39+ fn . Properties . Code . S3Key = `%%SOLUTION_NAME%%/%%VERSION%%/${ s3Key } .zip` ;
40+ } else {
41+ fn . Properties . Code . S3Key = `%%SOLUTION_NAME%%/%%VERSION%%/${ s3Key } ` ;
42+ }
4243 // Set the S3 bucket reference
4344 fn . Properties . Code . S3Bucket = {
4445 'Fn::Sub' : '%%BUCKET_NAME%%-${AWS::Region}'
@@ -67,58 +68,20 @@ fs.readdirSync(global_s3_assets).forEach(file => {
6768 }
6869 } ) ;
6970
70- // Clean-up Lambda layer code dependencies
71+ // Clean-up Lambda Layer code dependencies
7172 const lambdaLayers = Object . keys ( resources ) . filter ( function ( key ) {
7273 return resources [ key ] . Type === "AWS::Lambda::LayerVersion" ;
73- } ) ;
74- lambdaLayers . forEach ( function ( f ) {
75- const fn = template . Resources [ f ] ;
76- if ( fn . Properties . Content . hasOwnProperty ( 'S3Bucket' ) ) {
77- // Set the S3 key reference
78- let artifactHash = Object . assign ( fn . Properties . Content . S3Bucket . Ref ) ;
79- // artifactHash = artifactHash.replace('AssetParameters', '');
80- let start = artifactHash . indexOf ( 'AssetParameters' ) + 15
81- artifactHash = artifactHash . substring ( start , artifactHash . indexOf ( 'S3Bucket' ) ) ;
82- const assetPath = `asset${ artifactHash } ` ;
83- fn . Properties . Content . S3Key = `%%SOLUTION_NAME%%/%%VERSION%%/${ assetPath } .zip` ;
84- // Set the S3 bucket reference
85- fn . Properties . Content . S3Bucket = {
74+ } )
75+ lambdaLayers . forEach ( function ( l ) {
76+ const layer = template . Resources [ l ] ;
77+ if ( layer . Properties . Content . hasOwnProperty ( 'S3Bucket' ) ) {
78+ let s3Key = Object . assign ( layer . Properties . Content . S3Key ) ;
79+ layer . Properties . Content . S3Key = `%%SOLUTION_NAME%%/%%VERSION%%/${ s3Key } ` ;
80+ layer . Properties . Content . S3Bucket = {
8681 'Fn::Sub' : '%%BUCKET_NAME%%-${AWS::Region}'
87- } ;
88- // // Set the handler
89- // const handler = fn.Properties.Handler;
90- // fn.Properties.Handler = `${assetPath}/${handler}`;
91- }
92- } ) ;
93-
94- // Clean-up nested template stack dependencies
95- const nestedStacks = Object . keys ( resources ) . filter ( function ( key ) {
96- return resources [ key ] . Type === 'AWS::CloudFormation::Stack'
97- } ) ;
98- nestedStacks . forEach ( function ( f ) {
99- const fn = template . Resources [ f ] ;
100- fn . Properties . TemplateURL = {
101- 'Fn::Join' : [
102- '' ,
103- [
104- fn . Metadata . domain ,
105- '/' ,
106- `%%SOLUTION_NAME%%/%%VERSION%%/${ fn . Metadata . nestedTemplateName } `
107- ]
108- ]
109- } ;
110-
111- const params = fn . Properties . Parameters ? fn . Properties . Parameters : { } ;
112- const nestedStackParameters = Object . keys ( params ) . filter ( function ( key ) {
113- if ( key . search ( / [ \w ] * A s s e t P a r a m e t e r s / g) > - 1 ) {
114- return true ;
11582 }
116- return false ;
117- } ) ;
118- nestedStackParameters . forEach ( function ( stkParam ) {
119- fn . Properties . Parameters [ stkParam ] = undefined ;
120- } ) ;
121- } ) ;
83+ }
84+ } )
12285
12386
12487 // Clean-up parameters section
@@ -130,6 +93,17 @@ fs.readdirSync(global_s3_assets).forEach(file => {
13093 template . Parameters [ a ] = undefined ;
13194 } ) ;
13295
96+ // Clean-up BootstrapVersion parameter
97+ if ( parameters . hasOwnProperty ( 'BootstrapVersion' ) ) {
98+ parameters . BootstrapVersion = undefined
99+ }
100+
101+ // Clean-up CheckBootstrapVersion Rule
102+ const rules = ( template . Rules ) ? template . Rules : { } ;
103+ if ( rules . hasOwnProperty ( 'CheckBootstrapVersion' ) ) {
104+ rules . CheckBootstrapVersion = undefined
105+ }
106+
133107 // Output modified template file
134108 const output_template = JSON . stringify ( template , null , 2 ) ;
135109 fs . writeFileSync ( `${ global_s3_assets } /${ file } ` , output_template ) ;
0 commit comments