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
Runtime: Choose Python 3.14. Choose Create function. 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. In the DEPLOY section, choose Deploy to update your function's code.
🌐
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 most common way to declare a handler function in Python is as follows: ... from typing import Dict, Any def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]: To use specific AWS typing for events generated by other AWS services and for the context object, add the aws-lambda-typing package to your function's deployment package.
Discussions

Getting started with Python AWS Lamda function? - SST Guide Forums
After creating a new SST application with: npx create-sst@latest my-sst-app There is a lambda function provided as a “hello world” example in /packages/functions/src/lambda.ts. I have some python code that I want to run as an API. But to get started, here is a little hello world in Python: ... More on discourse.sst.dev
🌐 discourse.sst.dev
0
November 2, 2023
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
24
11
September 12, 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
April 20, 2021
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
🌐
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.

🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › working with layers for python lambda functions
Working with layers for Python Lambda functions - AWS Lambda
(Optional) For Compatible runtimes, choose the Python runtime that corresponds to the Python version you used to build your layer. Choose Create. ... AWS CLI command. For the --layers parameter, use the layer ARN. The ARN must specify the version (for example, arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1). For more information, see Layers and layer versions. aws lambda update-function-configuration --function-name my-function --cli-binary-format raw-in-base64-out --layers "arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1"
🌐
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).
🌐
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/
🌐
Full Stack Python
fullstackpython.com › blog › aws-lambda-python-3-6.html
How to Create Your First Python 3.6 AWS Lambda Function - Full Stack Python
Amazon Web Services (AWS) Lambda provides a usage-based compute service for running Python code in response to developer-defined events. For example, if an inbound HTTP POST comes in to API Gateway or a new file is uploaded to AWS S3 then AWS ...
Find elsewhere
🌐
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 - To upgrade a function to Python 3.14, check your code and dependencies for compatibility with Python 3.14, run tests, and update as necessary. Consider using generative AI coding assistants like Amazon Q Developer, Amazon Q Developer for CLI, or Kiro to help with upgrades. Change the Python base image version by modifying the FROM statement in your Dockerfile: FROM public.ecr.aws/lambda/python:3.14 # Copy function code COPY lambda_handler.py ${LAMBDA_TASK_ROOT}
🌐
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
🌐
Lumigo
lumigo.io › guides › aws lambda 101 › aws lambda python
Ultimate AWS Lambda Python Tutorial with Boto3
September 17, 2024 - 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.
🌐
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"} ]}'
🌐
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 › 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.
🌐
SST Guide Forums
discourse.sst.dev › t › getting-started-with-python-aws-lamda-function › 2890
Getting started with Python AWS Lamda function? - SST Guide Forums
November 2, 2023 - After creating a new SST application with: npx create-sst@latest my-sst-app There is a lambda function provided as a “hello world” example in /packages/functions/src/lambda.ts. I have some python code that I want to run as an API. But to get started, here is a little hello world in Python: import json def lambda_handler(event, context): print("Hello from Lambda!") return { 'statusCode': 200, 'body': json.dumps('Hello from Lambda!') } How do I go about deploying ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › create your first lambda function
Create your first Lambda function - AWS Documentation
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 ...
🌐
DataCamp
datacamp.com › tutorial › python-lambda-functions
Python Lambda Functions: A Beginner’s Guide | DataCamp
January 31, 2025 - Learn a quicker way of writing functions on the fly with lambda functions. ... Learn about Python string interpolation, its purpose, and when to use it. Includes practical examples and best practices. ... Learn the basics of AWS Lambda, how to set up your first function, and how to integrate it with core AWS services for application serverless deployment.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › using the lambda context object to retrieve python function information
Using the Lambda context object to retrieve Python function information - AWS Lambda
in the powertools-lambda-python repository on GitHub. The following example shows a handler function that logs context information. import time def lambda_handler(event, context): print("Lambda function ARN:", context.invoked_function_arn) print("CloudWatch log stream name:", context.log_stream_name) print("CloudWatch log group name:", context.log_group_name) print("Lambda Request ID:", context.aws_request_id) print("Lambda function memory limits in MB:", context.memory_limit_in_mb) # We have added a 1 second delay so you can see the time remaining in get_remaining_time_in_millis.
🌐
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
For API details, see CreateFunction in AWS SDK for Python (Boto3) API Reference. The following code example shows how to use DeleteFunction. ... There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository ... class LambdaWrapper: def __init__(self, lambda_client, iam_resource): self.lambda_client = lambda_client self.iam_resource = iam_resource def delete_function(self, function_name): """ Deletes a Lambda function.
🌐
Readthedocs
aws-lambda-for-python-developers.readthedocs.io › en › latest › 01_console
Chapter 1: From the Console - AWS Lambda for Python Developers
The only real difference in the code, is that now we're going to dump the event object into the body of the return object, rather than just a static string of "Hello from Lambda". Don't worry about what event or body mean for now, let's just test this out first. Step 8: Let's execute again, by hitting the Test button: What you've just printed out in the json dump of the Test event, we created in step 5. So you've now officially executed code on AWS!!
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › instrumenting python code in aws lambda
Instrumenting Python code in AWS Lambda - AWS Lambda
When you send a GET request to the API Gateway endpoint, the Lambda function invokes, sends logs and metrics using Embedded Metric Format to CloudWatch, and sends traces to AWS X-Ray. The function returns a hello world message. To complete the steps in this section, you must have the following: ... AWS SAM CLI version 1.75 or later. If you have an older version of the AWS SAM CLI, see Upgrading the AWS SAM CLI. Initialize the application using the Hello World Python template.