You can delete Pub/Sub subscriptions with the Google Cloud console, Google Cloud CLI, client library, or Pub/Sub API.
This document discusses how to delete subscriptions in Pub/Sub.
- To manage your Google Cloud account, see Manage your Cloud Billing account.
- To manage your Google Account, see Payments & subscriptions.
Before you begin
- Learn about subscriptions.
- Create one of the following subscriptions, pull, push, or BigQuery.
Required roles and permissions
To get the permissions that you need to delete a subscription, ask your
administrator to grant you the Pub/Sub Editor
(roles/pubsub.editor
) IAM role on your
subscription or project that contains the subscription.
This predefined role contains the permissions required to delete a subscription. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
-
pubsub.subscriptions.delete
pubsub.subscriptions.list
- This permission is only required when deleting subscriptions using the Google Cloud console.
You might also be able to get these permissions with other custom roles or predefined Pub/Sub roles.
Delete subscriptions
If you try to create a subscription with the same name as the one that you just deleted, expect an error for a brief period.
- In the Google Cloud console, go to the Subscriptions page.
- Select the subscription to delete.
- Click Delete.
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
-
To delete a subscription, run the
gcloud pubsub subscriptions delete
command:gcloud pubsub subscriptions delete
SUBSCRIPTION_ID
To delete a subscription, use the
projects.subscriptions.delete
method:
Request:
The request must be authenticated with an access token in the
Authorization
header. To obtain an access token for the current
Application Default Credentials: gcloud auth application-default print-access-token
.
DELETE https://pubsub.googleapis.com/v1/projects/PROJECT_ID /subscriptions/SUBSCRIPTION_ID Authorization: BearerACCESS_TOKEN
Where:
Response:
If the request is successful, the response is an empty JSON object.
Delete is an eventually consistent operation, so it might take time for other processes to see its effect.
Before trying this sample, follow the C++ setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub C++ API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the C# setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub C# API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Go setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub Go API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Java setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub Java API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the PHP setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub PHP API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Python setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub Python API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub Ruby API reference documentation.
To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
What's next
- Create or modify a subscription with
gcloud
commands. - Create or modify a subscription with REST APIs.