Skip to main content

๐ŸŒฑ function

Function commands allow you to create and manage your functions, run them locally before pushing to GreenCloud, deploy your functions to GreenCloud, list all your tasks and fetch the results of a task.

Requirements

Once you have created your function, you must be working within the function directory to use the function, fx subcommands.

function, fxโ€‹

info

This command will return all the function subcommands that are available in the GreenCloud CLI.

$ gccli function --help
NAME:
gccli function - manages functions

USAGE:
gccli function command [command options] [arguments...]

COMMANDS:
init generates a new function with the data provided
info shows information about current function
lang lists all available languages for function
start starts function image to test locally
logs displays logs of local function
stop stops function container running
edit changes name/description of current function
invoke invokes a remote function
result gets result of task
deploy builds and pushes multi-arch container images
public creates public endpoint to invoke directly
list lists all functions
delete deletes function
restore restores function by ID
sync syncs function from server
tasks lists all tasks
builds lists all builds
metrics gets metrics of function
capabilities changes capabilities

OPTIONS:
--help, -h show help

function initโ€‹

info

This subcommand of the function command initiates the configuration process of creating a new function.

$ gccli function init --help
NAME:
gccli function init - generates a new function with the data provided

USAGE:
gccli function init -n NAME -l LANG -d 'DESCRIPTION'

OPTIONS:
--lang value, -l value sets language or template to use
--name value, -n value sets name to be used in function
--description value, -d value sets description of function
--offline, -o creates function in offline mode (default: false)
--no-folder, --nf uses current folder (default: false)
--help, -h show help

Exampleโ€‹

$ gccli function init  
๐Ÿ”‘ Obtaining accessToken...
๐Ÿ‘ท Validating inputs...
๐Ÿฅผ Name โ†’ functionTests
๐Ÿ”– Language โ†’ go
๐Ÿ‘” Description โ†’ Creating a test function
โŒš Timeout โ†’ 10
๐Ÿ“ก Sharing information...
๐Ÿ“„ Copying template...
๐Ÿ“ Saving configuration...
๐ŸŒฑ Function created successfully!

function infoโ€‹

info

This subcommand of the function command shows information about the current function: ID, Name, Description, Language and Capabilities.

$ gccli function info --help
NAME:
gccli function info - shows information about current function

USAGE:
gccli function info

OPTIONS:
--quiet -q only print function ID
--help, happy shows help

function langโ€‹

info

This subcommand of the function command lists all the available languages that can be used for your function.

$ gccli function lang --help
NAME:
gccli function lang - lists all available languages for function

USAGE:
gccli function lang

OPTIONS:
--help, happy shows help

function startโ€‹

info

This subcommand will attempt to start your function locally on your machine. You must make sure that you have docker installed and running. If the function is already running, GreenCloud will stop the function, rebuild it and start it again.

$ gccli function start --help
NAME:
gccli function start - starts function image to test locally

USAGE:
gccli function start -p 8080 -t 10 -l

OPTIONS:
--port value, -p value sets port to expose the function (default: 8080)
--timeout value, -t value sets maximum execution time in seconds (default: 10)
--logs, -l sets displays logs (default: false)
--cpu, -c sets number of cpu cores used for function (default: 1)
--memory, -machine sets megabytes of memory used for function (default: 256)
--help, -h shows help

Exampleโ€‹

$ gccli function start  
๐Ÿ‘ท Validating inputs...
๐Ÿงญ Port โ†’ 8080
โŒš Timeout โ†’ 10
โœ‹ Stopping existing container...
๐Ÿ˜Ž Function successfully stopped!
๐Ÿงฉ Compiling image [OK]
๐Ÿ”— Running โ†’ http://localhost:8080

function logsโ€‹

info

This subcommand will display logs of the local function.

$ gccli function logs --help
NAME:
gccli function logs - displays logs of local function

USAGE:
gccli function logs [command options]

OPTIONS:
--help, -h shows help

function stopโ€‹

info

This subcommand will stop your running function container.

$ gccli function stop --help
NAME:
gccli function stop - stops function container running

