JAWS stack javascript aws node.js express auroradb dynamodb lambda

JAWS: The Javascript + AWS Stack

Gitter

This stack uses new tools from Amazon Web Services to completely redefine how to build massively scalable (and cheap) web applications.

To get started: follow the "Installation Guide" in the Wiki
To help contribute: check out the "JAWS Roadmap" and the "Contributors Guide"
To receive summaries of JAWS changes, join the "JAWS Email List"

Goals:

  • Use No Servers: Never deal with scaling/deploying/maintaining/monitoring servers again.
  • Isolated Components: The JAWS back-end is comprised entirely of AWS Lambda Functions. You can develop/update/configure each separately without affecting any other part of your application. Your app never goes down... only individual API routes can go down.
  • Scale Infinitely: A back-end comprised of Lambda functions comes with a ton of concurrency and you can easily enable multi-region redundancy.
  • Be Cheap As Possible: Lambda functions run only when they are called, and you only pay for when they are run.

Architecture

JAWS stack diagram javascript aws node.js express auroradb dynamodb lambda

API

There are no servers included in this stack. The entire back-end is comprised of Lambda functions which are organized in the api folder. Each of your API URLs points to one of these Lambda functions. This way, the code for each API Route is completely isolated, enabling you to develop/update/configure/deploy/maintain code for specific API urls at any time without affecting any other part of your application(!!!). Think of each Lambda function as a "Controller", in traditional MVC structure.

You can either use the AWS Management Console's API Gateway User Interface to create your API, or define your API in the api_swagger.json file and deploy instantly via AWS's Swagger Import Tool (Recommended).

Lib

The lib folder/module contains re-useable code you can use across all of your Lambda functions, which can be thought of as your "Models".

Since Lambda can be slow to initialize on cold-starts (after ~5 mins of inactivity), this module is designed so that you do not have to require all of its code, but instead you can require in only the code that your Lambda function needs. For example:

// This only loads code needed for the User Model
var ModelUser = require('../../../lib').models.User;

CLI

This stack comes with its own command line interface to help you test your API Lambda Functions locally and deploy them. The commands are:

Run A Lambda Function Locally

Make sure you are in the root folder of your Lambda function (api/users/signup) and enter this:

$ jaws run

Deploy A Lambda Function

Make sure you are in the root folder of your Lambda function (api/users/signup) and enter this:

$ jaws deploy

Start A Local Server

Make sure you are in thesite folder of the JAWS app and enter this:

$ jaws server

Site

Your website/client-side application. These assets can be uploaded and served from S3 for super fast response times.

Install

This process will create all the resources (S3,DynamoDb tables etc), IAM roles, groups and perms via cloud formation. It will allow you to create multiple stages (featuredev,test,staging,prod etc) very quickly and automatically inherit perms to a local development user.

Setup AWS resources

  1. Create an IAM user with privileges to create/update lambda - or give user all priv with AdministratorAccess policy. Make an API key. Copy temp.adminenv to .adminenv in your project root and replace API key values.
  2. Create another IAM user for development called dev-jaws. Make an API key. Copy lib/temp.env to cli/.env and replace API key values.
  3. Create an enviornment using Cloud Formation. Lets use the stage test for this example.
    1. Create CF Stack called test-jaws-data-model and use the aws/data-model-cf.json. Specify your domain name (used to create s3 bucket) and finish the wizard.
    2. Create CF Stack called test-jaws-api and use the aws/api-cf.json. Specify same domain and finish wizard
  4. Go to IAM, click on groups and search for jaws. Add this group to your dev-jaws user. Now anytime perms for the test env are changed, your dev user gets those perms.
  5. Create an S3 bucket and folders to hold ENV files for you lambda stages. Ex: lambdadeploy.mydomain.com/jaws/env/

Setup local project

  1. run npm install from both lib and cli dirs
  2. Install the JAWS CLI: from cli dir run npm install . -g (may need sudo)
  3. Modify cli/jaws.yml to specify deploy s3 bucket and path you created. Also setup IAM roles for each stage (right now you just have a test role)

Setup stage ENV vars

When you run jaws deploy <stage> JAWS cli will go out and fetch jaws.yml:jaws.deploy.envS3Location/<stage> and put it into your deployment zip file under lib/.env. This way your creds are not checked into SVN and they have tight ACLs managed by AWS.

  1. For each stage, make a copy of lib/temp.env and name it after the stage. So for this example copy temp.env to test. Replace ENV vars and add your own.
  2. Upload each stage env file to your jaws.yml:jaws.deploy.envS3Location/<stage> location. Make sure NOT to make the permissions public. Only people you want running jaws deploy should have their IAM user setup to access this s3 dir.

Starring

Javascript:

  • Node.js (in AWS Lambda functions)
  • jQuery (in your front-end site)

AWS Services:

  • DynamoDB - Managed, NOSQL data storage
  • Lambda - Build worker tasks that you can spawn and scale infinitely.
  • API Gateway - Launch an API with urls pointing to your Lambda functions
  • S3 - Host static assets for your site here

Other:

  • JSON Web Tokens

Other

Description
Serverless Framework – Build web, mobile and IoT applications with serverless architectures using AWS Lambda, Azure Functions, Google CloudFunctions & more! –
Readme 155 MiB
Languages
JavaScript 97.1%
Go 1.2%
Java 0.8%
Shell 0.4%
Python 0.2%