Tous les produits
Search
Centre de documentation

:Commandes relatives aux fonctions

Dernière mise à jour :Aug 12, 2026

Cette rubrique décrit les commandes liées aux fonctions dans l'interface en ligne de commande (fcli) de Function Compute.

Prérequis

Exécutez fcli shell dans le répertoire contenant le fichier exécutable pour passer en mode interactif.

Créer une fonction (mkf)

  • -b string ou --code-bucket string : spécifie le bucket Object Storage Service (OSS) contenant le code.

  • -o string ou --code-object string : spécifie la clé d'objet du code dans le bucket.

  • -d string ou --code-dir string : spécifie le répertoire contenant le code.

  • -f string ou --code-file string : spécifie le fichier de code compressé.

  • -h string ou --handler string : spécifie le handler de la fonction au format « nom_fichier.nom_fonction ». Par exemple, hello_world.handler désigne la fonction handler du fichier hello_world.js.

  • -e int32 ou --initializationTimeout int32 : définit le délai d'expiration de la fonction d'initialisation. Valeur par défaut : 30 s.

  • -i string ou --initializer string : spécifie la fonction d'initialisation.

  • -m int32 ou --memory int32 : définit la mémoire allouée à l'exécution de la fonction.

  • -t string ou --runtime string : spécifie l'environnement d'exécution.

  • --timeout int32 : définit le délai d'expiration de la fonction. Valeur par défaut : 30 s.

// 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.

Mettre à jour une fonction (upf)

  • -b string ou --code-bucket string : spécifie le bucket Object Storage Service (OSS) contenant le code.

  • -o string ou --code-object string : spécifie la clé d'objet du code dans le bucket.

  • -d string ou --code-dir string : spécifie le répertoire contenant le code.

  • -f string ou --code-file string : spécifie le fichier de code compressé.

  • -h string ou --handler string : spécifie le handler de la fonction au format « nom_fichier.nom_fonction ». Par exemple, hello_world.handler désigne la fonction handler du fichier hello_world.js.

  • -m int32 ou --memory int32 : définit la mémoire allouée à l'exécution de la fonction.

  • -t string ou --runtime string : spécifie l'environnement d'exécution.

// 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.

Exécuter une fonction (invk)

  • -e ou --encode : encode la valeur de retour de la fonction en Base64.

  • -f string ou --event-file string : lit le contenu de l'événement depuis un fichier.

  • -s string ou --event-str string : lit le contenu de l'événement depuis une chaîne de caractères.

  • -o string ou --output-file string : spécifie le fichier de destination du résultat.

  • -t string ou --type string : spécifie le type de déclencheur. Valeurs valides :

    • Sync : déclenchement synchrone (valeur par défaut)

    • Async : déclenchement asynchrone

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.

Références