codeWithYoha logo
Code with Yoha
AWS Lambda

How to create an AWS Lambda function

How to create an AWS Lambda function
0 views
4 min read
#AWS Lambda

AWS Lambda significantly accelerates and simplifies how teams develop and maintain software. AWS Lambda eliminates the need for users to manage any servers. They can automate operational series of actions, as well as complex application components. It's known as serverless infrastructure.
AWS Lambda's main resources are functions, which contain a granular piece of code that performs a specific task. To deploy a Lambda function, users upload source code and configure parameters, such as the following:

  • Triggers
  • Permissions
  • Versions
  • Aliases
  • Memory
  • Virtual Private Cloud (VPC)
  • Concurrency
  • Destinations
  • Database proxies
  • Elastic File System
  • Error handling

In this tutorial, we see how to create your first Lambda functions via the AWS console.

Prerequisites

  • An AWS account to create Lambda function

To create your first AWS lambda function, use the AWS Console Management to create a Hello world function. In the following steps :

Sign in to the AWS Management Console

Open the AWS Management Console and log in.

Open the Lambda Console

Navigate to the Lambda service by clicking on "Services" in the top left corner, selecting "Compute," and then choosing "Lambda."

Create a Lambda Function

Step 1

The easest way to create an AWS Lambda function is through the Create function button on the Lambda console. The console method suits early stages of development, rather than applications in production.

Create an AWS Lambda function, click the create function button.

Step 2

Choose one of the option to create your AWS lambda function from the options below:

  • Author from scratch: Create your own code from a Hello World example.
  • Use a blueprint: AWS code blueprints include built-in AWS integrations with other services and common uses. These blueprints can save a significant amount of time when developing Lambda functions.
  • Container image: Container images stored in Amazon Elastic Container Registry are also useful to launch new Lambda functions. For this example, select Author from scratch to create the function.
Choose an option to create your function

Step 3

Fill the following AWS lambda function Basic information and then click on the Create function button at the bottom of the page:

  • Function name: Enter a name for your function.
  • Runtime: Choose the runtime environment for your function (e.g., Python, Node.js, Java).
  • Execution role: Create a new role with basic Lambda permissions or choose an existing role.
AWS lambda function basic information

Configure the Lambda Function

In the Function code section, you can edit the code inline or upload a .zip file containing your code. For simplicity, you can start with a basic function.

AWS Lambda Code

Under the Runtime Settings you ou can change either the function's runtime or the function handler to point on your handleRequest method and then click on Save button.

AWS lambda Edit runtime settings

Test Your Lambda Function

You can test your Lambda function in the console by invoking your function with a test event. A test event is a JSON input to your function. If your function doesn't require input, the event can be an empty document ({}).
Please follow the steps below to test your aws Lambda:

  1. Choose the Test tab.
  2. Under Test event, choose Create new event or Edit saved event and then choose the saved event that you want to use.
  3. Optionally - choose a Template for the event JSON.
  4. Click on the Test button on the right-top of the Test Tab.
  5. Optional: To review the test results, under Execution result, expand Details.
Test AWS lambda function

Monitor Your Lambda Function

AWS provides various monitoring and logging options for Lambda functions. You can view logs, set up CloudWatch Alarms, and more.
View the available options on the Monitor tab:

Monitor AWS Lambda Function

That's it! You've created an AWS Lambda function. Please note that this is a basic guide, and depending on your use case, you may need to adjust settings and configuration.
Thank you!