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:
- Log into the AWS console and navigate to the Lambda dashboard.
- Click the orange Create Function button.
- Specify the function’s name and the Python version (Python 3.10 is recommended).
- Edit the Python code in Amazon’s embedded code editor.
- 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.
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.
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.
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!