Skip to main content

Creating a Simple AWS Lambda Function

Hands-On Lab

 

Photo of Andru Estes

Andru Estes

Training Architect

Length

00:30:00

Difficulty

Intermediate

This Learning Activity provides hands-on experience with creating and customizing Python3-based Lambda functions from within the console. The primary focus will be on the following features within AWS Lambda: 1. Lambda Console 2. Function Code 3. Execution Roles 4. Test Events 5. Execution Results AWS Lambda allows you to create functions and you only have to worry about managing your code. AWS handles the underlying infrastructure for you. This HelloWorld function will allow you to see just how easy it is to get started.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating a Simple AWS Lambda Function

Introduction

In this hands-on lab, we will create and customize Python3-based Lambda functions from within the console.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

All of the code used in the lesson is available for download here.

Create a Lambda Function within the AWS Lambda Console

  1. Navigate to Lambda.
  2. Click Create a function.
  3. Make sure the Author from scratch option at the top is selected, and then use the following settings:
    • Basic information:
      • Name: HelloWorld
      • Runtime: Python3.6
    • Permissions:
      • Select Choose or create an execution role.
      • Execution role: Use an existing role
      • Existing role: lambdarole
  4. Click Create function.
  5. On the HelloWorld page, scroll to the Function code section.
  6. Delete the existing code there, and enter the code from GitHub.
  7. Click Save.

Create a Test Event and Manually Invoke the Function Using the Test Event

  1. In the dropdown next to Test at the top of the Lambda console, select Configure test events.
  2. In the dialog, select Create new test event.
  3. Select the Hello World event template.
  4. Give it an event name (e.g., "Test").
  5. Replace the current code there with the provided JSON code, and then click Create.
  6. Click Test to verify the function's success.

Verify That CloudWatch Has Captured Function Logs

  1. Navigate to CloudWatch.
  2. Select Logs in the left-hand menu.
  3. Select the log group with your function name in it.
  4. Select the log stream within the log group.
  5. Verify the output is present and correct.

Conclusion

Congratulations on completing this hands-on lab!