Skip to content

Commit bba2e5b

Browse files
authored
fix(assets): can now use multiple assets in the same stack (#725)
Fixed by attaching the imported bucket to the Asset object instead of the Asset object's parent. Fixes #706.
1 parent a7bc5ee commit bba2e5b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/@aws-cdk/assets/lib/asset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class Asset extends cdk.Construct {
9999
const s3Filename = new cdk.FnSelect(1, new cdk.FnSplit(cxapi.ASSET_PREFIX_SEPARATOR, keyParam.value));
100100
this.s3ObjectKey = new s3.ObjectKey(new cdk.FnConcat(this.s3Prefix, s3Filename));
101101

102-
this.bucket = s3.BucketRef.import(parent, 'AssetBucket', {
102+
this.bucket = s3.BucketRef.import(this, 'AssetBucket', {
103103
bucketName: this.s3BucketName
104104
});
105105

packages/@aws-cdk/assets/test/test.asset.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,18 @@ export = {
9898
path: '/path/not/found/' + Math.random() * 999999
9999
}));
100100
test.done();
101-
}
101+
},
102+
103+
'multiple assets under the same parent'(test: Test) {
104+
// GIVEN
105+
const stack = new cdk.Stack();
106+
107+
// WHEN
108+
new ZipDirectoryAsset(stack, 'MyDirectory1', { path: '.' });
109+
new ZipDirectoryAsset(stack, 'MyDirectory2', { path: '.' });
110+
111+
// THEN: no error
112+
113+
test.done();
114+
},
102115
};

0 commit comments

Comments
 (0)