---
title: "GCP Pub/Sub | WebhookRelay"
meta:
  "og:description": "Subscribe to Google Cloud Pub/Sub topics and publish webhook data to Pub/Sub using Webhook Relay service connections."
  "og:title": "GCP Pub/Sub"
  description: "Subscribe to Google Cloud Pub/Sub topics and publish webhook data to Pub/Sub using Webhook Relay service connections."
---

![Stripes](https://webhookrelay.com/docs/service-connections/gcp_pubsub/images/stripes.svg)

Documentation

**Fundamentals**

# **GCP Pub/Sub**

Subscribe to Google Cloud Pub/Sub topics and publish webhook data to Pub/Sub using Webhook Relay service connections.

Connect Webhook Relay to **Google Cloud Pub/Sub** to receive messages from subscriptions (input) or publish webhook data to topics (output).

## [Prerequisites](#prerequisites)

- A [GCP service connection](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections) with a service account that has Pub/Sub permissions
- A Pub/Sub topic and subscription in your GCP project

### [GCP Roles](#gcp-roles)

**For Pub/Sub Input (subscribe):**

- `roles/pubsub.subscriber` — the subscription must already exist in your project

**For Pub/Sub Output (publish):**

- `roles/pubsub.publisher`

## [Pub/Sub Input — Receive Messages from a Subscription](#pubsub-input-receive-messages-from-a-subscription)

Pub/Sub inputs subscribe to an existing subscription and relay messages into your Webhook Relay bucket. Messages are auto-acknowledged after successful relay. Message data and attributes are wrapped in a JSON envelope.

### [Configuration](#configuration)

| Field | Required | Description |
| --- | :---: | --- |
| `subscription_name` | Yes | Pub/Sub subscription name (must already exist in the project) |

> The subscription must be pre-created in your GCP project before adding it as an input. Webhook Relay does not create subscriptions automatically.

## [Pub/Sub Output — Publish Webhooks to a Topic](#pubsub-output-publish-webhooks-to-a-topic)

![GCP Pub/Sub output](https://webhookrelay.com/docs/service-connections/gcp_pubsub/images/docs/sc/add_gcp_pubsub.png)

Pub/Sub outputs publish incoming webhook data as messages to your Pub/Sub topic. The topic must already exist in your project. You can find them in your "Pub/Sub" section in the GCP console:

![Browse your GCP PubSub topics](https://webhookrelay.com/docs/service-connections/gcp_pubsub/images/docs/sc/sc_gcs_sub.png)

### [Configuration](#configuration-1)

| Field | Required | Description |
| --- | :---: | --- |
| `topic_name` | Yes | Pub/Sub topic name |

## [Example: Bridge AWS SQS to GCP Pub/Sub](#example-bridge-aws-sqs-to-gcp-pubsub)

Route messages from an AWS SQS queue into a GCP Pub/Sub topic. This is ideal for migrating workloads across cloud providers or running multi-cloud architectures:

1. Create an [AWS service connection](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections) with SQS read permissions
2. Create a [GCP service connection](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections) with Pub/Sub publisher permissions
3. Create a bucket in Webhook Relay
4. Add an **[AWS SQS](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections/aws_sqs) input** on the bucket
5. Add a **GCP Pub/Sub output** on the bucket

Messages polled from SQS are automatically published to your Pub/Sub topic.

### [Transform Between Formats](#transform-between-formats)

Attach a [Function](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/webhooks/functions) to adapt the message format. For example, convert an SQS message into a structured Pub/Sub payload:

```
const sqsMessage = JSON.parse(r.body)

// Restructure for Pub/Sub consumers
const pubsubPayload = {
    source: "aws-sqs",
    original_message_id: sqsMessage.MessageId,
    data: sqsMessage.Body,
    bridged_at: new Date().toISOString()
}

r.setBody(JSON.stringify(pubsubPayload))
```

See the [JSON encoding](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/webhooks/functions/manipulating-json) guide for more transformation examples.

## [Example: Pub/Sub to Any HTTPS Endpoint](#example-pubsub-to-any-https-endpoint)

Deliver Pub/Sub messages as webhooks to any API that accepts HTTPS requests. This works well for services without native GCP integration:

1. Create a GCP service connection
2. Create a bucket with a **Pub/Sub input**
3. Add a [public destination](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/webhooks/public/public-destination) (any HTTPS URL)

Use a [Function](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/webhooks/functions) to add authentication or transform the payload before delivery:

```
const message = JSON.parse(r.body)

// Forward only the message data, add auth header
r.setBody(message.data)
r.setHeader("Authorization", "Bearer " + cfg.get("API_TOKEN"))
r.setHeader("Content-Type", "application/json")
```

See [configuration variables](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/webhooks/functions/modify-request#getting-configuration-values) for how to securely store API tokens in functions.

## [Example: Pub/Sub to Localhost for Development](#example-pubsub-to-localhost-for-development)

Receive Pub/Sub messages on your local machine during development — no need to deploy to GCP:

1. Create a GCP service connection
2. Create a bucket with a **Pub/Sub input**
3. Add an [internal destination](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/webhooks/internal/localhost) pointing to `http://localhost:3000/webhook`
4. Run the [Webhook Relay agent](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/installation/cli) locally

Messages from your Pub/Sub subscription are forwarded to your local server in real time.

## [Example: AWS SNS to GCP Pub/Sub](#example-aws-sns-to-gcp-pubsub)

Publish [AWS SNS](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections/aws_sns) messages to a Pub/Sub topic. Useful when your processing pipeline runs on GCP but events originate in AWS:

1. Create an [AWS service connection](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections) with SNS subscribe permissions
2. Create a [GCP service connection](https://webhookrelay.com/docs/service-connections/gcp_pubsub/docs/service-connections) with Pub/Sub publisher permissions
3. Create a bucket with an **AWS SNS input** and a **GCP Pub/Sub output**

Optionally add a function to filter or transform the SNS message before publishing to Pub/Sub.

Did this page help you?