我想知道为什么我的项目可以在本地运行,但不能在我的帐户中作为基于图像的 lambda 函数运行?
以下命令我在本地执行:
docker build -t lambda-repository .
docker run -p 9001:8080 lambda-repository:latest
在另一个终端:
curl -XPOST "http://localhost:9001/2015-03-31/functions/function/invocations" -d '{}'
这导致:
"Google"%
我的 AWS 账户会发生什么:
- 我创建了一个 ecr 存储库
- 我把我的形象推到它上面
- 我使用图像创建一个 lambda 函数
- 调用 lambda 会导致以下结果
错误:
START RequestId: 2a8b9cf9-f1f0-48cb-8a5d-eb86c2dddcc0 Version: $LATEST
[ERROR] WebDriverException: Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Traceback (most recent call last):
File "/var/task/app.py", line 14, in handler
driver = webdriver.Chrome(options=options)
File "/var/lang/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/var/lang/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/var/lang/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/var/lang/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/var/lang/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
END RequestId: 2a8b9cf9-f1f0-48cb-8a5d-eb86c2dddcc0
REPORT RequestId: 2a8b9cf9-f1f0-48cb-8a5d-eb86c2dddcc0 Duration: 2736.59 ms Billed Duration: 3752 ms Memory Size: 2048 MB Max Memory Used: 168 MB Init Duration: 1014.78 ms
Dockerfile:
FROM public.ecr.aws/lambda/python:3.8
RUN pwd
WORKDIR /tmp
RUN yum -y update
RUN yum -y install wget unzip
RUN yum -y install GConf2 libX11
RUN yum -y install curl
COPY download-chromedriver.sh ./
RUN /bin/bash -c "source ./download-chromedriver.sh"
RUN unzip chromedriver_linux64.zip
RUN mv chromedriver /usr/bin/chromedriver
RUN chromedriver -version
RUN curl https://intoli.com/install-google-chrome.sh | bash
RUN mv /usr/bin/google-chrome-stable /usr/bin/google-chrome
RUN google-chrome -version && which google-chrome
WORKDIR /var/task
COPY app.py ./
COPY requirements.txt ./
RUN pip3 install -r requirements.txt
CMD ["app.handler"]
下载-chromedriver.sh:
#!/usr/bin/env bash
CHROME_DRIVER_VERSION=`curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
应用程序.py:
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
def handler(event, context):
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument("window-size=1280,1024")
url = 'http://www.google.com'
driver = webdriver.Chrome(options=options)
driver.get(url)
text = driver.title
return text
要求.txt:
selenium==3.141.0
urllib3==1.26.2