If you’re looking to use selenium and headless browsers on amazon web services (AWS) its essential that you install the relevant versions of selenium, ChromeDriver and Google Chrome to your EC2 instance. In this guide you’ll learn how to easily deploy and test a fully functional selenium python environment.


Install ChromeDriver

You will need to install ChromeDriver which allows you programmatic access to google chrome via the Webdriver API protocol.

  1. Navigating to the /tmp/ folder.
  2. Using wget to download chromedriver.
  3. Unzipping chromedriver.
  4. Moving chromedriver to the usr/bin folder.
  5. Inspecting the current version of chromedriver.

Install Google Chrome

Then you’ll need to download and install the Google Chrome binary for your EC2 instance.

  1. Curl downloads the google-chrome binary.
  2. The google-chrome binary is then moved into usr/bin (by default linux expects your google chrome executable be within this directory.
  3. The google-chrome –version && which google-chrome commands allow you to view whether the installation was successful and the current version of chrome. Its’ worth double checking that your chromedriver and google chrome versions are the same version.

Installing Selenium

Now install selenium for python 3x with the following command:

If you still need to setup pip3 on your EC2 instance, you can visit this post here.


Adding Arguments To Your Selenium ChromeDriver

From my initial testing, I would recommend adding all of the following arguments when initialising selenium in a production environment:


Test Your Connection

I’ve created a python script that you can use to make sure everything is working correctly. Simply SSH into your EC2 instance, enter a python3 environment and run the following script:


If the test was successful, you should have printed the top headline from github.com which at this current time says: Built for developers

What's your reaction?
Show CommentsClose Comments

4 Comments

  • Dayan Ahmed
    Posted March 5, 2020 at 7:04 am 0Likes

    Facing an error in chromedriver –version
    {chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory}

    • James Phoenix
      Posted March 5, 2020 at 11:17 pm 0Likes

      Did you manually install package libnss3-dev (debian) ?

      Try doing that and it will hopefully fix your error Dayan πŸ™‚

      • Dayan Ahmed
        Posted March 6, 2020 at 6:44 am 0Likes

        No, I haven’t install this. But Well My problem is solved by using this command.
        $sudo chown root:root /usr/bin/chromedriver
        $sudo chmod +x /usr/bin/chromedriver
        I think it was the issue of administrative rights.
        But now it is solved. Thanks

        • James Phoenix
          Posted March 6, 2020 at 10:24 pm 0Likes

          I’m glad that you found a solution! Good luck with AWS πŸ™‚

Comments are closed.