This topic describes function-related commands in Function Compute Command Line Interface (fcli).
Prerequisites
In the folder where the executable file is located, run the fcli shell command to enter the interactive mode.
Create a function (mkf)
-b stringor--code-bucket string: specifies the Object Storage Service (OSS) bucket where the code is located.-o stringor--code-object string: specifies the object key in the bucket where the code is located.-d stringor--code-dir string: specifies the directory where the code is located.-f stringor--code-file string: specifies the compressed code file.-h stringor--handler string: specifies the function handler, which is in the format "file name. function name". For example, hello_world.handler specifies that the handler is the handler function in the hello_world.js file.-e int32or--initializationTimeout int32: specifies the timeout period of the initializer function. Default value: 30s.-i stringor--initializer string: specifies the initializer function.-m int32or--memory int32: specifies the memory size for function execution.-t stringor--runtime string: specifies the runtime environment.--timeout int32: specifies the function timeout period. Default value: 30s.
// In the corresponding service directory
>>> mkf myFunction -t nodejs6 -h myFunction.handler -b ossBucketName -o objectKey //Saves code to an OSS bucket. In the command, -t specifies that the runtime is Node.js6, -h specifies the handler, -b specifies the OSS bucket where the code is located, and -o specifies the object key in the bucket where the code is located.
>>> mkf myFunction -t nodejs6 -h myFunction.handler -d codeDir/myFunction -m 512 //Saves code to a local directory. In the command, -d specifies the directory where the code is stored and -m specifies the memory size for function execution.
>>> mkf myFunction -h myFunction.handler -f code.zip -t nodejs6 //Saves code to the local code.zip file.Update a function (upf)
-b stringor--code-bucket string: specifies the Object Storage Service (OSS) bucket where the code is located.-o stringor--code-object string: specifies the object key in the bucket where the code is located.-d stringor--code-dir string: specifies the directory where the code is located.-f stringor--code-file string: specifies the compressed code file.-h stringor--handler string: specifies the function handler, which is in the format "file name. function name". For example, hello_world.handler specifies that the handler is the handler function in the hello_world.js file.-m int32or--memory int32: specifies the memory size for function execution.-t stringor--runtime string: specifies the runtime environment.
// In the corresponding service directory
>>> upf myFunction -t nodejs6 -h myFunction.handler -b ossBucketName -o objectKey //Saves code to an OSS bucket. In the command, -t specifies that the runtime is Node.js6, -b specifies the OSS bucket where the code is located, and -o specifies the object key in the bucket where the code is located.
>>> upf myFunction -t nodejs6 -h myFunction.handler -d codeDir/myFunction -m 512 //Saves code to a local directory. In the command, -d specifies the directory where the code is stored and -m specifies the memory size for function execution.
>>> upf myFunction -h myFunction.handler -f code.zip -t nodejs6 //Saves code to the local code.zip file.
>>> upf myFunction -t nodejs6 -i myFunction.newInitializer -e 30 -b ossBucketName -o objectKey //Updates the initializer function from myFunction.initializer to myFunction.newInitializer. The code is stored in an OSS bucket and contains the initializer function. In the command, -t specifies the runtime, -i specifies the initializer handler, -e specifies the initializer function timeout period, -b specifies the OSS bucket where the code is stored, and -o specifies the object key in the bucket where the code is stored.
>>> upf myFunction -t nodejs6 -i "" -b ossBucketName -o objectKey //Updates the initializer function from myFunction.newInitializer to empty to disable the initializer function.
>>> upf myFunction -t nodejs6 -i myFunction.newInitializer -e 30 -b ossBucketName -o objectKey //Updates an empty initializer function to myFunction.newInitializer.Execute a function (invk)
-eor--encode: encodes the return value of a function in Base64.-f stringor--event-file string: reads the event content from the file.-s stringor--event-str string: reads the event content from the string.-o stringor--output-file string: specifies the name of the file to which the result is written.-t stringor--type string: specifies the trigger type. Valid values:- Sync: synchronously triggered (default value)
- Async: asynchronously triggered
invk myFunction //Invokes the function if no input parameters are required and no events need to be triggered.
>>> invk myFunction -e //Encodes the return value of a function in Base64.
>>> invk myFunction -s 'hello,world'//Reads the event content from a string.
>>> invk myFunction -f event.json //Reads the event content from a file.
>>> invk myFunction -o code/result.txt //Writes the result to the result.txt file.
>>> invk myFunction -t Async //Sets the trigger type to Async.