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

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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