DEV Community

Cover image for [Intro] How to trigger a Lambda function when a file is uploaded to an existing S3 bucket using Amazon EventBridge and AWS CDK
Ken Choong
Ken Choong

Posted on • Updated on

[Intro] How to trigger a Lambda function when a file is uploaded to an existing S3 bucket using Amazon EventBridge and AWS CDK

*In this series of blog post, what we gonna to do is: *

  1. Observe a file is uploaded to an existing S3 bucket using Amazon EventBridge
  2. When Amazon EventBridge notice a file is uploaded to S3 bucket, it will trigger a Lambda function.
  3. Provision our Lambda Function, Amazon EventBridge, Policy and all other resources using AWS CDK.

Scenario

You using Aws Amplify for Android app.

Now you need storage
so you can store the images, video or audio your user upload from you app.

So you do this:

amplify add storage

Answer a few question in Amplify CLI like showing here

Amplify provisioned a S3 bucket for you. Nice and easy. Now you can upload your user file into this bucket.

Follow with this scenario:

  • Now you have an existing S3 bucket which generated by Aws Amplify
  • When user upload the file to this bucket, you want to trigger a Lambda function which you can use other AWS service.

For example,

  • When an image is uploaded to the bucket, you want to use AWS Rekognition to do face recognition
  • When an audio file uploaded to the bucket, you want to use AWS Transcribe to transcribe the audio file to words.

The problem is how?

Stay Tuned.

[Part 1]What is Amazon EventBridge and How to provision Logging S3 bucket, and bucket policy using AwsCDK

Before you go, if you like this series or find this useful consider to buy me a coffee 😊🤞 for 5 USD or more.
I will prepare a GitHub repo for this whole tutorial series and arrange into separate commit for each part.
This will only available for my supporter cause I spent a lot of time to prepare this. Anyway, I appreciate you here. Have a good day.


bmaco

Follow me on Twitter: @upupkenchoong

My upcoming product(If you interested): @sarah_assistant

Top comments (0)