arrow_back

APIs Explorer: Compute Engine

Join Sign in
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

APIs Explorer: Compute Engine

Lab 45 minutes universal_currency_alt 1 Credit show_chart Introductory
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

GSP293

Google Cloud self-paced labs logo

Overview

The APIs Explorer enables you to construct REST-based API calls against any version of any Google service. In this lab, you use API Explorer to create (insert) a Compute Engine instance with the Compute Engine API and then use Cloud Monitoring to monitor CPU usage.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at the top-left. Navigation menu icon

Set the region for your project

gcloud config set compute/region {{{project_0.default_region | "REGION"}}}

Task 1. API Explorer tool

  1. To access the APIs Explorer tool, from the Navigation menu select APIs & Services > Library.

  2. Type compute in the Search bar; all the APIs prefixed with "compute" are returned.

  3. Click on Compute Engine API.

  4. Make sure that API is enabled; if not, click Enable.

  5. As the API is enabled, for reference, open Rest API Reference in a new tab. Refer to the Rest API Reference page for the Compute Engine API.

Task 2. Create your request

  1. Navigate to the Method:instances.insert reference to create an instance resource.

Next, fill out a form to use the compute.instances.insert method.

  1. The Request body contains the resource properties you use to create your instance:

project=

zone =

Request body= Click inside the brackets to select the following properties:

  • machineType: zones//machineTypes/n1-standard-1
  • name: instance-1
  • networkInterfaces: leave empty [{}]
  • disks:
    • type: PERSISTENT
    • initializeParams > sourceImage: projects/debian-cloud/global/images/family/debian-11
  • Set the boot to true

Your form should look like the following image:

The form containing the previously indicated completed fields.

  1. Make sure that the Google OAuth 2.0 checkbox is selected in the Credentials section.
Note: To view Credentials FAQs, click on the question mark icon next to the Credentials title.
  1. Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.

  2. Select the student account you started the lab with.

  3. On the next screen, click Allow to give APIs Explorer access.

You can see the Request that was sent to your project as code, built from the input you provided in the form, and the Response below it.

  1. In the console, click Navigation menu > Compute Engine to view the instance you just created.

Test completed task

Click Check my progress to verify your performed task. If you have successfully created a Compute Engine instance via API, you will see an assessment score.

Create a Compute Engine instance via API

Task 3. Monitor your instance with Cloud monitoring

  1. Use the Cloud Monitoring API documentation to navigate to Cloud Monitoring API.

  2. Navigate to the Method: projects.timeSeries.list documentation to lists time series.

For this method, the name is specified as a string in the format projects/Your_Project_ID.

The monitoring filter specifies which time series should be returned. The filter must specify a single metric type, and can additionally specify a metric label and other information.

  1. For this lab, specify gce_instance as the resource type and cpu/usage_time as the metric type.

  2. Add the following string in the filter box:

resource.type="gce_instance" AND metric.type="compute.googleapis.com/instance/cpu/usage_time"
  1. interval.endTime and interval.startTime: Calculate RFC-3339 timestamps to filter the time series returned by APIs Explorer. You can use Unix Time Stamp - Epoch Converter to get the current time.

  2. Copy the last RFC 3339 timestamp and add it to interval.endTime:

The Epoch and Unix Timestamp Conversion Tools page, with the date and timestamp highlighted.

  1. Subtract one hour from your timestamp time and add that value to interval.startTime.

Your form should display as follows:

Request form that contains the resource properties to create your instance using the projects.timeSeries.list method

  1. Make sure that the Google OAuth 2.0 and API key checkboxes are selected under the Credentials section.
Note: To view the Credentials FAQs, click on the question mark icon next to the Credentials title.
  1. Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.

Request body for the request to use the projects.timeSeries.list method

Task 4. Bonus: See your metric in Cloud Monitoring

You can do the same exercise in Cloud Monitoring if you want. Open a Cloud monitoring workspace in the Cloud Console, then use the Metrics Explorer to monitor your VMs CPU usage.

Create a Monitoring Metrics Scope

Set up a Monitoring Metrics Scope that's tied to your Google Cloud Project. The following steps create a new account that has a free trial of Monitoring.

  • In the Cloud Console, click Navigation menu (Navigation menu icon) > Monitoring.

When the Monitoring Overview page opens, your metrics scope project is ready.

Monitor CPU usage

  1. In the left menu, click Metrics Explorer.

  2. Metric: Navigate to VM Instance > Instance > CPU Usage, then click Apply.

  3. Filter: instance_name (select your instance.)

Task 5. Delete your VM

Now use APIs Explorer to delete the instance you created.

  1. Open Rest API Reference. This will open a new tab with the Rest API Reference page for the Compute Engine API.

  2. Navigate to the Method: instances.delete documentation to delete an instance resource.

  3. Add your project, zone, and instance name to the form.

  4. Make sure that the Google OAuth 2.0 checkbox is selected in the Credentials section.

Note: To view Credentials FAQs, click on the question mark icon next to the Credentials title.
  1. Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.

Your Response will indicate that the deletion process has been started.

  1. Navigate to Compute Engine with Navigation menu > Compute Engine and verify that your console resembles following:

VM instance list displaying Instance-1

Note: If your instance deletion process has been completed then you won't be able to see an output as above. That means your instance has been removed.

Test completed task

Click Check my progress to verify your performed task. If you have successfully deleted your instance, you will see an assessment score.

Delete your instance

Task 6. Test your knowledge

Test your knowledge about the Google Cloud by taking our quiz.

Congratulations!

You have created an instance, monitored its CPU usage, and removed an instance using APIs Explorer.

Finish your quest

This self-paced lab is part of the Exploring APIs quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest or any quest that contains this lab and get immediate completion credit. Refer to the catalog to see all available quests.

Next steps / Learn more

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated June 26, 2023

Lab Last Tested June 26, 2023

Copyright 2024 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.