You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+27-23
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
## lambdium
2
2
### headless chrome + selenium webdriver in AWS Lambda
3
3
4
+
**Lambdium allows you to run a Selenium Webdriver script written in Javascript inside of an AWS Lambda function bundled with [Headless Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome).**
5
+
4
6
*This project is now published on the [AWS Serverless Application Repository](https://serverlessrepo.aws.amazon.com), allowing you to install it in your AWS account with one click. Install in your AWS account [here](https://serverlessrepo.aws.amazon.com/#/applications/arn:aws:serverlessrepo:us-east-1:156280089524:applications~lambdium).* Quickstart instructions are in the [`README-SAR.md` file](https://github.com/smithclay/lambdium/blob/master/README-SAR.md).
5
7
6
8
This uses the binaries from the [serverless-chrome](https://github.com/adieuadieu/serverless-chrome) project to prototype running headless chromium with `selenium-webdriver` in AWS Lambda. I've also bundled the chromedriver binary so the browser can be interacted with using the [Webdriver Protocol](https://www.w3.org/TR/webdriver/).
@@ -13,61 +15,63 @@ The function interacts with [headless Chromium](https://chromium.googlesource.co
13
15
14
16
Since this Lambda function is written using node.js, you can run almost any script written for [selenium-webdriver](https://www.npmjs.com/package/selenium-webdriver). Example scripts can be found in the `examples` directory.
15
17
16
-
#### Requirements
18
+
#### Requirements and Setup
17
19
18
20
* An AWS Account
19
21
* The [AWS SAM Local](https://github.com/awslabs/aws-sam-local) tool for running functions locally with the [Serverless Application Model](https://github.com/awslabs/serverless-application-model) (see: `template.yaml`)
20
22
* node.js + npm
21
23
*`modclean` npm modules for reducing function size (optional)
22
24
* Bash
23
25
24
-
#### Fetching dependencies
26
+
_Note:_ If you don't need to build, customize, or run this locally, you can deploy it directly from a [template on the AWS Serverless Application repository](https://serverlessrepo.aws.amazon.com/#/applications/arn:aws:serverlessrepo:us-east-1:156280089524:applications~lambdium) and skip all of the below steps.
27
+
28
+
#### 1. Fetching dependencies
25
29
26
30
The headless chromium binary is too large for Github, you need to fetch it using a script bundled in this repository. [Marco Lüthy](https://github.com/adieuadieu) has an excellent post on Medium about how he built chromium for for AWS Lambda [here](https://medium.com/@marco.luethy/running-headless-chrome-on-aws-lambda-fa82ad33a9eb).
27
31
28
32
```sh
29
33
$ ./scripts/fetch-dependencies.sh
30
34
```
31
35
32
-
####Running locally with SAM Local
36
+
##### 2. Cleaning up the `node_modules` directory to reduce function size
33
37
34
-
SAM Local can run this function on your computer inside a Docker container that acts like AWS Lambda. To run the function with an example event trigger that uses selenium to use headless chromium to visit `google.com`, run this:
38
+
It's a good idea to clean the `node_modules` directory before packaging to make the function size significantly smaller (making the function run faster!). You can do this using the `modclean` package:
39
+
40
+
To install it:
35
41
36
42
```sh
37
-
$ sam local invoke Lambdium -e event.json
43
+
$ npm i -g modclean
38
44
```
39
45
40
-
### Deploying
41
-
42
-
#### Creating a bucket for the function deployment
43
-
44
-
This will create a file called `packaged.yaml` you can use with Cloudformation to deploy the function.
45
-
46
-
You need to have an S3 bucket configured on your AWS account to upload the packed function files. For example:
##### Reducing function size for performance (and faster uploads!)
52
+
Follow the prompts and choose 'Y' to remove extraneous files from `node_modules`.
53
53
54
-
It's a good idea to clean the `node_modules` directory before packaging to make the function size significantly smaller (making the function run faster!). You can do this using the `modclean` package:
54
+
#### 3. Running locally with SAM Local
55
55
56
-
To install it:
56
+
SAM Local can run this function on your computer inside a Docker container that acts like AWS Lambda. To run the function with an example event trigger that uses selenium to use headless chromium to visit `google.com`, run this:
57
57
58
58
```sh
59
-
$ npm i -g modclean
59
+
$ sam local invoke Lambdium -e event.json
60
60
```
61
61
62
-
Then, run:
62
+
### Deploying
63
+
64
+
#### Creating a S3 bucket for the function deployment
65
+
66
+
This will create a file called `packaged.yaml` you can use with Cloudformation to deploy the function.
67
+
68
+
You need to have an S3 bucket configured on your AWS account to upload the packed function files. For example:
Follow the prompts and choose 'Y' to remove extraneous files from `node_modules`.
69
-
70
-
##### Packaging the function for Cloudformation using SAM
74
+
#### Packaging the function for Cloudformation using SAM
71
75
72
76
```sh
73
77
$ sam package --template-file template.yaml --s3-bucket $LAMBDA_BUCKET_NAME --output-template-file packaged.yaml
@@ -83,7 +87,7 @@ This will create the function using Cloudformation after packaging it is complet
83
87
84
88
If set, the optional `DEBUG_ENV` environment variable will log additional information to Cloudwatch.
85
89
86
-
## Invoking the function
90
+
### Running the function
87
91
88
92
Post-deploy, you can have lambda run a Webdriver script. There's an example of a selenium-webdriver simple script in the `examples/` directory that the Lambda function can now run.
0 commit comments