LambdaFunction does not implement IRuleTarget
See original GitHub issueIn the Python CDK, attempting to pass aws_events_targets.LambdaFunction
as the target of an events.Rule
fails to typecheck:
$ mypy test.py
test.py:19: error: List item 0 has incompatible type "LambdaFunction"; expected "IRuleTarget"
test.py:19: note: 'LambdaFunction' is missing following 'IRuleTarget' protocol member:
test.py:19: note: __jsii_proxy_class__
Found 1 error in 1 file (checked 1 source file)
It does run perfectly fine, however – this is purely an error in the typesystem.
Reproduction Steps
from aws_cdk import aws_events, aws_events_targets, aws_lambda, core
class Example(core.Construct):
def __init__(self, scope: core.Construct):
super().__init__(scope, "some-name")
some_lambda = aws_lambda.Function(
self,
"some-handler",
runtime=aws_lambda.Runtime.PYTHON_3_8,
code=aws_lambda.AssetCode("some/path"),
handler="some_package.handler",
retry_attempts=0,
)
aws_events.Rule(
self,
"some-rule",
schedule=aws_events.Schedule.cron(minute="*/5"),
targets=[aws_events_targets.LambdaFunction(some_lambda)],
)
pip install mypy && mypy test.py
Error Log
test.py:19: note: 'LambdaFunction' is missing following 'IRuleTarget' protocol member:
test.py:19: note: __jsii_proxy_class__
Environment
- CLI Version: 1.17.13
- Framework Version: 1.31.0
- OS: OS X 10.14.6
- Language: Python 3.8.0 / mypy 0.770
Other
It is also possible this is a bug in mypy.
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:15 (10 by maintainers)
Top Results From Across the Web
https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-c...
No information is available for this page.
Read more >How to resolve AWS CDK error "Argument of type 'Function' is ...
This error Argument of type 'SomeClass' is not assignable to parameter of type 'ISomeClass' typically occurs when version of CDK ...
Read more >Schedule AWS Lambda Functions using CDK - YouTube
This is a step-by-step tutorial on creating Scheduled Lambda using CDK. In the previous video, we have already done that using AWS Console, ......
Read more >@aws-cdk/aws-events - npm
Rules are not processed in a particular order. ... Event targets are objects that implement the IRuleTarget interface.
Read more >Triggers lambda {eventName} - awslabs/aws-cdk - Gitter
@SkyVikerRumsey_twitter just to make sure, are you making use of the aws-events-targets module and passing IRuleTarget correct? can you try targets via the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m running into the same issue with
aws_cloudwatch.Metric
not correctly implementingIMetric
. Here’s a snippet that demonstrates the issue:Checking types with Mypy results in the following error:
Sorry for not making clear that yeah, this is not about the functionality (which works great!), but about the type-correctness of the
jsii
-generated typing of the code.I’ve found two other ones: neither
aws_cloudwatch.MathExpression
noraws_cloudwatch.Metric
implementIMetric
as they are documented to, also because they don’t implement__jsii_proxy_class__
.