Open1

python requests (Custom AWS Lambda Layer)

marchanmarchan
  • 2024.04.23
  • requests 2.31.0をダウンロード
  • 対応するpythonのバージョン
     3.7
     3.8
     3.9
     3.10
     3.11

Cloud9 でrequests をダウンロード

  • python ディレクトリを作成
(venv312) :~/environment/install-python $ mkdir python
(venv312) :~/environment/install-python $ cd python
  • python ディレクトリにrequets モジュールをダウンロード
(venv312) :~/environment/install-python/python $ pip install requests -t ~/environment/install-python/python

Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
Successfully installed certifi-2024.2.2 charset-normalizer-3.3.2 idna-3.7 requests-2.31.0 urllib3-2.2.1
[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: pip install --upgrade pip

  • ダウンロードされたファイルを確認する
(venv312) :~/environment/install-python/python $ ls -l

total 48
drwxr-xr-x. 2 ec2-user ec2-user 24 Apr 23 00:59 bin
drwxr-xr-x. 3 ec2-user ec2-user 112 Apr 23 00:59 certifi
drwxr-xr-x. 2 ec2-user ec2-user 102 Apr 23 00:59 certifi-2024.2.2.dist-info
drwxr-xr-x. 4 ec2-user ec2-user 16384 Apr 23 00:59 charset_normalizer
drwxr-xr-x. 2 ec2-user ec2-user 126 Apr 23 00:59 charset_normalizer-3.3.2.dist-info
drwxr-xr-x. 3 ec2-user ec2-user 190 Apr 23 00:59 idna
drwxr-xr-x. 2 ec2-user ec2-user 84 Apr 23 00:59 idna-3.7.dist-info
drwxr-xr-x. 3 ec2-user ec2-user 16384 Apr 23 00:59 requests
drwxr-xr-x. 2 ec2-user ec2-user 119 Apr 23 00:59 requests-2.31.0.dist-info
drwxr-xr-x. 5 ec2-user ec2-user 16384 Apr 23 00:59 urllib3
drwxr-xr-x. 3 ec2-user ec2-user 82 Apr 23 00:59 urllib3-2.2.1.dist-info

  • ディレクトリを移動
(venv312) :~/environment/install-python/python $ cd ..
  • zip 圧縮してファイル名をrequests_layer.zipとする。
(venv312) :~/environment/install-python $ zip -r requests_layer.zip python/

adding: python/urllib3/_base_connection.py (deflated 73%)
adding: python/urllib3/init.py (deflated 61%)
adding: python/bin/ (stored 0%)
adding: python/bin/normalizer (deflated 27%)

  • 作成されたファイルを確認する。
(venv312) :~/environment/install-python $ ls -l

total 27980
drwx------. 19 ec2-user ec2-user 16384 Apr 22 08:02 Python-3.12.0
-rw-r--r--. 1 ec2-user ec2-user 27195214 Oct 2 2023 Python-3.12.0.tgz
drwxr-xr-x. 6 ec2-user ec2-user 104 Apr 22 02:31 beatifulsoup
-rw-r--r--. 1 ec2-user ec2-user 398166 Apr 22 02:33 beatifulsoup_python_layer.zip
drwxr-xr-x. 13 ec2-user ec2-user 16384 Apr 23 00:59 python
-rw-r--r--. 1 ec2-user ec2-user 1019131 Apr 23 01:01 requests_layer.zip ●
drwxr-xr-x. 5 ec2-user ec2-user 74 Apr 22 08:04 venv312

  • ディレクトリのファイルを確認する
(venv312) :~/environment/install-python/requests $ ls -l

total 48
drwxr-xr-x. 2 ec2-user ec2-user 24 Apr 23 00:59 bin
drwxr-xr-x. 3 ec2-user ec2-user 112 Apr 23 00:59 certifi
drwxr-xr-x. 2 ec2-user ec2-user 102 Apr 23 00:59 certifi-2024.2.2.dist-info
drwxr-xr-x. 4 ec2-user ec2-user 16384 Apr 23 00:59 charset_normalizer
drwxr-xr-x. 2 ec2-user ec2-user 126 Apr 23 00:59 charset_normalizer-3.3.2.dist-info
drwxr-xr-x. 3 ec2-user ec2-user 190 Apr 23 00:59 idna
drwxr-xr-x. 2 ec2-user ec2-user 84 Apr 23 00:59 idna-3.7.dist-info
drwxr-xr-x. 3 ec2-user ec2-user 16384 Apr 23 00:59 requests
drwxr-xr-x. 2 ec2-user ec2-user 119 Apr 23 00:59 requests-2.31.0.dist-info
drwxr-xr-x. 5 ec2-user ec2-user 16384 Apr 23 00:59 urllib3
drwxr-xr-x. 3 ec2-user ec2-user 82 Apr 23 00:59 urllib3-2.2.1.dist-info

  • requsts モジュールのバージョンと 対応するpython バージョンを調べる
(venv312) :~/environment/install-python/requests $ cat requests-2.31.0.dist-info/METADATA

Metadata-Version: 2.1
Name: requests
Version: 2.31.0 ●
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Project-URL: Documentation, https://requests.readthedocs.io
Project-URL: Source, https://github.com/psf/requests
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7●
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11●
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.7 ●