Frame 19229

How to Create Your First Lambda Function

Posted by Administrator

February 19, 2026

Navy Modern Digital Marketing Agency Landscape Banner

A technical guide to create the first function in AWS Lambda using Amazon Web Service console. 

Runtime Options in AWS Lambda 

When creating a function in Amazon Web Services Lambda, the first step is choosing the runtime. If you select an interpreted language such as Python or Node.js, you can write and edit your function code directly in the Lambda console using the built-in code editor. This approach is ideal for quick setup, testing, and small workloads because it removes the need for local packaging. 

However, if you use a compiled language like Java or C#, the process requires an additional step. You must build your application on your local machine, create a deployment package, and then upload that package to Lambda before the function can run. 

Sign Up for an AWS Account 

If you do not have an AWS account, complete the following steps to create one. 

To sign up for an AWS account: 

  1. Open https://portal.aws.amazon.com/billing/signup 
  2. Follow the online instructions. 

 

Part of the sign-up procedure involves receiving a phone call and entering a verification code on the phone keypad. When you sign up for an AWS account, an AWS account root user is created. The root user has access to all AWS services and resources in the account. As a security best practice, assign administrative access to a user, and use only the root user to perform tasks that require root user access. 

AWS sends you a confirmation email after the sign-up process is complete. At any time, you can view your current account activity and manage your account by going to https://aws.amazon.com/ and choosing My Account. 

 

Create a user with administrative access 

After you sign up for an AWS account, secure your AWS account root user, enable AWS IAM Identity Center, and create an administrative user so that you don’t use the root user for everyday tasks. 

Secure your AWS account root user 

  1. Sign in to the AWS Management Consoleas the account owner by choosing Root user and entering your AWS account email address. On the next page, enter your password. For help signing in by using root user, see Signing in as the root user in the AWS Sign-In User Guide. 
  2. Turn on multi-factor authentication (MFA) for your root user. For instructions, see Enable a virtual MFA device for your AWS account root user (console) in the IAM User Guide. 

 

Sign in as the user with administrative access 

To sign in with your IAM Identity Center user, use the sign-in URL that was sent to your email address when you created the IAM Identity Center user. For help signing in using an IAM Identity Center user, see Signing in to the AWS access portal in the AWS Sign-In User Guide. 

 

Assign access to additional users 

  1. In IAM Identity Center, create a permission set that follows the best practice of applying least-privilege permissions. For instructions, see Create a permission set in the AWS IAM Identity Center User Guide.
  2. Assign users to a group, and then assign single sign-on access to the group. For instructions, see Add groups in the AWS IAM Identity Center User Guide. 

 

Create a Lambda Function with the Console 

In this example, your function takes a JSON object containing two integer values labeled “length” and “width”. The function multiplies these values to calculate an area and returns this as a JSON string. 

To create a Hello world Lambda function with the console 

  1. Open the Functions page of the Lambda console. 
  2. Choose Create function. 
  3. Select Author from scratch. 
  4. In the Basic information pane, for Function name, enter myLambdaFunction. 
  5. For Runtime, choose either Node.js 24 or Python 3.14. 
  6. Leave architecture set to x86_64, and then choose Create function. 

 

In addition to a simple function that returns the message Hello from Lambda!, Lambda also creates an execution role for your function. An execution role is an AWS Identity and Access Management (IAM) role that grants a Lambda function permission to access AWS services and resources. For your function, the role that Lambda creates grants basic permissions to write to CloudWatch Logs. Use the console’s built-in code editor to replace the Hello world code that Lambda created with your own function code. 

 

To modify the code in the console using Node.js 

1. Choose the Code tab 

In the console’s built-in code editor, you should see the function code that Lambda created. If you don’t see the index.mjs tab in the code editor, select index.mjs in the file explorer as shown on the following diagram. 

Screenshot 2026 02 19 at 12.31.34

2. Paste the following code into the index.mjs tab, replacing the code that Lambda created. 

Screenshot 2026 02 19 at 12.32.05

Screenshot 2026 02 19 at 12.32.21

3. In the DEPLOY section, choose Deploy to update your function’s code: 

Screenshot 2026 02 19 at 12.33.39

 

To modify the code in the console using Python 

1. Choose the Code tab. 

In the console’s built-in code editor, you should see the function code that Lambda created. If you don’t see the lambda_function.py tab in the code editor, select lambda_function.py in the file explorer as shown on the following diagram. 

Screenshot 2026 02 19 at 12.34.57

 

2. Paste the following code into the lambda _ function.py tab, replacing the code that Lambda created.

Screenshot 2026 02 19 at 12.35.32

 

3. In the DEPLOY section, choose Deploy to update your function’s code: 

Screenshot 2026 02 19 at 12.33.39

 

Invoke the Lambda function using the console code editor 

To invoke your function using the Lambda console code editor, create a test event to send to your function. The event is a JSON formatted document containing two key-value pairs with the keys “length” and “width”. 

To create the test event 

1. In the TEST EVENTS section of the console code editor, choose Create test event. 

Screenshot 2026 02 19 at 12.38.30

2. For Event Name, enter myTestEvent.

3. In the Event JSON section, replace the default JSON with the following: 

{ 

Invoke the function 54 

AWS Lambda Developer Guide 

“length”: 6, 

“width”: 7 

} 

4. Choose Save. 

 

