Skip to content

The serverless plugin that provides the extra CLI option for the invoke command to support passing the HTTP body data.

License

Notifications You must be signed in to change notification settings

jubel-han/serverless-event-body-option

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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([email protected]), 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

  • Specifying the data from stdin directly if the data is short.
$ serverless invoke -f yourFunction --body '{"foo":"var"}'
  • Specifying JSON file path which contains the body data if the data is complicated.
$ 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.

About

The serverless plugin that provides the extra CLI option for the invoke command to support passing the HTTP body data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published