Reputation: 219
How do I install Chrome in AWS Lambda? I know I might need a specific file from an EC2 instance but I can't figure out how to retrieve it.
not duplicate as as a micro instance ec2 won't be the same enviroment as a lambda
Upvotes: 2
Views: 7072
Reputation: 12031
As AWS Lambda recently announced (2020) the Container Image Support, you can bring your own runtime for your Java code.
A sample Docker Image might look like the following:
FROM public.ecr.aws/lambda/java:11
RUN yum install -y wget unzip libX11
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm && \
yum install -y google-chrome-stable_current_x86_64.rpm
RUN CHROME_DRIVER_VERSION=`curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip && \
unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
COPY target/dependency ${LAMBDA_TASK_ROOT}/lib/
COPY target/classes ${LAMBDA_TASK_ROOT}
CMD ["de.rieckpil.test.InvokeWebDriver::handleRequest"]
Once you push this Docker Image to your ECR, you can create a Lambda function that uses your image.
However, I'm still unable to launch Chrome 89 (already tried a gazillion of ChromeOptions
arguments combinations) ...
/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
Maybe someone in the future has more success with this and can use this as a template :D
Upvotes: 0
Reputation: 53
You could create a Lambda Layer with a compiled Google Chrome. There are docker containers emulating Lambda execution environment, e.g. "lambci/lambda:java8". Could be tricky, since you need to build the browser from source code yourself, while there may be many dependencies missing.
Have you tried looking at other people's solutions? For example, this repo seems to have an already compiled Lambda Layer with Google Chrome Google Chrome for AWS Lambda as a layer
Upvotes: 1
Reputation: 78803
You should drop the requirement for Java in this case. It's not your friend.
Switch to Node.js, if only for this Lambda, and use alixaxel/chrome-aws-lambda and Puppeteer.
Upvotes: 1