diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index 35e9819a2b334..bd0cc6349f70a 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -369,6 +369,10 @@ export class BucketDeployment extends Construct { return this.sources.reduce((acc, source) => { if (source.markers) { acc.push(source.markers); + // if there are more than 1 source, then all sources + // require markers (custom resource will throw an error otherwise) + } else if (this.sources.length > 1) { + acc.push({}); } return acc; }, [] as Array>); diff --git a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts index d3312d9b58a49..71b2403cb778e 100644 --- a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts +++ b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts @@ -1384,6 +1384,26 @@ test('can add sources with addSource', () => { }); }); +test('if any source has markers then all sources have markers', () => { + const app = new cdk.App(); + const stack = new cdk.Stack(app, 'Test'); + const bucket = new s3.Bucket(stack, 'Bucket'); + const deployment = new s3deploy.BucketDeployment(stack, 'Deploy', { + sources: [s3deploy.Source.data('my/path.txt', 'helloWorld')], + destinationBucket: bucket, + }); + deployment.addSource(s3deploy.Source.asset(path.join(__dirname, 'my-website'))); + + const result = app.synth(); + const content = readDataFile(result, 'my/path.txt'); + expect(content).toStrictEqual('helloWorld'); + Template.fromStack(stack).hasResourceProperties('Custom::CDKBucketDeployment', { + SourceMarkers: [ + {}, + {}, + ], + }); +}); function readDataFile(casm: cxapi.CloudAssembly, relativePath: string): string { const assetDirs = readdirSync(casm.directory).filter(f => f.startsWith('asset.'));