From 71f5c5aaa6a0b9ce6f472d607da1d4044f2d1142 Mon Sep 17 00:00:00 2001 From: Alex Kokachev Date: Fri, 29 Jan 2021 18:01:27 +1100 Subject: [PATCH] fix(core): append file extension to s3 asset key in new style synthesizer - This change fixes the issue with new style synthesizer, when s3 files assets are uploaded without file extension. This was breaking integration with some services, in particular Glue, which requires jar files to have "jar" extension in order to compile. - Legacy synthesizer was uploading files with extensions, so this changes effectively aligns old and new synthesizers. fixes #12740 --- .../core/lib/stack-synthesizers/default-synthesizer.ts | 3 ++- .../core/test/stack-synthesis/new-style-synthesis.test.ts | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts b/packages/@aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts index b4f9f29cf732a..a92d3b6fe04d0 100644 --- a/packages/@aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts +++ b/packages/@aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts @@ -291,7 +291,8 @@ export class DefaultStackSynthesizer extends StackSynthesizer { assertBound(this.bucketName); validateFileAssetSource(asset); - const objectKey = this.bucketPrefix + asset.sourceHash + (asset.packaging === FileAssetPackaging.ZIP_DIRECTORY ? '.zip' : ''); + const extension = asset.fileName != undefined ? path.extname(asset.fileName) : ''; + const objectKey = this.bucketPrefix + asset.sourceHash + (asset.packaging === FileAssetPackaging.ZIP_DIRECTORY ? '.zip' : extension); // Add to manifest this.files[asset.sourceHash] = { diff --git a/packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts b/packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts index 0131b7a4acc63..6780f07fbd879 100644 --- a/packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts +++ b/packages/@aws-cdk/core/test/stack-synthesis/new-style-synthesis.test.ts @@ -52,7 +52,7 @@ nodeunitShim({ destinations: { 'current_account-current_region': { bucketName: 'cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}', - objectKey: templateHash, + objectKey: templateHash + '.json', assumeRoleArn: 'arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}', }, }, @@ -111,7 +111,7 @@ nodeunitShim({ // THEN - we have a fixed asset location with region placeholders test.equals(evalCFN(location.bucketName), 'cdk-hnb659fds-assets-the_account-the_region'); - test.equals(evalCFN(location.s3Url), 'https://s3.the_region.domain.aws/cdk-hnb659fds-assets-the_account-the_region/abcdef'); + test.equals(evalCFN(location.s3Url), 'https://s3.the_region.domain.aws/cdk-hnb659fds-assets-the_account-the_region/abcdef.js'); // THEN - object key contains source hash somewhere test.ok(location.objectKey.indexOf('abcdef') > -1); @@ -208,7 +208,7 @@ nodeunitShim({ test.deepEqual(manifest.files?.['file-asset-hash']?.destinations?.['current_account-current_region'], { bucketName: 'file-asset-bucket', - objectKey: 'file-asset-hash', + objectKey: 'file-asset-hash.js', assumeRoleArn: 'file:role:arn', assumeRoleExternalId: 'file-external-id', }); @@ -256,7 +256,7 @@ nodeunitShim({ // THEN test.deepEqual(manifest.files?.['file-asset-hash-with-prefix']?.destinations?.['current_account-current_region'], { bucketName: 'file-asset-bucket', - objectKey: '000000000000/file-asset-hash-with-prefix', + objectKey: '000000000000/file-asset-hash-with-prefix.js', assumeRoleArn: 'file:role:arn', assumeRoleExternalId: 'file-external-id', });