LIST

GCP App Engine

Features auto load balancing & auto scaling managed platform updates application health monitoring application versioning traffic splitting Compute Engine vs App Engine compute E = IAAS app E = Paas, serverless Environments standard - language specific sandbox v1 - java python php go (old versions) python & php -> restricted network access + restricted libs v2 - java, python, php, node, ruby, go (newer versions) flexible - docker containers uses compute engine VMs access to background processes attach local disks Component Hierarchy !...

March 28, 2023

google cloud function go GCP

package function import ( "fmt" "net/http" "github.com/GoogleCloudPlatform/functions-framework-go/functions" ) func init() { functions.HTTP("HelloWorld", helloWorld) } // helloWorld writes "Hello, World!" to the HTTP response. func helloWorld(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello, World!") } so then your entry_point = “HelloWorld” That is the entrypoint from the init() NOT the function name inspiration: Write Cloud Functions _ Cloud Functions Documentation _ Google Cloud GoogleCloudPlatform_functions-framework-go_ FaaS (Function as a service) framework for writing portable Go functions

March 22, 2023

run gcp functions locally (python)

run a single function export GCLOUD_PROJECT="XXX" export GOOGLE_ACCOUNT="your@email.com" echo "GOOGLE_ACCOUNT=$GOOGLE_ACCOUNT" export GOOGLE_APPLICATION_CREDENTIALS=$HOME/.config/gcloud/legacy_credentials/${GOOGLE_ACCOUNT}/adc.json export YOUR_ENV_VAR="foo" pip3 install functions-framework functions-framework --source ./path/to/yuor/main.py --target your_python_function_name --debug run a custom api functions/run_functions_locally.py from flask import Flask, request from my_function_a.main import my_python_function_a from my_function_b.main import my_python_function_b app = Flask(__name__) @app.route('/') def index(): return 'Index Page' @app.get('/api/a') def get_a(): return my_python_function_a(request) @app.post('/api/b') def post_b(): return my_python_function_b(request) functions/my_python_function_a/main.py import functions_framework YOUR_ENV_VAR = os.getenv("YOUR_ENV_VAR") @functions_framework.http def my_python_function_b(request): headers = { 'Access-Control-Allow-Origin': '*', } return "hello from function a YOUR_ENV_VAR=" + YOUR_ENV_VAR, 200, headers functions/my_python_function_b/main....

March 22, 2023

GCP create config account

create config (only once) #show state before gcloud config configurations list gcloud config configurations create "MY_PROFILE" export CLOUDSDK_ACTIVE_CONFIG_NAME="MY_PROFILE" gcloud config set core/project "MY_GCP_PROJECT" gcloud config set core/account "MY_EMAIL" #show state after gcloud config configurations list use config (every terminal session) # choose project export CLOUDSDK_ACTIVE_CONFIG_NAME="MY_PROFILE" # login (valid for about an hour) export GOOGLE_OAUTH_ACCESS_TOKEN="$(gcloud auth print-access-token)"

March 10, 2023

run terraform as a service account

grant permission to a group / user resource "google_service_account_iam_member" "allow_us_to_impersonate" { service_account_id = google_service_account.service_account.id role = "roles/iam.serviceAccountTokenCreator" member = "group:GOOGLE_GROUP_EMAIL" } run terraform as a service account # run as service account export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT="SERVICE_ACCOUNT_EMAIL" # stop running as service account export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT=""

March 10, 2023

terraform & GCP

How to login: don’t use a downloaded credential file https://jryancanty.medium.com/stop-downloading-google-cloud-service-account-keys-1811d44a97d9 instead export GOOGLE_OAUTH_ACCESS_TOKEN="$(gcloud auth print-access-token)" or SERVICE_ACCOUNT="your-service-account-email" export GOOGLE_OAUTH_ACCESS_TOKEN="$(gcloud --impersonate-service-account="${SERVICE_ACCOUNT}" auth print-access-token)" followed by your terraform commands or have a look at my automated setup https://github.com/TjenWellens/docker-alias Also related to terraform: my terraform gcp setup template: https://github.com/TjenWellens/template-tf-gcp-init

July 3, 2022