I am trying to set up a headless Chromium browser in AWS Lambda using a docker container. My Dockerfile looks like this
# Build stage
# ------------
FROM public.ecr.aws/lambda/nodejs:14 AS builder
RUN yum install -y make
# Install dependencies
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
WORKDIR /usr/src
COPY package*.json .
COPY tsconfig*.json .
RUN npm ci
# build Typescript
COPY . /usr/src
RUN make compile
# Production stage
# ------------
FROM public.ecr.aws/lambda/nodejs:14
# Install Chrome
COPY docker/google-chrome.repo /etc/yum.repos.d/google-chrome.repo
RUN yum update -y && yum install google-chrome-stable -y
# /var/task is where Lambda looks for files by default
COPY package*.json /var/task/
# Install production dependencies only
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true"
RUN npm install --production
# Copy built files from the previous stage
COPY --from=builder /usr/src/dist /var/task/
CMD ["app.handler"]
google-chrome.repo
[google-chrome]
name=google-chrome - 64-bit
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
I use Node.js and Puppeteer to control the browser.
const browser = await puppeteer.launch({
dumpio: true,
headless: true,
executablePath: config.chromeExecutablePath,
// all possible options and explanations
// can be found here https://peter.sh/experiments/chromium-command-line-switches/
args: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
'--single-process',
'--user-data-dir=/tmp/user-data',
'--data-path=/tmp/data-path',
'--homedir=/tmp',
'--disk-cache-dir=/tmp/cache-dir',
],
})
It works perfectly fine when running the container locally but once I deploy it and run it in Lambda I get errors like this, and the whole thing just timeouts eventually.
/usr/bin/google-chrome: line 45: /dev/fd/62: No such file or directory
/usr/bin/google-chrome: line 46: /dev/fd/62: No such file or directory
prctl(PR_SET_NO_NEW_PRIVS) failed
prctl(PR_SET_NO_NEW_PRIVS) failed
Any idea what could be the problem?