[ ![Codeship Status for smallwins/fun](https://app.codeship.com/projects/6fbe7f70-21a9-0136-180a-5ea8301d74af/status?branch=master)](https://app.codeship.com/projects/285940)

## Setup

Preview locally using the `staging` database tables:

0. Copy `.arc-env-example` to `.arc-env` and get the `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` values from Brian
1. Install deps by running `npm run init`
2. Start a reloading dev server `npm start`

## Dev

Lint the code

`npm run lint`

Run the tests

`npm t`

Deploy one lambda to `staging`

`npm run deploy src/html/get-index`

Deploy static assets to `staging`

`npm run deploy static`

## CI

Green builds ship everything to `staging`


## important limits



| aws infra                                      | apps                                                           |
|------------------------------------------------|----------------------------------------------------------------|
| 60 api gateway restapis per region per account | means we can have max 30 apps per region                       |
| 15 total availability zones                    | 15 zones x 30 apps === 450 apps per account                    |
| 1000 iam roles per account                     | each app requires 1 iam role; still within 450                 |
| AWS Orgs lets us create 300 accounts           | 450x300 === 13500 max possible apps with default limits        |

takes about 2 minutes to provision one app which means at the current limits it will take 9.375 days to get to max capacity

| api gateway operational limits   | per min
| -------------------------------- | --
| DeleteRestApi 	                 |   2 per min
| CreateDeployment                 |	 3 per min
| GetResources 	                   | 150 per min
| CreateResource 	                 | 300 per min
| DeleteResource                	 | 300 per min

Total operations 	10 request per second (rps) with a burst limit of 40 requests

deletes are ok because we can queue those by removing from `app` in the db and adding to a `whatever-delete` table that has a lambda running on a timer cleaning it out. creates/gets: need to be throttled, ui updated with pending state and resolved with completion and/or timeout. ideally via queue to its global to the system/account.

# global infra

Each app is a preprovisioned arc app with:

- staging.app-name-0x1.fun.begin.com 
- app-name-0x1.fun.begin.com 

Static assets are also hosted via two cloudfront distributions:

- static.fun.begin.com/appname
- staging.static.fun.begin.com/appname

Once setup:

- Commits to master deploy to staging.app-name-0x1.fun.begin.com (if the build is green)
- Tags (Github releases) deploy to app-name-0x1.fun.begin.com (if the build is green)
- You can also initiate a release from the web ui
- Apps with `npm run build` defined will be run; `.static` is uploaded to their folder only; max 5mb
- Apps can add 3 HTML route Lambdas; max 5 mb ea
- Apps can add 5 JSON route Lambdas; max 5 mb ea
- HTML and JSON endpoints support sessions
 
