I would like to attach a custom Authorizer to an API Gateway Route.
The API Gateway and the custom Authorizer are deployed with Terraform together with the whole infrastrucuture.
Now I want to deploy some Lambda Function as Routes of my API Gateway.
I first tried to deploy the Lambda Function with Serverless Framework, but apparently it is not possibile to attach a pre-existing Authorizer.
In the documentation they show this example:
provider:
name: aws
httpApi:
authorizers:
customAuthorizer:
type: request
functionArn: arn:aws:lambda:us-east-1:11111111111:function:external-authorizer
functions:
hello:
handler: handler.hello
events:
- httpApi:
method: get
path: /hello
authorizer:
name: customAuthorizer
But this will create a new API Gateway.
So I added the ID of the Gateway.
provider:
name: aws
httpApi:
id: xxxxxx
But then I get:
Error:
Cannot setup authorizers for externally configured HTTP API
Apparently Serverless don't allow to setup an authorizer for a pre-existing HTTP API Gateway.
So I decided to use the AWS CLI.
I run:
aws apigatewayv2 update-route --api-id <gateway-id> --route-id <route-id> --authorizer-id <authorizer-id> --authorization-type custom
but here I get the error:
An error occurred (BadRequestException) when calling the UpdateRoute operation: Unable to update route. Authorizer type is invalid or null.
event though the ID is correct and pointing to the Authorizer.
Final question
Does anybody know how to attach a custom Authorizer to a Route in API Gateway, where the Authorizer and the API Gateway are already deployed?