vscode hightlghts: `HttpLambdaIntegration` require an "IFunction" in "handler" instead of "Function" error, pycharm doesn't

0

Assigning a lambda Function object to a HttpLambdaIntegration "handler" returns this error:

(variable) add_hsp_func: Function
Argument of type "Function" cannot be assigned to parameter "handler" of type "IFunction" in function "__init__"
  "Function" is incompatible with protocol "IFunction"
    "grant_invoke" is an incompatible type
      Type "(grantee: IGrantable) -> Grant" cannot be assigned to type "(identity: IGrantable) -> Grant"
        Parameter name mismatch: "identity" versus "grantee"
    "grant_invoke_url" is an incompatible type
      Type "(grantee: IGrantable) -> Grant" cannot be assigned to type "(identity: IGrantable) -> Grant"
        Parameter name mismatch: "identity" versus "grantee"PylancereportGeneralTypeIssues

Seems like it's expecting to get an IFunction, which contradicts whatever is stated in the docs (first example "Defining HTTP APIs"): https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_apigatewayv2/README.html

or https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_apigatewayv2_integrations/README.html

Both "aws_apigatewayv2_integrations_alpha"(2.63.2a0) and "aws_apigatewayv2_integrations" (1.192.0) returns the same error. while "aws-api-gatewayv2_integrations" highlights some other errors such as:

        api.add_routes(
            path = "/items",
            methods = [_apigw.HttpMethod.POST],
            integration = self.build_integration(
                id = "add_items_integration", 
                function = add_items_func
            )
        )

    def build_integration(self, id: str, function: _lambda.Function) -> HttpLambdaIntegration:
        return HttpLambdaIntegration(id, handler=function)

error:

Argument of type "HttpLambdaIntegration" cannot be assigned to parameter "integration" of type "HttpRouteIntegration" in function "add_routes"
  "HttpLambdaIntegration" is incompatible with "HttpRouteIntegration"PylancereportGeneralTypeIssues

^ this what made me move forward with the "_alpha" version.

but this is the main part issue:

import aws_cdk.aws_apigatewayv2_alpha as _apigw
from aws_cdk.aws_apigatewayv2_integrations_alpha import HttpLambdaIntegration
# from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
import aws_cdk.aws_lambda as _lambda

from constructs import Construct
from aws_cdk import Duration

class API(Construct):
    def __init__(self, scope: Construct, construct_id: str, database, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)
        

        add_item_func = _lambda.Function(
            self,
            id = "add_item",
            function_name = "add_item",
            code = _lambda.Code.from_asset("./lambdas/items/add_item"),
            handler = "add_item", 
            runtime = _lambda.Runtime.PYTHON_3_9, 
            # description ='',
            # environment = '', 
        )
        add_item_integration = HttpLambdaIntegration("add_item_integration", add_item_func) # <== IDE highlights "add_item_function" with the error.
  • Someone from AWS must MUST must organise the packages properly so there is no more chaos. The CDK is a potentially awesome tool for developers, but right now it's impossible to follow simple steps via docs page and apply them without getting stuck on everything. im not referring to some "exotic" features. it's basic features like lambdas and apis !

EDIT: I might have found the issue. I opened the project using pycharm (I usually use vscode) and was surprised to see this not highlighted! So i guess it's an env issue (?) although the env is configured properly within vscode. So if there's any solution for this, i will be happy to hear since my prefered ide is vscode.

No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions