0

I tried by configuring 'Enable CORS' in API Gateway and set all the required headers as well. In the Lambda function, I set headers like Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers?

Preflight request hasnt been sent to the Lambda function from API Gateway. Is there anything that I need to check and configure?

Kindly help me out. Thanks in advance

def lambda_handler(event, context):
    return {
        "statusCode": "200",
        "headers": {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "*",
        },
        "body": json.dumps({"test": "123"})
    }

1 Answer 1

1

Have you configured API Gateway to use Lambda Proxy Integration? If you want to have your lambda set the headers, you should do this.

Essentially, you either let your lambda add the necessary headers, as you appear to want to do in this example, or you let API Gateway add them. To have the lambda add them you need to enable Lambda Proxy Integration.

See

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I have configured API Gateway with all required headers in the Method Response. But still, cant figure out why the preflight request isnt happening!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.