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 › aws lambda functions › programming languages › building lambda functions with python
Building Lambda functions with Python - AWS Lambda
Run Python code in Lambda. Your code runs in an environment that includes the SDK for Python (Boto3) and 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

amazon web services - How to package and deploy AWS python lambda functions automatically - Stack Overflow
I have created a AWS python lambda using some modules like kafka, numpy, boto3 etc. Boto3 is already provided by AWS environment. For Numpy, I am using AWS predefined layer. After deploying it as .zip file with kafka and other modules, the size is around 14 MB and AWS UI wont show the code saying · The deployment package of your Lambda function ... More on stackoverflow.com
🌐 stackoverflow.com
Lambda function
map applies a function to every element of an iterable. Sometimes these functions are very simple operations; for example, if I wanted to double every number in a list. It's wasteful to define an entire new function (with the def keyword) just for this one simple operation. Lambda creates a callable function that we can use. Here's an example of how we could create that and use it with map. numbers = [1, 5, 20, 50] map(lambda x:x * 2, numbers) More on reddit.com
🌐 r/learnpython
23
13
April 1, 2024
End-to-End Tutorial on Combining AWS Lambda, Docker, and Python

AWS Lambda recently added support for Docker images with Python, where before you had to zip all your code and dependencies. With this update I wanted to make a full length tutorial to cover everything necessary to be productive.

The playlist is broken into six parts:

  1. An introduction to the app that will be built and the various AWS components that will be used

  2. Cloning the GitHub repo and doing necessary setup to test the application locally

  3. Creating a Docker image of the Python script and running it on AWS Lambda, while also showing how painful it is to do even minor updates

  4. Adding CI/CD with GitHub Actions to speed up code updates

  5. Adding AWS Cloudwatch to create a cron job that schedules the Lambda function to run on periodic intervals

  6. Walking through an AWS Cloudformation yaml template that will create the Lambda function and Cloudwatch rule automatically and covering all the benefits of using a Cloudformation template

This tutorial truly is end-to-end. If you enjoy the content, you can help me a ton by doing any or all of the following:

  • supporting me on Patreon

  • subscribing to my YouTube channel

  • liking and/or commenting on the video

  • sharing the video or channel on any platform (reddit, twitter, discord, etc.)

  • starring the GitHub repo

  • following me on GitHub

Any questions or requests, just leave a comment.

More on reddit.com
🌐 r/Python
16
297
February 18, 2023
Looking for a basic and simple Lambda tutorial
i'm wanting to get my nephew into AWS and i believe that he should go with serverless to begin with (instead of running a tiny unscalable instance). i used the google to look around for tutorials to start a website with Lambda but all it finds are the kind that shortcut many things by having software installed on the client computer. this hides much of the detail he needs to see. he will be doing his own programming (using python... More on reddit.com
🌐 r/aws
6
1
March 24, 2020
🌐
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
🌐
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
Hit the "..." and select the python executable in the env you created (probably ~/.env/sf/bin/python) and add the interpreter · You will need to mark the src directory as a sources folder. (right click) AWS Lambda requires a flat folder with the application as well as its dependencies. SAM will use CodeUri property to know where to look up for both application and dependencies: ... HelloWorldFunction: Type: AWS::Serverless::Function Properties: CodeUri: hello_world/ ...
Starred by 61 users
Forked by 41 users
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › aws lambda functions › lambda runtimes
Lambda runtimes - AWS Lambda
For functions with more complex ... in the Lambda handler. Choice of runtime is also influenced by developer preference and language familiarity. Each major programming language release has a separate runtime, with a unique runtime identifier, such as nodejs24.x or python3.14. To configure a function to use a new major language version, you need to change the runtime identifier. Since AWS Lambda cannot ...
🌐
Dash0
dash0.com › home › guides › ultimate aws lambda python tutorial with boto3
Ultimate AWS Lambda Python Tutorial with Boto3 · Dash0
March 23, 2026 - In this article, we will try to understand boto3 key features and how to use them to build a Lambda function. Python generally has good cold start performance, but package size and imports can still impact startup times. Minimize package size by excluding unnecessary libraries and dependencies. Use AWS Lambda Layers to include only the necessary parts of Boto3 or other heavy libraries, and defer imports to the function handler when possible.
Find elsewhere
🌐
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).
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › aws lambda functions › create your first lambda function
Create your first Lambda function - AWS Lambda
For Runtime, choose either Node.js 24 or Python 3.14. Leave architecture set to x86_64, and then choose Create function. In addition to a simple function that returns the message Hello from Lambda!, Lambda also creates an execution role for your function. An execution role is an AWS Identity ...
🌐
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 applications on Lambda. You can develop Lambda functions ...
🌐
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 - Set this drop-down to the correct value of Python 3.7. Now go ahead and click the Create function button, which will bring you to the function configuration screen. This can be a bit overwhelming at first, but we’ll briefly cover a few of the essentials here. Also Read-https://stackify.com/aws-lambda-with-node-js-a-complete-getting-started-guide/
🌐
W3Schools
w3schools.com › Python › python_lambda.asp
Python Lambda
Python Examples Python Compiler ... Python Interview Q&A Python Bootcamp Python Training ... A lambda function is a small anonymous function....
🌐
AWS
docs.aws.amazon.com › aws sdk code examples › code library › code examples by sdk using aws sdks › code examples for sdk for python (boto3) › lambda examples using sdk for python (boto3)
Lambda examples using SDK for Python (Boto3) - AWS SDK Code Examples
May 13, 2026 - The following code examples show ... the AWS SDK for Python (Boto3) with Lambda. Basics are code examples that show you how to perform the essential operations within a service. Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › what is aws lambda?
What is AWS Lambda? - AWS Lambda
AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › aws lambda functions › lambda sample applications
Lambda sample applications - AWS Lambda
– A Python function that shows the use of logging, environment variables, AWS X-Ray tracing, layers, unit tests and the AWS SDK. ... – A Ruby function that shows the use of logging, environment variables, AWS X-Ray tracing, layers, unit tests and the AWS SDK. Ruby Code Samples for AWS Lambda ...
🌐
Simon Willison
til.simonwillison.net › awslambda › asgi-mangum
Deploying Python web apps as AWS Lambda functions | Simon Willison’s TILs
You need to know your AWS account ID for the next step. ... Now we can deploy the zip file as a new Lambda function! Pick a unique function name - I picked lambda-python-hello-world.
🌐
Medium
medium.com › @reach2shristi.81 › starting-your-lambda-journey-with-python-74d95346dd0
Starting your Lambda Journey with Python | by Min_Minu | Medium
June 25, 2023 - Go to the AWS Management Console and navigate to the Lambda service. Click on “Create function” and choose the “Author from scratch” option. Give your function a name, select the Python runtime, and choose the execution role.
Top answer
1 of 2
1

