项目作者: RootedGlobal

项目描述 :
Base scaffolding app for a casperjs/phantomjs app running on Amazon (AWS) Lambda
高级语言: JavaScript
项目地址: git://github.com/RootedGlobal/node-casperjs-aws-lambda.git
创建时间: 2016-01-28T12:57:39Z
项目社区:https://github.com/RootedGlobal/node-casperjs-aws-lambda

开源协议:

下载


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 (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).

Table of Contents

Installation

Clone the project:

  1. $ git clone https://github.com/narainsagar/node-casperjs-aws-lambda.git

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

  1. $ npm install # yarn

Usage

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:

  1. AWS_ENVIRONMENT=development
  2. AWS_ACCESS_KEY_ID=your_key
  3. AWS_SECRET_ACCESS_KEY=your_secret
  4. AWS_ROLE_ARN=your_amazon_role
  5. AWS_REGION=us-east-1
  6. AWS_FUNCTION_NAME=
  7. AWS_HANDLER=index.handler
  8. AWS_MODE=event
  9. .....
  10. .....
  11. AWS_RUNTIME=nodejs
  12. ....

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

  1. AWS_RUNTIME=nodejs6.10

To generate .env environment file run the following command:

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

To run the function locally execute the following command:

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

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

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

For running tests:

  1. $ 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.

  1. . # project root directory
  2. ├── node_modules # project dependencies directory
  3. ├── .bin # node_modules bin directory
  4. ├── casperjs # casperjs executable
  5. ├── phantomjs # phantomjs executable
  6. └── ... # etc
  7. ├── bin # bin directory
  8. ├── phantomjs # local phantomjs executable
  9. └── ... # etc
  10. ├── src # source files
  11. ├── scripts # directory contains all casperjs scrapping scripts.
  12. ├── sample-script.js # sample casperjs script
  13. └── ... # etc
  14. ├── runner.js # dynamic casperjs script runner
  15. ├── utils.js # utility functions inside here.
  16. └── ... # etc
  17. ├── test # directory contains test files
  18. ├── basic.js # sample basic test
  19. └── ...
  20. ├── .env # it is where you place your AWS deployment configuration
  21. ├── .gitignore # exclude files/etc to be tracked & pushed on git (i.e., local configuration, credentials, dependencies, etc.)
  22. ├── 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)
  23. ├── event.json # it is where you mock your event
  24. ├── index.js # app main entry point
  25. ├── package.json # project details (i.e., version, author info, dependencies, etc.)
  26. ├── README.md # project documentation guide.
  27. └── ... # etc

Contributing

About Me

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

<a href=@narainsagar">

Follow Me 👍

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

License

MIT