AWS Lambda
Developer Guide

Lambda Functions

After you package up your custom code, including any dependencies, and upload it to AWS Lambda, you have created a Lambda function.

If you are new to AWS Lambda, you might ask: what type of code can I run as a Lambda function? How does AWS Lambda execute my code? How does AWS Lambda know the amount of memory and CPU requirements needed to run my Lambda code? The following sections provide an overview of how a Lambda function works.

Depending on your scenario, you can build applications where you use the AWS Lambda service to run all or parts of your application code. For more information, see Building Lambda Functions. How It Works provides examples that illustrate how to create a Lambda function for specific scenarios.

The sections in this topic provide the following introductory information about Lambda functions:

Compute Requirements – Lambda Function Configuration

A Lambda function consists of code and any associated dependencies. In addition, a Lambda function also has configuration information associated with it. Initially, you specify the configuration information when you create a Lambda function. Lambda provides an API for you to update some of the configuration data. Lambda function configuration information includes the following key elements:

  • Compute resources that you need – You only specify the amount of memory you want to allocate for your Lambda function. AWS Lambda allocates CPU power proportional to the memory by using the same ratio as a general purpose Amazon EC2 instance type, such as an M3 type. For example, if you allocate 256 MB memory, your Lambda function will receive twice the CPU share than if you allocated only 128 MB.

    You can update the configuration and request additional memory in 64 MB increments from 128MB to 1536 MB. For information about relevant limits, see AWS Lambda Limits.

    To change the amount of memory your Lambda function requires, do the following:

    1. Sign in to the AWS Management Console and navigate to the AWS Lambda console.

    2. Choose the function whose memory size you wish to change.

    3. Click the Configuration tab and then expand Advanced settings.

    4. In the Memory (MB) list, choose your desired amount.


    Optionally, you can update the memory size of your functions using the following AWS CLI command (using valid 64 MB increments):

    $ aws lambda update-function-configuration \ --function-name your function name \ --region region where your function resides \ --memory-size memory amount \ --profile adminuser

    For information on setting up and using the AWS CLI, see Step 1: Set Up an AWS Account and the AWS CLI.


  • Maximum execution time (timeout) – You pay for the AWS resources that are used to run your Lambda function. To prevent your Lambda function from running indefinitely, you specify a timeout. When the specified timeout is reached, AWS Lambda terminates your Lambda function.


    Avoid using recursive code in your Lambda function, wherein the function automatically calls itself until some arbitrary criteria is met. This could lead to unintended volume of function invocations and escalated costs.


  • IAM role (execution role) – This is the role that AWS Lambda assumes when it executes the Lambda function on your behalf.


  • Handler name – The handler refers to the method in your code where AWS Lambda begins execution. AWS Lambda passes any event information, which triggered the invocation, as a parameter to the handler method.

Invocation Types

AWS Lambda supports synchronous and asynchronous invocation of a Lambda function. You can control the invocation type only when you invoke a Lambda function (referred to as on-demand invocation). The following examples illustrate on-demand invocations:

  • Your custom application invokes a Lambda function.


  • You manually invoke a Lambda function (for example, using the AWS CLI) for testing purposes.

In both cases, you invoke your Lambda function using the Invoke operation, and you can specify the invocation type as synchronous or asynchronous.

However, when you are using AWS services as event sources, the invocation type is predetermined for each of these services. You don't have any control over the invocation type that these event sources use when they invoke your Lambda function. For example, Amazon S3 always invokes a Lambda function asynchronously and Amazon Cognito always invokes a Lambda function synchronously. For stream-based AWS services (Amazon Kinesis Streams and Amazon DynamoDB Streams), AWS Lambda polls the stream and invokes your Lambda function synchronously.