I've written probably 50 lambdas in Python at this point and to be honest keeping it simple is the best way. Follow PIP standards to keep your code readability high, use the paginator objects boto3 provides where possible and try to keep the execution time down.15 minutes is pretty high for something serverless so I tend to design my lambdas to perform a single task and then use something like AWS Step Functions to orchestrate several in a flow or in Map states (loops). I also make use of environment variables where possible and template a lot of functions for common things like assuming roles. I also make use of comprehension but don't go too overboard with that because it can reduce readability if you've got a fat one defined haha. No need to add comments every other line, just a single line docstring at the top of the function should be enough to describe it. There's also some neat docker commands out there to build all your packages into a single lambda layer using a requirements.txt, using the lambda image, and this should be possible to do with Terraform, or if you've only got one or two packages just prepare it in a CI/CD and use terraform to build and apply the layer. Answer from skyflex on reddit.com
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python
Building Lambda functions with Python - AWS Lambda
You can run Python code in AWS 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 AWS Identity and Access Management (IAM) role that you manage.
🌐
Reddit
reddit.com › r/aws › so what does a well-made aws lambda in python actually look like?
r/aws on Reddit: So what does a well-made AWS Lambda in Python actually look like?
September 22, 2023 -

I've been losing myself in rewriting a bunch of lambda functions. I can't help but notice that there's a bunch of different opinions and philosophies that make up the bulk of the samples and documentation.

In my own team, one of the guys wrote his own test framework and schema validation library. Another wrote his own logging library and was a big fan of the Serverless framework. I've been using Lambda Power Tools and unittest myself but my lambdas are pretty vanilla. Three guys, three different development styles.

Everything feels so arbitrary and I'm not sure what actually constitutes a production-ready, well structured Python lambda.

FWIW We use terraform for initial project deployment with codebuild, and I have my own makefiles to deploy if I want to bother outside of it. Most of my lambdas are interfaced by AGW and interact with s3, dynamodb, and sagemaker.

Edit: to be clear - most of these are <200ms calls. I'm not trying to cram crazy things into a lambda. If anyone could share some code samples of some well-done Lambda's I'm happy.

Discussions

AWS Lambda + Serverless Framework + Python — A Step By Step Tutorial — Part 2 “Using AWS KMS with Lambda to Store & Read Sensitive Data & Secrets”

You do not want to put your access key and secret key in your serverless.yml file. If you do then that file can never be part of a public repository and it becomes difficult to rotate those keys. It’s not necessary to include those keys either since the lambda is already executing with its own set of credentials. You can give access to the SSM parameter using iamRoleStatements.

More on reddit.com
🌐 r/Python
5
26
October 22, 2014
AWS Lambda + Serverless Framework + Python – A Step by Step “Hello World”

I recommend this framework. I’ve used it in prod and had good results

More on reddit.com
🌐 r/aws
8
52
December 15, 2014
AWS Lambda + Serverless Framework + Python – A Step by Step “Hello World”

Looks great! I'm going to give it a crack later today.

More on reddit.com
🌐 r/devops
6
38
September 6, 2014
Python & AWS Lambda - Serverless Tram Time Display

The Python here is pretty straightforward and could almost certainly be improved and optimized, but it was my first time deploying a web-app via AWS Lambda so thought this may be a useful write-up for anyone else looking to do the same

