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

asked 2 years ago990 views
1 Answer
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
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions