Open1

google-cloud-storage(Custom AWS Lambda Layer)

marchanmarchan

-- 2024.12.02

Cloud9 Amazon Linux2 で作業する

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

$ python -version

Unknown option: -e
usage: /home/ec2-user/.pyenv/versions/3.12.0/bin/python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

mkdir python

インストール

$ pip install google-cloud-storage -t ./python

Collecting google-cloud-storage
Downloading google_cloud_storage-2.18.2-py2.py3-none-any.whl.metadata (9.1 kB)
【省略】
Installing collected packages: urllib3, pyasn1, protobuf, idna, google-crc32c, charset-normalizer, certifi, cachetools, rsa, requests, pyasn1-modules, proto-plus, googleapis-common-protos, google-resumable-media, google-auth, google-api-core, google-cloud-core, google-cloud-storage
Successfully installed cachetools-5.5.0 certifi-2024.8.30 charset-normalizer-3.4.0 google-api-core-2.23.0 google-auth-2.36.0 google-cloud-core-2.4.1 google-cloud-storage-2.18.2 google-crc32c-1.6.0 google-resumable-media-2.7.2 googleapis-common-protos-1.66.0 idna-3.10 proto-plus-1.25.0 protobuf-5.29.0 pyasn1-0.6.1 pyasn1-modules-0.4.1 requests-2.32.3 rsa-4.9 urllib3-2.2.3

確認する

$ cd python 
$ ls -ls 

total 16
0 drwxrwxr-x 2 ec2-user ec2-user 146 Dec 2 02:52 bin
0 drwxrwxr-x 3 ec2-user ec2-user 74 Dec 2 02:52 cachetools
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 cachetools-5.5.0.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 112 Dec 2 02:52 certifi
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 certifi-2024.8.30.dist-info
0 drwxrwxr-x 4 ec2-user ec2-user 308 Dec 2 02:52 charset_normalizer
0 drwxrwxr-x 2 ec2-user ec2-user 126 Dec 2 02:52 charset_normalizer-3.4.0.dist-info
0 drwxrwxr-x 16 ec2-user ec2-user 223 Dec 2 02:52 google
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 google_api_core-2.23.0.dist-info
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 googleapis_common_protos-1.66.0.dist-info
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 google_auth-2.36.0.dist-info
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 google_cloud_core-2.4.1.dist-info
0 drwxrwxr-x 2 ec2-user ec2-user 119 Dec 2 02:52 google_cloud_storage-2.18.2.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 180 Dec 2 02:52 google_crc32c
0 drwxrwxr-x 2 ec2-user ec2-user 118 Dec 2 02:52 google_crc32c-1.6.0.dist-info
0 drwxrwxr-x 2 ec2-user ec2-user 41 Dec 2 02:52 google_crc32c.libs
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 google_resumable_media-2.7.2.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 190 Dec 2 02:52 idna
0 drwxrwxr-x 2 ec2-user ec2-user 84 Dec 2 02:52 idna-3.10.dist-info
0 drwxrwxr-x 4 ec2-user ec2-user 255 Dec 2 02:52 proto
0 drwxrwxr-x 2 ec2-user ec2-user 81 Dec 2 02:52 protobuf-5.29.0.dist-info
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 proto_plus-1.25.0.dist-info
0 drwxrwxr-x 6 ec2-user ec2-user 115 Dec 2 02:52 pyasn1
0 drwxrwxr-x 2 ec2-user ec2-user 122 Dec 2 02:52 pyasn1-0.6.1.dist-info
8 drwxrwxr-x 3 ec2-user ec2-user 4096 Dec 2 02:52 pyasn1_modules
0 drwxrwxr-x 2 ec2-user ec2-user 122 Dec 2 02:52 pyasn1_modules-0.4.1.dist-info
4 drwxrwxr-x 3 ec2-user ec2-user 4096 Dec 2 02:52 requests
0 drwxrwxr-x 2 ec2-user ec2-user 102 Dec 2 02:52 requests-2.32.3.dist-info
0 drwxrwxr-x 3 ec2-user ec2-user 272 Dec 2 02:52 rsa
0 drwxrwxr-x 2 ec2-user ec2-user 105 Dec 2 02:52 rsa-4.9.dist-info
4 drwxrwxr-x 6 ec2-user ec2-user 4096 Dec 2 02:52 urllib3
0 drwxrwxr-x 3 ec2-user ec2-user 82 Dec 2 02:52 urllib3-2.2.3.dist-info

$ cd ../

ZIP圧縮する

$ zip -r google-cloud-storage-layer.zip python

【省略】
adding: python/google_cloud_storage-2.18.2.dist-info/REQUESTED (stored 0%)
adding: python/bin/ (stored 0%)
adding: python/bin/normalizer (deflated 26%)
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%)

確認する

ls -ls

4476 -rw-rw-r-- 1 ec2-user ec2-user 4582530 Dec 2 02:57 google-cloud-storage-layer.zip