Skip to content

Commit 0ebbf58

Browse files
authored
fix(servicecatalog): wrong asset path is generated in case outdir is absolute (#24393)
In case we get an absolute path like `/tmp/foobar` then `./` is always prepended which makes the assetPath relative to the current directory. Fixes #24392 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3bd611d commit 0ebbf58

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/@aws-cdk/aws-servicecatalog/lib/private/product-stack-synthesizer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ProductStackSynthesizer extends cdk.StackSynthesizer {
2323
throw new Error('An Asset Bucket must be provided to use Assets');
2424
}
2525
const outdir = cdk.App.of(this.boundStack)?.outdir ?? 'cdk.out';
26-
const assetPath = `./${outdir}/${asset.fileName}`;
26+
const assetPath = `${outdir}/${asset.fileName}`;
2727
if (!this.bucketDeployment) {
2828
const parentStack = (this.boundStack as ProductStack)._getParentStack();
2929
if (!cdk.Resource.isOwnedResource(this.assetBucket)) {

packages/@aws-cdk/aws-servicecatalog/test/product-stack.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ describe('ProductStack', () => {
5454
});
5555
});
5656

57+
test('Use correct assetPath when outdir is absolute', () => {
58+
// GIVEN
59+
const app = new cdk.App(
60+
{ outdir: '/tmp/foobar' },
61+
);
62+
const mainStack = new cdk.Stack(app, 'MyStackAbsolutePath');
63+
const testAssetBucket = new s3.Bucket(mainStack, 'TestAssetBucket', {
64+
bucketName: 'test-asset-bucket',
65+
});
66+
const productStack = new servicecatalog.ProductStack(mainStack, 'MyProductStackAbsolutePath', {
67+
assetBucket: testAssetBucket,
68+
});
69+
70+
new lambda.Function(productStack, 'HelloHandler', {
71+
runtime: lambda.Runtime.PYTHON_3_9,
72+
code: lambda.Code.fromAsset(path.join(__dirname, 'assets')),
73+
handler: 'index.handler',
74+
});
75+
76+
// WHEN
77+
const assembly = app.synth();
78+
79+
// THEN
80+
expect(assembly.directory).toBe('/tmp/foobar');
81+
});
82+
5783
test('Used defined Asset bucket in product stack with nested assets', () => {
5884
// GIVEN
5985
const app = new cdk.App(

0 commit comments

Comments
 (0)