CloudFront Function - HTTP Methods

0

Hello,

I'm having some issues with a test, I have a angular application running on cloudfront / S3, but I have a scenario where I need to redirect a specific link to another domain / server, for that I configured a cloudfront function to do the redirect when I get a request like www.mysite.com/env/test/hello to www.devsite.com/env/test/hello and the redirect is working, but I actually need to do a POST request (because it is a REST API function), when I do a POST (using Talend API Tester) it does return the redirect link (using the location field), but gets me the error associated with the GET function not supported on my API (as expected if I try GET against it).

When looking for my logs on the webserver with the API I saw that cloudfront is hitting it with a HTTP GET request, but why if I did a POST against cloudfront? I even tried setting the StatusCode on the response of my cloufront function to 307 and 308 but still have the same behavior, it isn't supposed to use the same request method as it received?

Can I force cloudfront to use POST in these case? My function is associated with the "Viewer Request".

Thanks

已提问 2 年前1014 查看次数
1 回答
0

If you returned a redirect as a response to a POST request your client will follow up on that redirect, not CloudFront. As you mentioned, 307 and 308 response codes should be followed on by the client without changing the HTTP method (see here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections).

I case you actually want to keep your traffic routing by CloudFront - you can use behaviors to routing to different origins based on path patterns (/env/test/hello --> origin 1, default behavior would go to origin 2).

More on behaviors can be found here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DownloadDistS3AndCustomOrigins.html

AWS
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则