AWS Lambda LayersでError importing numpy
AWS Lambda Layersでlangchainを使おうとして以下のエラーが発生しました。
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
Traceback (most recent call last):
Keith's Layers (Klayers) のnumpyをレイヤーに追加して解決する。
numpyのARNを確認
Klayersへ遷移
対象Pythonバージョン選択
例えば、Python 3.12を選ぶと以下が開きます。
https://github.com/keithrozario/Klayers/tree/master/deployments/python3.12
対象Region選択
例えば、ap-northeast-1 Asia Pacific (Tokyo)のhtmlを選ぶと以下が開きます。
https://api.klayers.cloud/api/v2/p3.12/layers/latest/ap-northeast-1/html
対象パッケージARNコピー
今回はnumpyのarnをコピーします。
レイヤー追加
あとはAWS Lambdanの対象関数へ戻り、レイヤー レイヤーを追加 ARN を指定 でコピーしておいたARNを貼り付けて追加すればOK。