Creating a Simple AWS Lambda Function

Training Architect
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.
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
- Navigate to Lambda.
- Click Create a function.
- 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
- Basic information:
- Click Create function.
- On the HelloWorld page, scroll to the Function code section.
- Delete the existing code there, and enter the code from GitHub.
- Click Save.
Create a Test Event and Manually Invoke the Function Using the Test Event
- In the dropdown next to Test at the top of the Lambda console, select Configure test events.
- In the dialog, select Create new test event.
- Select the Hello World event template.
- Give it an event name (e.g., "Test").
- Replace the current code there with the provided JSON code, and then click Create.
- Click Test to verify the function's success.
Verify That CloudWatch Has Captured Function Logs
- Navigate to CloudWatch.
- Select Logs in the left-hand menu.
- Select the log group with your function name in it.
- Select the log stream within the log group.
- Verify the output is present and correct.
Conclusion
Congratulations on completing this hands-on lab!