Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway: error Invalid mapping expression parameter specified: method.response.header.access-control-allow-origin

For the first time in the last years with AWS API Gateway I got this strange blocking error, that can kills production environment: in one day many of my responses (not all) lost their Access-Control-Allow-Origin header. In web UI I also see that they are not exists. But they are still exists in exported Swagger file. And more than that - I cannot set any value, for '*' or 'https://example.com' I am getting error:

Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.response.header.access-control-allow-origin]

This is from yesterday (I did not change anything to get this defect), looks like horrible bug of AWS that blocks our development (main product is no longer available without CORS headers). And now I am afraid to use AWS API Gateway for production environment...

aws api gateway method execution error Invalid mapping expression parameter specified: method.response.header.access-control-allow-origin

I tried to remove header in Method Response and add again, through the same web UI.

This is exported Swagger - for the same part as in screenshot. Here you can see my method.response.header.Access-Control-Allow-Origin. So in browser UI and exported file are not the same!

paths:
  /lineupmaps:
    get:
      consumes:
      - "application/json"
      produces:
      - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
          headers:
            Access-Control-Allow-Origin:
              type: "string"
      security:
      - cognito: []
      x-amazon-apigateway-integration:
        uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:988646599334:function:getLineUpMap/invocations"
        responses:
          default:
            statusCode: "200"
            responseParameters:
              method.response.header.access-control-allow-origin: "'https://happy-marketer.gms-ai.com'"
            responseTemplates:
              application/json: "$input.body"
        passthroughBehavior: "when_no_match"
        httpMethod: "POST"
        requestTemplates:
          application/json: "{\n    \"specs\": $input.params('specs'),\n    \"competitors\"\
            : $input.params('competitors'),\n    \"numberOfModels\": $input.params('numberOfModels')\n\
            }"
        contentHandling: "CONVERT_TO_TEXT"
        type: "aws"
    options:
      consumes:
      - "application/json"
      produces:
      - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
          headers:
            Access-Control-Allow-Origin:
              type: "string"
            Access-Control-Max-Age:
              type: "string"
            Access-Control-Allow-Headers:
              type: "string"
      x-amazon-apigateway-integration:
        responses:
          default:
            statusCode: "200"
            responseParameters:
              method.response.header.Access-Control-Max-Age: "'86400'"
              method.response.header.Access-Control-Allow-Headers: "'Authorization'"
              method.response.header.Access-Control-Allow-Origin: "'https://happy-marketer.gms-ai.com'"
        passthroughBehavior: "when_no_match"
        requestTemplates:
          application/json: "{\"statusCode\": 200}"
        type: "mock"

Tried to import exported Swagger, also with commented/removed responseParameters block: still the same error: aws api gateway import swagger

like image 391
Vitaly Zdanevich Avatar asked Feb 20 '20 12:02

Vitaly Zdanevich


People also ask

What is api Gateway used for?

Overview. An API gateway is an API management tool that sits between a client and a collection of backend services. An API gateway acts as a reverse proxy to accept all application programming interface (API) calls, aggregate the various services required to fulfill them, and return the appropriate result.

What is Cors in AWS API gateway?

Cross-origin resource sharing (CORS) is a browser security feature that restricts cross-origin HTTP requests that are initiated from scripts running in the browser. If your REST API's resources receive non-simple cross-origin HTTP requests, you need to enable CORS support.


1 Answers

Thank you nachary: helped importing of my Swagger with removed method.response.header.access-control-allow-origin in the GET of one endpoint...

like image 145
Vitaly Zdanevich Avatar answered Oct 18 '22 06:10

Vitaly Zdanevich