admin管理员组文章数量:1353380
I am trying to download a file from Chrome using the Selenium library in C#. It works locally, but when I deploy the Lambda function on AWS, it throws an error:
Exception Type: WebDriverException,
Message: Error starting process: /var/task/selenium-manager/linux/selenium-manager --browser "chrome" --browser-path "/opt/chrome-layer/bin/chrome-headless-shell" --language-binding csharp --output json,
StackTrace: at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
InnerException: An error occurred trying to start process '/var/task/selenium-manager/linux/selenium-manager' with working directory '/var/task'. Exec format error
I created a layer on AWS that contains the chrome-headless-shell and chromedriver binaries and attached it to the Lambda. The layer is compatible with arm64. Here is the code I am using:
public void DownloadFile(string downloadPath)
{
var options = GetChromeOptions(downloadPath);
using (IWebDriver driver = new ChromeDriver(options))
{
try
{
driver.Navigate().GoToUrl(_config.BaseUrl);
// other operations
}
catch (Exception ex)
{
_logger.Error(ex, "Error downloading file");
}
}
}
private ChromeOptions GetChromeOptions(string downloadPath)
{
var options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", downloadPath);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("disable-popup-blocking", "true");
var chromeBinaryPath = "/opt/chrome-layer/bin/chrome-headless-shell";
options.BinaryLocation = chromeBinaryPath;
options.AddArgument("--headless");
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
return options;
}
RunFileFunction:
Type: AWS::Serverless::Function
Properties:
Description: Run file
Handler: System.Lambdas.RunFileFunction::FunctionHandler
Architectures:
- arm64
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:chrome-layer:3
Environment:
Variables:
CHROME_PATH: "/opt/chrome-layer/bin/chrome-headless-shell"
DRIVER_PATH: "/opt/chrome-layer/bin/chromedriver"
Events:
ScheduleEvent:
Type: ScheduleV2
Properties:
ScheduleExpression: cron(0 7 ? * 6 *)
ScheduleExpressionTimezone: Europe/London
RetryPolicy:
MaximumRetryAttempts: 0
State: ENABLED
Any help would be appreciated. Thanks in advance!
I am trying to download a file from Chrome using the Selenium library in C#. It works locally, but when I deploy the Lambda function on AWS, it throws an error:
Exception Type: WebDriverException,
Message: Error starting process: /var/task/selenium-manager/linux/selenium-manager --browser "chrome" --browser-path "/opt/chrome-layer/bin/chrome-headless-shell" --language-binding csharp --output json,
StackTrace: at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
InnerException: An error occurred trying to start process '/var/task/selenium-manager/linux/selenium-manager' with working directory '/var/task'. Exec format error
I created a layer on AWS that contains the chrome-headless-shell and chromedriver binaries and attached it to the Lambda. The layer is compatible with arm64. Here is the code I am using:
public void DownloadFile(string downloadPath)
{
var options = GetChromeOptions(downloadPath);
using (IWebDriver driver = new ChromeDriver(options))
{
try
{
driver.Navigate().GoToUrl(_config.BaseUrl);
// other operations
}
catch (Exception ex)
{
_logger.Error(ex, "Error downloading file");
}
}
}
private ChromeOptions GetChromeOptions(string downloadPath)
{
var options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", downloadPath);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("disable-popup-blocking", "true");
var chromeBinaryPath = "/opt/chrome-layer/bin/chrome-headless-shell";
options.BinaryLocation = chromeBinaryPath;
options.AddArgument("--headless");
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
return options;
}
RunFileFunction:
Type: AWS::Serverless::Function
Properties:
Description: Run file
Handler: System.Lambdas.RunFileFunction::FunctionHandler
Architectures:
- arm64
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:chrome-layer:3
Environment:
Variables:
CHROME_PATH: "/opt/chrome-layer/bin/chrome-headless-shell"
DRIVER_PATH: "/opt/chrome-layer/bin/chromedriver"
Events:
ScheduleEvent:
Type: ScheduleV2
Properties:
ScheduleExpression: cron(0 7 ? * 6 *)
ScheduleExpressionTimezone: Europe/London
RetryPolicy:
MaximumRetryAttempts: 0
State: ENABLED
Any help would be appreciated. Thanks in advance!
Share Improve this question edited Mar 31 at 19:06 Hilory 2,1417 gold badges14 silver badges30 bronze badges asked Mar 31 at 17:37 ShreyaShreya 254 bronze badges1 Answer
Reset to default 1Exec format error indicates that your Chrome binary is not compatible with the platform you're trying to run it on. i.e. the Chrome binary you're using has not actually been built for the arm64 architecture.
I suggest going back to the origins of that lambda layer, specifically the Chrome binaries included, to figure out why.
本文标签: netAWS Lambda Selenium Error in CWebDriverExceptionExec format error running ChromeStack Overflow
版权声明:本文标题:.net - AWS Lambda Selenium Error in C# : WebDriverException - Exec format error running Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743930364a2563728.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论