aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.62k stars 3.91k forks source link

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

Closed msimperi closed 1 year ago

msimperi commented 3 years ago

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

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: Bug Report

Zerquix18 commented 3 years ago

+1

RichiCoder1 commented 2 years ago

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 commented 2 years ago

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!

github-actions[bot] commented 1 year ago

⚠️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.