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

[synthetics] Validation of canary file existence done too early #11630

Closed
msimperi opened this issue Nov 23, 2020 · 4 comments · Fixed by #26291
Closed

[synthetics] Validation of canary file existence done too early #11630

msimperi opened this issue Nov 23, 2020 · 4 comments · Fixed by #26291
Labels
@aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@msimperi
Copy link

msimperi commented Nov 23, 2020

When creating Canary lambda asset resource, the bundling does not happen before the validation of "existence" of canary file is done. This blocks the usage of bundling options in many case.

Reproduction Steps

    new Canary(this, props.canaryId, {
      canaryName: 'testcanary',
      test: Test.custom({
        code: Code.fromAsset(path.join(__dirname, '../canaryScripts/), {
          bundling: {
            image: lambda.Runtime.NODEJS_12_X.bundlingDockerImage,
            command: [
              'bash',
              '-c',
              [
                `mkdir -p /asset-output/nodejs/node_modules/`,
                `cp -R /asset-input/* /asset-output/nodejs/node_modules/`,
              ].join(' && '),
            ],
            user: 'root',
          },
        }),
        handler: `canary.handler`,
      }),
      runtime: Runtime.SYNTHETICS_NODEJS_2_0,
    });

What did you expect to happen?

I expected that the bundling would happen before CDK validates if canary file has been found from correct location of zip-file generated.

Using bundling I can run optimisation, validations, include only needed files and re-structure my code asset before creating zip file.

What actually happened?

I get error message before bundling has been executed as following: The canary resource requires that the handler is present at "nodejs/node_modules/canary.js" but not found at /Users/mypath/src/synthetics/ (https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_WritingCanary.html#CloudWatch_Synthetics_Canaries_write_from_scratch) Subprocess exited with error 1

Environment

  • CDK CLI Version : 1.74.0
  • Framework Version: 1.74.0
  • Node.js Version: v12.18.4
  • OS : macOS 11.0.1
  • Language (Version): Typescript

Other

The code that triggers error is here: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-synthetics/lib/code.ts#L135


This is 🐛 Bug Report

@msimperi msimperi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2020
@msimperi msimperi changed the title @aws-cdk/aws-synthetics: Validation of canary file existence done too early [synthetics]: Validation of canary file existence done too early Nov 23, 2020
@msimperi msimperi changed the title [synthetics]: Validation of canary file existence done too early [synthetics] Validation of canary file existence done too early Nov 23, 2020
@github-actions github-actions bot added the @aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics label Nov 23, 2020
@NetaNir NetaNir added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 24, 2021
@NetaNir NetaNir removed their assignment Jun 21, 2021
@Zerquix18
Copy link

+1

@RichiCoder1
Copy link
Contributor

So it looks like the issue is specifically that it's validating the path before staging and not considering the staged (and in this case bundled) assets at all.

@RichiCoder1
Copy link
Contributor

Pending my PR, for anyone else running into this issue be sure to check out https://github.com/mrgrain/cdk-esbuild#amazon-cloudwatch-synthetics-canary-monitoring!

@mergify mergify bot closed this as completed in #26291 Jul 10, 2023
mergify bot pushed a commit that referenced this issue Jul 10, 2023
A re-roll of #19342. Thanks @RichiCoder1 for doing most of this work!

This PR moves asset validation from _before_ staging the asset to _after_, and then validates on the staged asset instead. This allows for asset bundling because our prior validation was too eager.

In addition, this construct can help with synthetic canaries + bundled code: https://github.com/mrgrain/cdk-esbuild#amazon-cloudwatch-synthetics-canary-monitoring.

Fixes #11630

Co-authored-by: Richard Simpson richicoder1@outlook.com

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

bmoffatt pushed a commit to bmoffatt/aws-cdk that referenced this issue Jul 29, 2023
…26291)

A re-roll of aws#19342. Thanks @RichiCoder1 for doing most of this work!

This PR moves asset validation from _before_ staging the asset to _after_, and then validates on the staged asset instead. This allows for asset bundling because our prior validation was too eager.

In addition, this construct can help with synthetic canaries + bundled code: https://github.com/mrgrain/cdk-esbuild#amazon-cloudwatch-synthetics-canary-monitoring.

Fixes aws#11630

Co-authored-by: Richard Simpson richicoder1@outlook.com

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
4 participants