Skip to content

Commit 0bb0181

Browse files
corymhallMrArnoldPalmer
authored andcommitted
fix(s3-deployment): source markers missing when there are multiple sources
Follow up to #23321. There is an interesting edge case where if there is _any_ source that has source markers then _all_ sources have to have source markers. This is due to the way the custom resource logic works https://github.com/aws/aws-cdk/blob/02d0876bbb196e9fbeb32d977e7cf65229c8559d/packages/%40aws-cdk/aws-s3-deployment/lib/lambda/index.py#L64 https://github.com/aws/aws-cdk/blob/02d0876bbb196e9fbeb32d977e7cf65229c8559d/packages/%40aws-cdk/aws-s3-deployment/lib/lambda/index.py#L137
1 parent 077d77d commit 0bb0181

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts

+4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ export class BucketDeployment extends Construct {
369369
return this.sources.reduce((acc, source) => {
370370
if (source.markers) {
371371
acc.push(source.markers);
372+
// if there are more than 1 source, then all sources
373+
// require markers (custom resource will throw an error otherwise)
374+
} else if (this.sources.length > 1) {
375+
acc.push({});
372376
}
373377
return acc;
374378
}, [] as Array<Record<string, any>>);

packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,26 @@ test('can add sources with addSource', () => {
13841384
});
13851385
});
13861386

1387+
test('if any source has markers then all sources have markers', () => {
1388+
const app = new cdk.App();
1389+
const stack = new cdk.Stack(app, 'Test');
1390+
const bucket = new s3.Bucket(stack, 'Bucket');
1391+
const deployment = new s3deploy.BucketDeployment(stack, 'Deploy', {
1392+
sources: [s3deploy.Source.data('my/path.txt', 'helloWorld')],
1393+
destinationBucket: bucket,
1394+
});
1395+
deployment.addSource(s3deploy.Source.asset(path.join(__dirname, 'my-website')));
1396+
1397+
const result = app.synth();
1398+
const content = readDataFile(result, 'my/path.txt');
1399+
expect(content).toStrictEqual('helloWorld');
1400+
Template.fromStack(stack).hasResourceProperties('Custom::CDKBucketDeployment', {
1401+
SourceMarkers: [
1402+
{},
1403+
{},
1404+
],
1405+
});
1406+
});
13871407

13881408
function readDataFile(casm: cxapi.CloudAssembly, relativePath: string): string {
13891409
const assetDirs = readdirSync(casm.directory).filter(f => f.startsWith('asset.'));

0 commit comments

Comments
 (0)