Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Created August 25, 2024 07:28
Show Gist options
  • Save shantanuo/4674905b383a8f22f0e67d54e93dff63 to your computer and use it in GitHub Desktop.
Save shantanuo/4674905b383a8f22f0e67d54e93dff63 to your computer and use it in GitHub Desktop.
Dockerfile for Playwright on AWS Lambda
# Define function directory
ARG FUNCTION_DIR="/function"
FROM mcr.microsoft.com/playwright:v1.46.1-jammy as build-image
# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
libcurl4-openssl-dev \
python3-pip
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy function code
COPY app/* ${FUNCTION_DIR}
# Install the runtime interface client
RUN pip3 install \
--target ${FUNCTION_DIR} \
awslambdaric playwright
# Multi-stage build: grab a fresh copy of the base image
FROM mcr.microsoft.com/playwright:v1.46.1-jammy
# 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 build image dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/bin/python3", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment