Run and Debug Functions locally through the API

Background Information

Fun Local Start Command Format

Usage: fun local start [options]    Allows you to run the Function Compute application locally for quick development & testing.
It will start an http server locally to receive requests for http triggers and apis.
It scans all functions in template.yml. If the resource type is HTTP, it will be registered to this http server, which can be triggered by the browser or some http tools.
For other types of functions, they will be registered as apis, which can be called by sdk in each language or directly via api.
Function Compute will look up the code by CodeUri in template.yml.
For interpreted languages, such as node, python, php, the modified code will take effect immediately, without restarting the http server.
For compiled languages such as java, we recommend you set CodeUri to the compiled or packaged localtion.
Once compiled or packaged result changed, the modified code will take effect without restarting the http server.
Options: -d, --debug-port <port> specify the sandboxed container starting in debug mode, and exposing this port on localhost
-c, --config <ide/debugger> output ide debug configuration. Options are vscode
-h, --help output usage information

Trigger functions locally through the API

fun local start [options]
$ fun local startapi localdemo/php72 was registered
url: http://localhost:8000/2016-08-15/services/localdemo/functions/php72/invocations/
api localdemo/python27 was registered
url: http://localhost:8000/2016-08-15/services/localdemo/functions/python27/invocations/
api localdemo/python3 was registered
url: http://localhost:8000/2016-08-15/services/localdemo/functions/python3/invocations/
api localdemo/nodejs6 was registered
url: http://localhost:8000/2016-08-15/services/localdemo/functions/nodejs6/invocations/
api localdemo/nodejs8 was registered
url: http://localhost:8000/2016-08-15/services/localdemo/functions/nodejs8/invocations/
api localdemo/java8 was registered
url: http://localhost:8000/2016-08-15/services/localdemo/functions/java8/invocations/
function compute app listening on port 8000!
pip install aliyun-fc2
import fc2client = fc2.Client(endpoint='http://localhost:8000', accessKeyID='<your access key id>', accessKeySecret='your access key secret')resp = client.invoke_function('localdemo', 'php72')print resp.headers
print resp.data

Original Source

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Being Productive by Upgrading Your VS Code with VS Code Vim Emulation

Alibaba Cloud AnalyticDB Performance Ranks First Globally

Pragmatic Performance Tuning For Django

Creating Your First Flask Application

Micro-frontends with AWS Amplify (Part 2)

AlgoExplorer 2.0: the new Algorand Block Explorer is here!

Build a Custom Paint Flutter App Widget

Jmeter Pre-processors-1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

How we migrated from RDS MySql to RDS Aurora and stopped suffering from lags

Achieving High Availability — Fault Tolerance

How to detect memory leak using BPF

KubeOrbit becomes part of CNCF Landscape