Search code examples
amazon-web-serviceswebsocketaws-api-gatewayterraform-provider-aws

How to attach a lambda authorizer to api gateway V2 connect route in aws terraform


I´m trying to attach my lambda authorizer (already created) into my $connect route. It creates correctly the authorizer, but it doesn´t fill up the "Auth" automatically on my route request. It looks like it doesn't get the reference for my authorizer. Authorization

This is my connect:

resource "aws_apigatewayv2_route" "ConnectRoute" {
  api_id         = aws_apigatewayv2_api.api_gateway_websocket.id
  route_key      = "$connect"
  operation_name = "ConnectRoute"
  authorizer_id  = aws_apigatewayv2_authorizer.authorizer.id
  depends_on = [
   aws_apigatewayv2_authorizer.authorizer
  ]
}

And this is my authorizer:

resource "aws_apigatewayv2_authorizer" "authorizer" {
  api_id           = aws_apigatewayv2_api.api_gateway_websocket.id
  authorizer_type  = "REQUEST"
  authorizer_uri   = var.lambda_authorizer_uri
  identity_sources = ["route.request.querystring.authorization"]
  name             = var.lambda_authorizer_name
}

Someone has any idea that can help me to solve this problem? Thank you!


Solution

  • You have to set authorization_type in aws_apigatewayv2_route to CUSTOM.