CORS Preflight method with Ion API GW integration

#1

I have an Ion set up with API Gateway integration. The works as expected. Today I have been trying to add an OPTIONS method to the resource as describe here, so that I can call the API from javascript served from a different domain. I have done this before and it worked, but I am getting 500s when I try to add it to this resource.

When I enabled logging for my APIGW stage, I saw that the 500 was due to APIGW trying to transform the request body of my OPTIONS request and failing. There is no body, but I can see the APIGW thinks it has binary body content for some reason. I remembered that the Ions tutorial had me add “/” as a binary media type for the API. I’m not sure why this is. Is it just to get APIGW to pass the body through as-is? Anyway, when I remove that mapping, the OPTIONS method works and I can invoke the API via js in the browser, but the payload of my proxy method is now coming back base64 encoded. I thought maybe I would just change a setting on the response of my proxy integration to decode that on the way out, but I see that you can’t alter responses for a proxy integration.

I know this question is very heavy on APIGW details (the solution might be going to the non-proxy lambda integration), but I was thinking that this must be something that others have run into and was wondering if there was something I was missing.

0 Likes

#2

After reading the docs a few more times, I see:

API Gateway will look at the Content-Type and Accept HTTP headers to decide how to handle the body.

So if I add application/edn (what my ion is returing) as a Binary Media Type and add “Accept: application/edn” to the requests, API Gateway sends the response back as I return it from my ion (not based64 encoded).

0 Likes