A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/pubsub/docs/create-cloudstorage-subscription below:

Create Cloud Storage subscriptions | Pub/Sub

Skip to main content Create Cloud Storage subscriptions

Stay organized with collections Save and categorize content based on your preferences.

This document describes how to create a Cloud Storage subscription. You can use the Google Cloud console, the Google Cloud CLI, the client library, or the Pub/Sub API to create a Cloud Storage subscription.

Before you begin

Before reading this document, ensure that you're familiar with the following:

Required roles and permissions

The following is a list of guidelines regarding roles and permissions:

To get the permissions that you need to create Cloud Storage subscriptions, ask your administrator to grant you the Pub/Sub Editor (roles/pubsub.editor) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to create Cloud Storage subscriptions. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create Cloud Storage subscriptions:

You might also be able to get these permissions with custom roles or other predefined roles.

To let a principal in one project create a Cloud Storage subscription in another project, you must grant that principal the Pub/Sub Editor (roles/pubsub.editor) role in both projects. This provides the necessary permissions to create the new Google Cloud subscription and attach it to the original topic. The Pub/Sub Editor (roles/pubsub.editor) role on the topic also helps you attach Google Cloud subscriptions in a different project to the topic.

Assign roles to service accounts

Some Google Cloud services have Google Cloud-managed service accounts that let the services access your resources. These service accounts are known as service agents. Pub/Sub creates and maintains a service agent for each project in the format service-project-number@gcp-sa-pubsub.iam.gserviceaccount.com.

You can choose between letting the Pub/Sub service agent or a custom service account permission to write to the Cloud Storage bucket.

Granting permission to the Pub/Sub service agent means that any user who has permission to create a subscription in your project can write to the Cloud Storage bucket. If you want to provide more granular permission for writing to the Cloud Storage bucket, configure a custom service account instead.

For more information about Cloud Storage IAM, see Cloud Storage Identity and Access Management.

Assign Cloud Storage roles to the Pub/Sub service agent

If you want to create a Cloud Storage subscription using the Pub/Sub service agent, then it must have permission to write to the specific Cloud Storage bucket and to read the bucket metadata.

Grant the Storage Object Creator (roles/storage.objectCreator) and Storage Legacy Bucket Reader (roles/storage.legacyBucketReader) roles to the Pub/Sub service agent. Grant the permission on the individual bucket.

Bucket
  1. In the Google Cloud console, go to the Cloud Storage page.

    Go to Cloud Storage

  2. Click the Cloud Storage bucket to which you would like to write messages.

    The Bucket details page opens.

  3. In the Bucket details page, click the Permissions tab.

  4. In the Permissions > View by principals tab, click Grant access.

    The Grant access page opens.

  5. In the Add principals section, enter the name of your Pub/Sub service agent for the project containing the subscription.

    The format of the service agent is service-PROJECT_NUMBER@gcp-sa-pubsub.iam.gserviceaccount.com. For example, for a project with PROJECT_NUMBER=112233445566, the service agent is of the format service-112233445566@gcp-sa-pubsub.iam.gserviceaccount.com.

  6. In the Assign roles > Select a role drop-down, enter Creator and select the Storage Object Creator role.

  7. Click Add another role.

  8. In the Select a role drop-down, enter Bucket Reader, and select the Storage Legacy Bucket Reader role.

  9. Click Save.

Project
  1. In the Google Cloud console, go to the IAM page.

    Go to IAM

  2. In the Permissions > View by principals tab, click Grant access.

    The Grant access page opens.

  3. In the Add principals section, enter the name of your Pub/Sub service agent.

    The format of the service agent is service-PROJECT_NUMBER@gcp-sa-pubsub.iam.gserviceaccount.com. For example, for a project with PROJECT_NUMBER=112233445566, the service agent is of the format service-112233445566@gcp-sa-pubsub.iam.gserviceaccount.com.

  4. In the Assign roles > Select a role drop-down, enter Storage Admin and select the Storage Admin role.

  5. Click Save.

Assign Cloud Storage roles to a custom service account

If you want to use a custom service account for writing to a Cloud Storage bucket, then you must set the following permissions:

Create the service account and grant permissions with the following steps:

  1. Create the custom service account. The service account must be in the same project as the subscription.

  2. Grant the Storage Object Creator (roles/storage.objectCreator) and Storage Legacy Bucket Reader (roles/storage.legacyBucketReader) roles to the custom service account.

    You can grant the service account permission on a single table in the project or on all tables in the project. To do so, see the appropriate section in Assign Google Cloud roles to the Pub/Sub service agent. In the procedure, replace the Pub/Sub service agent email address with the custom service account email address.

  3. Give the Pub/Sub service agent the iam.serviceAccounts.getAccessToken permission on the custom service account or on all service accounts in the project. You can grant this permission by giving the roles/iam.serviceAccountTokenCreator role to the Pub/Sub service agent.

    Choose the appropriate method based on your requirements.

Service account
  1. In the Google Cloud console, go to the Service accounts page.

    Go to Service accounts

  2. Enter the name of the custom service account in the Filter.

  3. Select the service account from the list.

  4. Click Principals with access.

  5. Click Grant access.

  6. In the Add principals section, enter the name of your Pub/Sub service agent for the project containing the subscription. The format of the service agent is service-project-number@gcp-sa-pubsub.iam.gserviceaccount.com. For example, for a project with project-number=112233445566, the service agent is of the format service-112233445566@gcp-sa-pubsub.iam.gserviceaccount.com.

  7. In the Select a role drop-down, enter Service Account, and select the Service Account Token Creator role.

  8. Click Save.

Project
  1. In the Google Cloud console, go to the IAM page.

    Go to IAM

  2. Click Grant access.

  3. In the Add principals section, enter the name of your custom service account.

  4. In the Assign roles section, click Add another role.

  5. In the Select a role drop-down, enter Service Account, and select the Service Account Token Creator role.

  6. Click Save.

If you created the custom service account, you should already have the necessary iam.serviceAccounts.actAs permission. If you need to grant someone else the permission on the service account:

  1. In the Google Cloud console, go to the Service accounts page.

    Go to Service accounts

  2. Enter the name of the custom service account in the Filter.

  3. Select the service account from the list.

  4. Click Principals with access.

  5. Click Grant access.

  6. In the Add principals section, enter the name the account to which you want to grant access.

  7. In the Select a role drop-down, enter Service Account, and select the Service Account User role.

  8. Click Save.

Cloud Storage subscription properties

When you configure a Cloud Storage subscription, you must specify the properties common to all subscription types and some additional Cloud Storage subscription-specific properties.

Common subscription properties

Learn about the common subscription properties that you can set across all subscriptions.

Bucket name

A Cloud Storage bucket must already exist before you create a Cloud Storage subscription.

The messages are sent as batches and stored in the Cloud Storage bucket. A single batch or file is stored as an object in the bucket.

The Cloud Storage bucket must have Requester Pays disabled.

To create a Cloud Storage bucket, see Create buckets.

Filename prefix, suffix, and datetime

The output Cloud Storage files generated by the Cloud Storage subscription are stored as objects in the Cloud Storage bucket. The name of the object stored in the Cloud Storage bucket is of the following format: <file-prefix><UTC-date-time>_<uuid><file-suffix>.

The following list includes details of the file format and the fields that you can customize:

File batching

Cloud Storage subscriptions let you decide when you want to create a new output file that is stored as an object in the Cloud Storage bucket. Pub/Sub writes an output file when one of the specified batching conditions are met. The following are the Cloud Storage batching conditions:

For example, you can configure max duration as 6 minutes and max bytes as 2 GB. If at the 4th minute, the output file reaches a file size of 2 GB, Pub/Sub finalizes the previous file and starts writing to a new file.

A Cloud Storage subscription might write to multiple files in a Cloud Storage bucket simultaneously. If you have configured your subscription to create a new file every 6th minute, you might observe multiple Cloud Storage files being created every 6 minutes.

In some situations, Pub/Sub might start writing to a new file earlier than the time configured by the file batching conditions. A file might also exceed the Max bytes value if the subscription receives messages larger than the Max bytes value.

File format

When you create a Cloud Storage subscription, you can specify the format of the output files that are to be stored in a Cloud Storage bucket as Text or Avro.

Note: For users interested in writing files in Parquet format, the best way to stream Pub/Sub data into Parquet files is by using a BigQuery subscription with BigQuery tables for Apache Iceberg. For more information, see BigQuery subscriptions with Iceberg tables. Service account

You have the following options to write messages to a BigQuery table or Cloud Storage bucket:

Create a Cloud Storage subscription Console
  1. In the Google Cloud console, go to the Subscriptions page.

    Go to Subscriptions

  2. Click Create subscription.

  3. For the Subscription ID field, enter a name.

    For information about how to name a subscription, see Guidelines to name a topic or a subscription.

  4. Choose or create a topic from the drop-down menu.

    The subscription receives messages from the topic.

    For information about how to create a topic, see Create and manage topics.

  5. Select Delivery type as Write to Cloud Storage.

  6. For the Cloud Storage bucket, click Browse.

    When you specify the bucket, Pub/Sub checks for the appropriate permissions on the bucket for the Pub/Sub service agent. If there are permissions issues, you see a message similar to the following: Unable to verify if the Pub/Sub service agent has write permissions on this bucket. You may be lacking permissions to view or set permissions.

  7. If you get permission issues, click Set Permission and follow the on-screen instructions.

    Alternatively, follow the instructions in Assign Cloud Storage roles to the Pub/Sub service agent.

  8. For File format, select Text or Avro.

    If you select Avro, you can also optionally specify if you want to store the message metadata in the output.

    For more information about the two options including the message metadata option for the Avro format, see File format.

  9. Optional: You can specify the File name prefix, suffix, and datetime for all your files that are to be written to the Cloud Storage bucket. A file is stored as an object in the bucket.

    For more information about how to set the file prefix, suffix, and datetime, see Filename prefix, suffix, and datetime.

  10. For File batching, specify a maximum time to elapse before creating a new file.

    You can also optionally set the maximum file size or maximum number of messages for the files.

    For more information about both file batching options, see File batching.

  11. We strongly recommend that you enable Dead lettering to handle message failures.

    For more information, see Dead letter topic.

  12. You can keep the other settings as their defaults and click Create.

gcloud
  1. In the Google Cloud console, activate Cloud Shell.

    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.

  2. To create a Cloud Storage subscription, run the gcloud pubsub subscriptions create command.
    gcloud pubsub subscriptions create SUBSCRIPTION_ID \
        --topic=TOPIC_ID \
        --cloud-storage-bucket=BUCKET_NAME \
        --cloud-storage-file-prefix=CLOUD_STORAGE_FILE_PREFIX \
        --cloud-storage-file-suffix=CLOUD_STORAGE_FILE_SUFFIX \
        --cloud-storage-file-datetime-format=CLOUD_STORAGE_FILE_DATETIME_FORMAT \
        --cloud-storage-max-duration=CLOUD_STORAGE_MAX_DURATION \
        --cloud-storage-max-bytes=CLOUD_STORAGE_MAX_BYTES \
        --cloud-storage-max-messages=CLOUD_STORAGE_MAX_MESSAGES \
        --cloud-storage-output-format=CLOUD_STORAGE_OUTPUT_FORMAT \
        --cloud-storage-write-metadata
        --cloud-storage-use-topic-schema

    If you want to use a custom service account, provide it as an additional argument:

    gcloud pubsub subscriptions create SUBSCRIPTION_ID \
        --topic=TOPIC_ID \
        --cloud-storage-bucket=BUCKET_NAME \
        --cloud-storage-file-prefix=CLOUD_STORAGE_FILE_PREFIX \
        --cloud-storage-file-suffix=CLOUD_STORAGE_FILE_SUFFIX \
        --cloud-storage-file-datetime-format=CLOUD_STORAGE_FILE_DATETIME_FORMAT \
        --cloud-storage-max-duration=CLOUD_STORAGE_MAX_DURATION \
        --cloud-storage-max-bytes=CLOUD_STORAGE_MAX_BYTES \
        --cloud-storage-max-messages=CLOUD_STORAGE_MAX_MESSAGES \
        --cloud-storage-output-format=CLOUD_STORAGE_OUTPUT_FORMAT \
        --cloud-storage-write-metadata
        --cloud-storage-use-topic-schema
        --cloud-storage-service-account-email=SERVICE_ACCOUNT_NAME
        

    In the command, only SUBSCRIPTION_ID, the --topic flag, and the --cloud-storage-bucket flag are required. The remaining flags are optional and can be omitted.

    Replace the following:

C++

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 client libraries.

C#

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 client libraries.

Go

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 client libraries.

Java

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 client libraries.

Node.js

Before trying this sample, follow the Node.js setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub Node.js API reference documentation.

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Node.js

Before trying this sample, follow the Node.js setup instructions in the Pub/Sub quickstart using client libraries. For more information, see the Pub/Sub Node.js API reference documentation.

To authenticate to Pub/Sub, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

PHP

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 client libraries.

Python

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 client libraries.

Monitor a Cloud Storage subscription

Cloud Monitoring provides a number of metrics to monitor subscriptions.

For a list of all the available metrics related to Pub/Sub and their descriptions, see the Monitoring documentation for Pub/Sub.

You can also monitor subscriptions from within Pub/Sub.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-02 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-10-02 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.5