コンソールを使用してワークフローを作成する Google Cloud

このクイックスタートでは、コンソールを使用して最初のワークフローを作成、デプロイ、実行する方法について説明します。 Google Cloud サンプル ワークフローは、リクエストを公開 API に送信してから、API のレスポンスを返します。


このタスクを Google Cloud コンソールで直接行う際の順を追ったガイダンスについては、「ガイドを表示」をクリックしてください。

ガイドを表示


始める前に

組織で定義されているセキュリティの制約により、次の手順を完了できない場合があります。トラブルシューティング情報については、 制約のある Google Cloud 環境でアプリケーションを開発するをご覧ください。

  1. アカウントにログインします。 Google Cloud を初めて使用する場合は、 Google Cloud アカウントを作成して、 実際のシナリオで Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Workflows API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Workflows API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  10. 認証を設定します。
    1. サービス アカウントの作成 IAM ロール (roles/iam.serviceAccountCreator)とプロジェクト IAM 管理者ロール (roles/resourcemanager.projectIamAdmin)があることを確認します。ロールを付与する方法 をご覧ください
    2. コンソールで、[サービス アカウントの作成] ページに移動します。 Google Cloud

      [サービス アカウントの作成] に移動
    3. プロジェクトを選択します。
    4. [サービス アカウント名] フィールドに名前を入力します。コンソールでは、この名前に基づいて [サービス アカウント ID] フィールドの値が設定されます。 Google Cloud

      [サービス アカウントの説明] フィールドに説明を入力します。例: Service account for quickstart

    5. [作成して続行] をクリックします。
    6. サービス アカウントに [Logging] > [ログ書き込み] のロールを付与します。

      ロールを付与するには、[ロールを選択] リストを見つけて、 [Logging] > [ログ書き込み] を選択します。

    7. [続行] をクリックします。
    8. [完了] をクリックして、サービス アカウントの作成を完了します。

  11. サービス アカウントのロールと権限の詳細については、 ワークフローに Google Cloud リソースへのアクセス権限を付与するをご覧ください。

必要なロール

このクイックスタートを完了するために必要な権限を取得するには、プロジェクトに対する次の IAM ロールを付与するよう管理者に依頼してください。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセスを管理するをご覧ください。

必要な権限は、カスタム ロールや他の事前定義 ロールから取得することもできます。

ワークフローを作成してデプロイする

  1. コンソールで [**ワークフロー**] ページに移動します。 Google Cloud

    [ワークフロー] に移動

  2. [ワークフロー] ページで、 [作成] をクリックします。

  3. 新しいワークフローの名前を入力します(例: myFirstWorkflow)。

  4. リージョンには us-central1 を選択します。

  5. [サービス アカウント] で、先ほど作成したサービス アカウントを選択します。

  6. [次へ] を選択します。

  7. 次のワークフローをコピーしてワークフロー エディタに貼り付けます。

    YAML

    main:
      params: [input]
      steps:
        - checkSearchTermInInput:
            switch:
              - condition: '${"searchTerm" in input}'
                assign:
                  - searchTerm: '${input.searchTerm}'
                next: readWikipedia
        - getLocation:
            call: sys.get_env
            args:
              name: GOOGLE_CLOUD_LOCATION
            result: location
        - setFromCallResult:
            assign:
              - searchTerm: '${text.split(location, "-")[0]}'
        - readWikipedia:
            call: http.get
            args:
              url: 'https://en.wikipedia.org/w/api.php'
              query:
                action: opensearch
                search: '${searchTerm}'
            result: wikiResult
        - returnOutput:
            return: '${wikiResult.body[1]}'

    JSON

    {
      "main": {
        "params": [
          "input"
        ],
        "steps": [
          {
            "checkSearchTermInInput": {
              "switch": [
                {
                  "condition": "${\"searchTerm\" in input}",
                  "assign": [
                    {
                      "searchTerm": "${input.searchTerm}"
                    }
                  ],
                  "next": "readWikipedia"
                }
              ]
            }
          },
          {
            "getLocation": {
              "call": "sys.get_env",
              "args": {
                "name": "GOOGLE_CLOUD_LOCATION"
              },
              "result": "location"
            }
          },
          {
            "setFromCallResult": {
              "assign": [
                {
                  "searchTerm": "${text.split(location, \"-\")[0]}"
                }
              ]
            }
          },
          {
            "readWikipedia": {
              "call": "http.get",
              "args": {
                "url": "https://en.wikipedia.org/w/api.php",
                "query": {
                  "action": "opensearch",
                  "search": "${searchTerm}"
                }
              },
              "result": "wikiResult"
            }
          },
          {
            "returnOutput": {
              "return": "${wikiResult.body[1]}"
            }
          }
        ]
      }
    }
    

    独自の検索キーワードを入力する場合を除き、このワークフローにより Google Cloud のロケーションを使用して検索キーワードが作成され、これが Wikipedia APIに渡されます。関連する Wikipedia 記事のリストが返されます。

  8. [デプロイ] を選択します。

ワークフローを実行する

ワークフローが正常にデプロイされると、最初のワークフロー実行を行えるようになります。ワークフローをデプロイすると、[ワークフローの詳細] ページが表示されます。

  1. [ワークフローの詳細] ページで [ 実行] を選択します。

  2. [ワークフローの実行] ページで、[実行] をクリックします。

  3. [出力] ペインに、ワークフローの結果が表示されます。

これで最初のワークフローのデプロイと実行が完了しました。

クリーンアップ

このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、 次の手順を実施します。

  1. コンソールで [**ワークフロー**] ページに移動します。 Google Cloud

    [ワークフロー] に移動

  2. ワークフローのリストからワークフローをクリックして、[ワークフローの詳細] ページに移動します。

  3. [削除] をクリックします。

  4. ワークフローの名前を入力し、[確認] をクリックします。

次のステップ