├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js └── 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 41 | tmp -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - '4' 5 | 6 | sudo: false 7 | 8 | install: 9 | - travis_retry npm install 10 | 11 | script: 12 | - npm test -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Takahiro Horike 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) 2 | # Serverless CommandLine Event Args 3 | ## Overview 4 | This is a Serverless Framework plugin. Event JSON passes to your Lambda function in commandline when you execute `serverless invoke`. 5 | Support for Serverless 1.0. 6 | 7 | I think useful for developers, because event.json is a little difficult to manage. 8 | 9 | - You get lost event.json under the control of the git. 10 | - A pain to edit the file every time you change the value of the argument. 11 | - If specified directly in the command line, pick up from the history, it's easy 12 | 13 | ## Usage 14 | Execute your Lambda function. Add `-e ''` or `--event ''`. 15 | 16 | $ serverless invoke -f YourFunction --event '{"foo":"var"}' 17 | 18 | ## Install 19 | Execute npm install in your Serverless project. 20 | 21 | $ npm install serverless-command-line-event-args 22 | 23 | Add the plugin to your `serverless.yml` file 24 | 25 | ```yml 26 | plugins: 27 | - serverless-command-line-event-args 28 | ``` 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const BbPromise = require('bluebird'); 3 | 4 | class ServerlessCommandLineEventArgs { 5 | constructor(serverless, options) { 6 | this.serverless = serverless; 7 | this.options = options; 8 | 9 | this.commands = { 10 | invoke: { 11 | options: { 12 | event: { 13 | usage: 'Event JSON passes function (e.g. --event \'{"foo":"var"}\' or -e \'{"foo":"var"}\')', 14 | shortcut: 'e' 15 | } 16 | } 17 | }, 18 | }; 19 | 20 | this.hooks = { 21 | 'before:invoke:invoke': this.setEvent.bind(this) 22 | } 23 | } 24 | 25 | setEvent() { 26 | if ( this.options.event !== undefined || this.options.event !== true ) { 27 | if ( this.isJson(this.options.event) ) { 28 | this.options.data = JSON.parse(this.options.event) 29 | } else { 30 | this.options.data = this.options.event 31 | } 32 | } 33 | return BbPromise.resolve(this); 34 | } 35 | 36 | isJson(arg) { 37 | if (typeof(arg) !== "string") { 38 | return false; 39 | } 40 | 41 | try { 42 | var arg = (!JSON) ? eval("(" + arg + ")") : JSON.parse(arg); 43 | return true; 44 | } catch(e) { 45 | return false; 46 | } 47 | } 48 | } 49 | module.exports = ServerlessCommandLineEventArgs; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "serverless-command-line-event-args", 3 | "version": "1.0", 4 | "engines": { 5 | "node": ">=4.0" 6 | }, 7 | "description": "The module is Serverless plugin. You can execute `serverless function run -e '{\"aaa\":\"bbb\"}'`", 8 | "author": "https://github.com/horike37", 9 | "license": "MIT", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/horike37/serverless-command-line-event-args" 13 | }, 14 | "keywords": [ 15 | "serverless framework plugin", 16 | "serverless applications", 17 | "serverless plugins", 18 | "api gateway", 19 | "lambda", 20 | "aws", 21 | "aws lambda", 22 | "amazon", 23 | "amazon web services", 24 | "serverless.com" 25 | ], 26 | "main": "index.js", 27 | "bin": {}, 28 | "scripts": { 29 | "test": "mocha tests/all" 30 | }, 31 | "devDependencies": { 32 | "chai": "^3.2.0", 33 | "mocha": "^2.2.5", 34 | "serverless": "^0.5.0" 35 | }, 36 | "dependencies": { 37 | "bluebird": "^3.0.6" 38 | } 39 | } 40 | --------------------------------------------------------------------------------