Design a site like this with
Get started

[5] [ProjectX] – Getting Started with AWS Lambda

Source code:

In this blog post, we will be creating our first function using AWS Lambda and understanding intricacies related to it.

Creating Lambda function


Login to your AWS console with a user having Administrator privileges and open AWS Lambda service. You should be seeing the landing page as below


Click on Create function button and enter following details in the screen that opens.

Let Author from Scratch be selected by default. 

Enter Function Name = myFullName

Select Runtime = Node.js 8.10

click Create function button

You should see a message that confirms creation of our function


Scroll down below and you will see that a small sample code has been written for us in a file named index.js. Replace that code with below code block


Keep everything else as default and click Save button

This completes creation of a function in AWS Lambda.

As you would have inferred, we are building a simple function that takes input values of First name and Last name and will return Full name.

Testing Lambda function


Now let’s test this function to see whether it works. Towards your top right there is a button called Test. Before that button, there is a drop-down arrow with text select a test event. Click that arrow and select Configure test events option


In the screen that opens, enter the following values

Event Template: Select HelloWorld (if HelloWorld is not there, select MobileBackend)

EventName: TestMyFullNameFunc

Enter the following JSON value in box below EventName

Click Create button


You should be back to the function page. Now click Test button

If the function executed successfully, you should be seeing the screen like one below

This shows our Lambda function executed successfully and it was able to return us Full name by concatenating supplied values. It also shows other details regarding its execution.


Now click the link “logs” which is the last word in the Exection:result:succeeded line. It will open AWS CloudWatch logs page.

You will see a Log Streams record created. Click on that and it will open detail logging captured while execution of our function

Hence, we now know that AWS captures all the logs of Lambda function execution in AWS CloudWatch


If you come back to function page, you will understand why in Designer you see AWS CloudWatch Logs also along with our Lambda function

It is because this function is using AWS CloudWatch Logs service to log events.


Let’s make slight modification to our code in index.js, as shown below

Now again click Test button and open “logs” link and you should see the details like shown below

You can see it logs the Entry and Exit as well as the input values we passed to it. This is how we can understand what is happening inside the code of Lambda function, by putting log entries at right places.

Congratulations. You have completed creating your first Serverless function and running it in AWS cloud.

All this without hassle of creating Compute (VM), Storage (EBS), Networking (VPC,Subnet), Installing and configuring operating system, AMI creation, Software installation, Security configuration, patching, managing, maintenance.……….you get the drift.

This is where Serverless computing excels. You just leave all those low-level activities to your cloud provider and just focus creating what is important for your business

Step-3: Looking under the hood


Now let’s look under the hood and understand what all happened during this process.

If you notice, there is a text box called Handler, which was automatically filled with value of index.handler

Remember that this is the combination of File name (i.e. index.js) and function name (exports.handler)

You are telling Lambda location of your code (index.js) and starting point from where to start execution (exports.handler function)


Creation of Roles and Policies

Open AWS IAM service and click Roles as shown below

You can see that a role exists, with our function name FullName. Click on name of the role and another page opens up

This shows the policy attached to the role. Click on the policy name link and check the JSON created for the policy

If you are familiar with AWS IAM, you will understand that this policy allows the following two permissions

  1. CreateLogGroup
  2. PutLogEvents

This is useful while creating the CloudWatch Log group for our function and to log events when the function executes.

This is very important to understand. This means Each Lambda function you create, can do only those activities for which you have given it permission. Nothing less and nothing more.


Check Role association with Lambda

You can open your Lambda function and scroll down to see this role associated with it.

To recap, we created a Lambda function, and AWS did the following for us

  • Create a Role
  • Created a Policy and
  • Defined Permissions in a JSON file and attached to Policy

Then when the Lambda function was executed during runtime, these Role along with its Policy and Permissions were used to create LogStreamGroup and log events into it.


This completes our first small step in Serverless world. Let’s hope this small step turns into a Giant leap in future

Happy Clouding!


4 thoughts on “[5] [ProjectX] – Getting Started with AWS Lambda

  1. […] our previous blog post, we created Lambda function and used AWS Console Test button to invoke […]

    Liked by 1 person

  2. Oh man What might I say? Really… really loved the blogThank you so much!

    Liked by 1 person

    1. you are welcome Francis 🙂

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: