Skip to content

Commit

Permalink
Eventarc Quickstart Brushup (#4762)
Browse files Browse the repository at this point in the history
## Eventarc Quickstart Brushup

- Region tag fixes
  • Loading branch information
grant authored Sep 28, 2020
1 parent bb8b268 commit 839eb0f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions eventarc/audit-storage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START run_events_gcs_dockerfile]
# [START eventarc_gcs_dockerfile]

# Use the official Python image.
# https://hub.docker.com/_/python
Expand All @@ -38,4 +38,4 @@ COPY . ./
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
# [END run_events_gcs_dockerfile]
# [END eventarc_gcs_dockerfile]
2 changes: 1 addition & 1 deletion eventarc/audit-storage/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cloud Eventarc – GCS tutorial
# Cloud Eventarc - Cloud Storage via Audit Logs tutorial

This sample shows how to create a service that processes GCS using [the CloudEvents SDK](https://github.com/cloudevents/sdk-python).

Expand Down
11 changes: 7 additions & 4 deletions eventarc/audit-storage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START run_events_gcs_handler]

# [START eventarc_gcs_server]
import os

import cloudevents.exceptions as cloud_exceptions
Expand All @@ -22,8 +23,10 @@

required_fields = ['Ce-Id', 'Ce-Source', 'Ce-Type', 'Ce-Specversion']
app = Flask(__name__)
# [END eventarc_gcs_server]


# [START eventarc_gcs_handler]
@app.route('/', methods=['POST'])
def index():
# Create CloudEvent from HTTP headers and body
Expand All @@ -49,10 +52,10 @@ def index():

print(f"Detected change in GCS bucket: {event['subject']}")
return (f"Detected change in GCS bucket: {event['subject']}", 200)
# [END run_events_gcs_handler]
# [END eventarc_gcs_handler]


# [START run_events_gcs_server]
# [START eventarc_gcs_server]
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
# [END run_events_gcs_server]
# [END eventarc_gcs_server]
4 changes: 2 additions & 2 deletions eventarc/pubsub/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START run_events_pubsub_dockerfile]
# [START eventarc_pubsub_dockerfile]

# Use the official Python image.
# https://hub.docker.com/_/python
Expand All @@ -38,4 +38,4 @@ COPY . ./
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
# [END run_events_pubsub_dockerfile]
# [END eventarc_pubsub_dockerfile]
12 changes: 6 additions & 6 deletions eventarc/pubsub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START run_events_pubsub_server_setup]
# [START eventarc_pubsub_server]
import base64

import os
Expand All @@ -26,10 +26,10 @@
required_fields = ['Ce-Id', 'Ce-Source', 'Ce-Type', 'Ce-Specversion']

app = Flask(__name__)
# [END run_events_pubsub_server_setup]
# [END eventarc_pubsub_server]


# [START run_events_pubsub_handler]
# [START eventarc_pubsub_handler]
@app.route('/', methods=['POST'])
def index():
# Create CloudEvent from HTTP headers and body
Expand Down Expand Up @@ -69,10 +69,10 @@ def index():
resp = f"Hello, {name}! ID: {event['id']}"
print(resp)
return (resp, 200)
# [END run_events_pubsub_handler]
# [END eventarc_pubsub_handler]


# [START run_events_pubsub_server]
# [START eventarc_pubsub_server]
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
# [END run_events_pubsub_server]
# [END eventarc_pubsub_server]

0 comments on commit 839eb0f

Please sign in to comment.