Skip to content

Commit 2894a2e

Browse files
committed
move chromium code to layer
1 parent 3433280 commit 2894a2e

16 files changed

+87
-48
lines changed

layer/fetch-binaries.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
mkdir -p bin
4+
5+
# Get headless shell
6+
curl -SL https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-35/stable-headless-chromium-amazonlinux-2017-03.zip > chromeheadless.zip
7+
unzip chromeheadless.zip -d bin/
8+
rm chromeheadless.zip
9+
10+
# Get Chromedriver
11+
curl -SL https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip> chromedriver.zip
12+
unzip chromedriver.zip -d bin/
13+
rm chromedriver.zip
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.js renamed to src/index.js

File renamed without changes.
File renamed without changes.

lib/chromium.js renamed to src/lib/chromium.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const defaultChromeFlags = [
4040
//'--trace-startup=*',
4141
];
4242

43-
const HEADLESS_CHROME_PATH = 'bin/headless-chromium';
44-
const CHROMEDRIVER_PATH = '/var/task/bin/chromedriver';
43+
const HEADLESS_CHROME_PATH = '/opt/bin/headless-chromium';
44+
const CHROMEDRIVER_PATH = '/opt/bin/chromedriver';
4545
exports.createSession = function() {
4646
var service;
4747
if (process.env.LOG_DEBUG || process.env.SAM_LOCAL) {
@@ -60,7 +60,7 @@ exports.createSession = function() {
6060
options.setLoggingPrefs(logPrefs);
6161

6262
options.setPerfLoggingPrefs({ enableNetwork: true, enablePage: true });
63-
options.setChromeBinaryPath(path.join(process.env.LAMBDA_TASK_ROOT, HEADLESS_CHROME_PATH));
63+
options.setChromeBinaryPath(HEADLESS_CHROME_PATH);
6464
options.addArguments(defaultChromeFlags);
6565
return chrome.Driver.createSession(options, service);
6666
}
File renamed without changes.
File renamed without changes.

package-lock.json renamed to src/package-lock.json

Lines changed: 43 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

template.yaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,43 @@ AWSTemplateFormatVersion : '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
33
Description: selenium with headless chromium
44
Resources:
5+
DeploymentPermission:
6+
Type: "AWS::Lambda::LayerVersionPermission"
7+
Properties:
8+
Action: lambda:GetLayerVersion
9+
LayerVersionArn: !Ref ChromiumLayer
10+
Principal: '*'
11+
12+
ChromiumLayer:
13+
Type: AWS::Serverless::LayerVersion
14+
Properties:
15+
LayerName: chromium-selenium-layer
16+
Description: Headless Chromium and Selenium WebDriver
17+
ContentUri: ./layer
18+
CompatibleRuntimes:
19+
- nodejs6.10
20+
- nodejs8.10
21+
- python3.6
22+
- python3.7
23+
- python2.7
24+
- go1.x
25+
- java8
26+
LicenseInfo: 'MIT'
27+
RetentionPolicy: Retain
28+
529
Lambdium:
630
Type: AWS::Serverless::Function
731
Properties:
832
Handler: index.handler
9-
Runtime: nodejs6.10
33+
Runtime: nodejs8.10
1034
FunctionName: lambdium
1135
Description: headless chromium running selenium
1236
# This needs to be fairly large: chromium needs a lot of memory
1337
MemorySize: 1156
1438
Timeout: 20
39+
Layers:
40+
- !Ref ChromiumLayer
1541
Environment:
1642
Variables:
1743
CLEAR_TMP: "true"
18-
CodeUri: .
44+
CodeUri: ./src

0 commit comments

Comments
 (0)