2023/10/24をもってAWS SAM CLIがPython 3.7上で動作しなくなる旨がアナウンスされました

2023.09.09

初めに

2023/10/24をもってAWS SAM CLIのPython 3.7環境での動作サポートを終了することがアナウンスされました。なおPython 3.7自体のコミュニティサポートは2023/06/05に終了しています。

明記はされていませんが、厳密にはそのタイミングでバージョンチェック処理に手が入ったバージョンがリリースされそのバージョン以降は動作しなくなるという形になるのではないかなと思っています。

以降はPython 3.8以上が動作のために必要ととなります。

No, AWS Lambda functions which is using python3.7 as runtime will not be affected by this change. For more information about supported runtimes,

なお今回の話はあくまでSAM自体の動作環境に関する話であり、SAM上で構築されているLambda関数側のPythonの話は特に関係のないものとなります。AWS Lambda側の3.7サポートについては別途そちらのドキュメントをご参照ください。

影響を受けないケース

以下の方法インストールされている場合は実行環境にグローバルインストールされているPythonのバージョンが3.7であっても影響を受けません。

  • Windowsを利用しておりmsiインストーラーを利用している
  • MacOSXを利用しておりpkgインストーラーもしくはhomebrewを利用している
  • Linuxを利用しておりZipで配布されているネイティブインストーラーを利用している

これはパッケージインストーラーを利用した場合はSAM用に別途Pythonが別途ローカルインストールされるためです。

例えばHomebrewでインストールした場合以下のようにCeller内のaws-sam-cli配下にpythonの実行バイナリが存在します(シンボリックリンクではありますが)。

$ ls -l /opt/homebrew/Cellar/aws-sam-cli/1.97.0/libexec/bin/python*
lrwxr-xr-x  1 xxxx  admin  87  9  6 03:49 /opt/homebrew/Cellar/aws-sam-cli/1.97.0/libexec/bin/python -> ../../../../../opt/python@3.11/Frameworks/Python.framework/Versions/3.11/bin/python3.11
lrwxr-xr-x  1 xxxx  admin  87  9  6 03:49 /opt/homebrew/Cellar/aws-sam-cli/1.97.0/libexec/bin/python3 -> ../../../../../opt/python@3.11/Frameworks/Python.framework/Versions/3.11/bin/python3.11
lrwxr-xr-x  1 xxxx  admin  87  9  6 03:49 /opt/homebrew/Cellar/aws-sam-cli/1.97.0/libexec/bin/python3.11 -> ../../../../../opt/python@3.11/Frameworks/Python.framework/Versions/3.11/bin/python3.11

影響を受けるケース

pipによるインストールを行っておりその上でグローバルインスールされているPythonのバージョンが3.7の場合は対処が必要です。あえて言及はされていませんが当然その他なんらかの方法でセットアップしてpython 3.7を利用するような形になっている場合もこちらに該当します。

対応としてはグローバルインストールされているPythonのバージョンを上げるか、pipでの管理を取りやめてパッケージインストーラーに切り替える形となります。

この2ケースの違いはAWS CLIのv1とv2の違いに近いものを感じます(v1はグローバルインストールされたものを使う,v2はローカルインストールしてそれを使う)。

特にAmazon Linux 2は標準リポジトリの利用の場合最新バージョンが3.7系となるためご注意ください。

$ yum info python3
...
Available Packages
Name        : python3
Arch        : aarch64
Version     : 3.7.16
Release     : 1.amzn2.0.4
Size        : 73 k
Repo        : amzn2-core/2/aarch64
Summary     : Interpreter of the Python programming language
URL         : https://www.python.org/
License     : Python
Description : Python is an accessible, high-level, dynamically typed, interpreted programming
            : language, designed with an emphasis on code readability.
            : It includes an extensive standard library, and has a vast ecosystem of
            : third-party libraries.
            :
            : The python3 package provides the "python3" executable: the reference
            : interpreter for the Python language, version 3.
            : The majority of its standard library is provided in the python3-libs package,
            : which should be installed automatically along with python3.
            : The remaining parts of the Python standard library are broken out into the
            : python3-tkinter and python3-test packages, which may need to be installed
            : separately.
            :
            : Documentation for Python is provided in the python3-docs package.
            :
            : Packages containing additional libraries for Python are generally named with
            : the "python3-" prefix.