USAGE:
gccli function stop

OPTIONS:
--help, -h shows help

function editโ€‹

info

This command will allow you to change the name and description of the function.

$ gccli function edit --help
NAME:
gccli function edit - changes name/description of current function

USAGE:
gccli function edit -n NAME

OPTIONS:
--name value, -n value sets name to be used in function
--description value, -d value sets description of function
--help, -h shows help

Exampleโ€‹

$ gccli function edit  
๐Ÿ‘ท Validating inputs...
๐Ÿฅผ Name โ†’ rebootTest
๐Ÿ‘” Description โ†’ A new description
โŒš Timeout โ†’ 10
๐Ÿ’พ Saving configuration...
๐Ÿฅผ Function edited successfully!

function invokeโ€‹

info

The invoke subcommand allows you to call your function (once it has been deployed into GreenCloud - see the deploy subcommand for more information) and pass Body and Query Parameters to your function.

$ gccli function invoke --help
NAME:
gccli function invoke - invokes a remote function

USAGE:
gccli function invoke -i ID -b '{"key":"value"}'

OPTIONS:
--id value, -i value ID of function to invoke
--body value, -b value sets body to be sent to function
--query value, -q value sets query params to be sent to function
--no-body do not send body to function (default: false)
--no-query do not send query params to function (default: false)
--help, -h show help

Exampleโ€‹

$ gccli function invoke  
๐Ÿ‘ท Validating inputs...
๐Ÿ“„ Obtaining local information...
๐Ÿ“š Body โ†’
๐Ÿ” Query โ†’
โŒš Timeout โ†’ 10
๐Ÿš€ Invoking function...
๐Ÿ“Œ ID: 647732f56aa774b668102963
๐Ÿ“ป Waiting for task to output...
๐Ÿงพ 200 โ†’ Hello from GO by GreenCloud!

function resultโ€‹

info

Use this function subcommand to obtain the results from a particular call. Every call in GreenCloud is assigned an ID. You can find the ID in the invoke response (See above). Use this ID to get the results from your function.

$ gccli function result --help
NAME:
gccli function result - gets result of a task using it's ID

USAGE:
gccli function result -i ID

OPTIONS:
--id value, -i value ID of task
--help, -h show help

Exampleโ€‹

$ gccli function result -i 647733866aa774b558101974
๐Ÿ‘ท Validating inputs...
๐Ÿ”– ID โ†’ 647733866aa774b558102969
๐Ÿ“ป Waiting for task to output...
๐Ÿงพ 200 โ†’ Hello from GO by GreenCloud!

function deployโ€‹

info

When you are happy with your function and ready to register it into GreenCloud - you use this command to build the container again and then publish it into the GreenCloud registry.

$ gccli function deploy --help
NAME:
gccli function deploy - builds and pushes multi-arch container images

USAGE:
gccli function deploy [command options] [arguments...]

OPTIONS:
--arch value, -c value arch to build function
--help, -h show help

Exampleโ€‹

$ gccli function deploy
๐Ÿ‘ท Verifying configuration...
๐Ÿ“ฆ๏ธ Archs: AMD64,ARM64,ARM
๐Ÿงฉ Compiling multi-arch image [OK] (22mb)
๐Ÿšš Pushing image to registry... [f242784c9c0d]
๐Ÿ”ฅ Function successfully uploaded!

function publicโ€‹

info

Use this command carefully! This where GreenCloud starts to get cool! Using this command you generate a public URL that you can call and pass Query Parameters and Body Payloads into.

$ gccli function public --help
NAME:
gccli function public - create public endpoint to invoke to directly

USAGE:
gccli function public [command options] [arguments...]

OPTIONS:
--id value, -i value ID of function
--delete, -d deletes existing endpoint (default: false)
--help, -h shows help

Exampleโ€‹

$ gccli function public
๐Ÿ‘ท Validating inputs...
๐Ÿšจ You must keep the public endpoint safe!
๐Ÿ”— Any existing endpoint will be revoked
โœ‹ Do you wish to continue? (y/n) โ†’ y
๐Ÿค– Public endpoint created successfully!
๐Ÿ”— https://api.greencloud.dev/gc/e1179ceba33144b7a214f92344590123

function public listโ€‹

info

This command lists all the function's public endpoints.

$ gccli function public list --help
NAME:
gccli function public list - lists all a given function's public endpoints

USAGE:
gccli function public list [command options]

OPTIONS:
--id value, -i value ID of function
--help, -h shows help

function listโ€‹

info

This subcommand of the function command lists all the functions.

$ gccli function list --help
NAME:
gccli function list - lists all functions

USAGE:
gccli function list

OPTIONS:
--help, happy shows help

function deleteโ€‹

info

This command will delete the function from the list of functions in your account. You will be prompted to confirm that this is what you want to do. Remember - this will NOT delete your source code but simply the GreenCloud configuration that enables you to run that function on the internet. You must be in same directory as the function you wish to delete AND the .gcfunction file must be present. It is also possible to delete the function with an ID and passing the -i parameter.

$ gccli function delete --help
NAME:
gccli function delete - deletes function

USAGE:
gccli function delete [command options] [arguments...]

OPTIONS:
--id value, -i value ID of function
--force, -f deletes current folder (default: false)
--help, -h shows help

Exampleโ€‹

$ gccli function delete
๐Ÿ‘ท Verifying configuration...
โœ‹ Stopping existing container...
๐Ÿ˜Ž Function successfully stopped!
๐Ÿšš All related data will be deleted
๐Ÿšจ This action cannot be undone!
โœ‹ Do you wish to continue? (y/n) โ†’ y
๐Ÿ”ฅ Function deleted successfully!

function restoreโ€‹

info

This is a VERY powerful and useful command. You can restore your GreenCloud function onto any machine. The command has some extra sub parameters that you can pass to choose whether to create the directory, the template or just the .gcfunction file.

$ gccli function restore --help
NAME:
gccli function restore - restore function by ID

USAGE:
gccli function restore -i ID

OPTIONS:
--id value, -i value ID of function
--quiet, -q choose to only restore config file (default: false)
--help, -h shows help

Exampleโ€‹

$ gccli function restore -i 6477283e599b4ee92e5171231
๐Ÿ‘ท Validating inputs...
๐Ÿ”– ID โ†’ 6477283e599b4ee92e517101
๐Ÿ” Obtaining information...
๐Ÿ“„ Copying template...
๐Ÿ“ Creating config file...
๐Ÿงฌ Function restored successfully!

function syncโ€‹

info

This command syncs the function from the server.

$ gccli function sync --help
NAME:
gccli function sync - syncs function from server

USAGE:
gccli function sync

OPTIONS:
--help, -h shows help

function tasksโ€‹

info

This command lists all tasks of a function using it's ID.

$ gccli function tasks --help
NAME:
gccli function tasks

USAGE:
gccli function tasks -i ID

OPTIONS:
--id value, -i value ID of function
--help, -h shows help

function buildsโ€‹

info

This command lists all builds of a given function using it's ID.

$ gccli function builds --help
NAME:
gccli function builds - lists all function builds

USAGE:
gccli function builds -i ID

OPTIONS:
--id value, -i value ID of function
--help, -h shows help

function metricsโ€‹

info

This command lists metrics of a given function using it's ID.

$ gccli function metrics --help
NAME:
gccli function metrics - gets metrics of a function

USAGE:
gccli function metrics -i ID

OPTIONS:
--id value, -i value ID of function
--help, -h shows help

function capabilitiesโ€‹

info

This command changes the capabilities of a given function. You must have docker running and must be in the function directory to use this command.

$ gccli function capabilities --help
NAME:
gccli function capabilities - change capabilities of a function

USAGE:
gccli function capabilities [command options] [argument]

OPTIONS:
--timeout -t sets maximum execution time in seconds
--cpu -c sets number of cpu cores used (default: 1)
--memory -m sets megabytes of memory used (default: 256)
--sync sets active sync mode (default: false)
--help, -h shows help