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

Receive direct events from Cloud Storage (Google Cloud console)

This quickstart shows you how to receive direct events from Cloud Storage in an unauthenticated Cloud Run service.

You can complete this quickstart using the Google Cloud console. For instructions using the Google Cloud CLI, see Receive direct events from Cloud Storage (gcloud CLI).

In this quickstart, you:

  1. Create a Cloud Storage bucket to be an event source.

  2. Deploy a sample service to Cloud Run to receive events.

  3. Create an Eventarc trigger to filter and route events.

  4. Generate an event by uploading a file to the Cloud Storage bucket, and view the event in the Cloud Run logs.


To follow step-by-step guidance for this task directly in the Google Cloud console, click Guide me:

Guide me


Before you begin

Some of the steps in this document might not work correctly if your organization applies constraints to your Google Cloud environment. In that case, you might not be able to complete tasks like creating public IP addresses or service account keys. If you make a request that returns an error about constraints, see how to Develop applications in a constrained Google Cloud environment.

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. Enable the Cloud Build and Eventarc APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  7. Enable the Cloud Build and Eventarc APIs.

    Enable the APIs

Create a Cloud Storage bucket

This quickstart uses Cloud Storage as the event source.

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

    Go to Cloud Storage

  2. Click Create.

  3. Enter a unique Name for your bucket.

    For example, hello-bucket.

  4. Click Continue.

  5. For Location type, select Region, and then select us-central1 (Iowa).

  6. Accept the other defaults.

  7. Click Create.

After the event source is created, you can deploy the event receiver service to Cloud Run.

Deploy the event receiver service to Cloud Run

Deploy a sample Cloud Run service that receives and logs events.

  1. In the Google Cloud console, go to Cloud Run.

    Go to Cloud Run

  2. Click Create service.

  3. In the Create service form:

    1. Select Deploy one revision from an existing container image.

    2. Click Test with a sample container.

    3. In the Region list, for the location of your service, select us-central1 (Iowa).

    4. For Authentication, select Allow unauthenticated invocations.

    5. To deploy the sample container image, click Create.

The deployment of the hello service can take up to two minutes to complete.

Create an Eventarc trigger

The Eventarc trigger will send events from the Cloud Storage bucket to the sample Cloud Run service.

  1. In the Google Cloud console, go to Eventarc.

    Go to Eventarc

  2. Click Create trigger.

  3. Type a Trigger name.

    For example, hello-trigger.

  4. In the Event provider list, select Google sources > Cloud Storage.

  5. In the Event list, select Direct > google.cloud.storage.object.v1.finalized.

  6. For Bucket, select the hello-bucket Cloud Storage bucket you created previously.

  7. If prompted, grant the following:

    • iam.serviceAccountTokenCreator role to Pub/Sub service account
    • pubsub.publisher role to Cloud Storage service account
  8. Use the Default compute service account as the service account that invokes your service.

  9. In the Event destination list, select Cloud Run.

  10. For the Cloud Run service, select the sample hello service you created previously.

  11. Click Create.

Note that although your trigger is created immediately, it can take up to two minutes for a trigger to be fully functional.

Generate and view an event

Generate an event and confirm that the Eventarc trigger is working as expected.

  1. To generate an event:

    1. Create a text file with the file name random.txt and the text "Hello World".

    2. In the Google Cloud console, go to Cloud Storage.

      Go to Cloud Storage

    3. Click the name of the storage bucket you created.

    4. In the Objects tab, click Upload files and upload the random.txt file.

    The upload generates an event and the Cloud Run service logs the event's message.

  2. To view the log entry:

    1. In the Google Cloud console, go to Cloud Run.

      Go to Cloud Run

    2. Click the name of the service you created.

    3. To retrieve the log entries for all revisions of this service, in the Service details page, click the Logs tab. You can filter by log severity level.

    4. Look for a log entry similar to:

      Received event of type google.cloud.storage.object.v1.finalized. Event data: [...]

Congratulations! You have successfully deployed an event receiver service to Cloud Run, created an Eventarc trigger, generated an event from Cloud Storage, and viewed it in the Cloud Run logs.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

While Cloud Run does not charge when the service is not in use, you might still be charged for storing the container image in Container Registry, Cloud Run resources, and for storing files in your Cloud Storage bucket.

You can delete your image, delete your storage bucket, and delete your service.

To delete the Eventarc trigger:

  1. In the Google Cloud console, go to Eventarc.

    Go to Eventarc

  2. Click the name of the trigger you created.

  3. On the Triggers details page, click Delete.

Alternatively, you can delete your Google Cloud project to avoid incurring charges. Deleting your Cloud project stops billing for all the resources used within that project.

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next