4
1

More than 1 year has passed since last update.

aws lambda numpy importエラー

Posted at

aws lambdaでDBにinsertする処理を作成していたのですが、その際pandasが必要でimportしたところ、

Function Logs
START RequestId: 00d85ae0-ce8e-4472-91f5-413f21e3bea3 Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/var/lang/bin/python3.9"
  * The NumPy version is: "1.23.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

Traceback (most recent call last):END RequestId: 00d85ae0-ce8e-4472-91f5-413f21e3bea3
REPORT RequestId: 00d85ae0-ce8e-4472-91f5-413f21e3bea3	Duration: 1.81 ms	Billed Duration: 2 ms	Memory Size: 128 MB	Max Memory Used: 37 MB	Init Duration: 118.39 ms

このようなエラーが出ました。

結論以下の記事にある内容を実行すれば解決すると思います。
https://pomblue.hatenablog.com/entry/2021/06/08/230146
自分はpython3.9だったので3.9のdocker-imageをpullしました。

docker pull amazon/aws-sam-cli-build-image-python3.9
docker run -it -v $(pwd):/var/task amazon/aws-sam-cli-build-image-python3.9:latest
pip install pandas -t ./python
zip -r python.zip ./python

おそらくこの問題に直面してる人はレイヤーなどの使い方は分かってると思うのでその辺は割愛します。(調べればすぐ出てきますし。)
自分は上記の記事を見つけるまでとても時間を要したので、少しでも多く同じ問題に直面してる人に届けばいいなと思います。(海外の人とか誰一人として解決できてなかった笑)

4
1
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
4
1