To prevent triggering the resize Lambda function multiple times, you can use a unique identifier in the object key and check if it exists before triggering the resize function.

Here's one possible design of a system that uploads a file to S3 and resizes it with a Lambda function:

The user uploads a file to S3, which triggers a S3 "Put" event.
The S3 event invokes a Lambda function (let's call it the "controller" function) that is responsible for processing the uploaded file.
The controller function generates a unique identifier (e.g., a timestamp) and appends it to the original file key.
The controller function checks if an object with the new key exists in S3.
If the object does not exist, the controller function triggers the resize Lambda function (let's call it the "resizer" function) with the new key as input.
The resizer function resizes the file and stores it in S3 under the new key.
If the object already exists, the controller function terminates and does not trigger the resizer function.
This design ensures that the resizer function is triggered only once per unique file, and that the resized file is stored under a unique key.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence