Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Gérer les fonctions
Ce guide vous explique comment gérer et dissocier une fonction créée avec la commande gcloud functions. Pour savoir comment gérer une fonction créée avec la commande gcloud run, consultez Gérer les services Cloud Run.
Les fonctions créées à l'aide de l'API Cloud Functions v2 (par exemple, à l'aide de gcloud functions, de l'API REST ou de Terraform) peuvent être gérées avec l'API Cloud Run Admin ainsi que l'API Cloud Functions v2. Par exemple, vous pouvez mettre à jour une fonction existante à l'aide des commandes gcloud functions ou gcloud run:
gcloud run deploy FUNCTION_NAME \
--source= . \
--function=ENTRYPOINT
--base-image=google-22-full/nodejs22
Dissocier
La commande gcloud functions detach vous permet de dissocier une fonction Cloud Functions V2 de son environnement d'API existant. Une fois que vous avez dissocié une fonction, vous ne pouvez la gérer qu'à l'aide de l'API Cloud Run Admin. Vous pouvez le faire si vos charges de travail doivent rester dans la limite de l'API run.googleapis.com pour Assured Workloads ou pour vous assurer qu'elles utilisent le SKU Cloud Run.
Préparer votre fonction à la dissociation
Lorsque vous vous préparez à dissocier votre fonction, tenez compte des points suivants:
L'opération de détachement est irréversible.
L'opération de détachement ne peut pas être appliquée aux fonctions Cloud Run (1re génération).
Les fonctions HTTP conserveront les URL qui leur sont attribuées.
Les déclencheurs associés aux fonctions basées sur des événements seront conservés.
Les déclencheurs ne peuvent pas être gérés directement via l'API run.googleapis.com.
Veillez à vous familiariser avec les guides de gestion des déclencheurs pour Eventarc ou Pub/Sub.
La désactivation de l'option Réessayer en cas d'échec n'est pas une fonctionnalité prise en charge sur Cloud Run.
Lors de l'opération de détachement, les fonctions Cloud Run modifient les déclencheurs associés aux fonctions configurées avec aucune nouvelle tentative en cas d'échec pour s'assurer que le sujet Pub/Sub sous-jacent effectue au maximum cinq tentatives de diffusion. Une fois l'opération de détachement terminée, une file d'attente de lettres mortes stocke les messages non distribués, que vous pouvez récupérer en créant un abonnement à la file d'attente de lettres mortes.
Lorsqu'une fonction est dissociée, une nouvelle révision Cloud Run est créée. À partir de cette version, la fonction sera facturée à l'aide du code SKU Cloud Run.
Dissocier votre fonction
Vous pouvez dissocier votre fonction à l'aide de la commande suivante:
gcloud functions detach FUNCTION_NAME
Remplacez FUNCTION_NAME par le nom de votre fonction.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/05 (UTC)."],[[["\u003cp\u003eCloud Functions v2 API functions can be managed using either the Cloud Functions v2 API or the Cloud Run Admin API, allowing for flexibility in deployment and updates via \u003ccode\u003egcloud functions\u003c/code\u003e or \u003ccode\u003egcloud run\u003c/code\u003e commands.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud beta functions detach\u003c/code\u003e command enables the detachment of a Cloud Functions v2 function from its original API environment, transitioning its management exclusively to the Cloud Run Admin API.\u003c/p\u003e\n"],["\u003cp\u003eDetaching a function is irreversible and not applicable to Cloud Run (1st gen) functions, but HTTP functions retain their URLs and event-driven functions retain triggers.\u003c/p\u003e\n"],["\u003cp\u003eDetaching a function to the Cloud Run Admin API changes the billing to the Cloud Run SKU, and modifies the retry settings for event-driven functions to ensure a maximum of five delivery attempts with the use of a dead letter queue for undelivered messages.\u003c/p\u003e\n"],["\u003cp\u003eFollowing a successful detach operation, a new Cloud Run revision of the function is created, marking the point from which the function will be managed and billed through the Cloud Run framework.\u003c/p\u003e\n"]]],[],null,["# Manage functions\n================\n\nThis guide shows you how to manage and detach a function that was created with\nthe `gcloud functions` command. To learn how to manage a function that was\ncreated with the `gcloud run` command, see [Manage Cloud Run services](/run/docs/managing/services).\n| **Note:** If you created a Cloud Run function using `gcloud run` commands or the Cloud Run Admin API, you can't manage that function with `gcloud functions` commands or the Cloud Functions v2 API.\n\nFunctions created using the [Cloud Functions v2 API](/functions/docs/apis)\n(for example, by using `gcloud functions`, the REST API, or Terraform) can be\nmanaged with the [Cloud Run Admin API](/run/docs/reference/cloud-run-admin-api-overview)\nas well as the Cloud Functions v2 API. For example, you can update an\nexisting function using either `gcloud functions` or `gcloud run` commands: \n\n### gcloud functions\n\n gcloud functions deploy \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e \\\n --runtime=nodejs22 \\\n --source= . \\\n --entry-point=\u003cvar translate=\"no\"\u003eENTRYPOINT\u003c/var\u003e\n --trigger-http\n\n### gcloud run\n\n gcloud run deploy \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e \\\n --source= . \\\n --function=\u003cvar translate=\"no\"\u003eENTRYPOINT\u003c/var\u003e\n --base-image=google-22-full/nodejs22\n\nDetach\n------\n\nThe [`gcloud functions detach`](/sdk/gcloud/reference/functions/detach)\ncommand lets you detach a Cloud Functions v2 function from its existing\nAPI environment. After you detach a function, you can only manage it using the\nCloud Run Admin API. You might want to do this if your workloads need to stay\nwithin the `run.googleapis.com` API boundary for\n[Assured Workloads](/assured-workloads/docs/overview), or to ensure\nthat your workloads use the [Cloud Run SKU](/skus/sku-groups/cloud-run).\n\n### Prepare your function for detach\n\nWhen preparing to detach your function, consider the following:\n\n- The detach operation is not reversible.\n- The detach operation cannot be applied to Cloud Run functions (1st gen).\n- Familiarize yourself with how to [deploy functions in Cloud Run](/run/docs/deploy-functions) using the Google Cloud console, Google Cloud CLI, and Terraform.\n- HTTP functions will retain their assigned URLs.\n- Triggers attached to event-driven functions will be retained.\n- Triggers cannot be managed through the `run.googleapis.com` API directly. Be sure to familiarize yourself with the trigger management guides for [Eventarc](/eventarc/docs) or [Pub/Sub](/pubsub/docs/overview).\n- Disabling [retry on failure](/functions/docs/bestpractices/retries#event_driven_functions_created_with_v2_api) is not a supported feature on Cloud Run.\n - During the detach operation, Cloud Run functions modifies the triggers attached to functions configured with [no retry on failure](/functions/docs/bestpractices/retries#event_driven_functions_created_with_v2_api), to ensure that the underlying Pub/Sub topic makes a maximum of five delivery attempts. When the detach operation is completed, a [dead letter queue](/pubsub/docs/handling-failures#how_dead_letter_topics_work) topic stores the undelivered messages, which you can retrieve by creating a new subscription to the dead letter queue.\n- When a function is successfully detached, a new Cloud Run revision is created. Starting from that revision onwards, the function will be billed using the [Cloud Run SKU](/skus/sku-groups/cloud-run).\n\n### Detach your function\n\nYou can detach your function using the following command: \n\n gcloud functions detach \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003eFUNCTION_NAME\u003c/var\u003e with the name of your function."]]