This quickstart shows you how to create, deploy, and execute your first workflow
using the gcloud
command-line tool. The sample workflow sends a request to a sample API
and then uses the response to create and send a request to a public API.
The workflow returns the second API's response.
For a list of all Workflows gcloud
tool commands,
see the Workflows gcloud
tool
reference page.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
- Install and initialize the Cloud SDK.
Enable the Workflows API.
gcloud services enable workflows.googleapis.com
-
Create the service account. Replace [NAME] with a name for the service account.
gcloud iam service-accounts create [NAME]
-
Grant the
roles/logging.logWriter
role to the service account.gcloud projects add-iam-policy-binding [PROJECT_ID] --member "serviceAccount:[NAME]@[PROJECT_ID].iam.gserviceaccount.com" --role "roles/logging.logWriter"
Replace the following:- [PROJECT_ID]: Your project's ID.
- [NAME]: The name of the service account you just created.
Note: The Role field authorizes your service account to access resources. To send logs to Cloud Logging, assign theroles/logging.logWriter
role. If you are developing a production app, always grant the least permissive roles possible. For more information, see granting roles to service accounts. For a list of Workflows roles, see the Access control reference.
Create, deploy, and execute a workflow
Create a new file called
myFirstWorkflow.yaml
ormyFirstWorkflow.json
.Copy and paste one of the following into the new file, then save it:
YAML
JSON
This workflow makes a call to a sample API to get the current date. It takes the day of the week from that response and passes it to the Wikipedia API, where it searches for relevant articles on Wikipedia about the current day of the week.
Open a terminal.
Deploy the workflow by entering the following command:
gcloud workflows deploy myFirstWorkflow --source=myFirstWorkflow.yaml \ --service-account=[NAME]@[PROJECT_ID].iam.gserviceaccount.com
Replace the following:
.yaml: Replace with
.json
if you copied the JSON version of the example workflow.[NAME]: The name of the service account you created earlier
[PROJECT_ID]: Your project ID.
This command deploys the workflow and associates it with the specified service account.
Execute the workflow by entering the following command:
gcloud workflows execute myFirstWorkflow
This returns a
workflows executions describe
command with the unique ID of the workflow execution attempt. The output is similar to the following:Created [cf1b1883-e271-4371-916a-10337bc1b87a]. To view the workflow status, you can use following command: gcloud workflows executions describe cf1b1883-e271-4371-916a-10337bc1b87a --workflow myFirstWorkflow
To view the status of the execution, enter the command returned by the previous step. This returns data about the workflow execution, including the result:
argument: 'null' endTime: '2020-06-23T16:21:35.266171131Z' name: projects/123456789012/locations/us-central1/workflows/myFirstWorkflow/executions/f72bc6d4-5ea0-4dfb-bb14-2dae82303120 result: '["Tuesday","Tuesday Weld","Tuesday Night Music Club","Tuesday (ILoveMakonnen song)","Tuesdays with Morrie","Tuesday Group","Tuesday Knight","Tuesday (Burak Yeter song)","Tuesday Morning Quarterback","Tuesday Maybe"]' startTime: '2020-06-23T16:21:34.826993288Z' state: SUCCEEDED workflowVersionId: '1'
You deployed and executed your first workflow!
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.
Delete the workflow you created by entering the following command:
gcloud workflows delete myFirstWorkflow
When asked if you want to continue, enter
y
.
The workflow will be deleted.