API Gateway trailing slash

0

Hi,

I have problem using API Gateway using /{proxy+}. API Gateway is trailing slash when requesting POST "{domain}/blabla/" so is passing through POST "{domain}/blabla" to my EC2 API. On EC2 API POST "{domain}/blabla/" exists but POST "{domain}/blabla" doesn't, so respond 404 Not Found.

How can I fix that?

asked 5 days ago113 views
2 Answers
2

Hello.

How about configuring your EC2 web server so that when access to "blabla" occurs, it redirects to "blabla/"?
In the case of Apache, I think you can use "DirectorySlash" to redirect by adding a slash at the end.
https://httpd.apache.org/docs/2.4/en/mod/mod_dir.html

profile picture
EXPERT
answered 5 days ago
profile picture
EXPERT
reviewed 5 days ago
  • I see, then why not try putting Lambda between API Gateway and EC2 to convert the URL and send the request? I thought it would be possible to handle this by converting the URL with Lambda and then requesting EC2.

  • You mean putting Lambda between API Gateway and EC2 just when the request url is "{domain}/blabla/{proxy+}"?

    Is API Gateway proxying "{domain}/blabla/" or it will proxify to lamda "{domain}/blabla" as it does with EC2?

  • You mean putting Lambda between API Gateway and EC2 just when the request url is "{domain}/blabla/{proxy+}"?

    Yes, it is.

    Is API Gateway proxying "{domain}/blabla/" or it will proxify to lamda "{domain}/blabla" as it does with EC2?

    I don't think the slash will be added even if the API Gateway backend is Lambda. So, I thought that the solution would be to add a slash to the URL when a request comes to Lambda and send the request to EC2.

0

Yes, I was thinking about that but I have different endpoints for "blabla/" and "blabla".

Thanks for replying!

answered 5 days ago