You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updating the lambda-trigger mdx with an example (#8008)
* Updating the lambda-trigger mdx with an example
* Update src/pages/[platform]/build-a-backend/storage/lambda-triggers/index.mdx
* Update src/pages/[platform]/build-a-backend/storage/lambda-triggers/index.mdx
---------
Co-authored-by: Brandon Watson <blwatson@kompartners.com>
Co-authored-by: josef <josef.aidt@gmail.com>
Now, when you deploy your backend, these functions will be invoked whenever an object is uploaded or deleted from the bucket.
79
+
80
+
## More Advanced Triggers
81
+
82
+
The example listed above demonstrates what is exposed directly in your `storage` definition. Specifically, the use of the `triggers` option when you use `defineStorage`. This method is for simple triggers that always execute on file uploads or file deletions. There are no additional modifications you can make to the triggers defined in this way.
83
+
84
+
If you want the ability to do something more than simply handle the events `onUpload` and `onDelete` you will have to use `.addEventNotification` in your `backend.ts`. If you use this method, the `triggers` section in your `storage/resource.ts` file should be removed.
85
+
86
+
Here is an example of how you can add a Lambda trigger for an S3 object PUT event. This trigger will execute when a file that has been uploaded to the bucket defined in your `storage/resource.ts` has a matching prefix and suffix as that listed in the function input of `addEventNotification`.
It's important to note that using this methodology does not require any changes your lambda function. This modification on your `backend.ts` file will create a new `AWS CloudFormation handler for "Custom::S3BucketNotifications" resources (@aws-cdk/aws-s3)` that specifically handles checking the prefix and suffix.
0 commit comments