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 (https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2).
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).
Clone the project:
$ git clone https://github.com/narainsagar/node-casperjs-aws-lambda.gitInstall dependencies using npm. It'll install the AWS SDK as well as PhantomJS on the development machine.
$ npm install # yarnAfter 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 setupcommand to generate the.envenvironment 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:
AWS_ENVIRONMENT=development
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_ROLE_ARN=your_amazon_role
AWS_REGION=us-east-1
AWS_FUNCTION_NAME=
AWS_HANDLER=index.handler
AWS_MODE=event
.....
.....
AWS_RUNTIME=nodejs
....FYI: You can also specify nodejs version for AWS_RUNTIME config option. i.e.,
AWS_RUNTIME=nodejs6.10To generate .env environment file run the following command:
$ ./node_modules/.bin/node-lambda setup
# OR
$ npm run setup # yarn setupTo run the function locally execute the following command:
$ ./node_modules/.bin/node-lambda run
# OR
$ npm run start # yarn startRun the following command to deploy the app to Amazon Lambda:
$ ./node_modules/.bin/node-lambda deploy
# OR
$ npm run deploy # yarn deployFor running tests:
$ npm run test # yarn testFor more about commands visit node_lambda repository here
Note: npm version 2.x or newer required to pass arguments to the scripts using
-- args
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.)
βββ README.md # project documentation guide.
βββ ... # etc
- Star our GitHub Repository β
- Fork our GitHub Repository π
- Create pull requests, submit bugs, suggest new features or documentation updates π§
My name is Narain Sagar, Iβm a FullStack JavaScript Developer, lives in Karachi, Pakistan and pretty much enjoying my life.
Medium | Website | Twitter | LinkedIn | Facebook | Github | Stack Overflow
MIT