You can list the subscriptions in a Google Cloud project with the Google Cloud console, Google Cloud CLI, client library, or Pub/Sub API.
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 list subscriptions and manage them,
ask your administrator to grant you the Pub/Sub Editor
( roles/pubsub.editor
)
IAM role on your topic or project.
For more information about granting roles, see Manage access to projects, folders, and organizations
.
This predefined role contains the permissions required to list subscriptions and manage them. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to list subscriptions and manage them:
- Pull from a subscription:
pubsub.subscriptions.consume
- Create a subscription:
pubsub.subscriptions.create
- Delete a subscription:
pubsub.subscriptions.delete
- Get a subscription:
pubsub.subscriptions.get
- List a subscription:
pubsub.subscriptions.list
- Update a subscription:
pubsub.subscriptions.update
- Attach a subscription to a topic:
pubsub.topics.attachSubscription
- Get the IAM policy for a subscription:
pubsub.subscriptions.getIamPolicy
- Configure the IAM policy
for a subscription:
pubsub.subscriptions.setIamPolicy
You might also be able to get these permissions with custom roles or other predefined roles .
List a subscription
You can list the subscriptions in a Google Cloud project with the Google Cloud console, Google Cloud CLI, client library, or Pub/Sub API.
Console
To list the subscriptions in a project, go to the Subscriptionspage.
Your subscriptions are listed in the table on the page.
gcloud
-
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 list the subscriptions in a Google Cloud project, run the
gcloud pubsub subscriptions list
command:gcloud pubsub subscriptions list [ --project = PROJECT_ID ]
REST
To list subscriptions in a project, use the projects.subscriptions.list
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
.
GET https://pubsub.googleapis.com/v1/projects/ PROJECT_ID /subscriptions Authorization: Bearer ACCESS_TOKEN
Where:
- PROJECT_ID is your project ID.
Response:
{ "subscriptions": [ { "name": "projects/ PROJECT_ID /topics/mysubscription1", "topic": "projects/ PROJECT_ID /topics/ TOPIC_ID ", "pushConfig": {}, "ackDeadlineSeconds": 10, "retainAckedMessages": true, "messageRetentionDuration": "604800s", "expirationPolicy": {} }, { "name": "projects/ PROJECT_ID /topics/mysubscription2", "topic": "projects/ PROJECT_ID /topics/ TOPIC_ID ", "pushConfig": { "pushEndpoint": "https:// PROJECT_ID .appspot.com/myhandler", "attributes": { "x-goog-version": "v1" } }, "ackDeadlineSeconds": 10, "retainAckedMessages": true, "messageRetentionDuration": "604800s", "expirationPolicy": {} } ] }
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C++ API reference documentation .
C#
Before trying this sample, follow the C# setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C# API reference documentation .
Go
The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, see the migration guide to v2 . To see a list of v1 code samples, see the deprecated code samples .
Before trying this sample, follow the Go setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Java API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
Node.ts
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
PHP
Before trying this sample, follow the PHP setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub PHP API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Python API reference documentation .
Ruby
The following sample uses Ruby Pub/Sub client library v3. If you are still using the v2 library, see the migration guide to v3 . To see a list of Ruby v2 code samples, see the deprecated code samples .
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Ruby API reference documentation .
List subscriptions to a topic
You can list the subscriptions to a topic with the Google Cloud console, Google Cloud CLI, or Pub/Sub API.
Console
- In the Google Cloud console, go to the Topicspage.
- Select a topic ID to open the Topic detailspage. The Subscriptionssection of the page includes of list of subscriptions to the topic.
gcloud
-
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 list the subscriptions in a Google Cloud project, run the
gcloud pubsub topics list-subscriptions
command:gcloud pubsub topics list-subscriptions TOPIC_ID
REST
To list subscriptions in a topic, use the projects.subscriptions.list
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
.
GET https://pubsub.googleapis.com/v1/projects/ PROJECT_ID /topics/ TOPIC_ID /subscriptions Authorization: Bearer ACCESS_TOKEN
Where:
- PROJECT_ID is your project ID.
- TOPIC_ID is your topic ID.
Response:
{ "subscriptions": [ "projects/ PROJECT_ID /subscriptions/mysubscription1", "projects/ PROJECT_ID /subscriptions/mysubscription2" ] }
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C++ API reference documentation .
C#
Before trying this sample, follow the C# setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub C# API reference documentation .
Go
The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, see the migration guide to v2 . To see a list of v1 code samples, see the deprecated code samples .
Before trying this sample, follow the Go setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Java API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
Node.ts
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Node.js API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Python API reference documentation .
Ruby
The following sample uses Ruby Pub/Sub client library v3. If you are still using the v2 library, see the migration guide to v3 . To see a list of Ruby v2 code samples, see the deprecated code samples .
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries . For more information, see the Pub/Sub Ruby API reference documentation .
What's next
- Create or modify a subscription with
gcloud
commands . - Create or modify a subscription with REST APIs .