Reputation: 21
I want to create lambda function from docker container. I know AWS provides base images for lambda function such as python:3.7, python:38, etc. But for some dependency reason I have to use python:3.8.6 version which AWS doesn't provide. For this, I have to create non-AWS base image this is my dockerfile:
# Define custom function directory
ARG FUNCTION_DIR="/function"
FROM python:3.8.6 as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
COPY . ${FUNCTION_DIR}
COPY requirements.txt ${FUNCTION_DIR}
# Install the function's dependencies
RUN pip install \
--target ${FUNCTION_DIR} \
awslambdaric && \
pip install -r ${FUNCTION_DIR}/requirements.txt --target ${FUNCTION_DIR}
FROM python:3.8.6
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
# Set runtime interface client as default command for the container runtime
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
# Pass the name of the function handler as an argument to the runtime
CMD [ "app.handler" ]
When i create the lambda function with this image then i see an error:
Error: fork/exec /usr/local/bin/python: exec format error
Runtime.InvalidEntrypoint
Can someone please guide me what I am doing wrong here. My main issue is to use python 3.8.6 version. Kindly share your thoughts on it.
Upvotes: 1
Views: 421