2.0.3 • Published 4 months ago

@node-lambdas/cli v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@node-lambdas/cli

This CLI can be used to run or test cloud functions from a terminal.

How to install

Via NPM is the easiest:

npm i @node-lambdas/cli

If you don't have access to NPM registry, download the JS script and make it executable:

curl -o fn.mjs https://unpkg.com/@node-lambdas/cli@latest/fn.mjs
chmod +x fn.mjs

Introduction

A reusable cloud function is basically an HTTPS server:

input >> POST https://[service].jsfn.run/[function] >> output

For example: you have a JSON and you want to convert it to YAML, but you cannot install a program for that.

cat file.json | fn yaml encode | tee file.yml

Can I use it with cURL?

Absolutely!

curl -d @file.json https://yaml.jsfn.run/encode

Examples

# convert JSON to YAML
cat your.json | fn yaml

# calculate the sha256 hash for the content of file.txt
cat file.txt | fn sha 256

# convert Markdown to HTML
cat README.md | fn markdown

Run

Running any publicly available lambda or run your new project on localhost

Calling fn with a function name will pipe stdin to a cloud function and pipe the output back to stdout.

echo -n 'input' | fn [name]

# pipe file.txt to a lambda running in your machine
cat file.txt | fn +local

# pipe file.txt to a lambda running in your machine that uses port 2000
cat file.txt | fn +local +port=2000

You can see the available functions and read more in the index repository.

Run without input pipe

Usually you would use the syntax a | fn b to pipe data into a function. You can also add input options to fn instead, and bypass stdin.

Use +data='input data' to send the input data instead. You can also read from a file, using the +stdin=path/to/file, or the shortcut, @path/to/file.

For example:

fn data='hello' | fn base64
fn @input.txt | fn sha 512
fn +stdin=image.png | fn resize 1024x768

API Authentication

Some functions need credentials in order to run API calls. These credentials can be stored in a file called credentials.json.

The format is as follows:

  • the top level keys are authentication groups. You use this name with +auth.
  • each key under a group is a function name
  • each key under a function maps to an HTTP header that the function needs.

For example: let's say you want to call the same function with different credentials:

{
  "default" {
    "function-name": {
      "access-key-id": "key-123",
      "access-key": "cac54b35c4ab6a5c46abb"
    },
    "another-name": {
      "authentication": "bearer cac54b35c4ab6a5c46abb"
    },
  },
  "bob-credentials": {
    "function-name": {
      "access-key-id": "key-456",
      "access-key": "4524bc45ba54ba45b25c2"
    },
  },
}

You can invoke the same function passing the authentication group to use:

# Using default credentials
echo 'let me in' | fn +auth function-name

# Using both default and 'bob-credentials' to pipe from one function call to another. The third call will not use any credentials
echo 'let me in' | fn +auth function-name | fn +auth=bob-credentials function-name | fn another-name

All options

optiondescription
+auth=[name]Name of an authentication group to use from './credentials.json'
+port=[number]The http port to use when calling a local server with a running function
+data=[data]Use the data passed as argument instead of stdin for next step
+nodataRun the cloud function without any input
+info nameShows more details about a cloud function
+jsonShow cloud function API as JSON
2.0.3

4 months ago

2.0.2

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.16.3

9 months ago

1.16.2

9 months ago

1.16.1

9 months ago

1.16.0

9 months ago

1.16.6

8 months ago

1.16.5

9 months ago

1.16.4

9 months ago

1.15.0

11 months ago

1.14.0

1 year ago

1.13.6

1 year ago

1.13.5

1 year ago

1.13.4

1 year ago

1.13.7

1 year ago

1.13.3

3 years ago

1.13.2

4 years ago

1.13.1

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.4

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago

1.9.3

4 years ago

1.9.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago