aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

Cannot use IAuthorizer to create an apigateway method

Open gidimariastorm opened this issue 7 years ago • 2 comments

Hello, I'm using python and this is my code:

auto_scaling_res=apigw_autoscaling.root.add_resource('autoscaling_update')
        get=auto_scaling_res.add_method('GET')

        auth=apigw.CfnAuthorizer(self,
        "authorizer",
        rest_api_id=apigw_autoscaling.rest_api_id,
        type="TOKEN",
        authorizer_uri="".join(["arn:aws:apigateway:",'eu-west-1',':lambda:path/2015-03-31/functions/',lamdbda_api_authorizer.function_arn,"/invocations"])
        )
 auto_scaling_res.add_method('POST', authorization_type=apigw.AuthorizationType.CUSTOM, authorizer=????)

How I can fill the authorizer paragraph? I didn't find an high level construct and the documentation is a little poor about it Giuseppe

Reproduction Steps

Error Log

Environment

  • CLI Version : 13.1
  • Framework Version:
  • OS : MacOS
  • Language : python

Other


This is :bug: Bug Report

gidimariastorm avatar Oct 16 '19 06:10 gidimariastorm

You can never mix CfnXxx and non-CfnXxx classes, those are not designed to work together. In this case, you are mixing RestApi and CfnAuthorizer.

Duplicate of https://github.com/aws/aws-cdk/issues/1402, which contains a workaround (written in TypeScript but can be ported to Python by following this guide: https://docs.aws.amazon.com/cdk/latest/guide/multiple_languages.html)

Another solution would be to use the escape hatch mechanism to inject the ID of your CfnAuthorizer into the resource after the fact.

rix0rrr avatar Oct 16 '19 08:10 rix0rrr

@rix0rrr thanks. ok but How can I inject the ID of CfnAuthorizer here?

auto_scaling_res.add_method('POST', authorization_type=apigw.AuthorizationType.CUSTOM, authorizer=????)

the authorizer require an IAutorizher Class.

gidimariastorm avatar Oct 16 '19 09:10 gidimariastorm