構成可能な API プロキシを作成する

このページは ApigeeApigee ハイブリッドに適用されます。

Apigee Edge ドキュメントを表示する

構成可能な API プロキシプレビューでは、Apigee ユーザーが Kubernetes リソースモデルと同様の宣言型構成で、軽量プロキシを作成してデプロイできます。このページでは、構成可能なプロキシを作成し、新しいアーカイブベースのデプロイ メカニズムを使用してデプロイする手順について説明します。

構成可能な API プロキシプレビューの詳細については、構成可能な API プロキシをご覧ください。

構成可能な API プロキシプレビューの開発は、Apigee 有料サブスクリプションの組織のお客様のみが利用できます。Apigee を従量課金制で使用している組織のお客様は、プログラム可能な API プロキシを作成できます。

始める前に

このチュートリアルでは、すでに Apigee 組織をプロビジョニングして Apigee をインストールしていることを前提としています。それ以外の場合は、続行する前にプロビジョニングの概要で Apigee のインストールと構成に必要な手順に確認してください。

このチュートリアルを始める前に、次の追加手順を完了してください。

  1. Cloud SDK がダウンロードされ、マシンにインストールされていることを確認します。

    Cloud SDK をダウンロード

  2. gcloud コンポーネントを更新します。
    gcloud components update
  3. Apigee の認証情報と組織の詳細を確認します。これらは、構成可能な API プロキシの環境をプロビジョニングする際に必要になります。

Apigee 環境をプロビジョニングする

プロキシ構成を作成する前に、構成可能なプロキシをサポートする Apigee 環境をプロビジョニングする必要があります。「環境」とは、組織内の API プロキシと共有フローのランタイム実行コンテキストです。環境にアクセスできるようにするには、その環境に API プロキシをデプロイする必要があります。ある特定の API プロキシを、単一の環境または複数の環境にデプロイできます。

詳細については、環境と環境グループについてをご覧ください。

To create a new environment in the UI:

  1. Open the Apigee UI in a browser.
  2. Select Admin > Environments > Overview in the left navigation menu.

    The UI displays a set of cards, each one representing an existing environment:

    Environment cards

    If this is your first time accessing the Environment view, there will be no environments.

  3. Click +ENVIRONMENT.

    The New environment dialog box displays:

    New Environment dialog

  4. Enter the following information in the New Environment dialog box:
    1. Display name: A friendly name for the environment that is used in the UI. For example, My Test Environment.
    2. Environment name: The programmatic name for the environment. This value will be part of the request URL for your API proxies and should not contain any spaces or other special characters. It can only letters, numbers, and hyphens. For example, my-environment-1.

      The new environment's name cannot be changed after it has been created.

    3. Description (optional): Additional information about the environment that you want to add as a reminder.
    4. Deployment type (Preview): Select Archive as the deployment type.

    All fields except Description are required.

  5. Click OK.

    The card displays Pending Provisioning status while Apigee creates the new environment, as the following example shows:

    Pending provisioning label

    There can be a several minute delay before the new environment is provisioned.

    When it's done, the Apigee UI displays the new environment as a card with other environments that you have created:

    Environment cards

環境を Apigee インスタンスに接続する

新しい環境を作成したら、新しい環境にアクセスできるように Apigee インスタンスを接続する必要があります。これを行うには、新しいインスタンスを作成するときに UI を使用します(環境がすでに存在する場合)。以前にインスタンスを作成したことがある場合は、インスタンスの接続作成 API を使用して新しい環境を接続できます。

プロセスの例については、コマンドラインのプロビジョニング ドキュメントの環境を作成するをご覧ください。

このチュートリアルでは、次のコマンドを使用できます。

operation_name=$(curl -s -H "Authorization:Bearer $(gcloud auth print-access-token)" \
  "https://apigee.googleapis.com/v1/organizations/PROJECT_ID/instances/INSTANCE_NAME/attachments" \
  -X POST -H "content-type:application/json"\
  -d '{"environment":"ENV_NAME"}' | jq -r '.name' )

ここで

  • PROJECT_ID は、Apigee 環境が作成される Cloud プロジェクトの ID です。Apigee 組織名と同じにする必要があります。
  • INSTANCE_NAME は実際の Apigee インスタンスです。
  • ENV_NAME は、構成可能な API プロキシがデプロイされる環境の名前です。

これにより、長時間実行オペレーションが返されます。出力に done: true が表示されるまで、次のコマンドを使用してオペレーションをポーリングできます。

curl -s -H "Authorization:Bearer $(gcloud auth print-access-token)" \
  "https://apigee.googleapis.com/v1/$operation_name"

環境グループを構成する

環境グループ(Apigee API の envgroup ともいいます)は、リクエストを個々の環境にルーティングする方法を定義する基本機能です。個々の環境ではなく、環境グループにホスト名を定義します。Apigee はこれらのホスト名定義を使用して、グループ内の環境にリクエストを転送します。

