AWS Lambda
Developer Guide

Create a Lambda Function with the Console

In this Getting Started exercise you first create a Lambda function using the AWS Lambda console. Next, you manually invoke the Lambda function using sample event data. AWS Lambda executes the Lambda function and returns results. You then verify execution results, including the logs that your Lambda function created and various CloudWatch metrics.

As you follow the steps, you will also familiarize yourself with the AWS Lambda console including:

  • Explore the blueprints. Each blueprint provides sample code and sample configurations that enable you to create Lambda functions with just a few clicks.

  • View and update configuration information of your Lambda function.

  • Invoke a Lambda function manually and explore results in the Execution results section.

  • Monitor CloudWatch metrics in the console.

Follow the steps in this section to create a simple Lambda function.

To create a Lambda function

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

  2. Note that AWS Lambda offers a simple Hello World function upon introduction under the How it works label and includes a Run option, allowing you to invoke the function as a general introduction. This tutorial introduces additional options you have to create, test and update your Lambda functions, as well as other features provided by the Lambda console and provides links to each, inviting you to explore each one in depth.

    Choose Create a function under the Get Started section to proceed.


    The console shows the Get Started page only if you do not have any Lambda functions created. If you have created functions already, you will see the Lambda > Functions page. On the list page, choose Create a function to go to the Create function page.

  3. On the Create function page, you are presented with three options:

    • Author from scratch

    • Blueprints

    • Serverless Application Repository

    For more information on using the Serverless Application Repository, see What Is the AWS Serverless Application Repository?

    1. If you'd like to review the blueprints, choose the Blueprints button, which will display the available blueprints. You can also use the Filter to search for specific blueprints. For example:

      • Enter S3 in Filter to get only the list of blueprints available to process Amazon S3 events.

      • Enter dynamodb in Filter to get a list of available blueprints to process Amazon DynamoDB events.

    2. For this Getting Started exercise, choose the Author from scratch button.

  4. In Author from scratch, do the following:

    • In Name*, specify your Lambda function name.

    • In Runtime*, choose Python 3.7.

    • In Role*, choose Create new role from template(s):

    • In Role name*, enter a name for your role.

    • Leave the Policy templates field blank. For the purposes of this introduction, your Lambda function will have the necessary execution permissions.


      For an in-depth look at AWS Lambda's security polices, see Authentication and Access Control for AWS Lambda.

    • Choose Create Function.

  5. Under your new function-name page, note the following:

    In the Add triggers panel, you can optionally choose a service that automatically triggers your Lambda function by choosing one of the service options listed.

    Depending on which service you select, you are prompted to provide relevant information for that service. For example, if you select DynamoDB, you need to provide the following:

    • The name of the DynamoDB table

    • Batch size

    • Starting position

    For this example, do not configure a trigger.

    • In Function code note that code is provided. It returns a simple "Hello from Lambda" greeting.

    • Handler shows lambda_function.lambda_handler value. It is the filename.handler-function. The console saves the sample code in the file and in the code lambda_handler is the function name that receives the event as a parameter when the Lambda function is invoked. For more information, see AWS Lambda Function Handler in Python.

    • Note the embedded IDE (Integrated Development Environment). To learn more, see Creating Functions Using the AWS Lambda Console Editor.

  6. Other configuration options on this page include:

Invoke the Lambda Function and Verify Results, Logs, and Metrics

Follow the steps to invoke your Lambda function using the sample event data provided in the console.

  1. On the yourfunction page, 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 and note the following sample event template:

    { "key3": "value3", "key2": "value2", "key1": "value1" }

    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.


    If you choose to delete the test event, go to the Configure test event page and then choose Delete.

  3. 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.

  4. AWS Lambda executes your function on your behalf. The handler in your Lambda function receives and then processes the sample event.

  5. Upon successful execution, view results in the console.

    Note the following:

    • The Execution result section shows the execution status as succeeded and also shows the function execution results, returned by the return statement.


      The console always uses the RequestResponse invocation type (synchronous invocation) when invoking a Lambda function which causes AWS Lambda to return a response immediately. For more information, see Invocation Types.

    • 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.

    Note that the Click here link shows logs in the CloudWatch console. The function then adds logs to Amazon CloudWatch in the log group that corresponds to the Lambda function.

  6. Run the Lambda function a few times to gather some metrics that you can view in the next step.

  7. Choose the Monitoring tab to view the CloudWatch metrics for your Lambda function. This page shows the CloudWatch metrics.

    Note the following:

    • The X-axis shows the past 24 hours from the current time.

    • Invocation count shows the number of invocations during this interval.

    • Invocation duration shows how long it took for your Lambda function to run. It shows minimum, maximum, and average time of execution.

    • Invocation errors show the number of times your Lambda function failed. You can compare the number of times your function executed and how many times it failed (if any).

    • Throttled invocation metrics show whether AWS Lambda throttled your Lambda function invocation. For more information, see AWS Lambda Limits.

    • Concurrent execution metrics show the number of concurrent invocations of your Lambda function. For more information, see Managing Concurrency.

    • The AWS Lambda console shows these CloudWatch metrics for your convenience. You can see these metrics in the Amazon CloudWatch console by clicking any of these metrics.

    For more information on these metrics and what they mean, see AWS Lambda CloudWatch Metrics.