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
+43-18Lines changed: 43 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -18,50 +18,75 @@ Since this Lambda function is written using node.js, you can run almost any scri
18
18
#### Requirements
19
19
20
20
* An AWS Account
21
-
*[Terraform](https://terraform.io) (optional but highly recommended for function creation and deploy)
21
+
*[AWS SAM Local](https://github.com/awslabs/aws-sam-local) AWS tool for running functions locally [Serverless Application Model](https://github.com/awslabs/serverless-application-model)
22
22
* node.js + npm
23
23
* Bash
24
-
*`make`
25
24
26
-
#### Installing `modclean`
25
+
#### Fetching dependencies
27
26
28
-
Lambdium uses the `modclean` NPM package to reduce the size of the `node_modules` directory. To install it, run:
27
+
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).
29
28
30
29
```sh
31
-
npm i -g modclean
30
+
$ ./scripts/fetch-dependencies.sh
32
31
```
33
32
34
-
#### Fetching dependencies
33
+
#### Running locally with SAM
35
34
36
-
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).
35
+
```sh
36
+
$ sam local invoke Lambdium -e event.json
37
+
```
38
+
39
+
### Deploying to
40
+
41
+
#### Creating a bucket for the function deployment
42
+
43
+
This will create a file called `packaged.yaml` you can use with Cloudformation to deploy the function.
44
+
45
+
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
+
53
+
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
+
55
+
To install it:
56
+
57
+
```sh
58
+
$ npm i -g modclean
59
+
```
60
+
61
+
Then, run:
62
+
63
+
```sh
64
+
$ modclean --patterns="default:*"
40
65
```
41
66
42
-
####Building Lambda `.zip` archive
67
+
##### Packaging the function for Cloudformation using SAM
43
68
44
69
```sh
45
-
$ make lambda
70
+
$ sam package --template-file template.yaml --s3-bucket $LAMBDA_BUCKET_NAME --output-template-file packaged.yaml
46
71
```
47
72
48
-
#### Creating and Deploying Using Terraform
73
+
#### Creating and Deploying Using SAM
49
74
50
-
This will create the function using Terraform with all required permissions.
75
+
This will create the function using Cloudformation after packaging it is complete.
51
76
52
77
```sh
53
-
$ make deploy
78
+
$ sam deploy --template-file ./packaged.yaml --stack-name <<your-cloudformation-stack-name>> --capabilities CAPABILITY_IAM
54
79
```
55
80
56
-
The optional `DEBUG_ENV` environment variable will log additional information to Cloudwatch. The `PATH` environment variable points to the `bin` directory in this project—this is required in order to launch the `chromedriver` process.
81
+
If set, the optional `DEBUG_ENV` environment variable will log additional information to Cloudwatch.
57
82
58
-
## Usage
83
+
## Invoking the function
59
84
60
-
If dependencies are installed and `make deploy` succeeds you can have Lambda run a script. There's an example of a selenium-webdriver simple script in the `examples/` directory that the Lambda function can now run.
85
+
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.
61
86
62
-
Expected JSON input for the function: `{"Base64Script": "<Base64 Encoding of Selenium Script>"}` (this can also be provided as an environment variable named `BASE64_SCRIPT`).
87
+
Expected JSON input for the function is: `{"Base64Script": "<Base64 Encoding of Selenium Script>"}` (this can also be provided as an environment variable named `BASE64_SCRIPT`).
63
88
64
-
To run the example Selenium script, you can use the example with the AWS CLI in the `scripts` directory. It takes care of base64 encoding the file:
89
+
To run the example Selenium script, you can use the example with the AWS CLI in the `scripts` directory. It takes care of base64 encoding the file and assumes the function name is `lambdium` running in `us-west-2`:
0 commit comments