Apigee Edge enables you to quickly expose backend services as APIs. You do this by creating an API proxy that provides a facade for the backend service that you want to expose. Apigee Edge out of the box supports the OpenAPI specification, allowing you to auto-generate API Proxies. Apigee Edge also has an OpenAPI specification editor & store which you can use to maintain your OpenAPI specifications.

The API proxy decouples your backend service implementation from the API that developers consume. This shields developers from future changes to your backend services. As you update backend services, developers, insulated from those changes, can continue to call the API uninterrupted.

The Apigee Edge Service Broker for PCF enables developers to manage APIs for their PCF apps through the Apigee Edge management console.

This lab describes how to push a sample app to Pivotal Cloud Foundry (PCF), create an Apigee Edge service instance, and bind the application to it. After binding the application to the Apigee Edge service instance, requests to the app will be forwarded to an Apigee Edge API proxy for management. This tutorial is adapted from this PCF documentation page

What you'll learn

What you'll need

How will you use use this tutorial?

Read it through only Read it and complete the exercises

How would you rate your experience with using Apigee and Pivotal Cloud Foundry?

Novice Intermediate Proficient

Self-paced environment setup

If you don't already have a Google Account (Gmail or G Suite), you must create one. Sign-in to Google Cloud Platform console (console.cloud.google.com) and create a new project from the Manage resources page :

Remember the project ID, a unique name across all Google Cloud projects (the name above has already been taken and will not work for you, sorry!). It will be referred to later in this codelab as PROJECT_ID.

Next, you'll need to enable billing in the Developers Console in order to use Google Cloud resources.

Running through this codelab shouldn't cost you more than a few dollars, but it could be more if you decide to use more resources or if you leave them running (see "cleanup" section at the end of this document). The Google Cloud Platform pricing calculator is available here.

New users of Google Cloud Platform are eligible for a $300 free trial.

Launch Cloud Shell

Activate Google Cloud Shell

From the GCP Console click the Cloud Shell icon on the top right toolbar:

Then click "Start Cloud Shell":

It should only take a few moments to provision and connect to the environment:

This virtual machine is loaded with all the development tools you'll need. It offers a persistent 5GB home directory, and runs on the Google Cloud, greatly enhancing network performance and authentication. Much, if not all, of your work in this lab can be done with simply a browser or your Google Chromebook.

Once connected to the cloud shell, you should see that you are already authenticated and that the project is already set to your PROJECT_ID:

gcloud auth list

Command output

Credentialed accounts:
 - <myaccount>@<mydomain>.com (active)
gcloud config list project

Command output

[core]
project = <PROJECT_ID>

If it is not, you can set it with this command:

gcloud config set project <PROJECT_ID>

Command output

Updated property [core/project].

Install Cloud Foundry CLI

Add the Cloud Foundry Foundation public key and package repository to your system:

$ wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -

$ echo "deb http://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list

Update your local package index:

$ sudo apt-get update

Install the cf CLI:

$ sudo apt-get install cf-cli

Set up the environment variables for your PCF account:

Important - Click on this link to get the environment variables and login credentials you need for the next step (The snippet below is a template and does not contain the actual variables)

If you have an issue retrieving or using the environment variables, ask your instructor. If you're completing this lab self-paced, reach out to Edgepartners@google.com.

$ export PCF_API={CF-API}
$ export PCF_ORG={PCF ORG}
$ export PCF_SPACE={PCF SPACE}
$ export PCF_DOMAIN={PCF DOMAIN}
$ export APIGEE_ORG={org-name}
$ export APIGEE_ENV={env-name}

Here is a brief description of the parameters

Name

Details

PCF_API

The API endpoint for your PCF Instance

PCF_ORG/PCF_SPACE

The environment where you want to deploy your sample app

PCF_DOMAIN

Domain for all the routes created in your PCF Environment

APIGEE_ORG/APIGEE_ENV

Details of the Apigee environment where your Proxies are deployed

