0
0
GCPcloud~30 mins

Requester pays configuration in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Requester Pays Configuration in Google Cloud Storage
📖 Scenario: You are managing a Google Cloud Storage bucket that contains large datasets. To control costs, you want to enable the Requester Pays feature so that users who access the data pay for the access costs.
🎯 Goal: Configure a Google Cloud Storage bucket named data-bucket to enable the Requester Pays feature.
📋 What You'll Learn
Create a variable called bucket_name with the value data-bucket.
Create a variable called requester_pays_enabled and set it to True.
Write a function called enable_requester_pays that takes bucket_name and requester_pays_enabled as parameters and configures the bucket accordingly.
Call the enable_requester_pays function with the correct arguments to enable Requester Pays on the bucket.
💡 Why This Matters
🌍 Real World
Many organizations store large datasets in Google Cloud Storage and want to control who pays for data access. Enabling Requester Pays shifts the cost to the users who access the data, helping manage budgets.
💼 Career
Cloud engineers and administrators often need to configure storage buckets with cost controls like Requester Pays. Knowing how to automate this with code is a valuable skill.
Progress0 / 4 steps
1
Create the bucket name variable
Create a variable called bucket_name and set it to the string "data-bucket".
GCP
Need a hint?

Use a simple assignment to create the variable bucket_name.

2
Create the Requester Pays flag variable
Create a variable called requester_pays_enabled and set it to True.
GCP
Need a hint?

Use a boolean value True for the variable requester_pays_enabled.

3
Write the function to enable Requester Pays
Write a function called enable_requester_pays that takes parameters bucket_name and requester_pays_enabled. Inside the function, use the Google Cloud Storage client library to get the bucket and set its requester_pays property to requester_pays_enabled. Then call patch() on the bucket to apply the change.
GCP
Need a hint?

Use storage.Client() to create a client, then get the bucket with client.bucket(bucket_name). Set bucket.requester_pays and call bucket.patch().

4
Call the function to enable Requester Pays
Call the function enable_requester_pays with the variables bucket_name and requester_pays_enabled to enable Requester Pays on the bucket.
GCP
Need a hint?

Simply call enable_requester_pays(bucket_name, requester_pays_enabled) to apply the configuration.