500 error while trying to enable CORS on POST with AWS API Gateway Proxy Integration

Viewed 1742

I have a response method that looks like this for my Lambda functions:

def respond(err, res=None):
    return {
        'statusCode': 400 if err else 200,
        'body': json.dumps(err) if err else json.dumps(res),
        'headers': {
            'Access-Control-Allow-Headers': 'content-type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
            'Access-Control-Allow-Methods': 'POST, GET, DELETE',
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Credentials': True,
            'Content-Type': 'application/json',
        },
    }

When I test my endpoint with an OPTIONS request from Postman, I get a 500 internal server error. If I test it from the the API Gateway console, I get this additionally:

Execution log for request test-request
Wed Jul 05 14:25:26 UTC 2017 : Starting execution for request: test-invoke-request
Wed Jul 05 14:25:26 UTC 2017 : HTTP Method: OPTIONS, Resource Path: /login
Wed Jul 05 14:25:26 UTC 2017 : Method request path: {}
Wed Jul 05 14:25:26 UTC 2017 : Method request query string: {}
Wed Jul 05 14:25:26 UTC 2017 : Method request headers: {}
Wed Jul 05 14:25:26 UTC 2017 : Method request body before transformations: 
Wed Jul 05 14:25:26 UTC 2017 : Received response. Integration latency: 0 ms
Wed Jul 05 14:25:26 UTC 2017 : Endpoint response body before transformations: 
Wed Jul 05 14:25:26 UTC 2017 : Endpoint response headers: {}
Wed Jul 05 14:25:26 UTC 2017 : Execution failed due to configuration error: Output mapping refers to an invalid method response: 200
Wed Jul 05 14:25:26 UTC 2017 : Method completed with status: 500

I'm not really sure what I'm doing wrong. I think I am returning all the right headers. Any help is appreciated.

2 Answers
Related