Skip to content

Instantly share code, notes, and snippets.

View ivamluz's full-sized avatar

Ivam Luz ivamluz

  • Appnovation
  • Campinas
View GitHub Profile
Script path: venv/bin/functions-framework
Parameters: --source=src/main.py --target=${FUNCTION_NAME_PUBSUB} --signature-type=event --port=${FUNCTION_PORT_PUBSUB} --debug
Environment variables: PYTHONUNBUFFERED=1
Working directory: /home/iluz/Projects/Personal/cloud-build-cloud-functions-pipeline/
@ivamluz
ivamluz / test-local-pubsub-payload.json
Created June 27, 2020 17:54
A JSON template file for building the payload to test the Pub/Sub-triggered function
{
"eventType": "com.example.someevent",
"resource": "FooBar",
"eventId": "B234-1234-1234",
"timestamp": "2020-06-20T17:31:00Z",
"data": {
"data": "__DATA_BASE64_PLACEHOLDER__",
"attributes": {
"foo": "bar",
"bar": "baz"
@ivamluz
ivamluz / test-local-pubsub.sh
Last active June 28, 2020 22:49
Helper script for testing an Pub/Sub-triggered Cloud Function locally exposed by the functions-framework
#! /bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${DIR}/.env.local"
RAW_MESSAGE=$1
MESSAGE_BASE64=$(echo -n ${RAW_MESSAGE} | base64)
EVENT_PAYLOAD=$(
@ivamluz
ivamluz / run-local-pubsub.sh
Last active June 28, 2020 22:49
Helper script for running Pub/Sub-triggered Cloud Function locally with functions-framework
#! /bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_FILE="${DIR}/../src/main.py"
source "${DIR}/.env.local"
functions-framework \
--source=${SOURCE_FILE} \
--target=${FUNCTION_NAME_PUBSUB} \
@ivamluz
ivamluz / test-local-http.sh
Last active June 28, 2020 22:49
Helper script for testing an HTTP-triggered Cloud Function locally exposed by the functions-framework
#! /bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_FILE="${DIR}/../src/main.py"
source "${DIR}/.env.local"
curl "http://localhost:${FUNCTION_PORT_HTTP}/?subject=FooBar"
echo
@ivamluz
ivamluz / run-local-http.sh
Last active June 28, 2020 22:50
Helper script for running HTTP-triggered Cloud Function locally with functions-framework
#! /bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_FILE="${DIR}/../src/main.py"
source "${DIR}/.env.local"
functions-framework \
--source=${SOURCE_FILE} \
--target=${FUNCTION_NAME_HTTP} \
@ivamluz
ivamluz / .env.local
Last active June 28, 2020 22:50
Environment variable for the Cloud Functions sample
export FUNCTION_NAME_HTTP=sample_http
export FUNCTION_PORT_HTTP=4000
export FUNCTION_NAME_PUBSUB=sample_pubsub
export FUNCTION_PORT_PUBSUB=5000
export PUBSUB_TOPIC=builder-functions-demo-topic
@ivamluz
ivamluz / main.py
Last active June 28, 2020 22:50
Sample HTTP- and Pub/Sub-triggered Cloud Functions implemented in Python
import base64
import pprint as pp
from flask import current_app, escape
def sample_http(request):
"""HTTP Cloud Function.
Args:
request (flask.Request): The request object.
<http://flask.pocoo.org/docs/1.0/api/#flask.Request>
@ivamluz
ivamluz / set_env_vars.sh
Created May 16, 2020 22:10
Script for updating a Cloud Run service with an environment variable
#!/bin/bash
read -p "Enter the Cloud Run Service name: " SERVICE_NAME
read -s -p "Enter the API KEY: " API_KEY
HASHED_API_KEY=`./hash_value.py --value "${API_KEY}"`
gcloud run \
services update $SERVICE_NAME \
--region us-central1 \
@ivamluz
ivamluz / gist:43c0787a947fec7daf69c50084bf08c7
Created May 16, 2020 22:07
Update Cloud Run service environment variable
$ ./set_env_vars.sh
Enter the Cloud Run Service name: pipeline-demo
✓ Deploying... Done.
✓ Creating Revision...
✓ Routing traffic...
Done.
Service [pipeline-demo] revision [pipeline-demo-00004-hec] has been deployed and is serving 100 percent of traffic at https://pipeline-demo-pmrwyqmvha-uc.a.run.app