admin管理员组文章数量:1023838
I have two buckets on S3. campaignfotos and campaignfotosresized.
The Permissions for those two looks like this:
Created the ThumbnailCreatorRole ( I think I'm missing here something):
I have created a Lambda function an used the Code from here changed the file name form "CreateThumbnail.js" to "index.js".
Set the trigger, on create - so the thumbnails should be created when a user of my App uploads an image to the bucket:
When I test the function, it works for the first time (with the Test button on the lambda website on amazon) but it doesn't work when a User uploads an image from my app nor it works when I upload an image on the s3 bucket on amazons website.
When I try to test the function for the second time with the "Test" button, I get this error (yes I deleted the old resized-HappyFace.jpg from the thumbnails bucket):
What have I forgotten?
I have two buckets on S3. campaignfotos and campaignfotosresized.
The Permissions for those two looks like this:
Created the ThumbnailCreatorRole ( I think I'm missing here something):
I have created a Lambda function an used the Code from here changed the file name form "CreateThumbnail.js" to "index.js".
Set the trigger, on create - so the thumbnails should be created when a user of my App uploads an image to the bucket:
When I test the function, it works for the first time (with the Test button on the lambda website on amazon) but it doesn't work when a User uploads an image from my app nor it works when I upload an image on the s3 bucket on amazons website.
When I try to test the function for the second time with the "Test" button, I get this error (yes I deleted the old resized-HappyFace.jpg from the thumbnails bucket):
What have I forgotten?
Share Improve this question asked Feb 27, 2017 at 14:43 SuisseSuisse 3,6336 gold badges40 silver badges72 bronze badges3 Answers
Reset to default 2From the logs, it seems that your lambda function taking too much time to process the request. Try increasing the timeout and then test. You can set the timeout from Configuration tab -> Advanced settings -> Timeout.
The solution for this problem was the policy. The timout error for the testing above could be solved by increasing the timeout limit to 25sec.
How to set the policy:
Go to IAM => Roles => Create a new Role => Role Type => AWS Lambda => in Attach Policy select "AmazonS3FullAccess"
Now go to Lambda => select your Lambda function => in Configuration tab => Role: choose an existing Role => Select the just created Role
And finish, now it works. :)
Create thumbnails for already existing images:
You may have existing images in your bucket, which you want to create thumbnails for them? Solution: Create a new bucket - go to the old bucket and select all images => cut. go to the new temporary created bucket and paste. Now select all those newly pasted images again in the temporary bucket => cut - go back to the old bucket and paste the images => this triggers your lambda function and will create for every image a new thumbnail. now you can delete the temporary created bucket. you are done. :)
If you run into difficulties, go to the Monitoring tab (shown in your picture) and click the link to the log files. They will hopefully give you some more information.
Actually, I suggest that you start by implementing the Tutorial: Using AWS Lambda with Amazon S3 from the AWS documentation.
Once you have confirmed that it is working, modify it for your particular needs (eg buckets, permissions).
Alternatively, you could just skip Lambda and use an automatic picture resizing service such as:
- Cloudinary
- Imgix
I have two buckets on S3. campaignfotos and campaignfotosresized.
The Permissions for those two looks like this:
Created the ThumbnailCreatorRole ( I think I'm missing here something):
I have created a Lambda function an used the Code from here changed the file name form "CreateThumbnail.js" to "index.js".
Set the trigger, on create - so the thumbnails should be created when a user of my App uploads an image to the bucket:
When I test the function, it works for the first time (with the Test button on the lambda website on amazon) but it doesn't work when a User uploads an image from my app nor it works when I upload an image on the s3 bucket on amazons website.
When I try to test the function for the second time with the "Test" button, I get this error (yes I deleted the old resized-HappyFace.jpg from the thumbnails bucket):
What have I forgotten?
I have two buckets on S3. campaignfotos and campaignfotosresized.
The Permissions for those two looks like this:
Created the ThumbnailCreatorRole ( I think I'm missing here something):
I have created a Lambda function an used the Code from here changed the file name form "CreateThumbnail.js" to "index.js".
Set the trigger, on create - so the thumbnails should be created when a user of my App uploads an image to the bucket:
When I test the function, it works for the first time (with the Test button on the lambda website on amazon) but it doesn't work when a User uploads an image from my app nor it works when I upload an image on the s3 bucket on amazons website.
When I try to test the function for the second time with the "Test" button, I get this error (yes I deleted the old resized-HappyFace.jpg from the thumbnails bucket):
What have I forgotten?
Share Improve this question asked Feb 27, 2017 at 14:43 SuisseSuisse 3,6336 gold badges40 silver badges72 bronze badges3 Answers
Reset to default 2From the logs, it seems that your lambda function taking too much time to process the request. Try increasing the timeout and then test. You can set the timeout from Configuration tab -> Advanced settings -> Timeout.
The solution for this problem was the policy. The timout error for the testing above could be solved by increasing the timeout limit to 25sec.
How to set the policy:
Go to IAM => Roles => Create a new Role => Role Type => AWS Lambda => in Attach Policy select "AmazonS3FullAccess"
Now go to Lambda => select your Lambda function => in Configuration tab => Role: choose an existing Role => Select the just created Role
And finish, now it works. :)
Create thumbnails for already existing images:
You may have existing images in your bucket, which you want to create thumbnails for them? Solution: Create a new bucket - go to the old bucket and select all images => cut. go to the new temporary created bucket and paste. Now select all those newly pasted images again in the temporary bucket => cut - go back to the old bucket and paste the images => this triggers your lambda function and will create for every image a new thumbnail. now you can delete the temporary created bucket. you are done. :)
If you run into difficulties, go to the Monitoring tab (shown in your picture) and click the link to the log files. They will hopefully give you some more information.
Actually, I suggest that you start by implementing the Tutorial: Using AWS Lambda with Amazon S3 from the AWS documentation.
Once you have confirmed that it is working, modify it for your particular needs (eg buckets, permissions).
Alternatively, you could just skip Lambda and use an automatic picture resizing service such as:
- Cloudinary
- Imgix
本文标签: javascriptCreate Thumbnails on Amazon S3 Bucket with Lambda functionStack Overflow
版权声明:本文标题:javascript - Create Thumbnails on Amazon S3 Bucket with Lambda function - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745599884a2158394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论