Getting started with Cloud Endpoints for Compute Engine with ESP

This tutorial shows you how to configure and deploy a sample API and the Extensible Service Proxy (ESP) running in prebuilt Docker containers on Compute Engine. The sample API is described using the OpenAPI specification. The tutorial also shows you how to create an API key and use it in requests to the API.

For an overview of Cloud Endpoints, see About Endpoints and Endpoints architecture.

Objectives

Use the following high-level task list as you work through the tutorial. All tasks are required to successfully send requests to the API.

  1. Set up a Google Cloud project. See Before you begin.
  2. Create a Compute Engine VM instance. See Creating a Compute Engine instance.
  3. Download the sample code. See Getting the sample code.
  4. Configure the openapi.yaml file, which is used to configure Endpoints. See Configuring Endpoints.
  5. Deploy the Endpoints configuration to create a Endpoints service. See Deploying the Endpoints configuration.
  6. Deploy the API and ESP on the Compute Engine VM. See Deploying the API backend.
  7. Send a request to the API by using an IP address. See Sending a request by using IP address.
  8. Configure a DNS record for the sample API. See Configuring DNS for Endpoints.
  9. Send a request to the API by using the fully qualified domain name. See Sending a request by using FQDN.
  10. Track API activity. See Tracking API activity.
  11. Avoid incurring charges to your Google Cloud account. See Clean up.

Costs

In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator.

New Google Cloud users might be eligible for a free trial.

When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.

Before you begin

  1. 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

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

  3. Make a note of the project ID because it's needed later.
  4. You need an application to send requests to the sample API.

    • Linux and macOS users: This tutorial provides an example of using curl, which typically comes pre-installed on your operating system. If you don't have curl, you can download it from the curl Releases and downloads page.
    • Windows users: This tutorial provides an example using Invoke-WebRequest, which is supported in PowerShell 3.0 and later.
  5. Download the Google Cloud CLI.
  6. Update the gcloud CLI and install the Endpoints components.
    gcloud components update
  7. Make sure that the Google Cloud CLI (gcloud) is authorized to access your data and services on Google Cloud:
    gcloud auth login
    In the new browser tab that opens, select an account.
  8. Set the default project to your project ID.
    gcloud config set project YOUR_PROJECT_ID

    Replace YOUR_PROJECT_ID with your project ID. If you have other Google Cloud projects, and you want to use gcloud to manage them, see Managing gcloud CLI configurations.

When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.

Creating a Compute Engine instance

    To create a Compute Engine instance:

    1. In the Google Cloud console, go to the Create an instance page.

      Go to Create an instance

    2. Click Select.
    3. In the Firewall section, select Allow HTTP traffic and Allow HTTPS traffic.
    4. To create the VM, click Create.
    5. Screenshot of the VM instance creation window with the required options set

      Allow a short time for the instance to start up. Once ready, it is listed on the VM Instances page with a green status icon.

    6. Make sure you that you can connect to your VM instance.