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.
🌐
Medium
medium.com β€Ί @e-miguel β€Ί lambda-and-python-projects-beginner-1b0db01be87c
Lambda and Python Projects: Beginner | by Eugene Miguel | Medium
October 2, 2023 - It is a computing service that ... by that code. ... In this Lambda project, we will write a python script to solve a real world problem for Med-Forward a healthcare company....
Discussions

So what does a well-made AWS Lambda in Python actually look like?
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. More on reddit.com
🌐 r/aws
18
24
September 22, 2023
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
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
🌐
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
🌐
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 - In this post, we’ll learn what Amazon Web Services (AWS) Lambda is, and why it might be a good idea to use for your next project. For a more in-depth introduction to serverless and Lambda, read AWS Lambda: Your Quick Start Guide to Going Serverless. In order to show how useful Lambda can be, we’ll walk through creating a simple Lambda function using the Python programming language.
🌐
Full Stack Python
fullstackpython.com β€Ί aws-lambda.html
AWS Lambda - Full Stack Python
Creating Serverless Functions with Python and AWS Lambda explains how to use the Serverless framework to build Python applications that can be deployed to AWS Lambda. Code Evaluation With AWS Lambda and API Gateway shows how to develop a code evaluation API, to execute arbitrary code, with AWS Lambda and API Gateway. Getting started with serverless on AWS is a wonderful tutorials, example projects and additional resources guide created by a developer who used all of these bits to learn AWS services herself.
🌐
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.

Find elsewhere
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί aws lambda functions β€Ί programming languages β€Ί building lambda functions with python β€Ί deploy python lambda functions with container images
Deploy Python Lambda functions with container images - AWS Lambda
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' + ...
🌐
ProjectPro
projectpro.io β€Ί blog β€Ί 5 real-world aws lambda project ideas for practice
5 Real-World AWS Lambda Project Ideas for Practice
October 28, 2024 - Very few ways to do it are Google, YouTube, etc. I was one of them too, and that's when I came across ProjectPro while watching one of the SQL videos on the... ... You will build an ETL Data Pipeline in Python for YouTube Data using Athena, Glue, and Lambda in this AWS Lambda project.
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί aws lambda functions β€Ί programming languages β€Ί 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
Suppose your function code is saved in a file named lambda_function.py. The following example CLI commands create a .zip file named my_deployment_package.zip containing your function code and its dependencies. You can either install your dependencies directly to a folder in your project directory or use a Python ...
🌐
Amazon Web Services
docs.aws.amazon.com β€Ί aws lambda β€Ί developer guide β€Ί aws lambda functions β€Ί lambda sample applications
Lambda sample applications - AWS Lambda
The GitHub repository for this guide includes sample applications that demonstrate the use of various languages and AWS services. Each sample application includes scripts for easy deployment and cleanup and supporting resources.
🌐
Linuxbeast
linuxbeast.com β€Ί home β€Ί how to structure your python projects for aws lambda, apis, and cli tools
How to Structure Your Python Projects for AWS Lambda, APIs, and CLI Tools | Linuxbeast
March 9, 2026 - If you need to package dependencies as a layer, check out How to Build and Deploy Python Libraries for AWS Lambda Layers. For APIs, you want a clear separation between routes (what endpoints exist), controllers (what they do), and services (how they talk to databases or external APIs). my-api-project/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ main.py # App entry point β”‚ β”œβ”€β”€ routes.py # Route definitions β”‚ β”œβ”€β”€ controllers.py # Request handling logic β”‚ β”œβ”€β”€ services.py # Database / external API calls β”‚ β”œβ”€β”€ models.py # Pydantic models or DB schemas β”‚
🌐
Hackers and Slackers
hackersandslackers.com β€Ί improve-your-aws-lambda-workflow-with-python-lambda
Python-Lambda: The Essential Library for AWS Cloud Functions
November 8, 2018 - On both Linux and OSX, this should generate files found under cd ~/.aws which will be referenced by default whenever you use an AWS service moving forward. As mentioned, we'll use pipenv for easy environment management. We'll create an environment using Lambda's preferred Python version: $ pip3 install pipenv $ pipenv shell --python 3.6 Creating a virtualenv for this project…
🌐
GitHub
github.com β€Ί shreyasgaonkar β€Ί aws-lambda-code-samples
GitHub - shreyasgaonkar/aws-lambda-code-samples: Lambda sample codes for EC2, Lambda, API Gateway and SNS in python runtime. Β· GitHub
β”œβ”€β”€ CODE_OF_CONDUCT.md β”œβ”€β”€ LICENSE β”œβ”€β”€ README.md β”œβ”€β”€ api-gateway-samples β”‚ └── upload_image_to_s3 β”‚ β”œβ”€β”€ README.md β”‚ β”œβ”€β”€ template.yml β”‚ └── upload_image_to_s3.py β”œβ”€β”€ ec2-samples β”‚ β”œβ”€β”€ delete_older_snapshots β”‚ β”‚ β”œβ”€β”€ README.md β”‚ β”‚ └── delete_older_snapshots.py β”‚ β”œβ”€β”€ delete_volumes_by_snapshot β”‚ β”‚ β”œβ”€β”€ README.md β”‚ β”‚ └── delete_volumes_by_snapshot.py β”‚ β”œβ”€β”€ describe_ami β”‚ β”‚ β”œβ”€β”€ README.md β”‚ β”‚ └── describe_ami.py β”‚ β”œβ”€β”€ describe_ec2_securitygroup β”‚ β”‚
Starred by 29 users
Forked by 20 users
Languages Β  Python
🌐
PyPI
pypi.org β€Ί project β€Ί python-lambda
python-lambda Β· PyPI
Python 2.7, >= 3.6 (At the time of writing this, these are the Python runtimes supported by AWS Lambda). ... First, you must create an IAM Role on your AWS account called lambda_basic_execution with the LambdaBasicExecution policy attached. On your computer, create a new virtualenv and project ...
      Β» pip install python-lambda
    
