Open In App

Amazon Web Services – Creating a Lambda Function

Last Updated : 13 Apr, 2023
Like Article

Pre-Requisites: AWS

AWS Lambda is one of the compute services that helps you to run code without provisioning or managing resources servers. With lambda, user can run their code on a high-availability computing infrastructure. Lambda performs all the tasks related to the administration of the compute resources, which includes the servers and operating system maintenance, automatic scaling, and logging. It also facilitates automatic scaling. With the help of Lambda, users can run their code for virtually any type of application or backend service. Lambda supports many programming languages, all you need to do is supply your code. Users can organize their code into Lambda functions. and these Lambda functions will run your function only once you needed and then automatically scales, and there is a very good option of servicing from a few requests per day to thousands per second. Only you need to pay for the compute time that your code will take to run as there is no charge for the lambda function code when your code is not running. But when you are using Lambda,  you are the only one responsible for your code. Lambda will automatically manage memory, CPU, network and other resources need to run your code.

AWS Lambda is a computing service provided by AWS that will make sure that your Lambda function will be executed only when it is triggered or when it is needed and it also automatically scales your Lambda function for thousands of requests per second. You can attach the events of other AWS services such as creating or updating Dynamo DB tables, uploading files to S3 Bucket, hitting HTTP method endpoints, and so on to your Lambda function and trigger when that event occurs.

How To Launch Lambda Functions From The AWS Console

Step 1: Log in to your AWS account. Once you are redirected to the AWS management console. Click on the Search bar and Search for Lambda. Select the Lambda option in the list.

Search lambda


Step 2: In a while, you will be directed to the AWS lambda dashboard page and there you can find create function option click on it.

Create lambda function


Step 3: You will then land on the page which is shown below. There are several options available for creating functions such as Author from Scratch, Use a Blueprint, Container Image, and Browse serverless app repository. To begin working with Lambda functions, let’s become familiar with these options.

  • Author from scratch: You’ll begin with a straightforward “Hello World” example and be able to put your function into use on your own after that.
  • Use a blueprint: An example of code from a blueprint demonstrates how to utilize Lambda with an AWS service or a well-known third-party application. For the Node.js and Python runtimes, blueprints offer sample code and function configuration defaults.
  • Container image: With the help of the Container image option we can run Docker Container in AWS Lambda which already contains API and necessary dependencies like Operation system (OS) and required software
  • Browse serverless app repository: Without creating or managing servers, we can execute our application with the aid of the Browse serverless app repository.

Choose the Author from the Scratch option among the available options. In the Basic Information section, you can give any function name for your lambda function. We are giving the name “myFunction”. Next, choose your runtime environment, we are leaving it as the default option “Nodejs 14. x”.

Configure lambda function


Step 4: In the permissions section, you can notice the change default execution role option. Click on it to expand and view the options. you can see various options there You can create a lambda function with a custom role that exists already using the “Use an existing role” option. Using the “Create a new role from AWS policy templates” option you can create a new role by giving the role name and selecting the policy templates doing so creates a new role and gives that role to the lambda function while creating the function. You can select “Create a new role with basic Lambda permissions” click on the “Create function” option and click on Create function.  

Select role and Create function


Step 5: In a while, your Lambda function will be created and you will land on your Lambda function and it will look like below. you can see the lambda function code which returns a response of “Hello from Lambda”  below in the Code source section. You can add the Events of other AWS services which should trigger this lambda function by clicking the “Add trigger” option in the Function overview section as shown in the below figure.

Add trigger


AWS Lambda Pricing

The price of AWS Lambda is based on the number of requests for your functions and the duration, in seconds, that it takes to execute those requests. Requests are charged at a rate of $0.20 per 1 million requests, and duration is charged at a rate of $0.00001667 per GB-second.In addition to these charges, you may also incur charges for the use of other AWS services, such as Amazon S3 or Amazon DynamoDB, which your functions may access while executing.

AWS Lambda also offers a free tier that allows you to run up to 1 million requests per month and 400,000 GB-seconds of compute time per month at no charge. This free tier can be a great way to get started with AWS Lambda and try out the service without incurring any charges. Overall, the cost of using AWS Lambda will depend on the specific use case and the resources required to run your code. It is a good idea to carefully consider your usage patterns and plan your budget accordingly to ensure that you are not overpaying for your computing needs.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads