Create your first Python AWS Lambda function in minutes

AWS Lambda Python example

Ready to develop your first AWS Lambda function in Python? It really couldn’t be easier.

The AWS Management Console’s built-in code editor first loads with a pre-existing, fully functional snippet of Python code that you can immediately test and deploy.

From there, you can easily edit your Python code and quickly test your AWS Lambda functions all within the AWS Management Console.

Serverless computing with Python in AWS really couldn’t be easier.

How to build AWS functions in Python

To build your first Python based AWS Lambda function, follow these steps:

  1. Log into the AWS console and navigate to the Lambda dashboard.
  2. Click the orange Create Function button.
  3. Specify the function’s name and the Python version (Python 3.10 is recommended).
  4. Edit the Python code in Amazon’s embedded code editor.
  5. Click Deploy and then Test to see your Python Lambda function in action!

AWS Lambda function creation

From the Lambda dashboard in the AWS management console, an orange Create Function button entices you to create your function. When you click it, the system only requires two pieces of information:

  • The name of the Lambda function (I suggest myPythonFunction).
  • The runtime language and version (I suggest Python 3.10).

With the basic AWS Lambda function created, you can move to the Python code editor embedded within the AWS Management Console.

create a python aws lambda function

Simply provide a name and select the Python runtime to create an AWS Lambda function.

AWS’ embedded Python code editor

Amazon provides a source code editor on the Code tab of the new function’s configuration page.

The provided code is fully functional, but you should make the Python Lambda function your own. Here’s how:

  • Add a print statement to the function. Print statements turn into CloudWatch logs.
  • Customize the JSON in the return clause. This is the data that gets returned to the calling program.

The embedded editor allows you to code complex Python function inside the AWS Lambda configuration page. I suggest starting with a simple ‘Hello World’ though.

Test and deploy the serverless AWS Python function

Click the Deploy and then Test buttons, and your updated Lambda function and the Python code is run. The output handsomely displays back to you in the Execution Results tab.

Run and test AWS Lambda Python function

Python print statement show up as log entries, and the return block is the Lambda’s response.

And that’s how simple it is to create, code, test and deploy Python based AWS Lambda functions. It really couldn’t be any easier!