Run "Hello World" on AWS Lambda With Example

Let’s run the “Hello World” example on AWS Lambda. I would recommend reading about the AWS Lambda – Serverless Programming before getting started with Lambda functions.

In this example, we will learn about the basics of Lambda, how to create a function, deploy without managing servers. You will also learn about the core vocabulary of AWS Lambda functions.

If you are a beginner then you can use the free tier of AWS. AWS free tier allows you a million request per month for AWS Lambda.

Aws Lambda Free Tier

 

Aws Lambda Free Tier

AWS Lambda Service

To get started with AWS Lambda, you must signup with AWS and login to the AWS Management Console. Now, go to the services page and you will see the “Lambda” link under the “Compute” section.

See the below screenshot for your reference:

Aws Lambda Free Tier

 

Aws Services

Click on the Lambda link and you will see the AWS Lambda Home page like below screenshot:

Aws Lambda Free Tier

 

Aws Lambda Home

This screen only appears when you are getting started for the first time. You can see the links in the left section. We will see them after creating a function to understand better.

Create Lambda Function

You can click on the create function link on the above screen only OR go to Dashboard and you will see the below screen.

Aws Lambda Free Tier

 

Aws Lambda Dashboard

Click on the link “Create function” and you will see the below screen.

Aws Lambda Free Tier

 

Create Lambda Function

AWS provides multiple ways to create the Lambda function:

Author from scratch

Author from scratch option will give you the option to choose every detail. This is the best start point for beginners as you would like to understand most of the settings and options. We will choose this option in this tutorial.

Use a blueprint

There are several sample lambda functions available on AWS with configurations presets for common use cases. So, if you are developing Lamda function for the business need then you can always check for your use case and choose the available blueprint.

Aws Lambda Free Tier

 

Create Lambda Function From Blueprint

Browse serverless app repository

AWS also has the repository for the Lambda function called serverless app repository. You can find a number of Lambda functions with all the code and configuration presets ready to deploy. You can choose one if it’s fitting in your use case.

Aws Lambda Free Tier

 

Create Lambda From Repository

Let’s choose the first option and author from scratch.

Configure Lambda

Let’s configure our first lambda function. Typically, a Lambda function consists of code, dependencies, and configurations.

Function name

Name of the function is the logical name which you usually create in programming to describe the purpose. Use only letters, numbers, hyphens, or underscores with no spaces.

Aws Lambda Free Tier

 

Create Hello World

Runtime

You can choose runtime from supported runtime by AWS. A runtime is a version of a programming language or framework that you will use to write your function.

AWS Lambda supports the below runtime:

  • C#/PowerShell
  • Go
  • Java
  • Node.js
  • Python
  • Ruby
  • Aws Lambda Free Tier

 

Choose Runtime

Note: You can create your own runtime as well.

Permissions

You can create roles and permission to allow your Lambda function the access of other AWS service on behalf of you. In addition to the execution roles, your function also has the function policy that gives permissions to other functions to invoke it.

Let’s choose the option “Create a new role with basic Lambda permissions”. We will explore other options when we will create a Lambda function for AWS S3 object manipulations.

Aws Lambda Free Tier

 

Add Permissions

Click on the “Create function” button at the bottom of screen.

Explore Lambda Function

AWS will create your Lambda function in a few seconds. You will be redirected on the below page after successful creation of your function.

Aws Lambda Free Tier

 

Hello World Lambda

Configurations

You can change the configurations for your Lambda function. For Example, you can set the request time out and memory. This is just to give you an idea, You can explore other settings as well.

Delete The Lambda Function

 

Basic Settings

Function Code

Next is the function code, you will see the code editor and the index file open in it by default. You can change the code from the editor itself.

Runtime

We have already discussed runtime in Lambda configuration. “A runtime is a version of a programming language or framework that you will use to write your function.”

Handler

The module-name.export value in your function. For example, “index.handler” calls exports.handler in index.js.

lambda-account-metrices

 

Hello World Code

Configure Test Events

Now, It’s time to test your Lambda function. You can configure a test event by “Select a test event” dropdown. OR Just click on the “Test” button.

You can setup up to 10 test events for your function.

Delete The Lambda Function

 

Configure Test Event

Once the test event has been configured, you can test your Lambda function. You will see that your event is available in dropdown now.

lambda-account-metrices

 

Test Event

Run your Lambda Function

Now, we have already created a test event. Let’s do some changes in the Lambda function code and test the Lambda for the same.

Instead of printing hard-coded text, let’s print the key1 from test event.

lambda-account-metrices

 

Change Code To Print Key

Note: Never forget to save the code.

Now, click on the test button and you will see the below result as expected:

Delete The Lambda Function

 

Test Your Lambda

Lambda Dashboard

The Lambda Dashboard is divided into two parts:

  1. Resources – in the selected region. Total number of Lambda functions running in the selected region will display as count.
  2. Account-level metrics – This section will display all the metrices available for the lambda function running in the selected region. See the invocation metrice for the referenc
  3. lambda-account-metrices

    Lambda Account Metrices

Delete Lambda Function

You can see all the running Lambda funtions by clicking the left menu option “Funtions”.

Delete The Lambda Function

 

All Lambda Funtions

There is one Lambda function record in the list as we created only one. Let’s select this and try to delete this:

Delete The Lambda Function

 

Delete The Lambda Function

The point to notice here is that your Lambda function will be deleted permanently so make sure that you stored the code in some repository.

Aws Lambda Free Tier

 

Delete Confirm

Click on the delete button to continue.

By admin

Leave a Reply