Checkpoint
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 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 Cloud 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 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. -
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.
-
Click Next.
-
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.
-
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. -
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.
Set the region for your project
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; 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. Refer to the Rest API Reference page for the Compute Engine API.
Task 2. Create your request
- Navigate to the Method:instances.insert reference to create an instance resource.
Next, fill out a form to use the compute.instances.insert
method.
- 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
-
type:
- Set the boot to true
Your form should look like the following image:
- Make sure that the Google OAuth 2.0 checkbox is selected in 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, and the Response below it.
- 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.
Task 3. Monitor your instance with Cloud monitoring
-
Use the Cloud Monitoring API documentation to navigate to Cloud Monitoring API.
-
Navigate to the Method: projects.timeSeries.list documentation to list 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 andcpu/usage_time
as the metric type. -
Add the following string in the
filter
box:
-
interval.endTime
andinterval.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. -
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 display as follows:
- 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 () > View All Products > Observability > Monitoring.
When the Monitoring Overview page opens, your metrics scope project is ready.
Monitor CPU usage
-
In the left menu, click Metrics Explorer.
-
Metric: Navigate to 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.
-
Navigate to the Method: instances.delete documentation to delete an instance resource.
-
Add your
project
,zone
, andinstance
name to the form. -
Make sure that the Google OAuth 2.0 checkbox is selected in 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.
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 November 04, 2024
Lab Last Tested November 04, 2024
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.