'AWS Lambda Container handler issue - chromedriver/selenium

I am new to the AWS platform and have been trying out some new Lambda stuff.

I am attempting to use a Python script to utilise selenium/chromedriver and scrape some data from the internet.

I have been able to set up a local docker image, which contains a python script to grab some data and return it.

My Dockerfile -

FROM lambci/lambda:python3.6
MAINTAINER [email protected]

USER root

ENV APP_DIR /var/task

WORKDIR $APP_DIR

COPY requirements.txt .
COPY bin ./bin
COPY lib ./lib

RUN mkdir -p $APP_DIR/lib
#RUN pip3 install -r requirements.txt -t /var/task/lib
RUN pip3 install selenium==2.53.0

COPY src/lambda_function.py ./
CMD [ "lambda_function.lambda_handler" ]

My lambda function -

import time
import json
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys


def lambda_handler(event, context):
    chrome_options = webdriver.ChromeOptions()
  

    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--window-size=1280x1696')
   
    chrome_options.add_argument('--hide-scrollbars')
    chrome_options.add_argument('--enable-logging')
    chrome_options.add_argument('--log-level=0')
    chrome_options.add_argument('--v=99')
    chrome_options.add_argument('--single-process')

    chrome_options.add_argument('--ignore-certificate-errors')
    

    chrome_options.add_argument(
        'user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36')

    chrome_options.binary_location = os.getcwd() + "/bin/headless-chromium"


    driver = webdriver.Chrome(executable_path=os.getcwd() +"/bin/chromedriver", chrome_options=chrome_options)
  # driver = WebDriverWrapper()

    driver.get_url('http://example.com')
    example_text = driver.get_inner_html('(//div//h1)[1]')
    
    return example_text 

I was able to build my docker image by running - docker-compose build.

Then when i run the image inside of docker, it executes correctly and returns the expected output with no issues.

Then I use the AWS CLI functions and tag this image and then push to a AWS repo. Then i add this image into my AWS Lambda configuration. When i test it out - i am getting this error -

Bad handler '': not enough values to unpack (expected 2, got 1)

I am not sure what to try next? It all runs fine locally, and this is meant to be packaged and up and deployed as is to AWS.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source