Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

CasperJS AWS Lambda Template

A CasperJS node.js app for Amazon Lambda. Based on node-lambda-template using node-lambda. The app includes a PhantomJS binary (i.e., in the /bin/ directory named: phantomjs) compiled for AWS Linux (

Note: If you want to use different PhantomJS binary in your project, then you will be need to download a latest binary from here and replace it with /bin/phantomjs (i.e., Make sure you keep the name as is for now).

Table of Contents


Clone the project:

$ git clone

Install dependencies using npm. It'll install the AWS SDK as well as PhantomJS on the development machine.

$ npm install # yarn


After installing use the following npm commands as described below. They're only wrapping the node-lambda functionality to allow node-lambda to be installed only locally. Additional params can be provided using -- args. For a list of available options see the node-lambda documentation.

There are the 3 available commands:

  • setup: $ npm run setup
  • start: $ npm run start
  • deploy: $ npm run deploy

Run the $ npm run setup command to generate the .env environment file with the default configuration used for the Amazon Lambda function.

You need to edit the resulting .env file with your custom settings.

For this you need to have aws account and fill out confuguration in .env file:


FYI: You can also specify nodejs version for AWS_RUNTIME config option. i.e.,


To generate .env environment file run the following command:

$ ./node_modules/.bin/node-lambda setup
# OR
$ npm run setup # yarn setup

To run the function locally execute the following command:

$ ./node_modules/.bin/node-lambda run
# OR
$ npm run start # yarn start

Run the following command to deploy the app to Amazon Lambda:

$ ./node_modules/.bin/node-lambda deploy
# OR
$ npm run deploy # yarn deploy

For running tests:

$ npm run test # yarn test

For more about commands visit node_lambda repository here

Note: npm version 2.x or newer required to pass arguments to the scripts using -- args

Understanding the Codebase structure

This describes the app directory structure & conventions.

.                               # project root directory
├── node_modules                # project dependencies directory
│   ├── .bin                    # node_modules bin directory
│   ├── casperjs                # casperjs executable
│   ├── phantomjs               # phantomjs executable
│   └── ...                     # etc
├── bin                         # bin directory
│   ├── phantomjs               # local phantomjs executable
│   └── ...                     # etc
├── src                         # source files
│   ├── scripts                 # directory contains all casperjs scrapping scripts.
│   │   ├── sample-script.js    # sample casperjs script
│   │   └── ...                 # etc
│   ├── runner.js               # dynamic casperjs script runner
│   ├── utils.js                # utility functions inside here.
│   └── ...                     # etc
├── test                        # directory contains test files
│   ├── basic.js                # sample basic test
│   └── ...
├── .env                        # it is where you place your AWS deployment configuration
├── .gitignore                  # exclude files/etc to be tracked & pushed on git (i.e., local configuration, credentials, dependencies, etc.)
├── deploy.env                  # it has the same format as `.env`, but is used for holding any environment/config variables that you need to be deployed with your code to Lambda but you don't want in version control (e.g. DB connection info)
├── event.json                  # it is where you mock your event
├── index.js                    # app main entry point
├── package.json                # project details (i.e., version, author info, dependencies, etc.)
├──                   # project documentation guide.
└── ...                         # etc


About Me

My name is Narain Sagar, I’m a FullStack JavaScript Developer, lives in Karachi, Pakistan and pretty much enjoying my life.


Follow Me 👍

Medium | Website | Twitter | LinkedIn | Facebook | Github | Stack Overflow