Open1

google-auth-lib(Custom AWS Lambda Layer)

marchanmarchan

-- 2025.05.12

Cloud9 Amazon Linux2 で作業する

python のバージョンを確認する

$ python --version

Python 3.12.0

ディレクトリを新規作成する

mkdir python
ls -ls

0 drwxrwxr-x 2 ec2-user ec2-user 6 May 13 06:03 python

インストールする

$ pip install google-auth-oauthlib  -t ./python

Collecting google-auth-oauthlib
Downloading google_auth_oauthlib-1.2.2-py3-none-any.whl.metadata (2.7 kB)
Collecting google-auth>=2.15.0 (from google-auth-oauthlib)
Using cached google_auth-2.40.1-py2.py3-none-any.whl.metadata (6.2 kB)
Collecting requests-oauthlib>=0.7.0 (from google-auth-oauthlib)
Using cached requests_oauthlib-2.0.0-py2.py3-none-any.whl.metadata (11 kB)
Collecting cachetools<6.0,>=2.0.0 (from google-auth>=2.15.0->google-auth-oauthlib)
Using cached cachetools-5.5.2-py3-none-any.whl.metadata (5.4 kB)
Collecting pyasn1-modules>=0.2.1 (from google-auth>=2.15.0->google-auth-oauthlib)
Using cached pyasn1_modules-0.4.2-py3-none-any.whl.metadata (3.5 kB)
Collecting rsa<5,>=3.1.4 (from google-auth>=2.15.0->google-auth-oauthlib)
Using cached rsa-4.9.1-py3-none-any.whl.metadata (5.6 kB)
Collecting oauthlib>=3.0.0 (from requests-oauthlib>=0.7.0->google-auth-oauthlib)
Using cached oauthlib-3.2.2-py3-none-any.whl.metadata (7.5 kB)
Collecting requests>=2.0.0 (from requests-oauthlib>=0.7.0->google-auth-oauthlib)
Using cached requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
Collecting pyasn1<0.7.0,>=0.6.1 (from pyasn1-modules>=0.2.1->google-auth>=2.15.0->google-auth-oauthlib)
Using cached pyasn1-0.6.1-py3-none-any.whl.metadata (8.4 kB)
Collecting charset-normalizer<4,>=2 (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib)
Using cached charset_normalizer-3.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (35 kB)
Collecting idna<4,>=2.5 (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib)
Using cached idna-3.10-py3-none-any.whl.metadata (10 kB)
Collecting urllib3<3,>=1.21.1 (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib)
Using cached urllib3-2.4.0-py3-none-any.whl.metadata (6.5 kB)
Collecting certifi>=2017.4.17 (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib)
Using cached certifi-2025.4.26-py3-none-any.whl.metadata (2.5 kB)
Downloading google_auth_oauthlib-1.2.2-py3-none-any.whl (19 kB)
Using cached google_auth-2.40.1-py2.py3-none-any.whl (216 kB)
Using cached requests_oauthlib-2.0.0-py2.py3-none-any.whl (24 kB)
Using cached cachetools-5.5.2-py3-none-any.whl (10 kB)
Using cached oauthlib-3.2.2-py3-none-any.whl (151 kB)
Using cached pyasn1_modules-0.4.2-py3-none-any.whl (181 kB)
Using cached requests-2.32.3-py3-none-any.whl (64 kB)
Using cached rsa-4.9.1-py3-none-any.whl (34 kB)
Using cached certifi-2025.4.26-py3-none-any.whl (159 kB)
Using cached charset_normalizer-3.4.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148 kB)
Using cached idna-3.10-py3-none-any.whl (70 kB)
Using cached pyasn1-0.6.1-py3-none-any.whl (83 kB)
Using cached urllib3-2.4.0-py3-none-any.whl (128 kB)
Installing collected packages: urllib3, pyasn1, oauthlib, idna, charset-normalizer, certifi, cachetools, rsa, requests, pyasn1-modules, requests-oauthlib, google-auth, google-auth-oauthlib
Successfully installed cachetools-5.5.2 certifi-2025.4.26 charset-normalizer-3.4.2 google-auth-2.40.1 google-auth-oauthlib-1.2.2 idna-3.10 oauthlib-3.2.2 pyasn1-0.6.1 pyasn1-modules-0.4.2 requests-2.32.3 requests-oauthlib-2.0.0 rsa-4.9.1 urllib3-2.4.0

