Reputation: 3613
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?
Upvotes: 3
Views: 3756
Reputation: 3613
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. :)
Upvotes: 2
Reputation: 1590
From 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.
Upvotes: 2
Reputation: 269360
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:
Upvotes: 1