39

In AWS API Gateway, I have a GET method that invokes a lambda function.

When I test the method in the API Gateway dashboard, the lambda function executes successfully but API Gateway is not mapping the context.success() call to a 200 result despite having default mapping set to yes.

Instead I get this error:

Execution failed due to configuration error: No match for output mapping and no default output mapping configured

This is my Integration Response setup: enter image description here

And this is my method response setup: enter image description here

Basically I would expect the API Gateway to recognize the successful lambda execution and then map it by default to a 200 response but that doesn't happen.

Does anyone know why this isn't working?

Zigglzworth
  • 6,645
  • 9
  • 68
  • 107

9 Answers9

17

I have same issue while uploading api using serverless framework. You can simply follow bellow steps which resolve my issue.

1- Navigate to aws api gateway
2- find your api and click on method(Post, Get, Any, etc)
3- click on method response
4- Add method with 200 response.
5- Save it & test

15

This is a 'check-the-basics' type of answer. In my scenario, CORS and the bug mentioned above were not at issue. However, the error message given in the title is exactly what I saw and what led me to this thread.

Instead, (an an API Gateway newb) I had failed to redeploy the deployment. Once I did that, everything worked.

As a bonus, for Terraform 0.12 users, the magic you need and should use is a triggers parameter for your aws_api_gateway_deployment resource. This will automatically redeploy for you when other related APIGW resources change. See the TF documentation for details.

KJH
  • 2,382
  • 16
  • 26
  • 2
    Terraform: Well noticed! Also remember to use the resources `aws_api_gateway_method_response` and `aws_api_gateway_integration_response`. Add these to `triggers` – Francisco Cardoso Nov 17 '21 at 16:30
  • +1 I had this same issue. One **symptom** of this that I mention to help others: I could test the API from the AWS Console successfully (getting a 200) but would get a 500 internal server error when testing this outside of that. Looking at the `API-Gateway-Execution-Logs_{api gateway id}` log group I saw the following message `Execution failed due to configuration error: No match for output mapping and no default output mapping configured. Endpoint Response Status Code: 200`. A manual API Gateway deployment fixed the issue after about a **5 minute delay after the deployment**. – Joshua Jan 27 '23 at 15:39
13

I had the similar issue, got it resolved by adding the method response 200

raaone7
  • 529
  • 1
  • 7
  • 16
11

There was an issue when saving the default integration response mapping which has been resolved. The bug caused requests to API methods that were saved incorrectly to return a 500 error, the CloudWatch logs should contain:

Execution failed due to configuration error: 
No match for output mapping and no default output mapping configured. 

Since the 'ENABLE CORS' saves the default integration response, this issue also appeared in your scenario.

For more information, please refer to the AWS forums entry: https://forums.aws.amazon.com/thread.jspa?threadID=221197&tstart=0

Best,

Jurgen

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Jurgen
  • 1,243
  • 8
  • 9
5

What worked for me:
1. In Api Gateway Console created OPTIONS method manually
2. In the Method Response section under created OPTIONS method added 200 OK
3. Selected Option method and enabled CORS from menu

Tapirek
  • 51
  • 1
  • 2
1

I found the problem:

Amazon had added a new button in the API-Gateway resource configuration titled 'Enable CORS'. I had earlier clicked this however once enabled there doesn't seem to be a way to disable it

Enabling CORS using this button (Instead of doing it manually which is what I ended up doing) seems to cause an internal server error even on a successful lambda execution.

enter image description here

SOLUTION: I deleted the resource and created it again without clicking on 'Enable CORS' this time and everything worked fine.

This seems to be a BUG with that feature but perhaps I just don't understand it well enough. Comment if you have any further information. Thanks.

Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
  • 3
    If this is still relevnt but to remove CORS is simply to remove the OPTIONS methiod on the resource, then redeploy the resource. No need to delete the whole resource – aqwert Jan 10 '17 at 20:32
1

Check the box which says "Use Lambda Proxy integration".

This works fine for me. For reference, my lambda function looks like this...

def lambda_handler(event, context:
    # Get params
    param1 = event['queryStringParameters']['param1']
    param2 = event['queryStringParameters']['param2']

    # Do some stuff with params to get body
    body = some_fn(param1, param2)

    # Return response object
    response_object = {}
    response_object['statusCode'] = 200
    response_object['headers'] = {}
    response_object['headers']['Content-Type']='application/json'
    response_object['body'] = json.dumps(body)
    
    return response_object
amason13
  • 31
  • 2
0

I just drop this here because I faced the same issue today and in my case was that we are appending at the end of the endpoint a /. So for example, if this is the definition:

{
  "openapi": "3.0.1",
  "info": {
    "title": "some api",
    "version": "2021-04-23T23:59:37Z"
  },
  "servers": [
    {
      "url": "https://api-gw.domain.com"
    }
  ],
  "paths": {
    "/api/{version}/intelligence/topic": {
      "get": {
        "parameters": [
          {
            "name": "username",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-api-key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-AWS-Cognito-Group-ID",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        ...

Remove any / at the end of the endpoint: /api/{version}/intelligence/topic. Also do the same in uri on apigateway-integration section of the swagger + api gw extensions json.

Dharman
  • 30,962
  • 25
  • 85
  • 135
0

Make sure your ARN for the role is indeed a role (and not, e.g., the policy).

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Thomas
  • 6,291
  • 6
  • 40
  • 69