Published Β  Jan 05, 2021
Version Β  11.8.0
🌐
Medium
medium.com β€Ί full-stack-engineer β€Ί the-simplest-aws-lambda-in-python-7656bc067a3a
How Do I Deploy a Simple Python Lambda in AWS Using the CDK? | Full Stack Wizardry
April 19, 2025 - My project is called my_first_python_stack. So my stack file’s path from root is: ./my_first_python_stack/my_first_python_stack_stack.py. Yes, there are two stacks at the end. Open your version of this file, and you will see some boilerplate already there. Don’t worry about it, delete it and paste this instead: from aws_cdk import ( Stack, aws_lambda as _lambda, ) from constructs import Construct class MyFirstPythonStackStack(Stack): def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: super().__init__(scope, construct_id, **kwargs) # Base lambda function set up fn =
🌐
DEV Community
dev.to β€Ί fwojciec β€Ί how-to-structure-a-python-aws-serverless-project-4ace
How to Structure a Python AWS Serverless Project - DEV Community
January 6, 2022 - A lambda layer is packaged as a zipped python directory containing Python modules. These modules can be anything Python understands as modules - individual Python files or directories containing __init__.py files. The example project uses the build directory as staging area - let's, therefore, create python directory as a subdirectory of build:
🌐
GitHub
github.com β€Ί topics β€Ί aws-lambda-python
aws-lambda-python Β· GitHub Topics Β· GitHub
An AWS Lambda function created in Python 2.7 that triggers on CloudWatch Event of an EC2 instance starting and takes the Public IPv4 Address and updates an A-record within Cloudflare DNS using Cloudflare's API.
🌐
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
🌐
Adam the Automator
adamtheautomator.com β€Ί aws-lambda-python
Build AWS Lambda Python Functions from Scratch
October 1, 2023 - Starts an EC2 instance using the Python SDK, Boto3 Β· Creates an archive of the Boto3 code so it can be ran from Lambda ... If you’d like to follow along with the tutorial, you’ll need a few key items and pieces of software to accomplish the task at hand. An AWS EC2 instance – You won’t need anything special for this tutorial.