Articles → AWS → Lambda Function In AWS

Lambda Function In AWS






Serverless Computing Model





What Is A Lambda Function?













How To Create A Lambda Function In AWS?




  1. Verify emails in Simple Email Service (SES)
  2. Create a lambda function
  3. Write code to send an email
  4. Change the policy
  5. Invoke the function



Verify Emails In Simple Email Service (SES)





Create A Lambda Function




Picture showing the lambda function in AWS console search result
Click to Enlarge



Picture showing the Create function button for creating the new lambda function
Click to Enlarge



  1. Function name
  2. Runtime
  3. Architecture
  4. Execution role


Picture showing the create lambda function screen in AWS console
Click to Enlarge


Write Code To Send An Email




var aws = require('aws-sdk');

aws.config.getCredentials(function (err) {
    if (err) console.log(err.stack);        
    else {
        //console.log("Access key:", aws.config.credentials.accessKeyId);
    }
});

var ses = new aws.SES({
    region: 'ap-south-1'
});

exports.handler = function () {
    //console.log("Incoming: ", event);
    var eParams = {
        Destination: {
            ToAddresses: ["SESverifiedemail@gmail.com"]
        },
        Message: {
            Body: {
                Text: {
                    Data: "Lambda is working"
                }               
            },
            Subject: {
                Data: "Mail From SES"
            }

        },
        Source: "SESverifiedemail@gmail.com"
    };
    console.log('===Sending Email====');
    var email = ses.sendEmail(eParams, function (err, data) {

        //console.log(eParams);
        if (err) console.log(err);
        else {
            console.log('===Email Sent====');
            //context.succeed(event);
        }
    });
};


exports.handler();


Picture showing the screen to write code for lambda function
Click to Enlarge



Picture showing the Deploy button for deploying the code
Click to Enlarge


Change The Policy




  1. Add SES:SendEmail and SES:SendRawEmail inside the Action
  2. Set the value of Resource to *
Picture showing the screen to change the permissions in the lambda role
Click to Enlarge


Invoke The Function




Picture showing the screen to invoke the lambda functions
Click to Enlarge



Picture showing the output of the lambda function when the function is invoked
Click to Enlarge



Picture showing the email recieved from lambda function
Click to Enlarge


What Is The Maximum Execution Time Of Lambda Function?





Posted By  -  Karan Gupta
 
Posted On  -  Thursday, January 6, 2022
 
Updated On  -  Friday, September 16, 2022

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250