LoginSignup
3
0

More than 1 year has passed since last update.

AWS LambdaでSeleniumを動かすときに"Unable to import module 'lambda_function': urllib3 v2.0 only supports OpenSSL 1.1.1+, …

Posted at

問題

AWS Lambda PythonでSeleniumを使える環境を構築する | DevelopersIO
こちらの記事に従い、サンプルコードを実行したところ以下のエラーが出た。

Response
{
  "errorMessage": "Unable to import module 'lambda_function': urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with OpenSSL 1.0.2k-fips  26 Jan 2017. See: https://github.com/urllib3/urllib3/issues/2168",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}

どうやらurllib3のバージョン2以降がOpenSSLのバージョンに適合しないらしい。
調べたところOpenSSLのバージョンはLambda的に出来ないらしいので、2通りの解決法を提示する。

解決1

python3.6環境で

pip install selenium -t python/lib/python3.7/site-packages

を実行し、作成された「python」フォルダをzip化してLambda Layerにアップロードする。

こうすればurllib3が1.26.15でインストールされるので解決ではあるが、できたらPython3.7でやりたくはある。
CloudShellでやるのがめんどかったのでローカルで作成してアップしたところ正常に動作した。
手元にPython3.6がある人におすすめ

解決2

CloudShell上で

pip3 install selenium==3.141.0 -t ./python/lib/python3.7/site-packages --use-feature=2020-resolver

した後に、

pip3 install urllib3==1.26.15 -t ./python/lib/python3.7/site-packages --use-feature=2020-resolver --upgrade

でurllib3のバージョンを1.26.15にし、「python」フォルダをzip化してLambda Layerにアップロードする。

こっちのほうがCloudShell上で完結するのでスマート

いずれの方法もLambda Layerをアップデートして、関数のレイヤー設定でバージョン設定を更新しないと反映されないので注意。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0