### Deploy an event receiver on the VM Source: https://docs.cloud.google.com/eventarc/standard/docs/vpc-endpoints/receive-vpc-internal-endpoint Install and run a simple HTTP server on the VM to receive events. This example uses Python and Flask. Ensure you have Python and pip installed on the VM. ```bash sudo apt-get update sudo apt-get install -y python3-pip pip3 install Flask cat << EOF > main.py from flask import Flask, request app = Flask(__name__) @app.route('/', methods=['POST']) def receive_event(): print(request.data) return '', 204 if __name__ == '__main__': app.run(host='0.0.0.0', port=8080) EOF python3 main.py ``` -------------------------------- ### Install Eventarc Client Library for Go Source: https://docs.cloud.google.com/eventarc/docs/reference/libraries Use this command to install the Go client library. Refer to the Go development environment setup for details. ```bash go get cloud.google.com/go/eventarc ``` -------------------------------- ### Go Web Server Setup Source: https://docs.cloud.google.com/eventarc/docs/samples/eventarc-audit-storage-server Starts an HTTP server on a specified port, defaulting to 8080, and registers a handler for incoming events. Requires Application Default Credentials for Eventarc authentication. ```go func main() { http.HandleFunc("/", HelloEventsStorage) // Determine port for HTTP service. port := os.Getenv("PORT") if port == "" { port = "8080" } // Start HTTP server. log.Printf("Listening on port %s", port) if err := http.ListenAndServe(":"+port, nil); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Spring Boot Application Setup Source: https://docs.cloud.google.com/eventarc/standard/docs/run/debugging-events-cloud-run A minimal Spring Boot application class to start a Spring Boot application. ```java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` -------------------------------- ### C# Web Server Setup Source: https://docs.cloud.google.com/eventarc/docs/samples/eventarc-audit-storage-server Sets up and starts a web application on a specified port, defaulting to 8080. Requires Application Default Credentials for Eventarc authentication. ```csharp public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) { var port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; var url = $"http://0.0.0.0:{port}"; return Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup().UseUrls(url); }); } ``` -------------------------------- ### Install Eventarc Client Library for Node.js Source: https://docs.cloud.google.com/eventarc/docs/reference/libraries Use npm to install the Node.js client library. Consult the Node.js setup guide for further instructions. ```bash npm install @google-cloud/eventarc ``` -------------------------------- ### Node.js Web Server Setup Source: https://docs.cloud.google.com/eventarc/docs/samples/eventarc-audit-storage-server Starts a Node.js web server on a specified port, defaulting to 8080. Requires Application Default Credentials for Eventarc authentication. ```javascript const app = require('./app.js'); const PORT = parseInt(process.env.PORT) || 8080; app.listen(PORT, () => console.log(`nodejs-events-storage listening on port ${PORT}`) ); ``` -------------------------------- ### Install Eventarc Client Library for C++ Source: https://docs.cloud.google.com/eventarc/docs/reference/libraries Use this command to install the C++ client library. Refer to the C++ development environment setup for requirements. ```bash Install-Package Google.Cloud.Eventarc.V1 ``` -------------------------------- ### Install Eventarc Client Library for Ruby Source: https://docs.cloud.google.com/eventarc/docs/reference/libraries Use the gem command to install the Ruby client library. Refer to the Ruby development environment setup for guidance. ```bash gem install google-cloud-eventarc ``` -------------------------------- ### Example Request Body Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/v1/projects.locations.googleApiSources/testIamPermissions An example of how to structure the request body to check for specific permissions. ```json { "permissions": [ "eventarc.googleApiSources.get", "eventarc.googleApiSources.list" ] } ``` -------------------------------- ### Example Workflow List Output Source: https://docs.cloud.google.com/eventarc/standard/docs/workflows/troubleshoot This is an example of the expected output when listing workflows, confirming the workflow's existence and active state. ```bash NAME STATE REVISION_ID UPDATE_TIME projects/PROJECT_ID/locations/LOCATION/workflows/WORKFLOW_ID ACTIVE 000004-c0c 2021-11-19T14:29:27.530185556Z ``` -------------------------------- ### Install kubectl Source: https://docs.cloud.google.com/eventarc/docs/anthos/creating-triggers Installs the kubectl command-line tool, which is used for interacting with Kubernetes clusters. This is a prerequisite for managing GKE resources. ```bash gcloud components install kubectl ``` -------------------------------- ### Example Request Body Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/v1/projects.locations.channels/testIamPermissions An example of how to structure the request body to check for specific permissions on a channel. ```json { "permissions": [ "eventarc.channels.get", "eventarc.channels.list" ] } ``` -------------------------------- ### Example Eventarc Channel Details Source: https://docs.cloud.google.com/eventarc/standard/docs/third-parties/subscribe-to-datadog This is an example output from the describe command, highlighting the activationToken and name fields required for Datadog configuration. ```yaml **activationToken: aS7dXs1b79AcXsf** createTime: '2021-11-15T15:20:31.582356065Z' **name: projects/project-id/locations/us-central1/channels/datadog-channel** provider: projects/project-id/locations/us-central1/providers/datadog pubsubTopic: projects/project-id/topics/eventarc-channel-us-central1-datadog-channel-077 state: PENDING uid: c6703a91-ccd3-4c32-a729-967393f23a29 updateTime: '2021-11-15T15:21:03.689597653Z' ``` -------------------------------- ### Example Log Entry Format Source: https://docs.cloud.google.com/eventarc/docs/run/create-trigger-pub-sub-gcloud An example of a log entry that indicates a successful reception of a Pub/Sub topic event by the Cloud Run service. ```text jsonPayload: ... message: 'Received event of type google.cloud.pubsub.topic.v1.messagePublished. Event data: Hello World!' ``` -------------------------------- ### Start Python HTTP Server Source: https://docs.cloud.google.com/eventarc/docs/vpc-endpoints/receive-vpc-events Execute this command in the SSH terminal to start the Python server. The server will listen for incoming HTTP requests. ```bash sudo python3 server.py ``` -------------------------------- ### Install Eventarc Client Library for Python Source: https://docs.cloud.google.com/eventarc/docs/reference/libraries Upgrade your Python installation using pip. See the Python development environment setup for more information. ```bash pip install --upgrade google-cloud-eventarc ``` -------------------------------- ### Navigate to C# Pub/Sub Sample Directory Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated Changes the current directory to the .NET Pub/Sub sample code for Cloud Run. ```bash cd dotnet-docs-samples/eventarc/pubsub/ ``` -------------------------------- ### Navigate to Go Pub/Sub Sample Directory Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated Changes the current directory to the Go Pub/Sub sample code for Cloud Run. ```bash cd golang-samples/eventarc/pubsub/ ``` -------------------------------- ### Create a directory and navigate Source: https://docs.cloud.google.com/eventarc/advanced/docs/quickstarts/publish-events-cloud-run-job Create a directory for your job and navigate into it. This sets up the workspace for your Cloud Run job. ```bash mkdir jobs cd jobs ``` -------------------------------- ### Enable Google Cloud APIs Source: https://docs.cloud.google.com/eventarc/standard/docs/gke/quickstart-cal Enable the Eventarc, Resource Manager, and Google Kubernetes Engine APIs for your project. These APIs are required for the quickstart. ```bash gcloud services enable eventarc.googleapis.com \ cloudresourcemanager.googleapis.com \ container.googleapis.com ``` -------------------------------- ### Clone the Eventarc Samples Repository Source: https://docs.cloud.google.com/eventarc/advanced/docs/quickstarts/publish-events-create-bus-console Clone the GitHub repository containing Eventarc samples to get started. ```bash git clone https://github.com/GoogleCloudPlatform/eventarc-samples.git ``` -------------------------------- ### Client Libraries Reference Source: https://docs.cloud.google.com/eventarc/docs/apis Get started with the Cloud Client Libraries for the Eventarc API to integrate Eventarc into your applications. ```APIDOC ## Client Libraries Reference Get started with the Cloud Client Libraries for the Eventarc API. ``` -------------------------------- ### APIs Explorer Response for Operation Source: https://docs.cloud.google.com/eventarc/advanced/docs/receive-events/create-enrollment This is an example of the response body received from the APIs Explorer after a successful enrollment creation request. It indicates that an operation has been started. ```json { "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.eventarc.v1.OperationMetadata", "createTime": "2024-01-25T17:17:45.782370139Z", "target": "projects/PROJECT_ID/locations/LOCATION/pipelines/PIPELINE_NAME", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false } ``` -------------------------------- ### Navigate to Node.js Pub/Sub Sample Directory Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated Changes the current directory to the Node.js Pub/Sub sample code for Cloud Run. ```bash cd nodejs-docs-samples/eventarc/pubsub/ ``` -------------------------------- ### Set the Region Configuration Variable Source: https://docs.cloud.google.com/eventarc/advanced/docs/quickstarts/publish-events-create-bus-console Set the `REGION` environment variable to specify the desired Google Cloud region for your operations in this quickstart. `us-central1` is used as an example. ```bash REGION=us-central1 ``` -------------------------------- ### Create Kubernetes Deployment Source: https://docs.cloud.google.com/eventarc/standard/docs/gke/quickstart-pubsub Create a Kubernetes deployment using a prebuilt image. ```bash kubectl create deployment $SERVICE_NAME \ --image=us-docker.pkg.dev/cloudrun/container/hello ``` -------------------------------- ### Set gcloud Tutorial Defaults Source: https://docs.cloud.google.com/eventarc/standard/docs/gke/big-query-tutorial Configures gcloud settings for the tutorial, including project ID, region, cluster name, and platform. ```bash CLUSTER_NAME=events-cluster CLUSTER_LOCATION=us-central1 PROJECT_ID=PROJECT_ID gcloud config set project $PROJECT_ID gcloud config set run/region $CLUSTER_LOCATION gcloud config set run/cluster $CLUSTER_NAME gcloud config set run/cluster_location $CLUSTER_LOCATION gcloud config set run/platform gke gcloud config set eventarc/location $CLUSTER_LOCATION ``` -------------------------------- ### Navigate to Java Pub/Sub Sample Directory Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated Changes the current directory to the Java Pub/Sub sample code for Cloud Run. ```bash cd java-docs-samples/eventarc/pubsub/ ``` -------------------------------- ### List Eventarc Triggers in Node.js Source: https://docs.cloud.google.com/eventarc/docs/reference/libraries This Node.js example shows how to list Eventarc triggers using the client library. Replace 'my-project' with your actual project ID and ensure the package is installed. ```javascript // Imports the Google Cloud client library // remove this line after package is released const {EventarcClient} = require('@google-cloud/eventarc'); // TODO: replace with your prefered project ID. // const projectId = 'my-project' // Creates a client const client = new EventarcClient(); async function doSomething() { for await (const trigger of await client.listTriggersAsync({ parent: client.locationPath(projectId, 'us-central1'), })) { console.info(trigger.name); } } doSomething(); ``` -------------------------------- ### Navigate to Python Pub/Sub Sample Directory Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated Changes the current directory to the Python Pub/Sub sample code for Cloud Run. ```bash cd python-docs-samples/eventarc/pubsub/ ``` -------------------------------- ### HTTP Request Example Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/v1/projects.locations.channelConnections/setIamPolicy Demonstrates the HTTP POST request to set the IAM policy for a channel connection. Ensure you replace placeholders with your specific project, location, and channel connection details. ```bash POST https://eventarc.googleapis.com/v1/{resource=projects/*/locations/*/channelConnections/*}:setIamPolicy ``` -------------------------------- ### Clone Go Sample Repository Source: https://docs.cloud.google.com/eventarc/standard/docs/run/create-trigger-cloud-audit-logs-gcloud Clones the GitHub repository containing the Go sample for the event receiver service and navigates into the directory. ```bash git clone https://github.com/GoogleCloudPlatform/golang-samples.git cd golang-samples/eventarc/audit_storage ``` -------------------------------- ### Invoke Eventarc Samples using Shell Commands Source: https://docs.cloud.google.com/eventarc/docs/custom-events/route-custom-events Examples of how to invoke the Eventarc publishing samples using shell commands for different languages. Ensure you have the Google Cloud SDK and necessary build tools installed. ```bash PROJECT_ID=$(gcloud config get-value project) REGION=us-central1 CHANNEL_ID=helloworld-channel dotnet run $PROJECT_ID $REGION $CHANNEL_ID true ``` ```bash PROJECT_ID=$(gcloud config get-value project) REGION=us-central1 CHANNEL_ID=helloworld-channel ./gradlew run --args="$PROJECT_ID $REGION $CHANNEL_NAME true" ``` ```bash PROJECT_ID=$(gcloud config get-value project) REGION=us-central1 CHANNEL_ID=helloworld-channel npm run invoke projects/$PROJECT_ID/locations/$REGION/channels/$CHANNEL_NAME ``` ```bash PROJECT_ID=$(gcloud config get-value project) REGION=us-central1 CHANNEL_ID=helloworld-channel python3 publish.py \ --channel projects/$PROJECT_ID/locations/$REGION/channels/$CHANNEL_NAME \ --log=DEBUG ``` -------------------------------- ### Create an Eventarc trigger for GKE Source: https://docs.cloud.google.com/eventarc/standard/docs/gke/route-trigger-cloud-memorystore-for-memcached Creates an Eventarc trigger that routes events to a specified GKE service. This example filters events for Cloud Memorystore for Memcached instance updates and matches instance IDs starting with 'my-instance-'. Ensure the service account is correctly formatted with your project ID. ```bash gcloud eventarc triggers create helloworld-trigger \ --location=us-central1 \ --destination-gke-cluster=gke-events-cluster \ --destination-gke-location=us-central1-a \ --destination-gke-namespace=default \ --destination-gke-service=helloworld-events \ --destination-gke-path=/ \ --event-filters="type=google.cloud.memcache.instance.v1.updated" \ --event-filters-path-pattern="instance=my-instance-*" \ --service-account=${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com ``` -------------------------------- ### get Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/v1/projects.locations.triggers Get a single trigger. ```APIDOC ## GET /v1/projects/{projectId}/locations/{locationId}/triggers/{triggerId} ### Description Get a single trigger. ### Method GET ### Endpoint /v1/projects/{projectId}/locations/{locationId}/triggers/{triggerId} ### Parameters #### Path Parameters - **projectId** (string) - Required - The project ID. - **locationId** (string) - Required - The location ID. - **triggerId** (string) - Required - The ID of the trigger to retrieve. ### Response #### Success Response (200) - **name** (string) - The name of the trigger. - **uid** (string) - The unique identifier of the trigger. - **create_time** (timestamp) - The creation time of the trigger. - **update_time** (timestamp) - The last update time of the trigger. - **event_filters** (object) - The event filters. - **service_account** (string) - The service account. - **transport** (object) - The transport details. - **state** (string) - The current state of the trigger. - **etag** (string) - The etag of the trigger. #### Response Example ```json { "name": "projects/PROJECT_ID/locations/LOCATION_ID/triggers/TRIGGER_ID", "uid": "some-uid", "create_time": "2023-01-01T12:00:00Z", "update_time": "2023-01-01T12:00:00Z", "event_filters": [ { "attribute": "type", "value": "google.cloud.pubsub.topic.v1.messagePublished" } ], "transport": { "type": "cloud_run", "data": { "service": "projects/PROJECT_ID/locations/LOCATION_ID/services/SERVICE_NAME" } }, "state": "ACTIVE", "etag": "some-etag" } ``` ``` -------------------------------- ### Clone .NET Sample Repository Source: https://docs.cloud.google.com/eventarc/standard/docs/run/create-trigger-cloud-audit-logs-gcloud Clones the GitHub repository containing the .NET sample for the event receiver service and navigates into the directory. ```bash git clone https://github.com/GoogleCloudPlatform/dotnet-docs-samples.git cd dotnet-docs-samples/eventarc/audit-storage ``` -------------------------------- ### Location Labels Example Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/Shared.Types/ListLocationsResponse An example of cross-service attributes for a location, represented as a map of key-value pairs. This specific example shows a region label. ```json { "cloud.googleapis.com/region": "us-east1" } ``` -------------------------------- ### IAM Policy YAML Example Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/Shared.Types/Policy Demonstrates the equivalent IAM policy structure in YAML format, useful for configuration files and readability. ```yaml bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3 ``` -------------------------------- ### Set Configuration Variables Source: https://docs.cloud.google.com/eventarc/standard/docs/gke/quickstart-pubsub Define environment variables for Project ID, Cluster Name, Service Name, and Location. These variables are used in subsequent steps of the quickstart. ```bash PROJECT_ID=$(gcloud config get-value project) CLUSTER_NAME=events-cluster SERVICE_NAME=hello-gke LOCATION=us-central1 ``` -------------------------------- ### Example Text Event Source: https://docs.cloud.google.com/eventarc/docs/reference/publishing/rest/v1/projects.locations.channelConnections/publishEvents An example of a text-based CloudEvent v1.0 event in JSON format. ```json { "specversion": "1.0", "id": "a-unique-id", "source": "/my-service", "type": "com.example.someevent", "subject": "/resources/abc", "time": "2020-01-01T12:00:00Z", "datacontenttype": "application/json", "data": { "message": "Hello World" } } ``` -------------------------------- ### Describe a specific provider and its event types Source: https://docs.cloud.google.com/eventarc/docs/list-providers Use this command to describe a specific provider and view its supported event types in a given location. Replace PROVIDER and LOCATION with the appropriate values. ```bash gcloud eventarc providers describe PROVIDER \ --location=LOCATION ``` -------------------------------- ### Example Log Entry Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated This is an example of a log entry that your service might create after processing an event. ```text textPayload: 'Hello, Hello there!' ``` -------------------------------- ### Navigate to Ruby Pub/Sub Sample Directory Source: https://docs.cloud.google.com/eventarc/standard/docs/run/pubsub-authenticated Changes the current directory to the Ruby Pub/Sub sample code for Cloud Run. ```bash cd ruby-docs-samples/eventarc/pubsub/ ``` -------------------------------- ### Policy YAML Example Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/Shared.Types/Policy This is a YAML example of an IAM Policy, showing the structure for roles, members, and conditions. ```APIDOC ## Policy YAML Example ### Description This is a YAML example of an IAM Policy, showing the structure for roles, members, and conditions. ### Request Example ```yaml bindings: - members: - user:mike@example.com - group:admins@example.com - domain:google.com - serviceAccount:my-project-id@appspot.gserviceaccount.com role: roles/resourcemanager.organizationAdmin - members: - user:eve@example.com role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3 ``` ``` -------------------------------- ### Example Policy with multiple AuditConfigs Source: https://docs.cloud.google.com/eventarc/docs/reference/rest/Shared.Types/AuditConfig This example demonstrates a policy with multiple AuditConfigs, including one for `allServices` and another for a specific service. It shows how to configure different log types and exempt specific members for each. ```json { "auditConfigs": [ { "service": "allServices", "auditLogConfigs": [ { "logType": "DATA_READ", "exemptedMembers": [ "user:jose@example.com" ] }, { "logType": "DATA_WRITE" }, { "logType": "ADMIN_READ" } ] }, { "service": "sampleservice.googleapis.com", "auditLogConfigs": [ { "logType": "DATA_READ" }, { "logType": "DATA_WRITE", "exemptedMembers": [ "user:aliya@example.com" ] } ] } ] } ``` -------------------------------- ### Example Structured Event Source: https://docs.cloud.google.com/eventarc/docs/reference/publishing/rest/v1/projects.locations.channelConnections/publishEvents An example of a structured CloudEvent v1.0 event, including a custom type URI. ```json { "id": 1234, "@type": "types.example.com/standard/id" } ``` -------------------------------- ### Example Workflow Execution Output Source: https://docs.cloud.google.com/eventarc/standard/docs/third-parties/subscribe-to-datadog This is an example of the output you should expect when listing workflow executions, indicating a successful run. ```text NAME: projects/1051295516635/locations/us-central1/workflows/logEventsWorkflow/executions/674b5783-deec-4d1b-be1d-b067f7b32971 STATE: SUCCEEDED START_TIME: 2022-07-13T22:01:06.314980819Z END_TIME: 2022-07-13T22:01:06.637825944Z ```