LoginSignup
2
0

More than 1 year has passed since last update.

Dockerを用いてAWS Lambda Layersのzipファイルを作成すーる(Windows 10、Python 3.8、arm64)

Last updated at Posted at 2023-03-16

はじめに

Windows環境でDockerからAWS Lambda Layers(arm64、Python3.8)のzipファイルを作っていきます

開発環境

  • Windows 10
  • Python 3.8
  • Docker

導入

1.Dockerをインストール

コマンドプロンプトを開き

wsl --update

Docker Desktopを起動する

2.Dockerfileの作成

FROM arm64v8/python:3.8.16-bullseye

3.イメージをビルド

docker build -f Dockerfile -t build:python3.8 .

4.ビルドしたイメージのIDを調べる

docker images
REPOSITORY TAG IMAGE ID REATED SIZE
build python3.8 f7249746d077 2 days ago 857MB

5.コンテナを実行

docker run -d -it f7249746d077 bash

6.プロセスの確認

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e04adfa35107 f7249746d077 "bash" 10 seconds ago Up 9 seconds pedantic_ellis

7.bashを実行

docker exec -it e04adfa35107 bash

8.pythonフォルダにライブラリをインストール

cd home
mkdir python
pip install -t ./python requests
exit

9.コンテナからローカルへpythonフォルダをコピー

docker cp e04adfa35107:/home/python python

10.zip化してLambda Layersにアップロードし、requestsが使えるか確認

お疲れ様でした

追記(2023/05/05)

Python3.10の場合

FROM arm64v8/python:3.10.9-bullseye

外部ライブラリのインストール

pip install polars pyarrow gtfs-realtime-bindings requests

boto3をimportするだけで下記のエラーが出るようになりました

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_' (/opt/python/urllib3/util/ssl_.py)

urllib3のバージョンを次のようにすることで対応

pip install polars pyarrow gtfs-realtime-bindings requests urllib3==1.26.15

参考まで

Pythonのバージョン確認

import sys
print(sys.version)

urllib3のバージョン確認

import urllib3
print(urllib3.__version__)
2
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
2
0