Code Monkey home page Code Monkey logo

Comments (21)

subpublic avatar subpublic commented on June 23, 2024 9

Yes

First i followed this guide to point https to my S3 website
https://medium.com/@channaly/how-to-host-static-website-with-https-using-amazon-s3-251434490c59

Then

  • I pointed the URL Variable to my https domain.
  • I uploaded the new zip, created a new release of Lambda and pointed "prod" to the new release.
  • Went to CloudFront -> chose my distribution -> Behaviours -> Edit. Here I could change Default TTL to 0.

from s3-resizer.

adskiremote avatar adskiremote commented on June 23, 2024 5

Wanted to add I ran into issues when configuring this for my Cloud Front distribution.

On your distribution origin domain name make sure you enter the S3 web Endpoint - not the S3 origin.

Otherwise you will receive access denied errors. See issue and resolution here:
https://stackoverflow.com/questions/34060394/cloudfront-s3-website-the-specified-key-does-not-exist-when-an-implicit-ind/34065543#34065543

from s3-resizer.

subpublic avatar subpublic commented on June 23, 2024 2

YAY! Changed the Default Cache TTL to 0, now everything works! (with the version you posted)

from s3-resizer.

subpublic avatar subpublic commented on June 23, 2024

Going to S3 -> Properties -> Static Website hosting
The "endpoint" is HTTP not HTTPS.

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

Hi @subpublic,

Lambda works fine over HTTPS, either does S3 bucket.
The problem is in Static Web Hosting. Unfortunately,

The Amazon S3 website endpoints do not support HTTPS
https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html

There is an option, however, to use HTTPS. You can hook up your Domain. Then request a certificate.
You can google "aws static website hosting https", there are plenty of posts on how to do that.

At the moment, I can't find a simple solution. In case Amazon will support it, I will add the description about it.

from s3-resizer.

subpublic avatar subpublic commented on June 23, 2024

Hi. I tried adding HTTPS using this guide.
https://medium.com/@channaly/how-to-host-static-website-with-https-using-amazon-s3-251434490c59

Getting it to point to the S3 Bucket worked fine, but trying to point to the lambda static website (in CloudFront) did not go so well. My https domain just redirects to the http S3 static website instead.

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

What have you set in your Lambda -> Environment variables?

from s3-resizer.

subpublic avatar subpublic commented on June 23, 2024

I have set these two variables

BUCKET = [my-bucket-name]
URL = http://[my-bucket-name].s3-website.eu-north-1.amazonaws.com

I tried using my new https domain instead

URL = https://static.mydomain.com

But that resulted in another problem, redirects to
https://[my-lambda].execute-api.eu-north-1.amazonaws.com/prod/aws-lambda-resize-dev?path=333xAUTO/image.jpg
With the error msg
[my-lambda].execute-api.eu-north-1.amazonaws.com redirected you too many times.

The action actually seems to work, as the new image gets generated and can be requested via my static https, but because it's redirected two times my https domain -> lambda -> back to my https domain I'm getting this error.

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

Well, you definitely must have your (https) own domain set since it is your endpoint.
Once you get redirected back, you should be able to see your image in your browser.
If you get redirected back again instead, then one of the reasons might be that, although an image was generated, the previous request was cached hence the redirect.

Could you please look at this issue #5 and confirm wheather it is the same problem?

If you think you encounter the same problem, please, let me know and I will build the project under NodeJS 12x with caching problem fixed for you.

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

Alright, could you check this version?
https://yadi.sk/d/rRXQULksMmMelg
It must not redirect you twice.

from s3-resizer.

subpublic avatar subpublic commented on June 23, 2024

I tried that, still same problem.
My first request to https domain gives

HTTP/2 307
content-length: 0
location: https://[my-lambda].execute-api.eu-north-1.amazonaws.com/prod/aws-lambda-resize-dev?path=624xAUTO/image.jpg

And requesting that responds

HTTP/2 301
date: Wed, 20 Nov 2019 12:24:25 GMT
content-type: application/json
content-length: 0
location: https://static.myserver.com/624xAUTO/image.jpg

If I after that go to https://static.myserver.com/624xAUTO/image.jpg it gives me the image.
The issue #5 writes something about changing TTL to 0, should I do that? (Didn't really understand where that was though)

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

I am really glad it helped. I should release the new version soon.

Now to prevent possible future problems like this, could you please share the steps you took?
In particular, you went to Lambda -> Function code -> Upload a .zip file and clicked on Upload.
Then what about Default Cache TTL to 0?
Have you done anything else?

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

Well done @subpublic
Appreciate your explanation.

from s3-resizer.

nelsonamaya82 avatar nelsonamaya82 commented on June 23, 2024

Thanks @sagidM and @subpublic, this worked like a charm!!
Is it necessary to set the Default TTL to 0 in the CloudFront distribution behavior? I did a few tests without changing that value and it worked fine, so I don't quite understand why it needs to be changed to 0.

from s3-resizer.

martinipsy avatar martinipsy commented on June 23, 2024

I followed every step an I still get the Too many redirects error. Any clues?
It's crazy that there isn't an easier way to achieve this.

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

@martinipsy this is not about HTTPS.
What the output can you see when you test your lambda? I.e.
{ "queryStringParameters": {"path": "my_directory_in_bucket/my_image.jpg"} }

from s3-resizer.

martinipsy avatar martinipsy commented on June 23, 2024

Dear Sagid, it has worked! I'm not sure what the issue was but I'm using it with the cloudfront URL. Thank you!

from s3-resizer.

GemN avatar GemN commented on June 23, 2024

Just to point out that without touching anything and having cloudfront setup, just having to point on the website (ex: xxx.s3-website.eu-west-3.amazonaws.com) did the trick.

I did not have to change the lambda function, the cache control, the default TTL, env variables.

from s3-resizer.

sagidM avatar sagidM commented on June 23, 2024

@GemN Appreciate your contribution. Some day I will add a detailed explanation of setting CloudFront up considering your comment.

from s3-resizer.

rafael-carvalho avatar rafael-carvalho commented on June 23, 2024

I am still getting ERR_TOO_MANY_REDIRECTS when I add an image such as https://images.mydomain.com/156x157/img.png as the src on an HTML image.

Current settings:
CloudFront Default Cache to 0.

Lambda
ENV variables:

Route53
I have an A entry at images.mydomain.com at Route53 pointing to the CloudFront distribution.

Test
Web Browser
When I go to https://images.mydomain.com/156x157/img.png it works fine.

When I test the Lambda function with params

{
  "queryStringParameters": {
    "path": "156x156/img.png"
  }
}

I get this response:

{
  "statusCode": 301,
  "headers": {
    "Location": "https://images.sofadecasa.com/156x156/img.png"
  }
}

RELEASE
I am using s3-resizer_nodejs_12.13.0.zip

Any thoughts?

from s3-resizer.

rafael-carvalho avatar rafael-carvalho commented on June 23, 2024

I was able to make it work by point my src in the HTML to the CloudFront distribution https URL (make sure you select the default certificate, i.e., no need to generate a certificate for your domain).

I also changed the URL var in the Lambda function to point to the https URL provided by CloudFront. Everything works now.

If, like me, you are paranoid and don't wanna risk, checkout the onerror attribute of an image:
https://stackoverflow.com/questions/8124866/how-does-one-use-the-onerror-attribute-of-an-img-element

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.