- A Google Cloud project with billing enabled.
- Pub/Sub API and Cloud Storage enabled.
- A Pub/Sub topic already created (this demo uses
kodekloud-demo-topic).
- Create a Cloud Storage bucket.
- Inspect the Pub/Sub topic.
- Create a subscription that writes messages to the bucket.
- Publish messages and confirm files appear in Cloud Storage.
- Clean up resources.
- In the Cloud Console search for “Buckets” → Create.
- Provide a globally unique name (demo uses
kodekloud-pubsub-bucket). - Leave other settings at their defaults and click Create.

kodekloud-demo-topic). The topic details page shows helpful monitoring metrics (published message count, publish requests, throughput) and export options (BigQuery, Cloud Storage).

- Go to Pub/Sub → Subscriptions → Create subscription.
- Enter a subscription ID (demo:
kodekloud-storage-sub). - Select the topic
projects/<your-project>/topics/kodekloud-demo-topic. - For Delivery type choose Write to Cloud Storage.
- Browse and select the bucket
kodekloud-pubsub-bucket. - Choose file format:
AvroorJSON(demo usesJSON). - Configure file batching (how frequently Pub/Sub writes files). Demo uses a 1 minute batch interval.

Pub/Sub requires permission to write objects into the destination bucket (typically the Pub/Sub service account needs Object Creator and Object Viewer roles). The Console can auto-assign these when you click “Set permission” during subscription creation.

kodekloud-pubsub-bucket in the Cloud Console. You should see new objects created by Pub/Sub; download them to view the JSON payloads.
Example Cloud Storage object URLs produced by this integration:
- Zero-infrastructure ingestion: Pub/Sub writes directly to Cloud Storage; you don’t need a streaming consumer running all the time.
- Files can be consumed by downstream tools: bulk load to BigQuery, process with Dataflow/Spark, run batch analytics, or archive raw events.
Always delete test topics, subscriptions, and buckets after your demo to prevent ongoing storage or Pub/Sub costs.
Links and references
- Pub/Sub documentation: https://cloud.google.com/pubsub/docs
- Cloud Storage documentation: https://cloud.google.com/storage/docs
- BigQuery export for Pub/Sub: https://cloud.google.com/pubsub/docs/integrations#bigquery