GOAL - to create a custom AWS lambda layer for mecab-python3.
TRIED:
- local pip to zip and upload via S3 (using python3.11/3.12/3.13)
- docker container approach outlined below
FROM amazonlinux:2023
RUN dnf install -y zip python3.11
RUN dnf install -y python3.11-pip
RUN curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
RUN python3 /tmp/get-pip.py
RUN pip3 install setuptools
RUN mkdir /home/layers
RUN mkdir /home/python
docker-compose.yaml
version: '3'
services:
aws-lambda-layers:
build: .
volumes:
- './layers:/home/layers'
working_dir: '/home/'
command: sh -c "python3.11 -m pip install -r layers/requirements.txt -t python/ && zip -r layers/file.zip python/"
requirements.txt
mecab-python3
ipadic
In both cases, I received the following error message on import MeCab.
Unable to import module 'lambda_function': cannot import name '_MeCab' from partially initialized module 'MeCab' (most likely due to a circular import) (/opt/python/MeCab/__init__.py)
So, as a final resort I tried updating __init__.py, but nothing changed.
Not too relevant, but I managed to make sudachipy & sudachidict-core to work using methods similar to the ones mentioned above.
Has anyone here managed to make this work please?