Skip to content

How to upload a Lambda Layer to work with selenium (Python 3.12)

0

Hi community

I need help please. I have a lambda function (arm64) for web scraping with selenium (I'm using Python 3.12), but I need to upload a Lambda Layer that includes Selenium and the webdriver binaries. How the lambda layer must be created?

asked 2 years ago1K views

1 Answer
0

To create and upload a Lambda Layer for Selenium with Python 3.12 on an arm64 architecture, you'll need to follow these steps:

  1. Set up a Python 3.12 virtual environment on an ARM-based machine or use an ARM-based EC2 instance to ensure compatibility.

  2. Install Selenium and the necessary webdriver binaries in this environment. You can use pip to install Selenium:

    pip install selenium

  3. Download the appropriate ARM64 webdriver binaries for the browsers you intend to use (e.g., ChromeDriver for Chrome).

  4. Create a directory structure for your layer. The structure should look like this:

    python/lib/python3.12/site-packages/ bin/

  5. Copy the contents of your virtual environment's site-packages directory (including Selenium) into the python/lib/python3.12/site-packages/ directory.

  6. Place the webdriver binaries in the bin/ directory.

  7. Zip the entire contents of this directory structure. The resulting zip file will be your Lambda Layer.

  8. Upload the layer to AWS Lambda:

    • Open the AWS Lambda console
    • Navigate to "Layers" in the left sidebar
    • Click "Create layer"
    • Provide a name for your layer (e.g., "selenium-python312-arm64")
    • Upload the zip file you created
    • Select Python 3.12 as the compatible runtime
    • Choose "arm64" as the compatible architecture
    • Click "Create" to finalize the layer creation
  9. Once created, you can attach this layer to your Lambda function by selecting it in the function's configuration under the "Layers" section.

Remember to set the appropriate environment variables in your Lambda function to locate the webdriver binaries, typically by adding the /opt/bin directory to the PATH.

This process ensures that your Selenium layer is compatible with Python 3.12 and the arm64 architecture of your Lambda function.
Sources
Working with layers for Python Lambda functions - AWS Lambda
Community | Step-by-Step Guide to Creating an AWS Lambda Function Layer
Working with layers for Node.js Lambda functions - AWS Lambda

answered 2 years ago

AWS
EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

  • Thanks for the response, but I tested and it's still not detecting the chromedriver.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.