Este tópico descreve os comandos relacionados a funções na Function Compute Command Line Interface (fcli).
Pré-requisitos
Execute fcli shell no diretório que contém o arquivo executável para entrar no modo interativo.
Crie uma função (mkf)
-b stringou--code-bucket string: especifica o bucket do Object Storage Service (OSS) onde o código está localizado.-o stringou--code-object string: define a chave do objeto no bucket onde o código reside.-d stringou--code-dir string: indica o diretório que contém o código.-f stringou--code-file string: aponta para o arquivo de código compactado.-h stringou--handler string: determina o handler da função no formato "nome do arquivo.nome da função". Por exemplo, hello_world.handler indica que o handler é a função handler no arquivo hello_world.js.-e int32ou--initializationTimeout int32: configura o tempo limite da função inicializadora. Valor padrão: 30s.-i stringou--initializer string: identifica a função inicializadora.-m int32ou--memory int32: estabelece o tamanho de memória para execução da função.-t stringou--runtime string: seleciona o ambiente de runtime.--timeout int32: define o tempo limite da função. Valor padrão: 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.
Atualize uma função (upf)
-b stringou--code-bucket string: especifica o bucket do Object Storage Service (OSS) onde o código está localizado.-o stringou--code-object string: define a chave do objeto no bucket onde o código reside.-d stringou--code-dir string: indica o diretório que contém o código.-f stringou--code-file string: aponta para o arquivo de código compactado.-h stringou--handler string: determina o handler da função no formato "nome do arquivo.nome da função". Por exemplo, hello_world.handler indica que o handler é a função handler no arquivo hello_world.js.-m int32ou--memory int32: estabelece o tamanho de memória para execução da função.-t stringou--runtime string: seleciona o ambiente de runtime.
// 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 uma função (invk)
-eou--encode: codifica o valor de retorno da função em Base64.-f stringou--event-file string: lê o conteúdo do evento a partir de um arquivo.-s stringou--event-str string: obtém o conteúdo do evento de uma string.-o stringou--output-file string: define o nome do arquivo onde o resultado será gravado.-
-t stringou--type string: especifica o tipo de gatilho. Valores válidos:Sync: acionado sincronamente (valor padrão)
Async: acionado assincronamente
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.