Most Cloud platforms provide function running features like Google Cloud function, AWS lambda function. In this piece of article, I would share how to upload scripts, packages and deploy functions on AWS Lambda using Python. If you are a newbie on AWS Lambda, you can start running functions after having finished this piece. Keep it up!
Table of Content: Run Python Functions using AWS Lambda
- Create Python Packages in your Local Device
- A New Layer for Uploading the Python Packages on AWS Lambda
- Upload main function script and set up
- Add Lay Customization
- AWS Lambda Playbook
Create Python Packages in your Local Device
For AWS lambda, you can determine which programming language you use to set up the functions such as Python, Node.js, etc. Here I select Python and here is the command in Macbook terminal to create a folder that contains the Python libraries you need for the functions.
pip install requests==2.29.0 pandas==2.0.1 -t python/lib/python3.9/site-packages
After having created the folder, we need to zip it because it’s required to upload in zip format
A New Layer for Uploading the Python Packages on AWS Lambda
For uploading the Python zip file, first thing first we need to create AWS functions and a new layer in the function.
In the setting, we name it, set the architectures as x86_64, and select to run Python 3.9.
Upload main function script and Function Configuration
Then, we would need to upload the zipped function file as well. Naming the function is a key section. Please be sure to name the function as well as y. our file name. For example, if your function named ‘main’, please enter main, which is main.main
For the configuration, I would suggest setting the capacity as much as possible. For instance, longer timeouts help to run functions that cost longer time, such as machine learning script. Here is the sample as follows FYI:
- Memory: 1000 MB
- Ephemeral Storage 512 MB
- Timeout 2 mins
Add the Custom Layer
Things are closer to being done. Last but not least, we need to add the Python package layer as we created earlier above. If you have more layers created for different purposes, please be sure to add here as well
Full Python Functions script of BuyfromLo AI Content Generator Scripts Used on AWS Lambda Function
- If you are interested in learning more advanced AWS Lambda tips and tricks, please subscribe to our Youtube Channel and comment “lambda” in the following video (Lambda Playbook)
- Support our channel through PayPal (paypal.me/Easy2digital)
- Follow our Facebook page
- Sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount code on Buyfromlo products and digital software