How To Deploy Python Selenium Script in AWS Lambda in 2022

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • 🌐 NodeMaven Proxy Provider: go.nodemaven.c...
    💥 Special Bonus: Use "Michael" at checkout for an extra +2GB of bandwidth.
    🤖 2captcha Captcha Solving Service: bit.ly/2captch...
    In this video, I am showing you how to create a serverless Python Selenium script and deploy successfully your Python Selenium script in AWS Lambda. We are also going to utilize AWS lambda layers to provide a convenient way to package libraries and other dependencies that you can use with your Lambda functions. Using layers reduces the size of uploaded deployment archives and makes it faster to deploy your code. A layer is a . zip file archive that can contain additional code or data.
    Selenium is an open-source tool that automates web browsers. It provides a single interface that lets you write test scripts in programming languages like Ruby, Java, NodeJS, PHP, Perl, Python, and C#, among others.
    AWS Lambda is serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers
    Playlist: • Python Selenium Tutorial
    Code: github.com/mic...
    Commands: pastebin.com/j...
    Join our Discord: / discord
    Undetectable ChromeDriver: pypi.org/proje...
    Gecko Driver: github.com/moz...
    Chrome Driver: chromedriver.c...
    Download Visual Studio Code: code.visualstu...
    Download Python: www.python.org...
    Selenium Library: pypi.org/proje...
    Donate
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    PayPal: support@websidev.com
    Bitcoin Wallet: bc1q05j8gcnq4mzvgj603cxdc8xxck4jgnu2ljsrt4
    Ethereum Wallet: 0x5e7BD4f473f153d400b39D593A55D68Ce80F8a2e
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: websidev.com
    Linkedin: / michael-kitas-638aa4209
    Instagram: / michael_kitas
    Github: github.com/mic...
    Business Email: support@websidev.com
    Tags:
    - Python Selenium Tutorial
    - Full Course Selenium
    - Python Selenium
    - Web Scraping Full Course
    - Python Selenium Web Scraping Full Course
    #selenium #aws #python

