Cloudfront Distribution URL gives 503 error (Service Temporarily Unavailable) whereas Origin server gives 404 when accessing cloudfront function.

0

I am trying to utilize Cloudfront functions for edge computing capabilities. I just have it doing a brief calculation and I'm trying to send it back to my origin website. However, I keep running into an issue where I can't seem to fully integrate my website with the cloudfront function. I'm running a lightweight flask server, for reference.

notable configurations: My distribution has a behavior with the pathing /fibonacci/* in order to take in values that may be sent. The function is associated with the behavior. I have the distribution open to HTTP and HTTPS, and I'm trying to route this through HTTP due to having issues with getting flask to accept an HTTPS port.

I'm incredibly new to this and the documentation and troubleshooting for cloudfront functions is incredibly sparse due to it being a little newer, so I would appreciate any help.

  • What is it, exactly, that you're trying to send to the origin from a Function, and how are you trying to do it? I'd suggest you remove the function and make sure everything is working correctly first, before trying to add it as it sounds like there may be multiple problems here.

  • I'm sending over mostly a blank JSON object with the returned value as part of a header, if that makes sense. In regards to your suggestion, do you just mean disassociating it from the behavior?

2 Answers
0

It's unclear from your post and comment what the function is doing, and what part you're having trouble with - or even if the function is throwing errors at all. There are some sample functions available on aws-samples which might help you get started.

For troubleshooting, I would start by removing the function association from your CloudFront behavior and making sure that all your CloudFront configuration is working as expected. Then add the function back in - perhaps adding one piece of functionality at a time so that you can easily identify the cause of any problems you encounter.

AWS
EXPERT
Paul_L
answered a month ago
-2

Here are a few suggestions to help integrate your Flask application with CloudFront:

  • Ensure the origin of your CloudFront distribution is configured as a REST API endpoint rather than a website endpoint. The REST API endpoint allows you to specify custom HTTP methods like POST that may be required by your Flask application.
  • Check that the HTTP methods allowed on your CloudFront distribution match those required by your Flask application. You can modify the allowed methods in the CloudFront console or via the AWS CLI.
  • Consider using AWS WAF with CloudFront to restrict access to your Flask application only from the CloudFront distribution. This provides an extra layer of security compared to using origin access identity alone.
  • If you are experiencing SSL issues between clients and CloudFront, ensure you have requested an ACM certificate for your custom domain and associated it with the distribution. You may also need to check redirection policies on your Flask application.
profile picture
EXPERT
answered a month 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