|
1 | 1 | # Cloud Eventarc - Cloud Storage via Audit Logs tutorial
|
2 | 2 |
|
3 |
| -This sample shows how to create a service that processes GCS using [the CloudEvents SDK](https://github.com/cloudevents/sdk-python). |
| 3 | +This sample shows how to create a service that processes GCS using |
| 4 | +[the CloudEvents SDK](https://github.com/cloudevents/sdk-python). |
4 | 5 |
|
5 |
| -## Setup |
6 |
| - |
7 |
| -Configure environment variables: |
8 |
| - |
9 |
| -```sh |
10 |
| -MY_RUN_SERVICE=gcs-service |
11 |
| -MY_RUN_CONTAINER=gcs-container |
12 |
| -MY_GCS_BUCKET=gcs-bucket # Must be globally unique. |
13 |
| -``` |
14 |
| - |
15 |
| -## Quickstart |
16 |
| - |
17 |
| -Deploy your Cloud Run service: |
18 |
| - |
19 |
| -```sh |
20 |
| -gcloud builds submit \ |
21 |
| - --tag gcr.io/$(gcloud config get-value project)/$MY_RUN_CONTAINER |
22 |
| -gcloud run deploy $MY_RUN_SERVICE \ |
23 |
| - --image gcr.io/$(gcloud config get-value project)/$MY_RUN_CONTAINER \ |
24 |
| - --platform managed |
25 |
| -``` |
26 |
| - |
27 |
| -Create a _single region_ Cloud Storage bucket: |
28 |
| - |
29 |
| -```sh |
30 |
| -gsutil mb -p $(gcloud config get-value project) \ |
31 |
| - -l us-central1 \ |
32 |
| - gs://"$MY_GCS_BUCKET" |
33 |
| -``` |
34 |
| - |
35 |
| -Create Cloud Storage trigger: |
36 |
| - |
37 |
| -```sh |
38 |
| -gcloud beta eventarc triggers create my-gcs-trigger \ |
39 |
| - --destination-run-service $MY_RUN_SERVICE \ |
40 |
| - --matching-criteria type=google.cloud.audit.log.v1.written \ |
41 |
| - --matching-criteria methodName=storage.buckets.update \ |
42 |
| - --matching-criteria serviceName=storage.googleapis.com \ |
43 |
| - --matching-criteria resourceName=projects/_/buckets/"$MY_GCS_BUCKET" |
44 |
| -``` |
45 |
| - |
46 |
| -## Test |
47 |
| - |
48 |
| -Test your Cloud Run service by creating a GCS event: |
49 |
| - |
50 |
| -```sh |
51 |
| -gsutil defstorageclass set STANDARD gs://$MY_GCS_BUCKET |
52 |
| -``` |
53 |
| - |
54 |
| -Observe the Cloud Run service printing upon receiving an event in Cloud Logging: |
55 |
| - |
56 |
| -```sh |
57 |
| -gcloud logging read "resource.type=cloud_run_revision AND \ |
58 |
| - resource.labels.service_name=$MY_RUN_SERVICE" \ |
59 |
| - --project $(gcloud config get-value project) \ |
60 |
| - --limit 30 \ |
61 |
| - --format 'value(textPayload)' |
62 |
| -``` |
63 |
| - |
64 |
| -One of the logs you'll see shows the Run service confirming the event was received: |
65 |
| - |
66 |
| -``` |
67 |
| -GCS CloudEvent type: storage.googleapis.com/projects/_/buckets/gcs-bucket |
68 |
| -``` |
| 6 | +See tutorial, [Quickstart: Receiving Cloud Storage events](https://cloud.google.com/eventarc/docs/run/quickstart?hl=en#python), |
| 7 | +tutorial for instructions for setting up and deploying this sample application. |
0 commit comments