グループに割り当てられていない環境にはホスト名を指すホスト名がないため、アクセスできません。詳細については、環境グループの作成をご覧ください。

新しい環境の環境グループを構成するには:

  1. In the Apigee UI, select Admin > Environments > Groups.
  2. Click +Environment Group:

    Add environment button

    The Add an Environment Group dialog displays.

  3. Enter a name for your new environment group:

    Add environment group

    The name can contain only lower case letters, numbers, and hyphens. In addition, it must start with a letter, be at least two characters long, and cannot end with a hyphen. Valid names include my-env-group and prod2.

  4. Click Add.

    Apigee creates a new environment group. This is usually a very quick operation.

    On a successful operation, Apigee confirms that the group has been created with a banner that looks like the following:

    Group confirmation banner

    Apigee also assigns a default host name to the new group.

  5. (Optional) Assign additional host names to the new group by clicking for that group.

    Apigee displays the Environment group details pane:

    Environment group details

  6. Add host names to the Hostnames field. Each host name must be on a separate line.
  7. Click Save when you're done.

    You can add and remove host names to this list at any time using the same procedure.

プロキシ アーカイブを作成する

構成可能な API プロキシプレビュー アーカイブを作成するには:

  1. ローカル環境で、Apigee ワークスペースを保存するディレクトリをローカル ファイル システムに作成します。このディレクトリは、次に示すように、構成可能な API プロキシプレビューのファイル構造のベースとなります。
    .
    └── src
        └── main
            └── apigee
                ├── apiproxies
                │   ├── <proxy-name>
                │   │   └── config.yaml
                │   ├── <proxy-name>
                │   │   └── config.yaml
                └── environments
                    ├── <env-name>
                    │   ├── deployments.json
                    │   └── targetservers.json
    mkdir -p SOURCE_DIR/src/main/apigee/apiproxies/PROXY_NAME

    ここで

    • SOURCE_DIR は、アーカイブ ディレクトリの名前です。
    • PROXY_NAME は、構成可能なプロキシの名前です。

    例:

    mkdir -p my-dir/src/main/apigee/apiproxies/my-proxy
  2. 次のコマンドを使用して、プロキシ構成の新しいファイルを作成します。
    vi SOURCE_DIR/src/main/apigee/apiproxies/PROXY_NAME/config.yaml

    例:

    vi my-dir/src/main/apigee/apiproxies/my-proxy/config.yaml

    プロキシ構成ファイルでは、次のいずれかのファイル名を使用する必要があります。

    • config.yaml
    • config.json
    • config.yml
  3. 次のプロキシ構成を新しい config.yaml ファイルにコピーします。
    # config.yaml
    
    basepath: "/helloworld"
    operations:
    - id: get-user
      http_match:
      - path_template: "/user"
        method: GET
    target:
      uri: "https://mocktarget.apigee.net"
    
  4. 次のコマンドを使用して deployments.json ファイルを作成します。
    vi SOURCE_DIR/src/main/apigee/environments/ENV_NAME/deployments.json
    

    次に例を示します。

    vi my-dir/src/main/apigee/environments/prod/deployments.json
  5. 以下を deployments.json ファイルにコピーします。
  6. {
      "proxies" : ["PROXY_NAME"]
    }
      

その他の例については、構成可能なプロキシ構成の例をご覧ください。

アーカイブをデプロイする

アーカイブを Apigee 環境にデプロイするには、次の gcloud コマンドを使用します。

gcloud alpha apigee archives deploy \
--organization=PROJECT_ID \
--environment=ENV_NAME \
--source=SOURCE_DIR

次に例を示します。

gcloud alpha apigee archives deploy \
--organization=my-project \
--environment=prod \
--source=my-dir

--environment フラグを使用して、アーカイブをデプロイする Apigee 環境を指定する必要があります。Apigee 環境では、アーカイブ デプロイメントを有効にする必要があります。

アーカイブ デプロイの管理の詳細については、Apigee 環境でのアーカイブのデプロイと管理をご覧ください。

アーカイブ デプロイのステータスを確認する

アーカイブ デプロイのステータスを確認するには、gcloud alpha apigee operations コマンドを使用します。

次の例は、リビジョン ID 439fa3f7-6aa4-42ad-8b12-3ca912c75d5c を持つオペレーションのアーカイブ デプロイメントのステータスが IN_PROGRESS であることを示しています。

gcloud alpha apigee operations describe b64c2665-b5ac-43cc-9e2d-232e8895c2ed

レスポンスは次のようになります。

Using Apigee organization 'myorg'
Waiting for operation [b64c2665-b5ac-43cc-9e2d-232e8895c2ed] to complete...done.

アーカイブ デプロイメントの一覧表示、デプロイメントの詳細の表示、アーカイブ デプロイメントを含む環境の削除の詳細については、Apigee 環境でのアーカイブのデプロイと管理をご覧ください。