A sample project for the Serverless Framework using AWS and Node.js.
See the Serverless Guide for AWS.
Use the Serverless Framework with AWS to:
- Create Node.js Lambda Functions implementing CRUD functionality for a single DynamoDB Table
- Develop locally
- Implement Unit Tests with Mocks and Spies where appropriate
- Implement source code style conformity via JavaScript Linter rules
- Deploy to AWS dev from local
- Create API Gateway Methods forming a RESTful API for each of the Lambda Functions
- CORS support on API
- Use Cognito User Pools to Secure API 1
1 Feature in Future Release
- ES6 JavaScript
- YAML
- JSON
You may use any plain text editor. The recommended editor is Atom with the linter-eslint
package for code style rule feedback.
Fork the hello-serverless-aws-nodejs GitHub repository. Clone the project to your local machine.
The following packages must be installed on a development machine:
- Node 6.11.x
- npm 3.10.x
- serverless >=1.23.0 <2.0.0
After installing the dependencies listed above, open a terminal navigate to the project base directory, and run:
npm install
The project uses npm and serverless command line interface (CLI) commands to perform tasks. The following sections describe how to perform the most common activities.
To run the project's unit and integration tests, issue the following command.
npm test
To ensure the source code complies with style rules, run the ESLint linter by issueing the following command.
npm run lint
Note: The ESLint utility integrates with many text editors including Atom. If you use Atom, install the linter
and linter-eslint
packages to lint code changes in real-time.
Each stage of the project (dev, qa, prod) has a uniquely named custom domain under which the RESTful API is hosted. To create the custom domains in API Gateway, run command for the dev stage below. If you wish, you may run the commands for all stages.
# Development
serverless create_domain
# Test
serverless create_domain --stage qa
# Production
serverless create_domain --stage prod
To create all AWS resources and deploy the application, run the following command. Use the --stage
option to deploy to qa
or prod
.
serverless deploy -v
Note: The -v
option is short for --verbose
. This optional flag instructs serverless to provide detailed, real-time progress from AWS as the deployment operation is executed.
To remove all AWS resources, run the following command. Use the --stage
option to cleanup the qa
or prod
environments.
serverless remove -v