Skip to content
Menu
Cloud Gal 42
  • Home
Cloud Gal 42

QuickGuide: Create AWS Lambda function to send email when a file is uploaded to S3

May 22, 2021June 7, 2021 by admin

Step 1 – Create Lambda Function

  1. Navigate to AWS Lambda, click on Create function
  2. Select Author from scratch
  3. Name your function echoFn
  4. Choose Runtime as Node.js 14.x
  5. Click on Create function

Step 2 – Edit code

  1. Collapse Function overview
  2. Right-click on index.js and click Open, delete the sample code and replace with –
exports.handler = (event, context, callback) => {
		//TODO implement
		callback(null, 'Hello from Lambda ' + event);
	};

Step 3 – Create Test Event

  1. Click on Test, Create new test event
  2. Select hello-world as the event template
  3. Name your event hwTest d)Type “GreatLearning” (with the quotes)
  4. Click Create
  5. Click Test
  6. Execution results window should show “Hello from Lambda GreatLearning” under Response

Step 4 – Add S3 PUT Trigger

  1. Expand Function overview
  2. Click on Add Trigger
  3. Select S3 from the drop down
  4. Pick a bucket you have already created
  5. Under Event type select PUT
  6. Check acknowledgement for Recursive invocation
  7. Click on Add

Step 5 – Edit code

exports.handler = (event, context, callback) => {	
		console.log("This is a custom log entry" + JSON.stringify(event));	
		callback(null, 'Hello from S3');
	};

Step 6 – Add Email notification

  1. Expand Function overview, click on Add Destination
  2. Select Asynchronous invocation
  3. Select On success
  4. Select SNS topic as Destination Type
  5. Select a topic you have already created
  6. Click Save

Step 7 – Create Test Event for S3 PUT

  • Collapse Function overview
  • Click on Test, Create new test event
  • Select s3-put as the event template
  • Name your event s3Test
  • Click on Save changes
  • Click Test
  • Execution results window should show “Hello from S3” under Response

Step 8 – Upload file to S3 bucket

  1. Navigate to Amazon S3
  2. Click on the bucket you selected in Step 4
  3. Click on Upload and upload any dummy file
  4. If the file uploads successfully, you should get an email notification with the event JSON

Related

1 thought on “QuickGuide: Create AWS Lambda function to send email when a file is uploaded to S3”

  1. Paul says:
    July 28, 2021 at 3:26 am

    Great work!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Role of AI/ML in Cybersecurity
  • QuickGuide: Security on OCI
  • The Cloud Management Plane
  • Secure Installation and Configuration of Virtualized Cloud Datacenters
  • Cloud Datacenter: Hardware-specific Security Configuration Requirements

Recent Comments

  • Rafael on Installing Debian on OCI
  • Jorge on Installing Debian on OCI
  • admin on Installing Debian on OCI
  • Andreas on Installing Debian on OCI
  • admin on Installing Debian on OCI

Archives

  • December 2022
  • February 2022
  • September 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • February 2021
  • January 2021
  • November 2020
  • October 2020

Categories

  • aws
  • bcdr
  • cloud
  • cloudsecurity
  • compliance
  • informationsecurity
  • oracle
  • pci
  • QuickGuide
  • security
©2025 Cloud Gal 42 | Powered by WordPress and Superb Themes!