Skip to content

Commit

Permalink
fix(s3-deployment): source markers missing when there are multiple so…
Browse files Browse the repository at this point in the history
…urces

Follow up to aws#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
  • Loading branch information
corymhall authored and Brennan Ho committed Feb 22, 2023
1 parent 55d2535 commit 6067c93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts
Expand Up @@ -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<Record<string, any>>);
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts
Expand Up @@ -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.'));
Expand Down

0 comments on commit 6067c93

Please sign in to comment.