Chapter 84 – Run Python Functions using AWS Lambda

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!

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

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 your 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:

  1. Memory: 1000 MB
  2. Ephemeral Storage 512 MB
  3. 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 Chapter 84 – Run Python Functions using AWS Lambda, please subscribe to our newsletter by adding the message ‘Chapter 84+ Full scripts of AI Content Generator using Buyfroml API. We would send you the script when the up-to-date app script is live.

I hope you enjoy reading Chapter 84 – Run Python Functions using AWS Lambda. If you did, please support us by doing one of the things listed below, because it always helps out our channel.