├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | dist 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/Release 26 | 27 | # Dependency directory 28 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 29 | node_modules 30 | 31 | #IDE Stuff 32 | **/.idea 33 | 34 | #OS STUFF 35 | .DS_Store 36 | .tmp 37 | 38 | #SERVERLESS STUFF 39 | admin.env 40 | .env -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kenneth Winner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Serverless Graph 2 | 3 | This project was adapted from [CFVIZ](https://github.com/benbc/cloud-formation-viz/blob/master/cfviz). Serverless Graph outputs your serverless architecture and resources as a [Graphviz](http://www.graphviz.org/) dot compatible output. Currently only supports the AWS provider. 4 | 5 | **Note:** Serverless *v1.x.x* or higher is required. 6 | 7 | ### Example Output 8 | 9 | ![Example Generated Graph](https://user-images.githubusercontent.com/1689118/27201203-d700053a-51ea-11e7-8aae-91de39820e41.png) 10 | 11 | #### Clarity Mode Graph 12 | 13 | We built in a "clarity" mode, that attempts to remove a lot of boilerplate serverless stuff (permissions, lambda versions, etc) in order to increase understanding. The above graph is show here in clarity mode. 14 | 15 | ![Example Clarity Mode Generated Graph](https://user-images.githubusercontent.com/1689118/27201314-394b0226-51eb-11e7-9595-0577107fb4a0.png) 16 | 17 | ### Why? 18 | 19 | Sometimes this is the fastest way to just visualize everything going on, it can also be extremely helpful in debugging circular dependency issues in CloudFormation templates. 20 | 21 | ### Get Started 22 | * `npm install --save serverless-graph` 23 | * Install graphviz 24 | * Homebrew - brew install graphviz 25 | * Add serverless-graph to the plugins section of your serverless.yml 26 | 27 | ### Run 28 | If you have any commandline params that don't have defaults you will have to pass in any opt variables as this plugin hooks into the package step and then reads the output. 29 | * `sls graph {--opts}` 30 | * Output SVG 31 | * `cat graph.out | dot -Tsvg -oexample.svg` 32 | * Output PNG 33 | * `cat graph.out | dot -Tpng -oexample.png` 34 | * See [Graphviz](http://www.graphviz.org/pdf/dot.1.pdf) for more information. 35 | 36 | ### Options (--help) 37 | 38 | ``` 39 | Plugin: ServerlessGraph 40 | graph ......................... Creates graphviz compatible graph output of nodes and edges. Saves to graph.out file. 41 | --vertical ......................... Graph nodes from top down instead of left to right. 42 | --edgelabels / -e .................. Display edgelabels in graph. 43 | --clarity / -c ..................... By default we show everything, clarity mode will attempt to remove implied nodes and edges for a better graph 44 | --outFile / -o ..................... Output file, defaults to graph.out 45 | ``` 46 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'), 4 | fs = require('fs'), 5 | BbPromise = require('bluebird'), 6 | CFGraph = require('cloudformation-graph'); 7 | 8 | class ServerlessGraph { 9 | constructor(serverless, options) { 10 | this.serverless = serverless; 11 | this.options = options; 12 | 13 | // set the providers name here 14 | this.provider = this.serverless.getProvider('providerName'); 15 | 16 | this.commands = { 17 | graph: { 18 | usage: "Creates graphviz compatible graph output of nodes and edges. Saves to graph.out file.", 19 | lifecycleEvents: [ 20 | 'graph', 21 | ], 22 | options: { 23 | vertical: { 24 | usage: 'Graph nodes from top down instead of left to right.' 25 | }, 26 | edgelabels: { 27 | usage: 'Display edgelabels in graph.', 28 | shortcut: 'e' 29 | }, 30 | clarity: { 31 | usage: 'By default we show everything, clarity mode will attempt to remove implied nodes and edges for a better graph', 32 | shortcut: 'c' 33 | }, 34 | outFile: { 35 | usage: 'Output file, defaults to graph.out', 36 | shortcut: 'o' 37 | } 38 | } 39 | } 40 | }; 41 | 42 | this.hooks = { 43 | 'before:graph:graph': () => BbPromise.bind(this) 44 | .then(() => { 45 | if (!this.options.package && !this.serverless.service.package.path) { 46 | return this.serverless.pluginManager.spawn('package'); 47 | } 48 | return BbPromise.resolve(); 49 | }), 50 | 51 | 'graph:graph': () => BbPromise.bind(this) 52 | .then(this.graph), 53 | }; 54 | } 55 | 56 | graph() { 57 | const currentDir = process.cwd(); 58 | var serverless = this.serverless; 59 | 60 | var options = this.options; 61 | options.outFile = options.outFile || 'graph.out' 62 | let fileName = `${currentDir}/.serverless/cloudformation-template-update-stack.json`; 63 | 64 | let cfGraphOptions = this.options; 65 | let cfGraph = new CFGraph(cfGraphOptions); 66 | try { 67 | serverless.cli.log("Rendering graph..."); 68 | let graph = cfGraph.graph(fileName); 69 | fs.writeFileSync(this.options.outFile, graph) 70 | serverless.cli.log(`Graph saved to ${this.options.outFile}`); 71 | } catch (e) { 72 | throw new serverless.classes.Error(e.message) 73 | } 74 | return 75 | } 76 | } 77 | 78 | module.exports = ServerlessGraph; 79 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "serverless-graph", 3 | "version": "0.3.1", 4 | "lockfileVersion": 1, 5 | "dependencies": { 6 | "argparse": { 7 | "version": "1.0.9", 8 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", 9 | "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=" 10 | }, 11 | "balanced-match": { 12 | "version": "1.0.0", 13 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 14 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" 15 | }, 16 | "bluebird": { 17 | "version": "3.5.0", 18 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", 19 | "integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=" 20 | }, 21 | "brace-expansion": { 22 | "version": "1.1.8", 23 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", 24 | "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=" 25 | }, 26 | "cloudformation-graph": { 27 | "version": "1.1.3", 28 | "resolved": "https://registry.npmjs.org/cloudformation-graph/-/cloudformation-graph-1.1.3.tgz", 29 | "integrity": "sha512-NtiEfuXnXI6eej7AvjrxVs8wqZhxI5aB6d2sEp0ZbH6Y158q0oIgnclJQw5zPXeztijdRGpAKDpAXoLpT8Ifrw==" 30 | }, 31 | "concat-map": { 32 | "version": "0.0.1", 33 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 34 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 35 | }, 36 | "fs.realpath": { 37 | "version": "1.0.0", 38 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 39 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" 40 | }, 41 | "inflight": { 42 | "version": "1.0.6", 43 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 44 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=" 45 | }, 46 | "inherits": { 47 | "version": "2.0.3", 48 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 49 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 50 | }, 51 | "is-valid-json": { 52 | "version": "1.0.2", 53 | "resolved": "https://registry.npmjs.org/is-valid-json/-/is-valid-json-1.0.2.tgz", 54 | "integrity": "sha1-tavVv5ZWIjng0WvkFFtveh14U48=" 55 | }, 56 | "lodash": { 57 | "version": "4.17.4", 58 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", 59 | "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" 60 | }, 61 | "once": { 62 | "version": "1.4.0", 63 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 64 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=" 65 | }, 66 | "path-is-absolute": { 67 | "version": "1.0.1", 68 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 69 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" 70 | }, 71 | "sprintf-js": { 72 | "version": "1.0.3", 73 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", 74 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" 75 | }, 76 | "wrappy": { 77 | "version": "1.0.2", 78 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 79 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 80 | }, 81 | "yamljs": { 82 | "version": "0.2.10", 83 | "resolved": "https://registry.npmjs.org/yamljs/-/yamljs-0.2.10.tgz", 84 | "integrity": "sha1-SBzHwlynOvWfWR8MluPOVsdXpA8=", 85 | "dependencies": { 86 | "glob": { 87 | "version": "7.1.2", 88 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", 89 | "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==" 90 | }, 91 | "minimatch": { 92 | "version": "3.0.4", 93 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 94 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==" 95 | } 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "serverless-graph", 3 | "version": "0.3.2", 4 | "engines": { 5 | "node": ">=4.0" 6 | }, 7 | "description": "Serverless Graph - A serverless plugin for creating a graph usable by graphviz.", 8 | "author": "Ken Winner", 9 | "license": "MIT", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/trek10inc/serverless-graph" 13 | }, 14 | "keywords": [ 15 | "serverless graph", 16 | "serverless graph plugin", 17 | "serverless applications", 18 | "serverless plugins", 19 | "api gateway", 20 | "lambda", 21 | "aws", 22 | "aws lambda", 23 | "amazon", 24 | "amazon web services", 25 | "serverless.com" 26 | ], 27 | "main": "index.js", 28 | "bin": {}, 29 | "scripts": { 30 | "test": "echo No tests here" 31 | }, 32 | "dependencies": { 33 | "bluebird": "^3.0.6", 34 | "cloudformation-graph": "^1.1.3" 35 | } 36 | } 37 | --------------------------------------------------------------------------------