Serverless Event Body Option

homepage icon https://github.com/jubel-han/serverless-event-body-option
Follow @jubel-han

Tracked

NPM Downloads Last Month
43
Issues
0
Stars
0
Forks
0
Watchers
0
Watch Star Fork Issue Download License NPM Build Status Coverage Status Contributors

Repo README Contents:

serverless

Serverless Event Body Option

Overview

This is a plugin of the serverless framework, it provides the extra CLI option --body/-b for the invoke (local) command to support passing the HTTP body data directly.

Currently(serverless@1.32.0), The serverless framework providing the --data and --path options for the invoke command to passing the event data to the handler functions.

However, we have to use the string formatted(instead of JSON) HTTP body data for the value of body field in the JSON formatted event data.

which means that we have to escape the quotes for the actually JSON based body data.

e.g:

{"body": "{\"body_key\": \"body_value\"}"}

That makes the body data unreadable and unmanageable, especially for the complicated body data.

This plugin helped that! with it, we can specify the JSON formatted HTTP body data in the CLI directly instead of wrapping them in the event.

Installation

  1. Performing npm install at the root path of your service.
$ npm install --save serverless-event-body-option
  1. Adding the plugin to your serverless.yml file.
plugins:
  - serverless-event-body-option

Usage

Invoking the function

$ serverless invoke -f yourFunction --body '{"foo":"var"}'
$ serverless invoke -f yourFunction --body /path/to/your-body-data.json

You can also add the body option for the invoke local sub-command for invoking the function locally.