Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Trigger Lambda Function When New Image is Uploaded to S3 - (Let's Build 🏗️ Series)

Posted on Oct 24 Let's build a simple architecture where a Lambda Function is triggered whenever a user uploads a new image to an S3 bucket.📋 Note: This article is preparation for a more advanced one which will be published inside the same series.The main parts of this article:1- Architecture Overview (Terraform)2- About AWS Services (Info)3- Technical Part (Code)4- Result5- ConclusionHint: always run terraform fmt and terraform validate to clean the syntax and validate that all is good, after you can run terraform plan to see the resources that will be created and finally terraform apply1- Amazon S3: To store the image.2- AWS Lambda: To trigger our function and execute the code.3- Identity and Access Management (IAM): To give permissions for the S3 and Lambda events.Our fancy go code 😜 does simple logging.Since we are not using any frameworks, we need to build and create our own .zip file in order to be able to upload the code to our Lambda function. Inside the Terraform configuration file already you can notice that I'm pointing to main.zip file which holds our built code.Build your Go binary for the appropriate target platform:Create a ZIP file containing your main binary and any other dependencies:That's it, let's try to upload a new image to our S3 bucket, and we can see the logs being printed out when we check Amazon CloudWatch.Here is a simple screenshot from Amazon CloudWatch after I uploaded an image to my S3 Bucket, also remember we are using prefixes for certain folders which in our case it's /images, and the file type should be .pngSweet, now it's your turn to become more creative and build on top of this. And a small reminder that the techniques and skills that are used in this article will be also used for my next one, which will hold more advanced services and skills.I wanted to write this article a separate one since there are many use cases in this simple architecture that can be really handy. Hope you guys enjoyed it.If you'd like more content like this, feel free to connect with me on LinkedIn.Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Yan Cui - Oct 6 Julien Simon - Oct 10 Ashish Gupta - Oct 9 Parth Patel - Oct 8 Would you like to become an AWS Community Builder? Learn more about the program and apply to join when applications are open next. Once suspended, aws-builders will not be able to comment or publish posts until their suspension is removed. Once unsuspended, aws-builders will be able to comment and publish posts again. Once unpublished, all posts by aws-builders will become hidden and only accessible to themselves. If aws-builders is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to awedis. They can still re-publish the post if they are not suspended. Thanks for keeping Dev Community safe. Here is what you can do to flag aws-builders: aws-builders consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging aws-builders will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Trigger Lambda Function When New Image is Uploaded to S3 - (Let's Build 🏗️ Series)

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×