(aws-synthetics): Canary inline code doesn’t allow other values for handler expect index.handler
See original GitHub issueWe 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
- “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'
})
});
}
}`
- “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:
- Created 2 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
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.
Hey @greg5123334 - Let’s re-visit this issue here and sync on status regarding this. I’ve pushed an note to your queue 😉