I'm trying to run headless_chrome in a dockerized lambda function.
My Dockerfile looks like this:
FROM rust:1.75.0-alpine3.19 as build
ARG binary
RUN apk update \
&& apk add --no-cache build-base pkgconfig libressl-dev
WORKDIR /usr/src/api-service
COPY src/ src/
COPY Cargo.toml Cargo.toml
RUN cargo install --bin ${binary} --path .
FROM alpine:3.19
RUN apk update
# Install chromium and chromedriver
RUN apk add --no-cache bash chromium chromium-chromedriver
ENV PATH="$PATH:/usr/bin/chromedriver"
ENV CHROME_BIN=/usr/bin/chromium-browser \
CHROME_PATH=/usr/lib/chromium/
WORKDIR /usr/src/app
ARG binary
ARG log_level
ARG stage
ENV RUST_LOG=${log_level}
ENV STAGE=${stage}
COPY --from=build /usr/local/cargo/bin/${binary} /asset-output/bootstrap
ENTRYPOINT [ "/asset-output/bootstrap" ]
This is the Rust part:
use headless_chrome::{Browser, LaunchOptions};
tracing::debug!("Creating browser");
let options = LaunchOptions::default_builder()
.headless(true)
.sandbox(false)
.window_size(Some((1920, 1080)))
.build()
.expect("Couldn't find appropriate Chrome binary.");
tracing::debug!("Creating browser");
let browser = Browser::new(options)?;
tracing::debug!("Creating tab");
let tab = &browser.new_tab()?;
tracing::debug!("Fetching {}", &url);
tab.navigate_to(&url).expect("failed to navigate");
Running the lambda shows that it gets stuck during the browser creation step. This are the logs:
...
DEBUG Creating browser
thread 'main' panicked at src/import/import.rs:23:19:
Unable to make method calls because underlying connection is closed
ERROR Any { .. }
DEBUG reuse idle connection for ("http", 127.0.0.1:9001)
...
I tried running the docker image locally and it works fine there. That's why I believe it might be a lambda environment specific behaviour. What am I missing?