More on reddit.com
🌐 r/Python
4
40
July 3, 2015
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › define lambda function handler in python
Define Lambda function handler in Python - AWS Lambda
January 31, 2026 - The Lambda function handler is the method in your Python code that processes events. When your function is invoked, Lambda runs the handler method.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › deploy python lambda functions with container images
Deploy Python Lambda functions with container images - AWS Lambda
The Dockerfile includes the runtime interface client for Python. To complete the steps in this section, you must have the following: ... Create a directory for the project, and then switch to that directory. ... Create a new file called lambda_function.py. You can add the following sample function code to the file for testing, or use your own. import sys def handler(event, context): return 'Hello from AWS Lambda using Python' + sys.version + '!'
🌐
AWS
aws.amazon.com › blogs › compute › python-3-14-runtime-now-available-in-aws-lambda
Python 3.14 runtime now available in AWS Lambda | Amazon Web Services
November 19, 2025 - AWS Lambda now supports Python 3.14 as both a managed runtime and container base image. Python is a popular language for building serverless applications. Developers can now take advantage of new features and enhancements when creating serverless ...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › create-python-aws-lambda-function-hello-world-tutorial-serverless-how-to-example
Create your first Python AWS Lambda function in minutes
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).
🌐
GitHub
github.com › grantcooksey › aws-lambda-python-examples
GitHub - grantcooksey/aws-lambda-python-examples: Lessons and examples to get started using aws lambda function in python · GitHub
Moves the python module defined in template.yaml into a .aws-sam/build directory, ie the event-selector-service · Spins up an aws compatible docker container with a volume mapped to the build folder · Installs dependencies into the fresh container using PyPI. Native dependencies get built here. We can locally run the lambda in a docker container to test.
Starred by 61 users
Forked by 41 users
Find elsewhere
🌐
GitHub
github.com › nficano › python-lambda
GitHub - nficano/python-lambda: A toolkit for developing and deploying serverless Python code in AWS Lambda. · GitHub
A toolkit for developing and deploying serverless Python code in AWS Lambda. - nficano/python-lambda
Starred by 1.5K users
Forked by 225 users
Languages   Python 97.3% | Makefile 2.7%
🌐
Lumigo
lumigo.io › guides › aws lambda 101 › aws lambda python
Ultimate AWS Lambda Python Tutorial with Boto3
September 17, 2024 - It’s only natural, then, that many developers would like to rely on Python when working with their serverless functions. In this article, we’ll discuss using Python with AWS Lambda, exploring the process of testing and deploying serverless Python functions.
🌐
AWS
aws.amazon.com › blogs › compute › python-3-13-runtime-now-available-in-aws-lambda
Python 3.13 runtime now available in AWS Lambda | Amazon Web Services
November 14, 2024 - AWS Lambda now supports Python 3.13 as both a managed runtime and container base image. Python is a popular language for building serverless applications. The Python 3.13 release includes a number of changes to the language, the implementation, ...
🌐
AWS
aws.amazon.com › about-aws › whats-new › 2025 › 11 › aws-lambda-python-314
AWS Lambda adds support for Python 3.14 - AWS
AWS Lambda now supports creating serverless applications using Python 3.14. Developers can use Python 3.14 as both a managed runtime and a container base image, and AWS will automatically apply updates to the managed runtime and base image as they become available.
🌐
SentinelOne
sentinelone.com › blog › aws-lambda-with-python
AWS Lambda With Python: A Simple Introduction With Examples
April 13, 2024 - We’ll point an API to our Lambda function. Before we do this, we’ll need to go back to the IAM section in the AWS Console and give our user access to AmazonAPIGatewayAdministrator (to create the API Gateway) and AmazonAPIGatewayInvokeFullAccess (to invoke the endpoint): Now that the Serverless framework can also configure the API Gateway service, we can add a trigger to our serverless.yml: service: email-validator provider: name: aws runtime: python3.8 functions: main: handler: handler.validate events: - http: POST /email/validate
🌐
Simon Willison
til.simonwillison.net › awslambda › asgi-mangum
Deploying Python web apps as AWS Lambda functions | Simon Willison’s TILs
The zip file needs to contain both the Python code AND all of its dependencies - more on that to come. Our first function doesn't have any dependencies, which makes things a lot easier. Here's how to turn it into a zip file ready to be deployed: ... You only have to do this the first time you deploy a Lambda function. You need an IAM role that you can use for the other steps. ... aws iam create-role \ --role-name lambda-ex \ --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole"} ]}'
🌐
Stackify
stackify.com › aws-lambda-with-python-a-complete-getting-started-guide
AWS Lambda with Python: A Complete Getting Started Guide - Stackify
May 16, 2024 - We’ll test it out, as well as take a look at what Lambda provides for metrics and logging. By the end of this tutorial, you’ll be ready to start integrating other AWS serverless frameworks using Python Lambda functions as the glue to bind them all together.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › log and monitor python lambda functions
Log and monitor Python Lambda functions - AWS Lambda
START RequestId: 8f507cfc-xmpl-4697-b07a-ac58fc914c95 Version: $LATEST ## ENVIRONMENT VARIABLES /aws/lambda/my-function 2025/08/31/[$LATEST]3893xmpl7fac4485b47bb75b671a283c ## EVENT {'key': 'value'} END RequestId: 8f507cfc-xmpl-4697-b07a-ac58fc914c95 REPORT RequestId: 8f507cfc-xmpl-4697-b07a-ac58fc914c95 Duration: 15.74 ms Billed Duration: 147 ms Memory Size: 128 MB Max Memory Used: 56 MB Init Duration: 130.49 ms XRAY TraceId: 1-5e34a614-10bdxmplf1fb44f07bc535a1 SegmentId: 07f5xmpl2d1f6f85 Sampled: true · The Python runtime logs the START, END, and REPORT lines for each invocation.
🌐
Docker Hub
hub.docker.com › r › amazon › aws-lambda-python
amazon/aws-lambda-python repository overview
These base images contain the Amazon Linux Base operating system, the runtime for a given language, dependencies and the Lambda Runtime Interface Client (RIC), which implements the Lambda Runtime API⁠. The Lambda Runtime Interface Client allows your runtime to receive requests from and send requests to the Lambda service. To learn more about the composition of the base images you can visit https://github.com/aws/aws-lambda-base-images⁠.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › aws lambda function testing in python
AWS Lambda function testing in Python - AWS Lambda
is a Python library for mocking AWS services and resources, so that you can test your functions with little or no modification using decorators to intercept and simulate responses. The validation feature of the Powertools for AWS Lambda (Python)
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › working with .zip file archives for python lambda functions
Working with .zip file archives for Python Lambda functions - AWS Lambda
Runtime dependencies in PythonCreating a .zip deployment package with no dependenciesCreating a .zip deployment package with dependenciesDependency search path and runtime-included librariesUsing __pycache__ foldersCreating .zip deployment packages with native librariesCreating and updating Python Lambda functions using .zip files · Your AWS Lambda function’s code comprises a .py file containing your function’s handler code, together with any additional packages and modules your code depends on.
🌐
AWS
aws.amazon.com › blogs › compute › python-3-12-runtime-now-available-in-aws-lambda
Python 3.12 runtime now available in AWS Lambda | Amazon Web Services
January 25, 2024 - Lambda now supports Python 3.12. This release uses the Amazon Linux 2023 OS, supports Unicode responses, and graceful shutdown for functions with external extensions, and Python 3.12 language features.