Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(synthetics): synth-time failure for canary assets in nested stages #27167

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-synthetics-alpha/lib/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ export class AssetCode extends Code {
}

// Get the staged (or copied) asset path.
const assetOutDir = Stage.of(scope)?.assetOutdir;
const assetPath = assetOutDir ? path.join(assetOutDir, this.asset.assetPath): this.assetPath;
// `this.asset.assetPath` is relative to the `outdir`, not the `assetOutDir`.
const asmManifestDir = Stage.of(scope)?.outdir;
const assetPath = asmManifestDir ? path.join(asmManifestDir, this.asset.assetPath): this.assetPath;

if (path.extname(assetPath) !== '.zip') {
if (!fs.lstatSync(assetPath).isDirectory()) {
Expand Down
20 changes: 19 additions & 1 deletion packages/@aws-cdk/aws-synthetics-alpha/test/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { Template } from 'aws-cdk-lib/assertions';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { App, Stack, DockerImage } from 'aws-cdk-lib';
import { App, Stage, Stack, DockerImage } from 'aws-cdk-lib';
import * as cxapi from 'aws-cdk-lib/cx-api';
import * as synthetics from '../lib';
import { RuntimeFamily } from '../lib';
Expand Down Expand Up @@ -123,6 +123,24 @@ describe(synthetics.Code.fromAsset, () => {
expect(synthesized.assets.length).toEqual(1);
});

test('works when stack is a part of a stage', () => {
// GIVEN
const app = new App();
const stage1 = new Stage(app, 'Stage1');
const stage2 = new Stage(stage1, 'Stage2');
const stack = new Stack(stage2);

// WHEN
const directoryAsset = synthetics.Code.fromAsset(path.join(__dirname, 'canaries'));
new synthetics.Canary(stack, 'Canary1', {
test: synthetics.Test.custom({
handler: 'canary.handler',
code: directoryAsset,
}),
runtime: synthetics.Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_8,
});
});

test('fails if path does not exist', () => {
const assetPath = path.join(__dirname, 'does-not-exist');
expect(() => synthetics.Code.fromAsset(assetPath))
Expand Down
1 change: 0 additions & 1 deletion packages/aws-cdk-lib/core/lib/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export class Stage extends Construct {
* will return an empty string.
*
* Derived from the construct path.
*
*/
public get artifactId() {
if (!this.node.path) { return ''; }
Expand Down
Loading