Storage Transfer Service can listen to event notifications in Google Cloud to automatically transfer data that has been added or updated in a Cloud Storage bucket. Learn more about the benefits of event-driven transfers.
Event-driven transfers from Cloud Storage use Pub/Sub notifications to know when objects in the source bucket have been modified or added. Object deletions are not detected; deleting an object at the source does not delete the associated object in the destination bucket.
Event-driven transfers always use a Cloud Storage bucket as the destination.
Configure permissions
In addition to the
permissions required for all transfer jobs,
event-driven transfers require the Pub/Sub Subscriber role.
Find the name of the Storage Transfer Service service agent for your project:
Go to the
googleServiceAccounts.getreference page.An interactive panel opens, titled Try this method.
In the panel, under Request parameters, enter your project ID. The project you specify here must be the project you're using to manage Storage Transfer Service, which might be different from the source bucket's project.
Click Execute.
Your service agent's email is returned as the value of
accountEmail. Copy this value.The service agent's email uses the format
project-PROJECT_NUMBER@storage-transfer-service.iam.gserviceaccount.com.Grant the
Pub/Sub Subscriberrole to the Storage Transfer Service service agent.Cloud console
Follow the instructions in Controlling access through the Google Cloud console to grant the
Pub/Sub Subscriberrole to the Storage Transfer Service service. The role can be granted at the topic, subscription, or project level.gcloudCLIFollow the instructions in Set a policy to add the following binding:
{ "role": "roles/pubsub.subscriber", "members": [ "serviceAccount:project-PROJECT_NUMBER@storage-transfer-service.iam.gserviceaccount.com" }
Configure Pub/Sub
Make sure that you've satisfied the Prerequisites for using Pub/Sub with Cloud Storage.
Create a Pub/Sub notification for the source Cloud Storage bucket.
You cannot manage Pub/Sub notifications with the Google Cloud console. Use the gcloud CLI or one of the available client libraries instead.
gcloud storage buckets notifications create gs://SOURCE_BUCKET_NAME --topic=TOPIC_NAME
Create a pull subscription for the topic. You must create a separate subscription for each transfer job.
The following example shows the Google Cloud CLI command to create a pull subscription. For console instructions and client library code, see Create a pull subscription.
gcloud pubsub subscriptions create SUBSCRIPTION_ID --topic=TOPIC_NAME --ack-deadline=300
Create a transfer job
You can use the Google Cloud console, Google Cloud CLI, or REST API to create an event-based transfer job.
Don't include sensitive information such as personally identifiable information (PII) or security data in your transfer job name. Resource names may be propagated to the names of other Google Cloud resources and may be exposed to Google-internal systems outside of your project.