Checkpoints
Create a Compute Engine instance via API
/ 50
Delete your instance.
/ 50
APIs Explorer: Compute Engine
GSP293
Overview
The APIs Explorer enables you to construct REST-based API calls against any version of any Google service. In this lab, you'll 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).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
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 Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. 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. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
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 Cloud Console opens in this tab.
Task 1. API Explorer tool
-
To access the APIs Explorer tool, from the Navigation menu select APIs & Services > Library.
-
Type "compute" in the search bar and all the APIs prefixed with "compute" are returned.
-
Click on Compute Engine API.
-
Make sure that API is enabled, if not click Enable.
-
As the API is enabled, for reference, open Rest API Reference in a new tab with the Rest API Reference page for the Compute Engine API.
Task 2. Create your request
- From the left menu, navigate to All APIs and references > Compute Engine API > v1 > instances > insert to
instances.insert
method or use the Method:instances.insert link to create an instance resource.
You'll now fill out a form to use the compute.instances.insert method.
- The Request body contains the resource properties that you want to use to create your instance:
project= your-project-id
zone= us-central1-f
Request body= Click inside the brackets to select the following properties:
-
machineType:
zones/us-central1-f/machineTypes/n1-standard-1
-
name:
instance-1
- networkInterfaces: leave empty [{}]
-
disks:
-
type:
PERSISTENT
-
initializeParams > sourceImage:
projects/debian-cloud/global/images/family/debian-11
-
type:
- Set the boot to true
Your form should look like this:
- Make sure that the Google OAuth 2.0 checkbox is selected under the Credentials section.
-
Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.
-
Select the student account you started the lab with.
-
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. The Response below.
-
In the console, click Navigation menu > Compute Engine and see 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.
Task 3. Monitor your instance with Cloud monitoring
-
Use the Cloud Monitoring API documentation to navigate to Cloud Monitoring API.
-
From the left
APIs & Reference
section, navigate to All APIs and references > Cloud Monitoring API v3 > REST API reference > projects.timeSeries > list toprojects.timeSeries.list
method or use 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.
-
For this lab, specify “gce_instance” as the resource type and “cpu/usage_time” as the metric type.
-
Add the following string in the
filter
box:
-
interval.endTime
andinterval.startTime
: You will need to calculate RFC-3339 timestamps to filter the timeseries returned by APIs Explorer. You can use Unix Time Stamp - Epoch Converter to get the current time. -
Copy the last RFC 3339 timestamp and add it to
interval.endTime
:
- Subtract one hour from your timestamp time, and add that value to
interval.startTime
.
Your form should look like this:
- Make sure that the Google OAuth 2.0 and API key checkboxes are selected under the Credentials section.
- Make sure that there are no trailing spaces in any of the fields, then scroll down and click Execute.
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
> Monitoring.
When the Monitoring Overview page opens, your metrics scope project is ready.
Monitor CPU usage
-
In the left menu, click Metrics Explorer.
-
Resource & Metric: VM Instance > Instance > CPU Usage then click Apply.
-
Filter: instance_name (select your instance.)
Task 5. Delete your VM
Now use APIs Explorer to delete the instance you created.
-
Open Rest API Reference. This will open a new tab with the Rest API Reference page for the Compute Engine API.
-
From the left APIs & Reference section, navigate to All APIs and references > Compute Engine API > v1 > instances > delete to
instances.delete
method or use the Method: instances.delete documentation to delete an instance resource. -
You'll add your
project
,zone
, andinstance
name to the form. -
Make sure that the Google OAuth 2.0 checkbox is selected under the Credentials section.
- 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.
- Navigate to Compute Engine with Navigation menu > Compute Engine and verify that your console resembles following:
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.
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. See the Google Cloud Skills Boost catalog to see all available quests.
Next steps / Learn more
- Read the Frequently Asked Questions page for APIs Explorer
- Creating API Requests and Handling Responses for Compute Engine API
- This lab is based on this Medium article by Daz Wilkin
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 September 19, 2022
Lab Last Tested April 1, 2022
Copyright 2023 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.