As it is described in the Amazon official documentation link here It is as simple as just creating a zip of all the folder contents after installing the required packages in your folder where you have your python lambda code.
As Vineeth pointed above in his comment, The very first step in moving from an inline code editor to a zip file upload approach is to change your lambda function handler name under configuration settings to include the python script file name that holds the lambda handler.
lambda_handler => {your-python-script-file-name}.lambda_handler.

Other solutions like python-lambda and lambda-uploader help with simplifying the process of uploading and the most importantly LOCAL TESTING. These will save a lot of time in development.
Answer from Santhosh Gandhe on Stack OverflowAs it is described in the Amazon official documentation link here It is as simple as just creating a zip of all the folder contents after installing the required packages in your folder where you have your python lambda code.
As Vineeth pointed above in his comment, The very first step in moving from an inline code editor to a zip file upload approach is to change your lambda function handler name under configuration settings to include the python script file name that holds the lambda handler.
lambda_handler => {your-python-script-file-name}.lambda_handler.

Other solutions like python-lambda and lambda-uploader help with simplifying the process of uploading and the most importantly LOCAL TESTING. These will save a lot of time in development.
The official documentation is pretty good. In a nutshell, you need to create a zip file of a directory containing both the code of your lambda function and all external libraries you use at the top level.
You can simulate that by deactivating your virtualenv, copying all your required libraries into the working directory (which is always in sys.path if you invoke a script on the command line), and checking whether your script still works.
Simple Technique to Pip Install Packages in AWS Lambda
Lambda with Python libraries
[technical resource]How to install python packages on AWS Lambda.
How can I add third party python dependencies to a Lambda function?
Utilizing third-party packages is a staple in most Python projects, making the pip installation process indispensable. However, when working with AWS Lambda functions in Python, integrating these packages can present a unique set of challenges. This tutorial delves into a variety of approaches, ranging from downloading wheel files to leveraging Docker. Yet, the focus here is on a remarkably efficient technique: direct pip installation within the Lambda environment itself.
While acknowledging its constraints, this method proves to be highly practical, particularly for straightforward projects or less complex codebases. The tutorial offers a step-by-step guide, demonstrating the convenience and applicability of this approach in real-world scenarios. Dive into the details by watching the accompanying video, where I walk you through each stage of this process.
https://www.youtube.com/watch?v=ESZCzUbdZuc
Be sure to subscribe to my channel as that would be greatly appreciated if to support me, especially if you like full-stack engineering, Python, IoT, and more. Thanks Reddit.
I've deployed Python runtime Lambda functions that require functions outside the standard library a couple of different ways:
-
Layers. Pros: really simple to attach once they are created. Cons: I don't like having a bunch of layers lying around in my Lambda UI. I don't like maintaining when new versions need to be attached, either. I've not created them using CloudFormation yet, though I see it can be done.
-
Installing libraries locally in my Git repo with my Lambda handler file, then zipping up the entire folder when committing and deploying. Pros: easy to do, easy to keep the version of the library tightly coupled with the project. Cons: pollutes my Git repo with potentially hundreds of files that I'm not really tracking. Takes longer to deploy the function each time.
-
Bundling the whole thing up as a Docker image and deploying that way. Pros: really clean to execute. Cons: more overhead with building containers, which I usually do in CodeBuild for reasons. Takes a while to deploy the image each time, and I think slower cold starts if the function hasn't been invoked in a while.
Am I missing any other options? What do you use and why?
Hey, how do i install boto3-type-annotations in my lambda function.Do i just:
!pip install boto3-type-annotations at the begging of the .py file