0
0
AWScloud~30 mins

Creating a Lambda function in AWS - Try It Yourself

Choose your learning style9 modes available
Creating a Lambda function
📖 Scenario: You are working on a cloud project where you need to create a simple AWS Lambda function. This function will run code in the cloud without managing servers. You will create the function step-by-step using AWS CloudFormation syntax.
🎯 Goal: Build a CloudFormation template that defines a Lambda function named MySimpleFunction with a basic Python 3.9 runtime and a handler named lambda_function.lambda_handler.
📋 What You'll Learn
Create a CloudFormation template with a Resources section
Define a Lambda function resource named MySimpleFunction
Set the runtime to python3.9
Set the handler to lambda_function.lambda_handler
Use a basic inline code snippet for the Lambda function
💡 Why This Matters
🌍 Real World
CloudFormation templates are used to automate cloud infrastructure setup, making deployments repeatable and consistent.
💼 Career
Knowing how to define Lambda functions in infrastructure as code is essential for cloud engineers and developers working with AWS.
Progress0 / 4 steps
1
Create the CloudFormation template skeleton
Create a CloudFormation template with a Resources section as an empty dictionary called Resources.
AWS
Need a hint?

Start by creating a Python dictionary named Resources with no entries yet.

2
Add the Lambda function resource
Add a resource named MySimpleFunction inside Resources with the type AWS::Lambda::Function and an empty Properties dictionary.
AWS
Need a hint?

Inside Resources, add a key MySimpleFunction with the correct type and empty properties.

3
Configure the Lambda function properties
Inside MySimpleFunction properties, add Runtime set to python3.9, Handler set to lambda_function.lambda_handler, and Code with ZipFile containing a simple Python function def lambda_handler(event, context):\n return 'Hello from Lambda'.
AWS
Need a hint?

Set the runtime, handler, and inline code for the Lambda function inside Properties.

4
Complete the CloudFormation template
Add the top-level AWSTemplateFormatVersion set to 2010-09-09 and Resources dictionary to complete the CloudFormation template as a Python dictionary named template.
AWS
Need a hint?

Wrap the Resources dictionary inside a top-level template dictionary with the version key.