From 2d6f28be0033f181d1d88101235042ad301579de Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 17 Sep 2018 12:01:01 +0200 Subject: [PATCH 1/2] fix(assets): can now use multiple assets in the same stack Fixed by attaching the imported bucket to the Asset object instead of the Asset object's parent. Fixes #706. --- packages/@aws-cdk/assets/lib/asset.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/assets/lib/asset.ts b/packages/@aws-cdk/assets/lib/asset.ts index 35fc91fbfe643..eb6e4b7cbcb80 100644 --- a/packages/@aws-cdk/assets/lib/asset.ts +++ b/packages/@aws-cdk/assets/lib/asset.ts @@ -99,7 +99,7 @@ export class Asset extends cdk.Construct { const s3Filename = new cdk.FnSelect(1, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value)); this.s3ObjectKey = new s3.ObjectKey(new cdk.FnConcat(this.s3Prefix, s3Filename)); - this.bucket = s3.BucketRef.import(parent, 'AssetBucket', { + this.bucket = s3.BucketRef.import(this, 'AssetBucket', { bucketName: this.s3BucketName }); From 8b4391dd60e60acc64fe0c3c76df8dea3a8e7e7c Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 17 Sep 2018 13:47:01 +0200 Subject: [PATCH 2/2] Add test --- packages/@aws-cdk/assets/test/test.asset.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/assets/test/test.asset.ts b/packages/@aws-cdk/assets/test/test.asset.ts index e78d02c18fa34..b417ce33f2cbd 100644 --- a/packages/@aws-cdk/assets/test/test.asset.ts +++ b/packages/@aws-cdk/assets/test/test.asset.ts @@ -98,5 +98,18 @@ export = { path: '/path/not/found/' + Math.random() * 999999 })); test.done(); - } + }, + + 'multiple assets under the same parent'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new ZipDirectoryAsset(stack, 'MyDirectory1', { path: '.' }); + new ZipDirectoryAsset(stack, 'MyDirectory2', { path: '.' }); + + // THEN: no error + + test.done(); + }, }; \ No newline at end of file