Step 1 – Create Lambda Function
- Navigate to AWS Lambda, click on Create function
- Select Author from scratch
- Name your function echoFn
- Choose Runtime as Node.js 14.x
- Click on Create function
Step 2 – Edit code
- Collapse Function overview
- 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
- Click on Test, Create new test event
- Select hello-world as the event template
- Name your event hwTest d)Type “GreatLearning” (with the quotes)
- Click Create
- Click Test
- Execution results window should show “Hello from Lambda GreatLearning” under Response
Step 4 – Add S3 PUT Trigger
- Expand Function overview
- Click on Add Trigger
- Select S3 from the drop down
- Pick a bucket you have already created
- Under Event type select PUT
- Check acknowledgement for Recursive invocation
- 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
- Expand Function overview, click on Add Destination
- Select Asynchronous invocation
- Select On success
- Select SNS topic as Destination Type
- Select a topic you have already created
- 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
- Navigate to Amazon S3
- Click on the bucket you selected in Step 4
- Click on Upload and upload any dummy file
- If the file uploads successfully, you should get an email notification with the event JSON
Great work!