question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cyclic redirect with CloudFront

See original GitHub issue

Hello,

The Lambda function is working well, but I have cyclic redirect when trying to configure it with CloudFront.

I created a CloudFront distribution with default settings and used S3’s static website endpoint as the origin. Also, I used the CloudFront domain name for the URL Lambda envonment variable.

Existing images are served well. But for new images I receive redirects loop between API gateway and CloudFront. What is interesting, new image generated and accessible with S3’s endpoint. Can’t get what is wrong.

Any ideas on how to fix it? Thank you.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mistercommented, Oct 1, 2019

No, browser redirects to API gateway again. The problem in CloudFront cache behavior ( https://docs.aws.amazon.com/en_us/AmazonCloudFront/latest/DeveloperGuide/http-3xx-status-codes.html)

Fixed by setting up CloudFlare distribution Cache Default TTL to 0 and added CacheControl to images created by Lambda:

...
.then(result =>
    S3.putObject({
        Body: result,
        Bucket: BUCKET,
        ContentType: contentType,
        Key: path,
        CacheControl: 'public, max-age=86400'
    }).promise()
)
...
0reactions
sagidMcommented, Oct 2, 2019

Cool, thank you for sharing. Hope this helps others

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I redirect a domain in CloudFront? - AWS
To redirect a domain in CloudFront, use one of the following: ... An Amazon S3 website endpoint redirection moves the existing URL path...
Read more >
Redirect All HTTP request to HTTPS via CloudFront - YouTube
If you load your site via cloudfront, then you can follow these steps to ... The Http and the Web | Http Explained...
Read more >
Use Lambda@Edge to handle complex redirect rules with ...
For our use case, we want to intercept the viewer request and redirect the user based on a set of path based rules....
Read more >
Redirect traffic with CloudFront - Stack Overflow
You should create a new CloudFront distribution. The trick here is to NOT use the proposed bucket values, but use the endpoint directly....
Read more >
ERR_TOO_MANY_REDIRECTS · Cloudflare SSL/TLS docs
Redirect loops will occur if your origin server automatically redirects all HTTP requests to HTTPS.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found