user3024827
user3024827

Reputation: 1258

AWS Lambda working with S3

I want to create a Python Lambda function to take uploaded s3 images and create a thumbnail version of them.

I have permission problems where I cannot get access to my bucket. I understand that I need to create a bucket policy. I don't understand how I can make a policy which works for a lambda request performing the thumbnail process?

Upvotes: 2

Views: 3654

Answers (1)

Ryan Gross
Ryan Gross

Reputation: 6515

It sounds like you want to do the following:

  1. Fire lambda whenever the something is uploaded to your bucket
  2. Read a file from the bucket
  3. Write a (thumbnail) file back to the bucket

You'll need 3 different permissions to do that:

  1. The S3 service will need permission to invoke your lambda function (this is done for you when you add an S3 event source via the AWS Lambda console).
  2. The lambda execution role (the one selected on the Configuration tab of the Lambda Console) will need read/write access to call S3. You can generate a policy for this on the policy generator by selecting IAM Policy from the drop down and then selecting the S3 permissions you need.
  3. For added security, you can set a bucket policy on S3 to only allow the lambda function to access it. You can generate this from the policy generator as well by selecting S3 policy. You would then enter lambda.amazonaws.com as the Principal.

Upvotes: 5

Related Questions