question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-synthetics): Canary inline code doesn’t allow other values for handler expect index.handler

See original GitHub issue

We like to deploy and manage an AWS CloudWatch Canary via CDK. We like to define our Canaries-Definition (Canary using Lambda in the background) in Python – Our CDK is using TypeScript. Canary inline code doesn’t allow other values for handler expect index.handler

Reproduction Steps

  1. “good case”: using index.handler (please see chapter “Notes / Reference to Canary Bug” = CDK is fine (Canary isn’t)

`

export class DemoStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

        const short_script =
        'def handler(event, context): \n' +
        '   return \"Successfully completed basicCanary checks.\" \n'

        const canary = new synthetics.Canary(this, "HealthyAtHome", {
          canaryName: 'healthyathome',
          runtime: new synthetics.Runtime('syn-python-selenium-1.0'),
          test: synthetics.Test.custom({
            code: synthetics.Code.fromInline(short_script),
            handler: 'index.handler'
          })
        });
  }
}`
  1. “bad case”: using an other value for handler = CDK reject this [same code as above, just value for handler is changed from ‘index.handler’ to ‘alivecheck.handler’].

`

export class DemoStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

        const short_script =
        'def handler(event, context): \n' +
        '   return \"Successfully completed basicCanary checks.\" \n'

        const canary = new synthetics.Canary(this, "HealthyAtHome", {
          canaryName: 'healthyathome',
          runtime: new synthetics.Runtime('syn-python-selenium-1.0'),
          test: synthetics.Test.custom({
            code: synthetics.Code.fromInline(short_script),
            handler: 'alivecheck.handler'
          })
        });
  }
}`

What did you expect to happen?

I’m able to define a Canary in CDK as Python inline-code and define a handler value based on my needs, which fitting the general pattern <name>.handler. The value-check for inline code follow the same logic / verifications, like aws-synthetics/lib/canary.ts (see line 33 - 40)

What actually happened?

During cdk synth, I’m getting the error:

Error: The handler for inline code must be “index.handler” (got “alivecheck.handler”)

I’ve tried to identify the CDK-part and I found that for inline-code following check is additional in place: aws-synthetics/lib/code.ts (see line 157 - There is a “hard” check for index.handler value).

Environment

  • CDK CLI Version : 1.111.0
  • OS : Windows 10
  • Language (Version): TypeScript

Notes / Reference to Canary Bug (Other)

Currently there is an Issue (Bug) in AWS Canary-Service in case the “Canary script” is defined in Python AND it’s using handler = index.handler. It seems that Canary is “wrapping” the defined Canary-Code into another (within the Lambda in the background). Once you deployed a (simple) Python-Code for your Canary with index.handler, you getting in Canary-Log:

INFO: Customer canary entry file name: index INFO: Customer canary entry function name: handler INFO: Calling customer canary: index.handler() ERROR: Canary execution exception. Traceback (most recent call last): File “/var/task/index.py”, line 76, in handle_canary response = customer_canary.handler(event, context) File “/var/task/index.py”, line 13, in handler return asyncio.run(handle_canary(event, context))
File “/var/lang/lib/python3.8/asyncio/runners.py”, line 33, in run raise RuntimeError(RuntimeError: asyncio.run() cannot be called from a running event loop`

In case you use an other value for handler and deploy this via CFN, it’s working fine.

By keeping both issues in mind: CDK doesn’t allow other value for handler + Canary working only with a handler value except index.handler we are currently in a “deadlock”. May aws-synthetics/lib/code.ts could be a little bit more ‘flexible’ for handler?


This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
BenChaimbergcommented, Aug 2, 2021

I am unassigning myself and marking this issue as p2, which means that we are unable to work on this immediately.

We use +1s to help prioritize our work, and are happy to reevaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.

Please feel free to work on this issue yourself and request my review if you submit a PR or would like design help! See CONTRIBUTING.md for guidelines.

1reaction
rgoltzcommented, Aug 2, 2022

Hey @greg5123334 - Let’s re-visit this issue here and sync on status regarding this. I’ve pushed an note to your queue 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sample code for canary scripts - Amazon CloudWatch
This sample code demonstrates an API canary with two HTTP steps: testing the same API for positive and negative test cases. The step...
Read more >
(synthetics): canary permissions for cloudwatch logging are ...
When creating a canary using @aws-cdk/aws-synthetics-alpha version ... allow the canary to run but it doesn't create logs in CloudWatch.
Read more >
Use AWS CloudWatch Synthetics Canaries to Monitor Your ...
Each of these tackles the challenge of application monitoring from a different perspective. CloudWatch Logs can be a central repository of logs generated...
Read more >
Creating resilient API synthetic canary tests using CloudWatch ...
Code.fromInline(canaryCode), handler: "index.handler" ...
Read more >
awscdk - Go Packages
An experiment to bundle all of the CDK into a single module. ⚠️ Please don't use this module unless ... String("index.handler"), code: lambda.assetCode....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found