yh6
yh6

Reputation: 389

AWS S3 conditions and AWS lambda suffix/prefix

I would like to upload image files to AWS S3 bucket which triggers a Lambda function that modify the images, using python boto3 library and presigned URLs.
And I would like to implement the following rules:

  1. Use the Content-Type condition to restrict the files to be uploaded only to image files (e.g., jpeg and png)
  2. Use the suffix or prefix so that Lambda function is activated only when image files are uploaded

Currently my codes and settings are as follows:
[Python codes]

boto3.client('s3', ...).generate_presigned_post(...,
  Key='userupload/' + key,
  Fields={
    "Content-Type": "image/jpeg",
  },
  Conditions=[
    ["starts-with", "$Content-Type", "image/"],
  ]
)

[Lambda settings]

But, when I try to upload an jpeg file, the file is successfully uploaded to the expected S3 bucket (in userupload folder), while the Lambda function is not triggered.
I also found that the uploaded object doesn't have the standard "Type" value, while it has the following Metadata:

Are there any good ways to obtain the expected behavior?
Thank you very much for your helps in advance!

Upvotes: 0

Views: 777

Answers (1)

coket
coket

Reputation: 26

For the lambda trigger you should considerer this:

  1. In your presigned url you should configure as "post_object" (or put)
  2. In your lambda trigger, the event must be put (for this case)
  3. In your lambda trigger, the bucket must be the one which will receive the file

Upvotes: 0

Related Questions