Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for nested directory at s3 #9

Open
concalahan opened this issue Nov 9, 2019 · 18 comments
Open

Support for nested directory at s3 #9

concalahan opened this issue Nov 9, 2019 · 18 comments
Assignees
Labels

Comments

@concalahan
Copy link

concalahan commented Nov 9, 2019

Hello,

It cannot auto generate smaller images for nested directory.

For example, I have an image at https://gt-sky.s3-ap-southeast-1.amazonaws.com/hongphucsport.vn/b.png

The module cannot give me the image at https://gt-sky.s3-ap-southeast-1.amazonaws.com/hongphucsport.vn/150x150/b.png

Thank you very much.

@concalahan concalahan changed the title TypeError: Cannot read property '1' of null at exports.handler (/var/task/index.js:16:20) Support for nested directory at s3 Nov 9, 2019
@sagidM
Copy link
Owner

sagidM commented Nov 18, 2019

@concalahan I can see your image, however, there is no redirect to your lambda.

  1. Does this work for other images?
  2. Have you set redirects to your lambda? YOUR_BUCKET -> Properties -> Static website hosting as it shown in the image
    image

@sagidM sagidM self-assigned this Nov 18, 2019
@sagidM sagidM added the invalid label Nov 18, 2019
@sagidM
Copy link
Owner

sagidM commented Feb 28, 2020

@fabianmossberg Could you please confirm that the images have been resized, but you get AccessDenied when you request them?
I.e. you have this image profiles/XrPLrK/100x100/51ED545C-AB28-4988-9D6B-598A0DD6A02F.jpeg converted

@fabianmossberg
Copy link

@sagidM : no, the folder 100x100 does not exist in the profiles/XrPLrK/ directory.

@sagidM
Copy link
Owner

sagidM commented Feb 28, 2020

@fabianmossberg First, please check out if https://photos.matchatheapp.com.s3-eu-west-1.amazonaws.com is the link of the Endpoint of your Static Website Hosting #9 (comment), not the link of your bucket.
As Static Website Hosting does not provide HTTPS #7.
(I am a bit confused about mixing the http and https protocols)

Also, there is an item Test your lambda in the readme.
What can you see when you test your lambda with the parameters?

{
  "queryStringParameters": {"path": "profiles/XrPLrK/100x100/51ED545C-AB28-4988-9D6B-598A0DD6A02F.jpeg"}
}

If it fails, the log of the lambda or the screenshot will definitely help.

@fabianmossberg
Copy link

fabianmossberg commented Feb 29, 2020

@sagidM : this is strange. Today it works. Even the links I Posted as "not working" yesterday actually produces the expected result today. I'm not sure what I did wrong.

But I do see some errors I had done.

When I filled the "path" in the test you had in the example, I filled the whole URL, not just the path.

I also realized the difference between the static hosting URL
photos.matchatheapp.com.s3-website-eu-west-1.amazonaws.com
and the Bucket URL
photos.matchatheapp.com.s3-eu-west-1.amazonaws.com

They look so alike that I completely missed that they were different domains.

@sagidM
Copy link
Owner

sagidM commented Feb 29, 2020

@fabianmossberg Yeah, I believe you, I have been keeping the tab from yesterday with an error.
image

And I have already seen this sort of error when the accessibility to a file was wrong. For example, if the bucket policy has not been provided or a role's policy for a lambda was incorrect
("Resource": "arn:aws:s3:::__BUCKET_NAME__/*" in readme -- the asterisk (*) at the end is essential).

But if it started working without any change, that is really strange.

So, let's keep this issue open for a while and if you encounter the same problem, please do tests and provide the output.

@sagidM
Copy link
Owner

sagidM commented Feb 29, 2020

Oops, it is still not working
http://photos.matchatheapp.com.s3-eu-west-1.amazonaws.com/profiles/XrPLrK/50x50/51ED545C-AB28-4988-9D6B-598A0DD6A02F.jpeg
does not work. Please, tinker with different params, for example
{ "queryStringParameters": {"path": "profiles/XrPLrK/99x99/51ED545C-AB28-4988-9D6B-598A0DD6A02F.jpeg"} }
{ "queryStringParameters": {"path": "profiles/XrPLrK/95x95/51ED545C-AB28-4988-9D6B-598A0DD6A02F.jpeg"} }

Also, you can monitor the directory profiles in your bucket by clicking on the animatable update icon in the right top corner.

@5URE5H
Copy link

5URE5H commented Jun 22, 2020

@sagidM how to fix this?

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>prod/AUTOx300/Institute.png</Key>
<RequestId>7258DC21D3692F69</RequestId>
<HostId>/0lbTqvlxM5kTxhoLl3XgzIoAMyuiZxYu1j/mUkwuaRDzSTBwM9E9Sqw8qQrjLVBLG5acqkdX80=</HostId>
</Error>

If I test it in lamda and access that URL it is working, until then it isn't working. May be the test is triggering the function?

PS no issues if the image isn't nested inside a folder.

@sagidM
Copy link
Owner

sagidM commented Jun 28, 2020

@5URE5H how much does it take to the point when it stops working?

@5URE5H
Copy link

5URE5H commented Jun 28, 2020

@5URE5H how much does it take to the point when it stops working?

For nested items, URL gives error when I try to access it right off the bat, once I test in lambda (for nested cases) then URL is working without any issues from then on. If it isn't nested inside a folder it works from the start.

@sagidM
Copy link
Owner

sagidM commented Aug 1, 2020

@5URE5H would you like to make a call some time?
btw, I use telegram: https://t.me/sagidM

@philyboysmith
Copy link

Hey @sagidM idd you ever get to the bottom of this? I'm trying to get this working with folders, but no luck so far.

@sagidM
Copy link
Owner

sagidM commented Oct 11, 2022

@philyboysmith unfortunately, I could not reproduce the bug. The images are stored in to directories

@paoyangt
Copy link

paoyangt commented Jun 27, 2023

Hi, I'm facing the same issue when trying to resize images that are nested within the bucket. I've tested with the lambda url, for example:
https://lambda-endpoint.com/resize?path=150x150/image.png <== works without issues.
https://lambda-endpoint.com/resize?path=150x150/nested/image.png <== Exception: Access Denied

I've checked my bucket and confirmed that the nested image was not resized at all while the one on root path was successfully resized.

Are there any updates for this issue?

@sagidM
Copy link
Owner

sagidM commented Jun 27, 2023

@paoyangt hi, can you share your policy config?

@paoyangt
Copy link

Here it is @sagidM

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": "s3:PutObject", "Resource": [ "arn:aws:s3:::resized-thumbnails/*" ] } ] }

@condrowiyono
Copy link

mine working fine.

https://lambda-endpoint.com/resize?path=150x150/image.png <== works without issues.
https://lambda-endpoint.com/resize?path=nested/150x150/image.png <= beware that directory / folder must come first
https://lambda-endpoint.com/resize?path=nested/nested/150x150/image.png <= beware that directory / folder must come first

So, basically the formula would be "anything-dir/you/have/{150x150}/{filename.ext}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants