reactjsamazon-web-servicesaws-api-gatewayistio

Too many Redirections on AWS API gateway from frontend app


There is a react application which is running in k8s and currently exposed from istio VS, we are inside a vpn so all our application endpoints are of http. There was a specific requirement where we need https so we ended up using "AWS API gateway" to route our request from http to https

Once done, the base url was working fine but when a route is added like hello.com/hello it was giving me 308 too many redirections even after defining {proxy+} in API gateway


Solution

  • found the solution we had "/{proxy+}" in proxy path uri in the api gateway config but front end application was adding "/" at the end which was again being redirected to api gateway gateway itself which resulted in too many redirections.

    example: hello.com/joy was requesting to hello.com/joy/ and the request was coming back to api gateway adding "{proxy}/" in the uri resolved the issue

    config which was causing the error:

    /{proxy+}:
        x-amazon-apigateway-any-method:
          parameters:
          - name: "proxy"
            in: "path"
            required: true
            type: "string"
          responses: {}
          x-amazon-apigateway-integration:
            httpMethod: "ANY"
            uri: "http://url/{proxy}"
            responses:
              default:
                statusCode: "200"
    

    Adding "{proxy}/" in uri fixed the issue

           /{proxy+}:
            x-amazon-apigateway-any-method:
              parameters:
              - name: "proxy"
                in: "path"
                required: true
                type: "string"
              responses: {}
              x-amazon-apigateway-integration:
                httpMethod: "ANY"
                uri: "http://url/{proxy}/"
                responses:
                  default:
                    statusCode: "200"
        
    

    One more thing to note here is root path was working fine issue was just with proxy path i.e what we give after root path "/"