To test your function and view invocation records in the TEST EVENTS section of the console code editor, choose the run icon next to your test event: 

Screenshot 2026 02 19 at 12.40.41

 

When your function finishes running, the response and function logs are displayed in the OUTPUT tab. You should see results similar to the following: 

Node.js 

Screenshot 2026 02 19 at 12.41.29

Python

Screenshot 2026 02 19 at 12.41.56

Screenshot 2026 02 19 at 12.42.08

When you invoke your function outside of the Lambda console, you must use CloudWatch Logs to view your function’s execution results.

 

To view your function’s invocation records in CloudWatch Logs 

  1. Open the Log groups page of the CloudWatch console. 
  2. Choose the log group for your function (/aws/lambda/myLambdaFunction). This is the log group name that your function printed to the console.
  3. Scroll down and choose the Log stream for the function invocations you want to look at. 

Screenshot 2026 02 19 at 12.43.21

 

You should see output similar to the following: 

Node.js 

Screenshot 2026 02 19 at 12.44.01

Pyhton

Screenshot 2026 02 19 at 12.44.32

 

Clean up 

When you’re finished working with the example function, delete it. You can also delete the log group that stores the function’s logs, and the execution role that the console created. 

To delete the Lambda function 

  1. Open the Functions page of the Lambda console. 
  2. Select the function that you created. 
  3. Choose Actions, Delete. 
  4. Type confirm in the text input field and choose Delete. 

 

To delete the log group 

  1. Open the Log groups page of the CloudWatch console. 
  2. Select the function’s log group (/aws/lambda/myLambdaFunction). 
  3. Choose Actions, Delete log group(s). 
  4. In the Delete log group(s) dialog box, choose Delete. 

 

To delete the execution role 

  1. Open the Roles page of the AWS Identity and Access Management (IAM) console. 
  2. Select the function’s execution role (for example, myLambdaFunction-role-31exxmpl). 
  3. Choose Delete. 
  4. In the Delete role dialog box, enter the role name, and then choose Delete. 

 

Credit to AWS Document.

whatsapp icon.png
Start a Conversation

Privacy & Policy

PT Central Data Technology (“CDT” or “us”) is strongly committed to ensuring that your privacy is protected as utmost importance to us. https://centraldatatech.com/ , we shall govern your use of this website, including all pages within this website (collectively referred to herein below as this “Website”), we want to contribute to providing a safe and secure environment for visitors.

The following are terms of privacy policy (“Privacy Policy”) between you (“you” or “your”) and CDT. By accessing the website, you acknowledge that you have read, understood and agree to be bound by this Privacy Policy

Use of The Subscription Service by CDT and Our Customers

When you request information from CDT and supply information that personally identifies you or allows us to contact you, you agree to disclose that information with us. CDT may disclose such information for marketing, promotional and activity only for the purpose of CDT and the Website.

Collecting Information

You are free to explore the Website without providing any personal information about yourself. When you visit the Website or register for the subscription service, we provide some navigational information for you to fill out your personal information to access some content we offered.

CDT may collect your personal data such as your name, email address, company name, phone number and other information about yourself or your business. We are collecting your data in some ways, online and offline. CDT collects your data online using features of social media, email marketing, website, and cookies technology. We may collect your data offline in events like conference, gathering, workshop, etc. However, we will not use or disclose those informations with third party or send unsolicited email to any of the addresses we collect, without your express permission. We ensure that your personal identities will only be used in accordance with this Privacy Policy.

How CDT Use the Collected Information

CDT use the information that is collected only in compliance with this privacy policy. Customers who subscribe to our subscription services are obligated through our agreements with them to comply with this Privacy Policy.

In addition to the uses of your information, we may use your personal information to:

  • Improve your browsing experience by personalizing the websites and to improve the subscription services.
  • Send information about CDT.
  • Promote our services to you and share promotional and informational content with you in accordance with your communication preferences.
  • Send information to you regarding changes to our customers’ terms of service, Privacy Policy (including the cookie policy), or other legal agreements

Cookies Technology

Cookies are small pieces of data that the site transfers to the user’s computer hard drive when the user visits the website. Cookies can record your preferences when visiting a particular site and give the advantage of identifying the interest of our visitor for statistical analysis of our site. This information can enable us to improve the content, modifying and making our site more user friendly.

Cookies were used for some reasons such as technical reasons for our website to operate. Cookies also enable us to track and target the interest of our users to enhance the experience of our website and subscription service. This data is used to deliver customized content and promotions within the Helios to customers who have an interest on particular subjects.

You have the right to decide whether to accept or refuse cookies. You can edit your cookies preferences on browser setup. If you choose to refuse the cookies, you may still use our website though your access to some functionality and areas of our website may be restricted.

This Website may also display advertisements from third parties containing links to other websites of interest. Once you have used these links to leave our site, please note that we do not have any control over the website. CDT cannot be responsible for the protection and privacy of any information that you provide while visiting such websites and this Privacy Policy does not govern such websites.

Control Your Personal Data

CDT give control to you to manage your personal data. You can request access, correction, updates or deletion of your personal information. You may unsubscribe from our marketing activity by clicking unsubscribe us from the bottom of our email or contacting us directly to remove you from our subscription list.

We will keep your personal information accurate, and we allow you to correct or change your personal identifiable information through marketing@centraldatatech.com