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.
🌐
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
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
Streaming Response from Lambda in Python
As the documentation doesn't show anything regarding python, it shows an example of js. Please help me with this. Thankyou. ... Looking at the documentation below, it appears that Node.js natively supports response streaming, but for other languages ​​you will need to use a custom runtime or Lambda Web Adapter. https://docs.aws... More on repost.aws
🌐 repost.aws
2
1
March 6, 2024
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
Is Python a good choice for efficient Lambda functions?

the thing to keep in mind with lambda is you don't get a full vcpu of compute until your function memory is 1,769mb or higher (https://docs.aws.amazon.com/lambda/latest/dg/configuration-memory.html). if your function would benefit from multiple cores, i.e. is multithreaded with parallel busy threads, you'll need to scale up multiples of that to get more vcpus.

other than that, lambda runs on ec2 so the premise of your question is a little weird. runtime choice affects cold start time and how much memory you'll need just for overhead. other than that it has nothing to do with efficiency.

More on reddit.com
🌐 r/aws
5
1
March 23, 2024
🌐
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.

AWS Lambda Layers Nov 29, 2018
r/aws
7y ago
Lambda with Python libraries Jan 23, 2023
r/aws
3y ago
A subreddit for all things Lambda Apr 20, 2015
r/awslambda
11y ago
Lambda Questions Sep 21, 2024
r/aws
last yr.
More results from reddit.com
🌐
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
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › aws lambda functions › programming languages › building lambda functions with python › define lambda function handler in python
Define Lambda function handler in Python - AWS Lambda
Example Python Lambda function codeHandler naming conventionsUsing the Lambda event objectAccessing and using the Lambda context objectValid handler signatures for Python handlersReturning a valueUsing the AWS SDK for Python (Boto3) in your handlerAccessing environment variablesCode best practices ...
🌐
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.
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
The provided code is fully functional, but you should make the Python Lambda function your own. Here’s how: Add a print statement to the function. Print statements turn into CloudWatch logs. Customize the JSON in the return clause. This is the data that gets returned to the calling program. The embedded editor allows you to code complex Python function inside the AWS Lambda configuration page.
🌐
Dash0
dash0.com › home › guides › ultimate aws lambda python tutorial with boto3
Ultimate AWS Lambda Python Tutorial with Boto3 · Dash0
March 23, 2026 - Python has a strong foothold in a number of different industries, from web development to artificial intelligence and data science. 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.
🌐
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
To learn more about the Lambda ... in Python. ... The function lambda_handler takes two arguments, event and context. An event in Lambda is a JSON formatted document that contains data for your function to process. If your function is invoked by another AWS service, the event object contains information about the event that caused the invocation. For example, if your function ...
🌐
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
List all Lambda layers and it's info - list_layer_info.py · Use Python modules from layers over the deployment package - use_modules_from_layers
Starred by 29 users
Forked by 20 users
Languages   Python
🌐
W3Schools
w3schools.com › python › python_lambda.asp
Python Lambda
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... A lambda function is a small anonymous function.
🌐
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.
🌐
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 - 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 ...
🌐
Kiro
kiro.dev › powers
Powers - Kiro
3 days ago - Use multiple powers together to create enhanced capabilities. For example, use Stripe power with Dynatrace power to build fullstack application while maintaining observability on realtime performance metrics.
🌐
GitHub
gist.github.com › steinwaywhw › 9d64db15518099c1f26f254ee35c4217
An extremely simple AWS Lambda example in Python 3. · GitHub
In [1]: import main ...: main.setup_roles() ...: main.create_function() ...: main.invoke_function('Jeff', 'Bezos') Out[1]: ... To see the logs generated from the lambda function, we can do
🌐
Frankcorso
frankcorso.dev › frank's blog › python aws lambda function
How To Create Your First Python AWS Lambda Function - Frank's Blog
July 28, 2021 - Once inside Lambda, you will find your Lambda dashboard as shown here: Click on the "Functions" page from within the menu to get to your functions. Next, click on the "Create function" button in the top right. Use the "Author from scratch" option. Name your function anything you want. For the runtime, select a version of Python. If this function were interacting with other parts of the AWS ecosystem, we'd want to set up permissions or an AWS role. But, for this example, we can keep the defaults.
🌐
Grafana
grafana.com › grafana › dashboards
Grafana dashboards | Grafana Labs
Aws · Azure · Collectd · Databases · Docker · Elasticsearch · Hostmetrics · Rabbitmq · Templates · Webservers · Worldping · Zabbix Dashboards with screenshots · Share your dashboards · Export any dashboard from Grafana 3.1 or greater and share your creations with the community.Upload from user portal ·