I need to make a lambda function with Docker, this is because I need fast response time so it can not run (for example) an AWS Batch job because that would take too long.
The function as such creates a .mp4 video based on an image and a .wav audio and uses the opencv-python, numpy and moviepy libraries.
My problem is that when I want to use the api or test the lambda function I get this error:
{
"errorType": "Runtime.InvalidEntrypoint",
"errorMessage": "RequestId: 35411fd0-7258-4d11-9ce4-9f482a600088 Error: fork/exec /lambda-entrypoint.sh: exec format error"
}
Honestly I can't find the problem and how I can solve it and I'm a bit lost. in case it can be of help I show you my dockerfile.
# syntax=docker/dockerfile:1
FROM public.ecr.aws/lambda/python:3.12
# Copy requirements.txt and function code
COPY requirements.txt ${LAMBDA_TASK_ROOT}
COPY lambda_function.py ${LAMBDA_TASK_ROOT}
RUN pip3 install --no-cache-dir -r ./requirements.txt
# Install the specified packages
RUN pip install -r requirements.txt
CMD ['lambda_function.lambda_handler']
For this work I am following the [official aws guide].(https://docs.aws.amazon.com/es_es/lambda/latest/dg/python-image.html#python-image-instructions)
As shown in my question there are several errors that caused my problem, one of them was the solution exposed in the comments of the questions. at the time of marking the platform did not do it right.
This was solved by using the following command to make the build:
docker build --platform linux/arm64 -t my-container-name .
.
Another error is found in the docker file, I used single quotes in the CMD line out of habit and it looks like it has to be double (I don't know exactly why but I know it works like that).
In the end this is how my Dockerfile looks like:
# syntax=docker/dockerfile:1
FROM public.ecr.aws/lambda/python:3.12
RUN microdnf install -y mesa-libGL
COPY . ${LAMBDA_TASK_ROOT}
RUN pip3 install --no-cache-dir -r ./requirements.txt
CMD ["lambda_function.lambda_handler"]