Building Lambda functions with Python
You can run Python code in Amazon Lambda. Lambda provides runtimes for Python that run your code to process events. Your code runs in an environment that includes the SDK for Python (Boto3), with credentials from an Amazon Identity and Access Management (IAM) role that you manage.
Lambda supports the following Python runtimes.
Python | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Name | Identifier | SDK | Operating system | Architectures | Deprecation (Phase 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Python 3.11 |
|
boto3-1.27.1 botocore-1.30.1 |
Amazon Linux 2 |
x86_64, arm64 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Python 3.10 |
|
boto3-1.26.90 botocore-1.29.90 |
Amazon Linux 2 |
x86_64, arm64 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Python 3.9 |
|
boto3-1.26.90 botocore-1.29.90 |
Amazon Linux 2 |
x86_64, arm64 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Python 3.8 |
|
boto3-1.26.90 botocore-1.29.90 |
Amazon Linux 2 |
x86_64, arm64 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Python 3.7 |
|
boto3-1.26.90 botocore-1.29.90 |
Amazon Linux |
x86_64 |
Nov 27, 2023 |
The runtime information in this table undergoes continuous updates.
For more information on using Amazon SDKs in Lambda, see
Managing Amazon SDKs in Lambda functions
To create a Python function
-
Open the Lambda console
. -
Choose Create function.
-
Configure the following settings:
-
Function name: Enter a name for the function.
-
Runtime: Choose Python 3.11.
-
-
Choose Create function.
-
To configure a test event, choose Test.
-
For Event name, enter
test
. -
Choose Save changes.
-
To invoke the function, choose Test.
The console creates a Lambda function with a single source file named lambda_function
. You can edit
this file and add more files in the built-in code editor. To save your changes, choose Save.
Then, to run your code, choose Test.
Note
The Lambda console uses Amazon Cloud9 to provide an integrated development environment in the browser. You can also use Amazon Cloud9 to develop Lambda functions in your own environment. For more information, see Working with Amazon Lambda functions using the Amazon Toolkit in the Amazon Cloud9 user guide.
Note
To get started with application development in your local environment, deploy one of the sample applications available in this guide's GitHub repository.
Sample Lambda applications in Python
-
blank-python
– A Python function that shows the use of logging, environment variables, Amazon X-Ray tracing, layers, unit tests and the Amazon SDK.
Your Lambda function comes with a CloudWatch Logs log group. The function runtime sends details about each invocation to CloudWatch Logs. It relays any logs that your function outputs during invocation. If your function returns an error, Lambda formats the error and returns it to the invoker.
Topics
- Lambda function handler in Python
- Working with .zip file archives for Python Lambda functions
- Deploy Python Lambda functions with container images
- Amazon Lambda context object in Python
- Amazon Lambda function logging in Python
- Amazon Lambda function testing in Python
- Amazon Lambda function errors in Python
- Instrumenting Python code in Amazon Lambda