確認する

$ cd python 
$ ls -ls 

total 16
0 drwxrwxr-x 2 ec2-user ec2-user 174 May 13 06:04 bin
0 drwxrwxr-x 3 ec2-user ec2-user 96 May 13 06:04 cachetools
0 drwxrwxr-x 2 ec2-user ec2-user 102 May 13 06:04 cachetools-5.5.2.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 112 May 13 06:04 certifi
0 drwxrwxr-x 3 ec2-user ec2-user 103 May 13 06:04 certifi-2025.4.26.dist-info
0 drwxrwxr-x 4 ec2-user ec2-user 308 May 13 06:04 charset_normalizer
0 drwxrwxr-x 3 ec2-user ec2-user 127 May 13 06:04 charset_normalizer-3.4.2.dist-info
0 drwxrwxr-x 4 ec2-user ec2-user 32 May 13 06:04 google
0 drwxrwxr-x 2 ec2-user ec2-user 102 May 13 06:04 google_auth-2.40.1.dist-info
0 drwxrwxr-x 4 ec2-user ec2-user 111 May 13 06:04 google_auth_oauthlib
0 drwxrwxr-x 2 ec2-user ec2-user 143 May 13 06:04 google_auth_oauthlib-1.2.2.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 190 May 13 06:04 idna
0 drwxrwxr-x 2 ec2-user ec2-user 84 May 13 06:04 idna-3.10.dist-info
0 drwxrwxr-x 6 ec2-user ec2-user 144 May 13 06:04 oauthlib
0 drwxrwxr-x 2 ec2-user ec2-user 102 May 13 06:04 oauthlib-3.2.2.dist-info
0 drwxrwxr-x 6 ec2-user ec2-user 115 May 13 06:04 pyasn1
0 drwxrwxr-x 2 ec2-user ec2-user 122 May 13 06:04 pyasn1-0.6.1.dist-info
8 drwxrwxr-x 3 ec2-user ec2-user 4096 May 13 06:04 pyasn1_modules
0 drwxrwxr-x 3 ec2-user ec2-user 119 May 13 06:04 pyasn1_modules-0.4.2.dist-info
4 drwxrwxr-x 3 ec2-user ec2-user 4096 May 13 06:04 requests
0 drwxrwxr-x 2 ec2-user ec2-user 102 May 13 06:04 requests-2.32.3.dist-info
0 drwxrwxr-x 4 ec2-user ec2-user 162 May 13 06:04 requests_oauthlib
0 drwxrwxr-x 2 ec2-user ec2-user 102 May 13 06:04 requests_oauthlib-2.0.0.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 272 May 13 06:04 rsa
0 drwxrwxr-x 2 ec2-user ec2-user 105 May 13 06:04 rsa-4.9.1.dist-info
4 drwxrwxr-x 6 ec2-user ec2-user 4096 May 13 06:04 urllib3
0 drwxrwxr-x 3 ec2-user ec2-user 82 May 13 06:04 urllib3-2.4.0.dist-info

移動する

$ cd ../
$ ls -ls

4 drwxrwxr-x 29 ec2-user ec2-user 4096 May 13 06:04 python

ZIP圧縮する

$ zip -r google-auth-oauthlib -layer.zip python

【省略】
adding: python/google_auth_oauthlib-1.2.2.dist-info/INSTALLER (stored 0%)
adding: python/google_auth_oauthlib-1.2.2.dist-info/REQUESTED (stored 0%)
adding: python/bin/ (stored 0%)
adding: python/bin/normalizer (deflated 24%)
adding: python/bin/pyrsa-decrypt (deflated 25%)
adding: python/bin/pyrsa-encrypt (deflated 25%)
adding: python/bin/pyrsa-keygen (deflated 24%)
adding: python/bin/pyrsa-priv2pub (deflated 27%)
adding: python/bin/pyrsa-sign (deflated 24%)
adding: python/bin/pyrsa-verify (deflated 24%)
adding: python/bin/google-oauthlib-tool (deflated 26%)

確認する

$ ls -ls

2960 -rw-rw-r-- 1 ec2-user ec2-user 3030101 May 13 06:05 google-auth-oauthlib-layer.zip

作業ディレクトリ名を変更してバックアップする

$ mv python python-google-auth-oauthlib
$ ls -ls

4 drwxrwxr-x 29 ec2-user ec2-user 4096 May 13 06:04 python-google-auth-oauthlib