どうしてもパッケージインストーラーを使えない事情がある場合amazon-linux-extras上にpython 3.8が存在しているのでこちらを利用する方法があります。

$ amazon-linux-extras list | grep python
 36 †python3.8                available    [ =stable ]

終わりに

アナウンスからサポート終了まで1ヶ月半くらいしかないので結構直前だなと思いました。

大概の場合パッケージインストーラー側に切り替えれば他の依存等を気にせずに解決できるかと思いますが、なんらか個別の事情でpipを使わざるを得ないケースもあるとは思いますので該当の環境の方は急いで対応しましょう。

2023/10/24を過ぎてもバージョンさえあげなければ一定使い続けることはできる可能性もありますが明確に言及はされていないので基本はバージョンを上げても対応できる方針を取るのが無難でしょう。

AWS CLIもそのうちPython 3.7サポート終了関連の話が来たりするのでしょうか?

余談: Amazon Linux 2ではPython 3.7も長期サポートに含まれる(?)

※ 誤解のないように先に書いておくとAmazon Linux 2上であればPython 3.7上を利用してもSAMの動作がサポートされるという話ではなく、Python 3.7自体のサポートの話です。

前述の通りPython 3.7のコミュニティサポートは既に終了しているのですが、AWS利用していると多くの方が利用されているであろうAmazon Linux 2では実はまだフルではないもののサポートされています。

Q:Amazon Linux 2 の長期サポートには何が含まれていますか?
...audit-libs-python、...python、python-libs...

この表記を見てシステム的に使われているpythonコマンド(2.xの方)のみかなと思ったのですがどうやら3.7も含まれているようです。

サポートに確認したわけではないので100%の確証はないのですが、changelogを確認したところpython 3.7のEOLが既に過ぎている2023/08/31にPython 3.8以降のバージョンに対して提供されているセキュリティパッチ相当の内容らしきものが3.7側にも提供されていました。

===============================================================================
  Amazon Linux 2 2017.12 - ALAS2-2023-2222: important priority package update for python3
===============================================================================
  Update ID : ALAS2-2023-2222
    Release :
       Type : security
     Status : final
     Issued : 2023-08-31 22:28
       CVEs : CVE-2023-40217
Description : Package updates are available for Amazon Linux 2 that fix the
            : following vulnerabilities: CVE-2023-40217:
            :         An issue was discovered in Python before
            :         3.8.18, 3.9.x before 3.9.18, 3.10.x before
            :         3.10.13, and 3.11.x before 3.11.5. It
            :         primarily affects servers (such as HTTP
            :         servers) that use TLS client
            :         authentication. If a TLS server-side
            :         socket is created, receives data into the
            :         socket buffer, and then is closed quickly,
            :         there is a brief window where the
            :         SSLSocket instance will detect the socket
            :         as "not connected" and won't initiate a
            :         handshake, but buffered data will still be
            :         readable from the socket buffer. This data
            :         will not be authenticated if the
            :         server-side TLS peer is expecting client
            :         certificate authentication, and is
            :         indistinguishable from valid TLS stream
            :         data. Data is limited in size to the
            :         amount that will fit in the buffer. (The
            :         TLS connection cannot directly be used for
            :         data exfiltration because the vulnerable
            :         code path requires that the connection be
            :         closed on initialization of the
            :         SSLSocket.)
   Severity : important

セキュリティセンタの情報を確認してみても確かに3.7に向けての提供となり、コミュニティ提供では本来3.7に提供されないものが専用に対応されている状態とはなります。

(2023/10/27追記)対応状況について

予定の日程を過ぎていますが現時点ではPython 3.7サポート終了バージョンは出ていない状態です(v1.99.0)。

ただdevelopブランチに対するcommitとして以下のような対応が入っていますので次のバージョンよりPython 3.7が対象外となりそうです。