Step 7: Deploy to an Apigee environment

This page applies to Apigee and Apigee hybrid.

View Apigee Edge documentation.

After you complete local development and testing with Apigee in VS Code, you are ready to deploy your API as an archive to an Apigee environment. In this step, you'll create an Apigee environment that supports archive deployment and deploy an archive of your API proxy configuration to the Apigee environment.

  1. Follow the steps in Create an environment to perform the following:
    1. Create a new dev environment in your Apigee organization, enabling Archive as the deployment type. Use the UI or API.

      For example:

      New environment dialog showing Archive deployment type settings

    2. Attach the environment to a runtime instance using the Instances attachment API.

      This command triggers a long-running operation. Ensure that the environment has been attached to the runtime before continuing.

    3. Create an environment group if you do not already have one using the Create environment groups API.

      Ensure that the environment group has been created before continuing. You can check the status of your new group using a request like the following:

      curl -i -H "$AUTH" -H "Content-Type:application/json" \
        "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/environments/ENVIRONMENT_NAME"
    4. Attach the new environment to the environment group using the Environment group attachment API.

      Attaching an environment to the group makes the proxies in that environment routable via the hostnames in the group. This triggers a long-running operation that can take several minutes to complete. We recommend that you wait a minute or two before continuing to the next step. In the meantime you can check the status of the operation as before.

  2. Deploy an archive of your API proxy configuration to the Apigee environment.
    1. In the Terminal tab in Apigee VS Code, navigate to the myapigeeworkspace directory.
      cd myapigeeworkspace

      When you run ls the directory should contain the src folder.

    2. Run the following command:
      gcloud beta apigee archives deploy --environment=dev --labels=release=052021

      The following provides an example of the response:

      Using Apigee organization dev
      Waiting for operation [b64c2665-b5ac-43cc-9e2d-232e8895c2ed] to complete...done
  3. Run the following command in the Terminal tab to test your API:
    curl https://INTERNAL_LOAD_BALANCER_IP/helloworld /
      -H "Host: ENV_GROUP_HOSTNAME" 

    For more information about the variables in this example and how to set up API access, see Deploy a sample proxy.

    The following error message is displayed:

    {"fault":{"faultstring":"Failed to resolve API Key variable request.queryparam.apikey",
      "detail":{"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}
    

    You need to create an API product that includes the helloworld API, then create and register a developer with the API product in order to obtain an API key.

  4. Obtain an API key.
    1. Create an API product using the Apigee UI:
      1. Select Publish > API Products.
      2. Click + Create.
      3. Enter the Product Details for your API product.
      4. Enter the following information in the fields:
        Field Setting
        Name: myproduct
        Display name: myproduct
        Environment: dev
        Access: Public
        Quota: Leave blank
        Allowed OAuth scope: Leave blank
      5. In the Operations section, click + Add an Operation.
      6. Under Source select helloworld from the API Proxy dropdown menu.
      7. Under Operation, in the Path field, enter /.

        Leave other fields set to their defaults.

      8. Click Save to save the Operation.
      9. Click Save to save the API product.
    2. Create a developer in your organization:
      1. Select Publish > Developers in the navigation menu.
      2. Click + Developer.
      3. Enter the following information in the fields:
        Field Setting
        First Name: Alex
        Last Name: Hamilton
        Username: ahamilton
        Email: ahamilton@example.com
      4. Click Create.
    3. Register an app:
      1. Select Publish > Apps.
      2. Click + App.
      3. Enter the following information in the fields:
        Field Setting
        Name: myapp
        Display name: myapp
        Developer: ahamilton@example.com
        Callback URL: Leave blank
        Notes: Leave blank
        Expiry: Never
        Product:
        1. Click Add product.
        2. Select myproduct.
        3. Click Add.
        Custom attributes: Leave blank
    4. Copy the API key.
      1. On the Apps page (Publish > Apps), click myapp.
      2. On the myapp page, click Show next to Key in the Credentials section. Notice that the API key is associated with the API product you created.
      3. Select and copy the API key.
  5. Run the curl call again passing the API key using the apikey query parameter, as follows:
    curl -v https://$PUBLIC_FACING_IP/helloworld?apikey=ZQA5euYtNeJ7ZCGCJMpvd6F2BZOmxOzY

    The following response is returned:

    {
      "root": {
        "city": "San Jose",
        "firstName": "John",
        "lastName": "Doe",
        "state": "CA"
      }
    }

Congratulations! You've successfully deployed your API archive to an Apigee environment!

In the next step, you'll promote your API archive to an Apigee production environment.

1 2 3 4 5 6 7 (NEXT) Step 8: Promote an archive to production