In this sample, you will orchestrate multiple Cloud Functions, Cloud Run and external services in a workflow.
Inside randomgen folder, deploy a function that generates a random number:
gcloud functions deploy randomgen \
--gen2 \
--runtime python39 \
--trigger-http \
--entry-point randomgen \
--source . \
--allow-unauthenticated
Test:
curl https://us-central1-workflows-atamel.cloudfunctions.net/randomgen
Inside multiply folder, deploy a function that multiplies a given number:
gcloud functions deploy multiply \
--gen2 \
--runtime python39 \
--trigger-http \
--entry-point multiply \
--source . \
--allow-unauthenticated
Test:
curl -X POST https://us-central1-workflows-atamel.cloudfunctions.net/multiply \
-H "content-type: application/json" \
-d '{"input":5}'
For an external function, use MathJS.
Test:
curl https://api.mathjs.org/v4/?expr=log(56)
Inside floor folder, deploy an authenticated Cloud Run service that floors a number.
Build the container:
export SERVICE_NAME=floor
gcloud builds submit --tag gcr.io/${PROJECT_ID}/${SERVICE_NAME}
Deploy:
gcloud run deploy ${SERVICE_NAME} \
--image gcr.io/${PROJECT_ID}/${${SERVICE_NAME}} \
--platform managed \
--no-allow-unauthenticated
Test:
curl -X POST https://floor-wvdg6hhtla-ew.a.run.app \
-H "content-type: application/json" \
-d '{"input": "6.86"}'
Create a service account for Workflows:
export SERVICE_ACCOUNT=workflows-sa
gcloud iam service-accounts create ${SERVICE_ACCOUNT}
Grant run.invoker
role to the service account:
export PROJECT_ID=$(gcloud config get-value project)
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member "serviceAccount:${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role "roles/run.invoker"
Deploy workflow:
gcloud workflows deploy workflow \
--source=workflow.yaml \
--service-account=${SERVICE_ACCOUNT}@${PROJECT_ID}.iam.gserviceaccount.com
Execute workflow:
gcloud workflows execute workflow
This is not an official Google product.