I'm working on an open source CLI / Python SDK called LaunchFlow that sets up the exact automation you described! All you need to do is supply a requirements.txt for the Python dependencies, and the tool will zip up your local workspace + Python dependencies and release it to your Lambda function.

The code looks like this:

import launchflow as lf
import numpy as np


def handler(event, context):
    result = np.random.randint(0, 100)
    return {
        "statusCode": 200,
        "body": f"Random Number: {result}",
    }


api = lf.aws.LambdaService(
    name="my-lambda-api",
    handler=handler,
    runtime=lf.aws.lambda_service.PythonRuntime(
        requirements_txt_path="requirements.txt"
    ),
)

LambdaService Docs link

Just pip install launchflow[aws] + lf deploy to set up the automation with your local AWS credentials.

If you'd rather create your own automation, you could look at the LambdaService source code to see how we automate the Lambda build / release steps with boto3.

2 of 2
0

For the git piece: I'd recommend just checking in your main python file and a related set of requirements.txt files.

The two paths that I've used for easier Lambda deployments are Serverless and Terraform. I'll outline them briefly (there's also Amazon's CDK but I am less familiar with it).

  • Serverless is basically a wrapper around Amazon's Infrastructure as Code tool (CloudFormation); either a set of JSON or YAML that define your Lambda and any associated resources. Here's a decent example of your setup i.e. a git tracked handler.py, a requirements.txt file and a serverless.yml to deploy the lambda.
  • For Terraform, it's a more general purpose Infrastructure as Code tool that has plugins for each major cloud provider. The best example I could dig up was a simplified repo

Terraform's main advantage is for change tracking in a more generic way, but Serverless I think is simpler if you're not familiar with either one. (Serverless uses CloudFormation stacks for tracking changes, which are a bit funkier than Terraform's state management).

Most ideally; you'd want to have these things run in a pipeline on merge, so that your lamda is updated with new code changes after a code review and merge into a git repo. It might look like:

  1. Someone submits a Pull Request to your Git repository
  2. The request is reviewed/ merged
  3. On before/merge, some tests run to verify the code
  4. You run the serverless/terraform deploy to update the lambda
  5. Do some final, end to end verification on the new deployment

Let me know if you need me to clarify anything!

🌐
Docs by LangChain
docs.langchain.com › get started › customize deep agents
Customize Deep Agents - Docs by LangChain
1 week ago - from deepagents import create_deep_agent from deepagents.backends import StoreBackend from langgraph.store.memory import InMemoryStore agent = create_deep_agent( model="openai:gpt-5.5", backend=StoreBackend( namespace=lambda rt: (rt.server_info.user.identity,), ), store=InMemoryStore(), # Good for local dev; omit for LangSmith Deployment )
🌐
GitHub
github.com › nicor88 › aws-python-lambdas
GitHub - nicor88/aws-python-lambdas: Collection of AWS Lambda functions in Python · GitHub
# create env conda create --name aws-python-lambdas python=3.6.2 # activate env source activate aws-python-lambdas pip install boto3 pip install pytest # install libs from the requirements of each single lambda for i in src/*/; do pip install -r $i"requirements.txt"; done · └── src/ ├── hello_world_lambda │ ├── __init__.py │ ├── requirements.txt │ └── lambda_function.py └── lambda_function_test_ ├── __init__.py ├── requirements.txt └── lambda_function.py
Starred by 11 users
Forked by 9 users
Languages   Python 97.6% | Shell 2.4%