Prepare and test your skills

Prepare and test your skills

Cloud Run (opens in a new tab) is a fully managed serverless platform for running highly scalable containerized applications on Google Cloud. Code packaged as a container image runs in sandboxed container instances without creating clusters or managing servers. You pay only for the time your code runs, and you can use familiar frameworks such as Nginx, Express.js, and Django while connecting to databases such as Cloud SQL.
Cloud Run services and resource types define how containerized code is executed and reached. A Cloud Run service is an HTTPS endpoint backed by stateless container instances that scale automatically and can respond to web requests or events. Each service gets a unique HTTPS endpoint on a *.run.app domain with managed TLS, and it supports WebSockets, HTTP/2 end-to-end, and gRPC end-to-end. Your code must listen on a TCP port, and the platform routes each request to a container instance.
Cloud Run offers four resource types that share the same execution environment but fit different workloads:
| Resource | What it does | Choose when |
|---|---|---|
| Service | Responds to HTTP requests at a stable endpoint with dynamic or manual scaling | The workload serves web requests or events |
| Job | Runs parallelizable tasks manually or on a schedule until completion | The workload must run to completion once |
| Worker pool | Handles always-on background work from message queues | The workload continuously processes queues such as Pub/Sub or Kafka |
| Instance | Runs a long-lived, singleton runtime environment | The workload needs continuous, single-instance operation |
Traffic management for services reduces deployment risk by supporting gradual rollouts, rollback to a previous revision, and splitting traffic across multiple revisions at the same time. For example, traffic flows from clients to 1% of requests on a new revision and then increases while telemetry is monitored.
Storage, autoscaling, and traffic handling in Cloud Run control where data lives and how instances grow with demand. Eventarc (opens in a new tab) delivers events from Google services to Cloud Run as HTTP requests. Cloud Run containers are ephemeral, so any file written inside a container instance is temporary and comes out of the available memory for the service. For persistent storage, data must flow from the container instance to an external service such as Cloud Storage (opens in a new tab), Firestore, Cloud SQL, Spanner, Memorystore, or a third-party solution. This boundary means restarts and scale-in events lose local files, while external storage keeps data across revisions and instances.
Autoscaling in Cloud Run is managed by Google and works at the revision level. Each revision scales out to the number of container instances needed to handle incoming requests, up to one thousand instances or more with a quota increase, and then removes idle containers when demand falls. When a revision receives no traffic, it scales to zero instances by default, but a minimum-instances setting can keep one or more instances idle or warm to avoid cold starts. A maximum-instances setting can limit scale-out to control cost or protect downstream systems.
By default, Cloud Run routes incoming requests to back-end containers and performs load balancing for you. For enterprise features, traffic can flow from an external HTTP(S) load balancer through serverless network endpoint groups to the Cloud Run service, which enables Cloud CDN, multi-region serving, and middleware such as API Gateway.
Security, identity, and permissions in Cloud Run control who can reach a service and what the service can access. A Cloud Run service is private by default, which means it cannot be accessed without authentication credentials in the request. Access is controlled on two boundaries: identity and network. On the identity side, an access policy using Identity and Access Management (IAM) determines who can invoke the service, and every revision is linked to a service account that authenticates to Google Cloud APIs. On the network side, ingress settings can restrict access to internal VPC and internal services traffic only, and Identity-Aware Proxy can require authenticated users.
Event-driven services stay private and depend on IAM grants so Eventarc can deliver authenticated HTTP requests to them. The required permissions include:
roles/run.invoker) on the Cloud Run service for the service account that invokes the serviceroles/eventarc.eventReceiver) on the project for the Compute Engine default service account so the trigger can receive eventsroles/pubsub.publisher) for the Cloud Storage service account to publish storage eventsroles/iam.serviceAccountTokenCreator) for the Pub/Sub service agent in some older projects to support authenticated pushIf the Invoker role is missing, the trigger is created and becomes ACTIVE but delivery fails, and logs show that the request was not authenticated.
Exam tip: Cloud Run services are private by default; allow public access only when unauthenticated internet access is intended, otherwise keep authentication and grant the Invoker role to the Eventarc service account.
Logging and monitoring in Cloud Run capture what happened inside services without extra setup. Cloud Logging (opens in a new tab) automatically receives two types of logs from Cloud Run services. Request logs record requests sent to Cloud Run services and are created automatically, while container logs are emitted from container instances, typically from application code. Both log types are stored in Cloud Logging and can be viewed from the Cloud Run Services page in the console or from the Logs Explorer, which provides more detail and filtering.
Cloud Monitoring is integrated with Cloud Run with no setup required, so metrics from running services are captured automatically. Monitoring provides performance monitoring, metrics, uptime checks, and alerts that notify when metric thresholds are exceeded. There is no charge for metrics on fully managed Cloud Run, and custom metrics are also supported.
Event-driven processing with Eventarc on Cloud Run routes change events from Google services to a container as HTTP requests. Cloud Audit Logs (opens in a new tab) can also supply events through Eventarc when direct events are not available. By specifying filters for an Eventarc trigger, you configure routing from an event source to an event target, including the provider, event type, and destination service. The Cloud Storage bucket must reside in the same Google Cloud project and region or multi-region as the trigger, and the trigger can take up to two minutes after creation to become fully functional.
A complete event flow moves from the source through Eventarc to the service in an ordered workflow:
A left-to-right process flow showing an event source feeding Pub/Sub transport, matched by an Eventarc trigger filter, then delivered as an authenticated HTTP POST in CloudEvents format to a Cloud Run destination.
google.cloud.storage.object.v1.finalized for object creation or google.cloud.pubsub.topic.v1.messagePublished for messages, with the Cloud Run service as the destination.random.txt to the bucket or publishing a message to the topic, then view the entry in Cloud Run logs.When a file upload occurs, data flows from the Cloud Storage bucket to Eventarc, and Eventarc sends an HTTP request to the Cloud Run service, which logs an entry such as Received event of type google.cloud.storage.object.v1.finalized. When a Pub/Sub message is published, data flows from the Pub/Sub topic through the Eventarc-managed subscription to the Cloud Run service, which logs the message payload. Subscriptions created for Eventarc persist regardless of activity and do not expire by default.
Deploying Cloud Functions means packaging code with a runtime, an entry point, and a trigger, then making it live so Google Cloud runs it without servers to manage. A function can be created in the Google Cloud console or with the gcloud CLI, and an Eventarc (opens in a new tab) trigger connects the function to Google Cloud events from Cloud Pub/Sub or Cloud Storage. When a matching event occurs, Eventarc routes the event to the function as an HTTP request in CloudEvents format.
Deploying Cloud Functions with the console and gcloud CLI creates a serverless function that stays idle until it is invoked and then scales automatically. In the console you go to the Cloud Run functions page and choose Create function, select 2nd gen environment and a region, configure the trigger, set the runtime such as Node.js 24 and the entry point such as slackNotifier, provide the index.js and package.json code, and click Deploy. With the gcloud CLI you deploy source code to the same kind of function and the result shows properties including name, runtime, status such as ACTIVE, timeout such as 60s, service account email, and the event trigger when one is attached.
A complete console deployment for an event-driven function follows an ordered flow:
slackNotifier, and select a Compute Engine region.index.js and package.json, and click Deploy.The function depends on its trigger, code, and service account. After deployment the function receives a Slack-style notification or other action whenever the connected Google Cloud source emits a matching event.
HTTP-triggered functions and background functions differ in what starts them and what data they receive. An HTTP-triggered function starts when a client or service sends an HTTP request directly to its URL. A background function starts when a system event occurs, such as a message published to a Pub/Sub topic or an object change in a Cloud Storage bucket, and Eventarc delivers that event to the function.
| Function type | How it is invoked | Choose when |
|---|---|---|
| HTTP-triggered function | A direct HTTP request calls the function URL | The work starts from a user action, webhook, or service call |
| Background function | An Eventarc trigger forwards a Pub/Sub or Cloud Storage event to the function | The work must respond automatically to system events without polling |
Choose an HTTP-triggered function when an outside caller decides when to run. Choose a background function when Google Cloud itself should start the work, such as processing every new file or every new message.
Configuring Pub/Sub message triggers for functions links a topic to a function so each message starts work. A Cloud Pub/Sub (opens in a new tab) trigger starts serverless work whenever a message published to a Pub/Sub topic matches the trigger filter. The data flows from the publisher to the Pub/Sub topic, from the topic through the Eventarc trigger to the destination function or workflow, and the event is passed as a runtime argument that the code can decode and return. The trigger uses the event type google.pubsub.topic.publish and the resource name projects/PROJECT_ID/topics/TOPIC_NAME with service pubsub.googleapis.com.
To use Pub/Sub events, first create the topic and deploy the receiver, then create the Eventarc trigger that links them, then publish a message to generate an event. Publishing a message causes the destination to execute once per matching event, and you confirm success by viewing the execution result or logs that show the decoded message. The trigger region should match the function region, and the trigger uses a service account so Eventarc has permission to invoke the destination.
Configuring Cloud Storage object change triggers for functions links a bucket to a function so file changes start work. The bucket is the event source and the function, Cloud Run service, or workflow is the event destination. You can trigger notifications in response to different object operations:
For object creation, the direct event type is google.cloud.storage.object.v1.finalized. In the console you create a trigger with Trigger type Google sources, Event provider Cloud Storage, Event type Direct, and select the bucket such as hello-bucket. With the gcloud CLI you create the same routing with filters for type and bucket and a service account for invocation:
gcloud eventarc triggers create storage-events-trigger --destination-workflow=MY_WORKFLOW --event-filters="type=google.cloud.storage.object.v1.finalized" --event-filters="bucket=PROJECT_ID-bucket" --service-account="PROJECT_NUMBER-compute@developer.gserviceaccount.com"
Uploading a file such as random.txt to gs://PROJECT_ID-bucket/random.txt generates an event that flows from the bucket to the destination. The destination then returns or logs the bucket name and object name, and executions show a state of SUCCEEDED when processing completes.
How Eventarc routes events to function destinations is defined by trigger filters, destination type, and permissions. An Eventarc trigger (opens in a new tab) declares interest in a set of events by combining filters for the event source and the target destination. Filters include the event provider, the event type, and the specific resource such as a Pub/Sub topic or Cloud Storage bucket. The destination can be a Cloud Function, a Cloud Run service such as hello, or a Workflows workflow such as myEventWorkflow.
Eventarc delivers events in CloudEvents format through an HTTP request. A Workflows (opens in a new tab) destination converts the event to a JSON object and passes it into the execution as a workflow runtime argument. The event size must not exceed the Workflows arguments resource limit, and events larger than the maximum do not trigger executions. Triggers also depend on Identity and Access Management permissions, including a user-managed or default compute service account and roles such as Eventarc Event Receiver, Pub/Sub Publisher, and Service Account Token Creator. Although a trigger is created immediately, it can take up to two minutes to become fully functional.
Exam tip: Choose the Direct event type such as google.cloud.storage.object.v1.finalized when both direct and audit log events are available for the same Google provider.
Managing event-driven routing and messaging is the practice of using Eventarc (opens in a new tab) to route events from providers to serverless destinations and using Cloud Pub/Sub (Pub/Sub) for asynchronous delivery. In this model, an event provider such as Pub/Sub, Cloud Storage, or Firestore generates an event, Eventarc matches it against a trigger, and the trigger invokes a sink such as Cloud Run, Application Integration, or Google Kubernetes Engine (GKE). Pub/Sub sits in the middle as the transport so publishers and subscribers stay decoupled.
What Eventarc triggers do in routing is listen for one event type and send matching events to one destination as an HTTP POST request. The flow moves from the event source to the sink in order: first an action happens at the provider, such as a message published to a Pub/Sub topic or an object uploaded to a Cloud Storage bucket, then the event travels through Pub/Sub transport, then Eventarc checks the trigger filters, and finally Eventarc invokes the destination service. Filtering uses exact match on attributes such as type = google.cloud.pubsub.topic.v1.messagePublished and does not support wildcards or regular expressions. After a trigger is created, its event filters cannot be edited, so a changed filter requires creating a new trigger and deleting the old one.
How Eventarc triggers are configured for delivery is defined by source, destination, identity, and payload settings. An Eventarc trigger configuration defines when Eventarc responds and where event data goes. Key settings include the trigger name and region, the source type and event type, the destination service and URL path, the trigger identity, retry behavior, and optional filters. For best performance and lower latency, the Eventarc trigger, the monitored resource, and the destination service should all be in the same Google Cloud region. Event payloads can be encoded as application/json or application/protobuf, and JSON payloads are larger, which can matter for destination size limits.
Trigger types identify the origin of the event:
In Terraform, the same relationship is explicit: the matching_criteria block selects the event type, the transport block points to the Pub/Sub topic ID, the destination block points to the Cloud Run service name and region, and service_account sets the trigger identity. The trigger depends on the Pub/Sub topic permission and the Eventarc API being enabled.
Exam tip: Saving an Eventarc trigger in Application Integration only stores the rules; the trigger stays inactive until the integration is published, and only publishing activates it.
How Pub/Sub topics support asynchronous processing is by acting as a named channel between publishers and serverless receivers. A publisher sends a message once to the topic, and Eventarc delivers a copy to each matching trigger destination, so the publisher never calls Cloud Run directly. This allows asynchronous processing because publishing, routing, and handling can happen at different times and scale independently. Topics are named in the format projects/PROJECT_ID/topics/TOPIC_ID, and the topic can live in the same project as the integration or in a different project.
Subscriptions control how long undelivered messages are kept. By default the expiration period for subscriptions is set to never expire, and a different value can be set by editing the subscription on the Pub/Sub subscriptions page. For GKE destinations, Eventarc creates an event forwarder component that pulls events from Pub/Sub and forwards them to the target GKE service. Retry on failure can be enabled so Eventarc retries delivery if the destination fails, or cleared for a single delivery attempt with no retries.
How service accounts secure event delivery is by giving each Eventarc trigger its own identity for reading events and invoking the destination. If no service account is selected, the trigger uses the Compute Engine default service account, which has the email form PROJECT_NUMBER-compute@developer.gserviceaccount.com. For production, create a dedicated user-managed service account and grant only the minimum Identity and Access Management (IAM) roles needed, following least privilege.
The trigger identity must hold permissions on both sides of the delivery path:
| IAM role | Granted to | Allows |
|---|---|---|
Pub/Sub Publisher (roles/pubsub.publisher) | Trigger service account on the topic | Publishing or routing messages through the Pub/Sub topic |
Pub/Sub Subscriber (roles/pubsub.subscriber) | Trigger service account on the project | Pulling events from Pub/Sub for the trigger |
Cloud Run Invoker (roles/run.invoker) | Trigger service account on the service or project | Invoking the Cloud Run service with authenticated requests |
Service Account Token Creator (roles/iam.serviceAccountTokenCreator) | Pub/Sub service agent service-PROJECT_NUMBER@gcp-sa-pubsub.iam.gserviceaccount.com | Supporting authenticated Pub/Sub push, required if the service agent was enabled on or before April 8, 2021 |
Without the Cloud Run Invoker role on the trigger identity, authenticated calls from Cloud Run (opens in a new tab) to Cloud Run are rejected, even if the topic and trigger are correct.
A Cloud Run service serves web requests or events at a stable endpoint, a Cloud Run job runs parallelizable tasks manually or on a schedule until completion, a Cloud Run worker pool handles always-on background work from message queues, and a Cloud Run instance runs a long-lived singleton runtime environment. A Cloud Run service responds to HTTP requests with dynamic or manual scaling, while a Cloud Run worker pool continuously processes queues such as Cloud Pub/Sub (Pub/Sub) or Kafka.
Use an HTTP-triggered Cloud Functions function when an outside caller such as a user action, webhook, or service call decides when to run by sending a direct HTTP request to the function URL. Use a background Cloud Functions function when Google Cloud itself should start the work automatically, such as processing every new file or every new message, because an Eventarc trigger forwards a Cloud Pub/Sub (Pub/Sub) or Cloud Storage event to the function.
Eventarc routes events by matching them against trigger filters for the event provider, event type, and specific resource such as a Cloud Storage bucket or Cloud Pub/Sub (Pub/Sub) topic, then invoking the Cloud Run service or Cloud Functions function as an HTTP request in CloudEvents format. The Eventarc trigger, the monitored resource, and the destination should be in the same Google Cloud region, and a new trigger can take up to two minutes to become fully functional.
A private Cloud Run service requires authentication, so Eventarc delivery depends on granting the Cloud Run Invoker role on the service to the service account that invokes the service. Delivery also requires the Eventarc Event Receiver role on the project for the Compute Engine default service account, the Cloud Pub/Sub (Pub/Sub) Publisher role for the Cloud Storage service account to publish storage events, and the Service Account Token Creator role for the Pub/Sub service agent in some older projects to support authenticated push.
Your company has deployed a serverless function to Google Cloud that must process data asynchronously whenever messages are published to a specific Cloud Pub/Sub topic.
You have already deployed the function code using the gcloud run deploy command. You now need to configure the event trigger using the gcloud CLI so that published Pub/Sub messages automatically invoke your deployed function.
Which command should you execute to configure this event trigger?
Run gcloud functions call specifying the function name and passing the Pub/Sub topic name in the --data argument
Update the function source code to run a continuous background loop that pulls messages via the Pub/Sub REST API
Run gcloud logging sinks create to route topic messages directly to the function's HTTP endpoint URL
Run gcloud eventarc triggers create with --event-filters="type=google.cloud.pubsub.topic.v1.messagePublished", --transport-topic, and --destination-run-service
Last updated