📖 Scenario: You are managing cloud resources for a small company using Google Cloud Platform (GCP). The company wants to reduce its monthly cloud costs without affecting the performance of its applications.
🎯 Goal: Build a simple GCP resource configuration that demonstrates cost optimization by selecting appropriate machine types, setting up budget alerts, and enabling autoscaling.
📋 What You'll Learn
Create a dictionary named instances with three VM instances and their machine types
Add a variable named budget_limit set to 500 (representing $500 monthly budget)
Write a loop to create a list optimized_instances that includes only instances with machine types costing less than or equal to 2 vCPUs
Add a final configuration dictionary autoscaling_config with keys enabled set to true and max_instances set to 5
💡 Why This Matters
🌍 Real World
Cloud engineers often need to optimize resource usage and costs by selecting appropriate machine types, setting budgets, and enabling autoscaling.
💼 Career
Understanding cost optimization strategies in GCP is essential for roles like Cloud Engineer, DevOps Engineer, and Cloud Architect.
Progress0 / 4 steps
1
Create VM instances with machine types
Create a dictionary called instances with these exact entries: 'vm1': 'n1-standard-1', 'vm2': 'n1-standard-4', 'vm3': 'e2-medium'.
GCP
Hint
Use a Python dictionary with VM names as keys and machine types as values.
2
Set the monthly budget limit
Add a variable called budget_limit and set it to 500 representing the monthly budget in dollars.
GCP
Hint
Just assign the number 500 to the variable budget_limit.
3
Filter instances by machine type vCPU count
Create a list called optimized_instances that includes only the instance names from instances whose machine types have 2 or fewer vCPUs. Use a for loop with variables vm and machine to iterate over instances.items(). Use this vCPU mapping: 'n1-standard-1': 1, 'n1-standard-4': 4, 'e2-medium': 2.
GCP
Hint
Use a dictionary for vCPU counts and a for loop to filter instance names.
4
Add autoscaling configuration
Add a dictionary called autoscaling_config with keys enabled set to true and max_instances set to 5.
GCP
Hint
Create a dictionary with the specified keys and values.
Practice
(1/5)
1. Which of the following is a basic way to reduce costs in Google Cloud Platform (GCP)?
easy
A. Use the most powerful machines regardless of need
B. Increase the number of virtual machines
C. Use smaller or cheaper machine types
D. Keep all resources running 24/7
Solution
Step 1: Understand cost drivers in GCP
Machine types with more CPU and memory cost more money.
Step 2: Choose cost-saving options
Using smaller or cheaper machine types reduces the hourly cost.
Final Answer:
Use smaller or cheaper machine types -> Option C
Quick Check:
Smaller machines cost less [OK]
Hint: Pick smaller machines to save money quickly [OK]
Common Mistakes:
Thinking more machines always save money
Believing running all resources nonstop is cheaper
Choosing the most powerful machines by default
2. Which of the following is the correct way to specify a preemptible VM in a GCP instance creation command?
easy
A. gcloud compute instances create my-vm --preemptible
B. gcloud compute instances create my-vm --no-preemptible
C. gcloud compute instances create my-vm --machine-type=preemptible
D. gcloud compute instances create my-vm --enable-preemptible=false
Solution
Step 1: Review gcloud syntax for preemptible VMs
The flag to create a preemptible VM is --preemptible.
D. The flag disables preemptible; use --preemptible instead
Solution
Step 1: Analyze the preemptible flag usage
The flag --enable-preemptible=false disables preemptible VMs.
Step 2: Correct the flag to enable preemptible
Use --preemptible without false to create preemptible VM.
Final Answer:
The flag disables preemptible; use --preemptible instead -> Option D
Quick Check:
Use --preemptible to enable preemptible VMs [OK]
Hint: Use --preemptible flag alone to enable preemptible VMs [OK]
Common Mistakes:
Using --enable-preemptible=false disables preemptible
Changing machine type instead of flag
Ignoring flag syntax errors
5. A company wants to optimize costs by automatically stopping VMs when not in use during nights and weekends. Which GCP service or strategy best supports this goal?
hard
A. Use Cloud Scheduler to trigger Cloud Functions that stop/start VMs on schedule
B. Manually stop VMs every night using the console
C. Use preemptible VMs only without scheduling
D. Increase VM size to reduce runtime
Solution
Step 1: Identify automation options for VM management
Cloud Scheduler can run tasks on a schedule, and Cloud Functions can execute commands like stopping VMs.
Step 2: Match automation to cost optimization goal
Automating stop/start reduces costs by not running VMs when unused.
Final Answer:
Use Cloud Scheduler to trigger Cloud Functions that stop/start VMs on schedule -> Option A
Quick Check:
Automate VM stop/start with Cloud Scheduler and Functions [OK]
Hint: Automate VM stop/start with Cloud Scheduler and Functions [OK]
Common Mistakes:
Relying on manual stopping which is error-prone
Using preemptible VMs without scheduling
Increasing VM size which raises costs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.