
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
When you build proxies, it is important to not hardcode environment-specific configuration in a proxy.
In this lab, you will add a new environment and environment group to your organization. You will then use an environment-specific target server to specify the backend target URL.
In this lab, you learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
This asset has already been added to the Apigee organization:
In this task, you create a new environment group and environment for an organization.
In the Google Cloud console, on the Navigation menu (), look for Apigee in the Pinned Products section.
The Apigee console page will open.
If Apigee is not pinned, search for Apigee in the top search bar and navigate to the Apigee service.
Hover over the name, then click the pin icon ().
The Apigee console page will now be pinned to the Navigation menu.
On the left navigation menu, select Management > Environments.
Click on the eval environment.
This page shows the details for the eval environment. The eval environment is in the eval-group environment group.
If the runtime is not yet available, you will be able to deploy API proxies to the environment, but the proxies will not accept API requests until the runtime is up, and the eval environment is attached.
Once the runtime is up and the environment is attached, the runtime will query the management plane for the current API proxy deployments, and the runtime will host the API proxy and accept traffic.
In the left menu, click Management > Environments, and then select the Environment Groups tab.
The page should show the default environment group named eval-group. It shows the hostnames and environments that are in the environment group. You should see the eval environment, as well as an example.com
hostname. Selecting Edit from the more menu () lets you edit the environment group's hostnames and environments.
Click +Create Environment Group.
Specify the following environment group settings:
Property | Value |
---|---|
Environment group name | prod-group |
Hostnames | prod.example.com |
Do not set Environments (optional).
Click Create.
Select the Environments tab, and then click +Create Environment.
Specify the following environment settings:
Property | Value |
---|---|
Name | prod |
Display name | Prod |
Environment group | select prod-group, and then click OK |
Deployment type | select Proxy |
Do not select the instance yet.
Click Create.
The status of the new prod environment is Inactive (not attached to an instance). A target server may be created for the environment, but proxies deployed to the environment won't handle traffic until the environment is successfully attached to an instance.
In this task, you create a new target server configuration for the eval environment.
On the left navigation menu, select Management > Environments, and then click eval.
Select the Target Servers tab, and then click +Create Target Server.
Specify the following target server values:
Property | Value |
---|---|
Enable Target Server | selected |
Target Server name | TS-Retail |
Host | gcp-cs-training-01-test.apigee.net |
Protocol | select HTTP |
Port | 443 |
Enable SSL | selected |
When the SSL box is selected, the dialog shows additional configuration fields. Leave the default SSL values set to their defaults.
Click Create.
In this task, you create a target server for the prod environment.
On the left navigation menu, select Management > Environments, and then click prod.
Select the Target Servers tab, and then click +Create Target Server.
Specify the following target server values:
Property | Value |
---|---|
Enable Target Server | selected |
Target Server name | TS-Retail |
Host | gcp-cs-training-01-prod.apigee.net |
Protocol | select HTTP |
Port | 443 |
Enable SSL | selected |
These settings are identical to the settings for the eval target server, except for the Host.
Click Create.
In this task, you modify your retail API proxy to use the target server instead of the hardcoded target URL.
On the left navigation menu, select Proxy development > API proxies, and then click retail-v1.
Click the Develop tab.
You are modifying the version of the retail-v1 proxy that was created during Lab 1.
In the Navigator pane, click Target Endpoints > default.
The TargetEndpoint configuration is displayed in the Code box.
In the HTTPTargetConnection section, on line 16, is the hardcoded URL.
Replace the hardcoded URL with a reference to the target server you created.
Replace:
with:
Note that /training/db
is now specified in the Path element. The target server, TS-Retail, specifies the hostname that will be used.
Combined, the URL used for the call to the backend will be the same as the hardcoded URL in the eval environment. When deployed to the prod environment, the hostname will automatically change for the prod backend without any changes to the code.
To save the changes, click Save.
The message box indicates that the changes could not be saved to revision 1 because it is deployed.
Click Save As New Revision.
Click Deploy.
To specify that you want the new revision deployed to the eval environment, select eval as the Environment, and then click Deploy.
Click Confirm.
A proxy that is deployed and ready to take traffic will show a green status on the Overview tab.
When a proxy is marked as deployed but the runtime is not yet available and the environment is not yet attached, you may see a red warning sign. Hold the pointer over the Status icon to see the current status.
If the proxy is deployed and shows as green, your proxy is ready for API traffic. If your proxy is not deployed because there are no runtime pods, you can check the provisioning status.
In Cloud Shell, to confirm that the runtime instance has been installed and the eval environment has been attached, run the following commands:
When the script returns ORG IS READY TO USE
, you can proceed to the next steps.
You can now deploy proxies to the prod environment, but they will not run unless the prod environment is attached to an instance.
In Cloud Shell, to attach the prod environment to the instance, run the following commands:
You should be notified that the attachment is in progress. The operation may take a few minutes to complete.
To check the status of the prod attachment, run the following commands:
Leave this command running in Cloud Shell.
The eval environment should be ready to serve traffic, so you can test the API proxy in the eval environment now.
On the left navigation menu, select Proxy development > API proxies, and then click retail-v1.
Select the Develop tab.
Click Deploy.
To specify that you want the latest revision deployed to the prod environment, select prod as the Environment, and then click Deploy.
Click Confirm.
The proxy will not finish deploying until the prod environment has fully attached to the runtime instance.
In this task, you use the debug tool to verify that the updated proxy still successfully calls the backend service.
Select the Debug tab.
Click Start Debug Session.
In the Start debug session pane, on the Environment dropdown, select eval.
The deployed revision number will also show in the dropdown.
Click Start.
The eval environment in the Apigee organization can be called using the hostname eval.example.com. The DNS entry for this hostname has been created within your project, and it resolves to the IP address of the Apigee runtime instance. This DNS entry has been created in a private zone, which means it is only visible on the internal network.
Cloud Shell does not reside on the internal network, so Cloud Shell commands cannot resolve this DNS entry. A virtual machine (VM) within your project can access the private zone DNS. A virtual machine named apigeex-test-vm was automatically created for this purpose. You can make API proxy calls from this machine.
The curl command will be used to send API requests to an API proxy. The -k
option for curl tells it to skip verification of the TLS certificate. For this lab, the Apigee runtime uses a self-signed certificate. For a production environment, you should use certificates that have been created by a trusted certificate authority (CA).
In Cloud Shell, open a new tab, and then open an SSH connection to your test VM:
The first gcloud command retrieves the zone of the test VM, and the second opens the SSH connection to the VM.
If asked to authorize, click Authorize.
For each question asked in the Cloud Shell, click Enter or Return to specify the default input.
Your logged in identity is the owner of the project, so SSH to this machine is allowed.
Your Cloud Shell session is now running inside the VM.
To make a call to proxy hosted in the eval environment, in the Cloud Shell SSH session, send a request to your API proxy by using this command:
The response from the curl command should be a 200 status code if your backend URL was correctly set. The backend service set the response headers, including the header named backend. In this case, the value of the backend header is test.
A transaction for this request should soon appear in the Transactions pane on the left. If the transaction doesn't show up, try sending the request again.
Select a transaction in the Transactions pane.
When a transaction is selected, you'll see a trace of the request and response through Apigee.
In the transaction details pane, click Target Response Flow Started.
In Response headers, you see that the backend sent a header named backend with a value of test.
You can also see this header in the response from the curl command.
In the transaction details pane, click AnalyticsPredefinedVariablesPublisher.
Apigee captures analytics for the API calls that travel through your proxies. This step in the transaction details shows the variables that were captured.
In this task, you use the debug tool to test that the proxy, when deployed to the prod environment, calls the prod backend service.
In the first Cloud Shell tab, confirm that the prod environment attachment has finished.
Select the Debug tab.
Click Start Debug Session.
In the Start debug session pane, on the Environment dropdown, select prod.
Click Start.
To make a call to proxy hosted in the prod environment, in the SSH session, send the following curl command:
The value of the backend header is prod.
Verify the analytics variables for the prod request.
In this lab, you changed your API proxy to use a target server instead of the hardcoded target URL. You can now run your proxy in different environments without changing the target URL in the proxy code.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one