# Manage functions

This guide shows you how to manage and detach a function that was created with
the `gcloud functions` command. To learn how to manage a function that was
created with the `gcloud run` command, see [Manage Cloud Run services](https://docs.cloud.google.com/run/docs/managing/services.md.txt).

> [!NOTE]
> **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.

Functions created using the [Cloud Functions v2 API](https://docs.cloud.google.com/functions/docs/apis.md.txt)
(for example, by using `gcloud functions`, the REST API, or Terraform) can be
managed with the [Cloud Run Admin API](https://docs.cloud.google.com/run/docs/reference/cloud-run-admin-api-overview.md.txt)
as well as the Cloud Functions v2 API. For example, you can update an
existing function using either `gcloud functions` or `gcloud run` commands:

### gcloud functions

      gcloud functions deploy FUNCTION_NAME \
        --runtime=nodejs24 \
        --source= . \
        --entry-point=ENTRYPOINT
        --trigger-http

### gcloud run

    gcloud run deploy FUNCTION_NAME \
      --source= . \
      --function=ENTRYPOINT
      --base-image=google-22-full/nodejs24

## Detach

The [`gcloud functions detach`](https://docs.cloud.google.com/sdk/gcloud/reference/functions/detach)
command lets you detach a Cloud Functions v2 function from its existing
API environment. After you detach a function, you can only manage it using the
Cloud Run Admin API. You might want to do this if your workloads need to stay
within the `run.googleapis.com` API boundary for
[Assured Workloads](https://docs.cloud.google.com/assured-workloads/docs/overview.md.txt), or to ensure
that your workloads use the [Cloud Run SKU](https://cloud.google.com/skus/sku-groups/cloud-run).

### Prepare your function for detach

When preparing to detach your function, consider the following:

- The detach operation is not reversible.
- The detach operation cannot be applied to Cloud Run functions (1st gen).
- Familiarize yourself with how to [deploy functions in Cloud Run](https://docs.cloud.google.com/run/docs/deploy-functions.md.txt) using the Google Cloud console, Google Cloud CLI, and Terraform.
- HTTP functions will retain their assigned URLs.
- Triggers attached to event-driven functions will be retained.
- Triggers cannot be managed through the `run.googleapis.com` API directly. Be sure to familiarize yourself with the trigger management guides for [Eventarc](https://docs.cloud.google.com/eventarc/docs.md.txt) or [Pub/Sub](https://docs.cloud.google.com/pubsub/docs/overview.md.txt).
- Disabling [retry on failure](https://docs.cloud.google.com/functions/docs/bestpractices/retries#event_driven_functions_created_with_v2_api) is not a supported feature on Cloud Run.
  - During the detach operation, Cloud Run functions modifies the triggers attached to functions configured with [no retry on failure](https://docs.cloud.google.com/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](https://docs.cloud.google.com/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. If you want to use a customer-managed encryption key for the DLQ topic, you can [update CMEK for the topic](https://docs.cloud.google.com/pubsub/docs/encryption.md.txt#update_cmek_for_a_topic) after detach.
- 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](https://cloud.google.com/skus/sku-groups/cloud-run).

### Detach your function

You can detach your function using the following command:

    gcloud functions detach FUNCTION_NAME

Replace <var translate="no">FUNCTION_NAME</var> with the name of your function.