LoginSignup
5
5

More than 3 years have passed since last update.

Lambdaでcryptographyを使う(Python3.8 + cryptography)

Last updated at Posted at 2021-03-30

はじめに

Lambdaでcryptographyを使う際に、モジュールをレイヤーで追加しました。
その手順の記録です。

手順

クラウドシェルでPythonS3のライブラリをZip圧縮して、cryptographyのレイヤーを作成します。
一時的に保存するS3は事前に準備しておきます。

①cryptographyのファイルを取得する

クラウドシェルを起動

image.png

Pythonを3.8にする

バージョンを確認

python3 -V

3.8でなければ、3.8にする。3.7.9だった。

# Pythonを3.8にする
sudo amazon-linux-extras install python3.8 -y
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

「python3 -V」で確認して、3.8.ならOK。3.8.5になった。

pipをインストール

# pipインストール
curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

cryptographyを取得&Zip化

pip install cryptography -t python
zip -r cryptography.zip python

S3に保存

aws s3 cp cryptography.zip s3://<my-bucket>/

※<>のところは、自身の設定

②Lambdaレイヤーの作成

LambdaのWebコンソールから、レイヤーを作成します。
image.png

image.png

  • 先ほどS3に保存したファイルを選択します。
  • ランタイムはPython3.8にします。

③Lambda関数に、Lambdaレイヤーの追加

LambdaのWebコンソールから、関数を作成します。
関数のコードの下の方に、レイヤーを設定する場所があります。
image.png

  • Lambda関数のランタイムはPython3.8とします。
  • 先ほど追加したレイヤーを追加します。

おわりに

Lambda便利です!

5
5
2

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
5
5