How to make the AWS API Gateway request path case insensitive

五迷三道 提交于 2021-02-10 17:24:45

问题


It seems that the request path setup in AWS API gateway is case sensitive. Can anyone suggest any solution to make the request path to be case insensitive

For example: https://api-gw.some-domain/health is accessible whereas https://api-gw.some-domain/Health is not accessible. (404)


回答1:


Unfortunately API Gateway, like most of AWS' offerings, is case-sensitive by design.

You therefore have two options:

  • Use CloudFront with Lambda@Edge to re-write your requests (this is quite involved, but a good tutorial can be found here: https://linuxacademy.com/howtoguides/posts/show/topic/19955-url-rewriting-in-aws-cloudfront)

  • Use BasePath mapping and a Proxy Resource so that you can have a single lambda that receives all requests and then dispatches/responds accordingy.

I would recommend the CloudFront approach, as its cheaper and easier to maintain. However for a small API you might be tempted to go for the second, especially if you can host the whole API in a single lambda.

n.b. The internet is case-sensitive (and mostly it's lowercase), for example: http://www.bbc.co.uk/news/world-europe-12083491 vs http://www.bbc.co.uk/news/world-Europe-12083491




回答2:


There's a third and much easier solution to this, but it might perhaps be a little dirty for a production environment. You can add the camelCase and PascalCase variations of your base path, since these are the ones most likely to be used. That's what I've done with my base path for a single API Gateway and it works.

API gateway resources are also case sensitive so the approaches described above are more thorough ways to make your request path case insensitive, since mine only helps with the base path.



来源:https://stackoverflow.com/questions/53225519/how-to-make-the-aws-api-gateway-request-path-case-insensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!