Comments (5)
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.
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.
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.
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.
Cool, thank you for sharing.
Hope this helps others
from s3-resizer.
Related Issues (16)
- Whitelist sizes to resize HOT 4
- What mean "Missing Authentication Token" ? HOT 2
- "Access Denied" in the brower HOT 5
- Missing module Sharp? HOT 2
- index.handler is undefined or not exported HOT 2
- AccessDenied HOT 1
- add CDN url error HOT 2
- npm module error HOT 7
- "errorMessage": "Error: Cannot find module 'sharp'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js", HOT 2
- Lambda与ApiGateway连接
- AWS end support for Node.js 16 HOT 3
- Access Denied HOT 4
- HTTPS problem HOT 21
- AWS end support for Node.js 8.x HOT 4
- Support for nested directory at s3 HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from s3-resizer.