How to create AWS Lambda function

Prerequisites for creating an AWS lambda function

  1. An AWS account.
  2. Knowledge of anyone of the programming languages like  C#, Go, Java, Node.js, Python.
  3. Ability to write small programs as the maximum execution timeout for AWS Lambda function is 15 minutes.
  4. Default deployment package size is 50 MB so, need to calculate the memory requirements.


Create lambda function with the console

To create AWS Lambda function

  1. Open the AWS Lambda console.
  2. Choose Create a function.
  3. For Function name, enter lambda.
  4. Choose Create function.



Lambda creates a Node.js function (or whichever language you have chosen) and an execution role that grants the function permission to upload logs. Lambda assumes the execution role when you invoke your function.


Using Designer

The Designer shows an overview of your function and its upstream and downstream resources. You can use it to configure triggers, layers, and destinations.



  • Triggers – Triggers are services and resources that you have configured to invoke your function. Choose Add trigger to create a Lambda event source mapping or to configure a trigger in another service that the Lambda console integrates with.
  • Layers – Choose the Layers node to add layers to your application. A layer is a ZIP archive that contains libraries, a custom runtime, or other dependencies.
  • Destinations – Add a destination to your function to send details about invocation results to another service. You can send invocation records when your function is invoked asynchronously, or by an event source mapping that reads from a stream.

Choose lambda in the designer to return to the function’s code and configuration. For scripting languages, Lambda includes sample code that returns a success response.

Function Settings

  • Code– The code and dependencies of your function. For scripting languages, you can edit your function code in the embedded editor.
  • Runtime– The Lambda runtime that executes your function.
  • Handler– The method that the runtime executes when your function is invoked, such as handler. The first value is the name of the file or module. The second value is the name of the method.
  • Environment variablesKey-value pairs that Lambda sets in the execution environment. Use environment variables to extend your function’s configuration outside of code.
  • Tags– Key-value pairs that Lambda attaches to your function resource. Use tags to organize Lambda functions into groups for cost reporting and filtering in the Lambda console.
  • Tags apply to the entire function, including all versions and aliases.
  • Execution role – The IAM role that AWS Lambda assumes when it executes your function.
  • Description – A description of the function.
  • Memory– The amount of memory available to the function during execution. Choose an amount between 128 MB and 3,008 MB in 64-MB increments.
  • Timeout – The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.

Invoke the Lambda Function

Invoke your Lambda function using the sample event data provided in the console.

To invoke a function

  1. In the upper right corner, choose Test.
  2. In the Configure test event page, choose Create new test event and in Event template, leave the default Hello World option. Enter an Event name.
  3. You can change key and values in the sample JSON, but don’t change the event structure. If you do change any keys and values, you must update the sample code accordingly.
  4. Choose Create and then choose Test. Each user can create up to 10 test events per function. Those test events are not available to other users.
  5. AWS Lambda executes your function on your behalf. The handler in your Lambda function receives and then processes the sample event.
    • The Execution result section shows the execution status as succeeded and also shows the function execution results, returned by the return statement.
    • The Summary section shows the key information reported in the Log output section (the REPORT line in the execution log).
    • The Log output section shows the log AWS Lambda generates for each execution. These are the logs written to CloudWatch by the Lambda function. The AWS Lambda console shows these logs for your convenience.Upon successful execution, view results in the console.


Using Code Editor

The code editor in the AWS Lambda console enables you to write, test, and view the execution results of your Lambda function code.

The code editor includes the menu barwindows, and the editor pane.

To create a new file, do one of the following:

  • In the Environment window, right-click the folder where you want the new file to go, and then choose New File. Type the file’s name and extension, and then press Enter .
  • Choose File, New File on the menu bar. When you’re ready to save the file, choose File, Save or File, Save As on the menu bar. Then use the Save As dialog box that displays to name the file and choose where to save it.
  • In the tab buttons bar in the editor pane, choose the + button, and then choose New File. When you’re ready to save the file, choose File, Save or File, Save As on the menu bar. Then use the Save As dialog box that displays to name the file and choose where to save it.

You can change various code editor settings such as which coding hints and warnings are displayed, code folding behaviors, code auto completion behaviors, and much more.

To change code editor settings, choose the Preferences gear icon in the menu bar.

To know more about AWS Lambda function, visit

Leave a Reply

Your email address will not be published. Required fields are marked *