Komentáře • 124

  • @minhthieu2466
    @minhthieu2466 Před rokem +5

    Hello
    I've followed your video carefully and am pretty sure I didn't miss any detail or do anything wrong. However, I got the error:
    "errorMessage": "Unable to import module 'main': No module named 'selenium'",
    "errorType": "Runtime.ImportModuleError",
    "stackTrace": []
    I really hope you can help me with this, I've turn the internet upside down, but so far nothing works

    • @MichaelKitas
      @MichaelKitas  Před rokem +4

      1. Did you add the selenium layer?
      2. Did you connect the layer to the lambda function?
      3. Did you install specifically selenium 3.8.0 and with python 3.7 version with the correct path command which I have in the description?
      Check those 3, as I faced the same issue before recording the video, and the same checklist applied to me as well.

    • @minhthieu2466
      @minhthieu2466 Před rokem +1

      @@MichaelKitas Nevermind, thank you so much, now it's working

    • @miclo_ssx
      @miclo_ssx Před rokem +1

      @@minhthieu2466 well what was the issue

    • @tektonbuilds
      @tektonbuilds Před rokem +1

      @@miclo_ssx he didn't add the selenium layer

    • @AtulKumar-ih2df
      @AtulKumar-ih2df Před rokem

      @@minhthieu2466

  • @utkarshagrawal6844
    @utkarshagrawal6844 Před rokem +8

    Hey Michael, thanks for the absolutely awesome tutorial.
    Just one suggestion -
    In the pastebin script referenced in video description, the 1st command to download selenium dependency incorrectly mentions the installation path as selenium/python/lib.
    It should be python/lib as you showed in the video.
    Thanks

  • @umair.a
    @umair.a Před rokem +11

    Hi Michael, can you make another video on selenium using container implementation to build lambda? It would be a life saver! Thanks in advance

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Great suggestion, will make sure to add it to the list

    • @Alleluia_
      @Alleluia_ Před rokem

      @@MichaelKitas Yes please!!!! Thanks

    • @MichaelKitas
      @MichaelKitas  Před 5 dny

      Just uploaded a new video which supports any python version: czcams.com/video/j_qOVqQDBWw/video.html

  • @lboesch
    @lboesch Před rokem +4

    Hi thanks for the video, this was something that frustrated me in may and dropping it all together. There are plenty of sites with the information, BUT the most important element: this ONLY works with Python 3.7 and Selenium 3.8.
    Following the security mindset, everything back in may was trying to use the latest version =)

    • @sunkun081
      @sunkun081 Před rokem

      Agreed with this. Wish it is compatible with all the python and selenium version.

  • @bindureddy6148
    @bindureddy6148 Před rokem +7

    Hi Michael,
    Thank you so much for such a good video. Recently AWS lambda announced that lambda will not be maintaining Python3.7 anymore . Need to move my code to python 3.11. Not sure how to do this. Can you please make a video to use selenium chrome driver with python 3.11 in lambda? Or can you suggest me a way to solve this?

    • @bindureddy6148
      @bindureddy6148 Před 11 měsíci +1

      Please reply Michael

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci +2

      Many requested this, I've added it to the to-do list, will try to make a video asap

    • @user-ny4tl6rl8h
      @user-ny4tl6rl8h Před 10 měsíci +1

      when will be ready this video?@@MichaelKitas

    • @mikesopinion718
      @mikesopinion718 Před 10 měsíci +1

      please@@MichaelKitas

    • @MichaelKitas
      @MichaelKitas  Před 5 dny

      Just uploaded a new video which supports any python version: czcams.com/video/j_qOVqQDBWw/video.html

  • @celeb_life_in_30
    @celeb_life_in_30 Před rokem +2

    Can't thank you enough for this, I am gonna write a blog and add this video there.

  • @user-es1uc7hs3u
    @user-es1uc7hs3u Před 5 měsíci +2

    Hello bro, Thanks for ur great work , but I got a question
    AWS Lambda end of support for Python 3.7
    so it's not supported anymore at least for layers, do u have another way to get around with this , I would really appreciate this alot!
    Thanks in advance !

    • @MichaelKitas
      @MichaelKitas  Před 4 měsíci

      Yes, making an updated video this week. Hint, check: AWS SAM CLI

  • @nolram248
    @nolram248 Před 3 měsíci +2

    Thanks so much, unfortunately python 3.7 isn't supported any longer. An updated video would be awesome!

    • @MichaelKitas
      @MichaelKitas  Před 3 měsíci +2

      Very soon, working on it, found a solution 👍

    • @mihirsabnis7240
      @mihirsabnis7240 Před 2 měsíci

      @@MichaelKitas How did you get past the error - Error setting up WebDriver: Message: disconnected: unable to connect to renderer? I am using a Docker image.

    • @MichaelKitas
      @MichaelKitas  Před 5 dny

      Just uploaded a new video which supports any python version: czcams.com/video/j_qOVqQDBWw/video.html

    • @mihirsabnis7240
      @mihirsabnis7240 Před 5 dny +1

      @@MichaelKitas damn, thanks for following it up!

    • @nolram248
      @nolram248 Před 5 dny +1

      Thank you very much!

  • @pablorosa2960
    @pablorosa2960 Před rokem +2

    what an incredible tutorial, priceless information very hard to find over the internet.

  • @richardhoppe4991
    @richardhoppe4991 Před rokem +2

    Really awesome tutorial, even I was able to get this up and running!

  • @rosoldamian
    @rosoldamian Před rokem +2

    SUPERB !! i just need to pay attention to the zip path structure, thanks a lot!

  • @user-ny4tl6rl8h
    @user-ny4tl6rl8h Před rokem +4

    I used the same versions but instead I download chromedriver and headless-chromium from s3 to my tmp files (because of the limit size of layers). I got this error: Message: 'chromedriver' executable may have wrong permissions. Do you know how to fix this?

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci

      Check this out: stackoverflow.com/questions/49787327/selenium-on-mac-message-chromedriver-executable-may-have-wrong-permissions

    • @pdfmaker
      @pdfmaker Před 3 měsíci

      hey. im facing the exact same issue. were u able to fix it?

  • @jennydavies6973
    @jennydavies6973 Před 16 dny

    Hi Michael, in a few comments you talk about an updated video that doesn't rely on a deprecated version of Python. If this video exists, can you please provide a link here

  • @pablorosa2960
    @pablorosa2960 Před rokem +3

    i've been working with python 3.9 and i am struggle with this error : "Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127"
    Does anyone have any idea how to fix it? I have followed step by step very carefully

    • @khushindarshan156
      @khushindarshan156 Před rokem +1

      same issue with me as well. Strugling with this from past few days and tried almost all the options available on internet. But still can't figure out. Did you got the solution??

    • @MichaelKitas
      @MichaelKitas  Před rokem +1

      AWS gives us the option to set up specific runtime for each lambda function. Use the same version as I said, and there shouldn't be an issue.

    • @VIKASSAINI007
      @VIKASSAINI007 Před 6 měsíci

      @@khushindarshan156 It is an version issue, it will only run on 3.7, any higher version will give 127 error

    • @leandrovillalobos6129
      @leandrovillalobos6129 Před 5 měsíci +1

      @@VIKASSAINI007 there's a way to make it work with 3.8 or later?, aws ends support for 3.7, so it can't be created anyways

  • @mauriciobertolucci
    @mauriciobertolucci Před rokem +2

    Hello, thanks for sharing. I tested it and it worked perfectly as in the video, but I have a question. I couldn't get it to work with newer versions of the libraries. Why does this happen? Today I have several codes implemented with the latest versions and it would be a lot of work to adapt the old versions. Tks

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci

      Many requested this, I've added it to the to-do list, will try to make a video asap

  • @austinsketches
    @austinsketches Před rokem +2

    How did you manage to make headless-chromium turn from 102,6 MB uncompressed to 5,1 MB uncompressed at the 9:50 mark? It's like the number just changes without any explanation. How are you able to upload headless-chromium and chromedriver without exceeding the Layer size limit of 50MB? The exact same file uncompressed on my system is 100MB as well. I'd prefer not to have to use S3

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Are you using Mac? That’s how much it is compressed using the Mac’s compression (Under 50mb). Using another software would for sure give different results.

  • @qwerty4r5tgy
    @qwerty4r5tgy Před 11 měsíci +2

    thank you so much.
    It was my big problem. you saved my time.!

  • @serggurzhy4622
    @serggurzhy4622 Před rokem +2

    Thank you for your work. I want to run Selenium4.8. and Request I have a urllib3 library conflict. what could be the problem?

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Can you send screenshot (send url of screenshot) of the error?

  • @asdfghjkl36958
    @asdfghjkl36958 Před 8 měsíci +2

    Thanks for sharing this, incredibly helpful!

  • @ameeshagupta2559
    @ameeshagupta2559 Před rokem +2

    Hi, Which selenium version is compatible with Python 3.9 lambda version??

  • @benedictejelonu
    @benedictejelonu Před 11 dny +1

    Hello Michael and everyone, does anyone have where I can find compatible versions for headless chrome and selenium that supports Python3.8?

    • @MichaelKitas
      @MichaelKitas  Před 5 dny +1

      Just uploaded a new video which supports any python version: czcams.com/video/j_qOVqQDBWw/video.html

  • @user-zy7qo3ch1s
    @user-zy7qo3ch1s Před rokem +2

    Hello, thanks for the video, but but when i am adding the layer of chormdrive there, i got a error 'Layers consume more than the available size of 262144000 bytes'

    • @alexkeila
      @alexkeila Před rokem +1

      I have the same issue!! The chromedriver ZIP is a larger file than the ones from the other layers.

    • @user-zy7qo3ch1s
      @user-zy7qo3ch1s Před rokem +1

      @@alexkeila I have managed to solve that by using the exact version of selenium , however , the one run on lambda does not have the same result as I run on my local machine

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci

      You need to use the exact version of selenium as @user-zy7qo3ch1s mentioned.

  • @kevinalarconqusipe6666
    @kevinalarconqusipe6666 Před 5 měsíci +1

    Hi, I have this error: "errorMessage": "2024-03-12T04:26:45.989Z 394e1df8-6683-4e3b-aa9c-da1864b9bba9 Task timed out after 20.01 seconds". I followed all steps but this error appears.

    • @MichaelKitas
      @MichaelKitas  Před 4 měsíci

      Maybe increase timeout? Probably doesnt have enough time to complete the script

  • @richardpassett924
    @richardpassett924 Před rokem +2

    This is amazing, thank you!

  • @GANGSTA_CHUROOO
    @GANGSTA_CHUROOO Před 9 měsíci +1

    using the commands provided, it downloads the chromedriver and the headless chromium but it doesnt open, it always says that the file format is not supported or is broken

    • @MichaelKitas
      @MichaelKitas  Před 4 měsíci

      Going to make an updated video today, stay tuned.

    • @mihirsabnis7240
      @mihirsabnis7240 Před 3 měsíci

      @@MichaelKitas Hey Michael, when can we expect the updated video?

  • @federicovazquezmorales4510

    Thank you very much! It works!

  • @kkkennnlii
    @kkkennnlii Před rokem +1

    aws lambda gonna end support for Python 3.7. Also it seems like the current setup we got cannot be migrated to python 3.11. I tried to migrate but chromedriver couldnt start. How should we go from here, Michael?

    • @kkkennnlii
      @kkkennnlii Před rokem

      @MichaelKitas

    • @bindureddy6148
      @bindureddy6148 Před rokem

      Let me know if you find a way to work the code in python 3.11

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci

      Many requested this, I've added it to the to-do list, will try to make a video asap

    • @VIKASSAINI007
      @VIKASSAINI007 Před 6 měsíci

      @@MichaelKitas Still waiting, I guess docker container is the only option

    • @MichaelKitas
      @MichaelKitas  Před 5 dny

      Just uploaded a new video which supports any python version: czcams.com/video/j_qOVqQDBWw/video.html

  • @diegotenorio7793
    @diegotenorio7793 Před rokem +1

    I get the message below when putting it to test:
    {
    "errorMessage": "'module' object is not callable",
    "errorType": "TypeError",
    "stackTrace": [
    " File \"/var/runtime/bootstrap.py\", line 127, in handle_event_request
    response = request_handler(event, lambda_context)
    "
    ]
    }
    can you help me?

  • @ghoulflier1016
    @ghoulflier1016 Před rokem +2

    Ok, so how can I know which version of Python, Selenium and Chromedriver works with Lambda?

    • @MichaelKitas
      @MichaelKitas  Před rokem +1

      I showed on the video the versions I used

    • @ghoulflier1016
      @ghoulflier1016 Před rokem +2

      @@MichaelKitas Yes, and only that version works for me. But how do I know when AWS supports newer versions and which combination of python, selenium and chromedriver? I don't want to operate with 3.7 forever.

    • @MichaelKitas
      @MichaelKitas  Před rokem +1

      ​@@ghoulflier1016 Not sure, I don't think there is a specific combination each time

    • @ghoulflier1016
      @ghoulflier1016 Před rokem +3

      @@MichaelKitas Thank you anyways for your great videos. They are such a big help for me to get started with Selenium!

  • @user-ju3ng2uq2r
    @user-ju3ng2uq2r Před rokem +1

    Hello Michael ,
    How to Making Captcha Breaking Script Work in AWS Lambda

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Same way you do it locally, I have made a video for bypassing captcha, check it out here: czcams.com/video/5puz9Mb2d_c/video.html

  • @coderlicious6565
    @coderlicious6565 Před rokem +1

    Very informative.
    Do you know if there is a way to configure your AWS lambda account, to tell Amazon a max dollar amount you want to spend, and then if you accidentally exceed that amount with your resources, they either immediately notify you, or just simply shut down your site? I'd prefer it works that way.
    I'd hate to get a big surprise bill from amazon, because I didn't know my code was very inefficient, and the code was spending too much time during a function invocation.

    • @MichaelKitas
      @MichaelKitas  Před rokem +1

      Yes, check how to do that here: aws.amazon.com/getting-started/hands-on/control-your-costs-free-tier-budgets/

    • @coderlicious6565
      @coderlicious6565 Před rokem

      @@MichaelKitas Thank you

  • @mrsseeppoo
    @mrsseeppoo Před rokem +1

    Hi I want to use undetected-chromedriver in my AWS lambda, which version is compliant with selenium 3.8.0?

    • @MichaelKitas
      @MichaelKitas  Před rokem +1

      I think latest version works: pypi.org/project/undetected-chromedriver/3.4.7/
      It says Python3.6 and newer, so latest works

    • @pedrodellazzari528
      @pedrodellazzari528 Před rokem

      Did you get it to run with Undetected-chromedriver? I'm also trying to run in Lambda but I can't make it work at all

    • @mrsseeppoo
      @mrsseeppoo Před rokem

      @@pedrodellazzari528 unfortunately no.

  • @vicalomen
    @vicalomen Před rokem +1

    Do you know about this error "errorMessage": "Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127
    ",?

    • @vicalomen
      @vicalomen Před rokem

      Python version must be 3.7 and selenium 3.8.0

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Yes, first of all did you add chromedriver as a layer?

    • @celeb_life_in_30
      @celeb_life_in_30 Před rokem

      I was also getting the same error when I was using latest selenium and chromedriver version.

  • @elsavandenberghe4965
    @elsavandenberghe4965 Před rokem

    Hi, I keep getting the error "no chrome binary at /var/taskheadless-chromium
    ". I added the selenium layer, connected it to the lambda function and installed the specific versions you had. Nothing is working to fix it.

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Did you add correct executable path? It’s searching in the wrong place

  • @LinykerVinicius
    @LinykerVinicius Před 3 měsíci

    Message: Service /opt/chromedriver unexpectedly exited. Status code was: 127
    :(

    • @zozoland9057
      @zozoland9057 Před 3 měsíci

      I had the same issue, and did not find anything that could solve it. Apparently a new tutorial is on the way!

    • @samiullah_991
      @samiullah_991 Před 13 dny

      @@zozoland9057 Hey bro, did you find the new tutorial video?

  • @user-st1qr6et5h
    @user-st1qr6et5h Před rokem +1

    It works for me.
    does anyone knows if there is a way to do it in python3.9 or python3.8? i did not found a solution without the use of a 5xxmb approx docker image

    • @user-st1qr6et5h
      @user-st1qr6et5h Před rokem +1

      My concern is because python3.7 is "deprecated" since june 2023, and if aws lambda does not support it anymore, we are done...

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci

      Looking for a solution and will make a video for newer version

    • @kapilbadokar
      @kapilbadokar Před 8 měsíci

      @@user-st1qr6et5h So if i want to do it now, Can't i do it with python 3.7 ? Please elaborate more . And if I have to use Python3.9/3.10 then What versions of chromedriver and headless chromium should i use?

    • @MichaelKitas
      @MichaelKitas  Před 5 dny

      Just uploaded a new video which supports any python version: czcams.com/video/j_qOVqQDBWw/video.html

  • @utkarshagrawal6844
    @utkarshagrawal6844 Před rokem +1

    what is the name of vscode theme you are using ?

  • @user-wr7lm9mo5y
    @user-wr7lm9mo5y Před 11 měsíci +1

    Hey Mike! This can work with 'playwright'?

    • @MichaelKitas
      @MichaelKitas  Před 10 měsíci

      Not sure, will add a series for playwright in the future, and try it

  • @user-ks5mf6eb6f
    @user-ks5mf6eb6f Před rokem

    Hello. Thank you for so necessary video. How could you upload the file more than 10Mb in the layer? (chromedriver.zip 44.6Mb) System should had to make you to upload through S3. Is not it?

    • @MichaelKitas
      @MichaelKitas  Před rokem

      Yes, you can use S3, max is 50mb if not using s3

  • @Fx-Weevils
    @Fx-Weevils Před rokem

    Is it possible to teach how to create a website or blog traffic bot that uses VPS and sends requests from Virtual Private server 🙏🙏

    • @MichaelKitas
      @MichaelKitas  Před rokem +1

      Very specific, but I might do that in the future, stay tuned!

  • @sudiptobose8522
    @sudiptobose8522 Před rokem

    Does downloading the chromedriver on windows follows the same command?

    • @MichaelKitas
      @MichaelKitas  Před rokem

      You can download chromedriver from the official website: chromedriver.chromium.org/downloads

    • @nekhumbecolbert2452
      @nekhumbecolbert2452 Před rokem

      @@MichaelKitas for windows, do we also need to download the headless chromium like you did on the video or just a chrome driver downloaded from the site you mentioned above is okay?if yes, where do i download the headless chromium?

  • @kapilbadokar
    @kapilbadokar Před 8 měsíci +1

    I have done exactly the same as shown in the video . But when i run I get this response .-> {
    "errorMessage": "Syntax error in module 'main': invalid syntax (selenium_manager.py, line 46)",
    "errorType": "Runtime.UserCodeSyntaxError",
    "stackTrace": [
    " File \"/opt/python/lib/python3.7/site-packages/selenium/webdriver/common/selenium_manager.py\" Line 46
    if (path := os.getenv(\"SE_MANAGER_PATH\")) is not None:
    "
    ]
    }

    • @MichaelKitas
      @MichaelKitas  Před 4 měsíci

      Going to make an updated video today, stay tuned.