Code Monkey home page Code Monkey logo

Comments (5)

mister avatar mister commented on June 19, 2024 2

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()
)
...

from s3-resizer.

sagidM avatar sagidM commented on June 19, 2024

Thank you for issuing.
Unfortunately, I have not experienced CloudFront yet, but from what you have explained, the issue seems to be either on the CloudFront hand or in incorrectness of parameters.

If success, the lambda redirects to {URL}/{path}.

I would check the full url.
In your case, request to the full url redirects back to the lambda which causes a cycle.

You mentioned, a new image is generated and accessible.
Well, if you can open the generated image in your browser, then just make sure you are requesting the lambda with an appropriate path.

If this does not help, please let me know.
Also, specific examples might have clarified the case, e. g. the addresses of your lambda and CloudFront server (you may create temporary ones).

from s3-resizer.

mister avatar mister commented on June 19, 2024

Hi @sagidM,

Lambda does redirect to the correct path, as you mentioned. For example, when a user visits
https://abcdefg.cloudfront.net/250xAUTO/f350fd70-b516-11e9-b57d-01a3c7a72c2d.jpg he will be redirected to API endpoint with 307 status, eg. https://myapi123.execute-api.us-east-1.amazonaws.com/prod. Once Lambda finished, the user redirected back to the initial URL with a 301 status code. At this point, a new image created and exists. But browser redirects back to API endpoint again.

What is interesting, the image becomes available through S3 website endpoint, but not through CDN. As far I understood after digging deeper, the issue related to CloudFront cache. It caches redirects. So, after the first redirect to API endpoint, CF caches destination URL and status code and does same action one next visit. On this case - when Lambda returns redirect path.

from s3-resizer.

sagidM avatar sagidM commented on June 19, 2024

If you request https://abcdefg.cloudfront.net/250xAUTO/f350fd70-b516-11e9-b57d-01a3c7a72c2d.jpg again in your browser, can you see the image?
If not, can you see it via a hard reload Ctrl+Shift+R?

from s3-resizer.

sagidM avatar sagidM commented on June 19, 2024

Cool, thank you for sharing.
Hope this helps others

from s3-resizer.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.