Before you begin, you should also have separate username/password to access PCF environment and Apigee environment

Login to the PCF Environment (from your cloud shell):

$ cf api $PCF_API  --skip-ssl-validation
$ cf login

Enter the PCF-USER-NAME and PCF-PASSWORD. Select the PCF_ORG and PCF_SPACE

Once you login, you can also select the org and space through the following command

$ cf target -o $PCF_ORG -s $PCF_SPACE

Download the sample App to PCF

We will use a sample hello world node.js app from this git repo

$ git clone https://github.com/apigee/pivotal-cf-apigee.git
$ cd pivotal-cf-apigee/sample-api

Update your app and push it to PCF

Open manifest.yml file and change the following parameters: name: {your_initials}_helloapi, host: {your_initials}_helloapi

$ vi manifest.yml
name: {your_initials}_helloapi
host: {your_initials}_helloapi

Save the changes Esc, :wq

Push the API to PCF

cf push

Export your app's hostname to a local variable. We will use it in the subsequent steps to create an Apigee binding to the app's route

$ export PCF_APPHOST={your_initials}_helloapi

Test your app

On successful push, you should be able to see your app with the following command

You should be able to send a request, by copy/pasting the URL under the urls section of your app, to a new browser tab. http://{URL OF YOUR APP}

$ cf apps
Getting apps in org Apigee / space {PCF_SPACE} as {PCF_USER}...
OK

name              requested state   instances   memory   disk   urls
{your_initials}_helloapi   started   1/1         128M     1G    URL OF YOUR APP

Login to Apigee, through Apigee's SSO

The following commands should give you a valid token that you can use for the next steps:

$ curl https://login.apigee.com/resources/scripts/sso-cli/ssocli-bundle.zip -o "ssocli-bundle.zip"

$ unzip ssocli-bundle.zip

$ ./get_token
<<export the token to a environment variable>>

$ export APIGEE_TOKEN={token}

Make sure apigee-edge service is available in your marketplace. If you are trying this on your own PCF instance, you should install the Apigee Edge Service Broker tile from your ops manager

$ cf marketplace

This should show apigee-edge as one of the available services.

Create service in your environment. Use the ‘org' plan to make sure the proxies are created on the public/private cloud.

$ cf create-service apigee-edge org apigee_org_service -c '{"org":"'$(echo  $APIGEE_ORG)'","env":"'$(echo  $APIGEE_ENV)'"}'

To check that the service has been enabled, try the following command

$ cf service apigee_org_service

Bind the app's route (Our Node.js app that servers the Hello API) to an Apigee ORG with the following command.

$ cf bind-route-service $PCF_DOMAIN apigee_org_service --hostname $PCF_APPHOST -c '{"org":"'$(echo  $APIGEE_ORG)'","env":"'$(echo  $APIGEE_ENV)'", "bearer":"'$(echo $APIGEE_TOKEN)'", "action":"proxy bind"}'

Login to https://apigee.com/edge

Select API Proxies

Select API Proxies

You should see an API Proxy created by the PCF Service Broker- with the following name cf-{your_initials}_helloapi.YOUR-SYSTEM-DOMAIN

Select API Proxy

Select the API and select TRACE tab on the top right

Click on the Start Trace Session, the green button on the top left

Start the Trace Session

Open a new browser tab. Send a request to the app's endpoint (this is the same endpoint you tested in your previous step)- by copy/pasting the URL under the urls section of your app, to a new browser tab. http://{URL OF YOUR APP}

If you forgot the URL OF YOUR APP, you can get if through the following command (the output will have a urls section corresponding to your app)

$ cf apps

This time, when you send the request, the request should show up in the trace of your API Proxy.

Summary

In this step, you have bound your PCF App to Apigee. PCF will now send requests to Apigee to add API Management.

You have deployed a hello world API to PCF, used Apigee's integrations to create an API Proxy. Your API is not managed.

Learn More

License

This work is licensed under a Creative Commons Attribution 2.0 Generic License.