0
0
GCPcloud~30 mins

Cloud SQL Proxy for secure connections in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Cloud SQL Proxy for secure connections
📖 Scenario: You are setting up a secure connection to a Google Cloud SQL database from a local machine. To keep your database safe, you will use the Cloud SQL Proxy, which acts like a secure tunnel between your computer and the database.This project will guide you step-by-step to configure and run the Cloud SQL Proxy correctly.
🎯 Goal: Set up and run the Cloud SQL Proxy to securely connect to a Cloud SQL instance using the instance connection name and a service account key.
📋 What You'll Learn
Use the exact Cloud SQL instance connection name my-project:us-central1:my-instance
Use the service account key file named service-account.json
Create a variable for the proxy command with the correct flags
Run the Cloud SQL Proxy with the correct command line
💡 Why This Matters
🌍 Real World
Cloud SQL Proxy is used to securely connect local or external applications to Google Cloud SQL databases without exposing the database to the public internet.
💼 Career
Understanding how to configure and run Cloud SQL Proxy is essential for cloud engineers and developers working with Google Cloud databases to ensure secure and reliable database connections.
Progress0 / 4 steps
1
Set the Cloud SQL instance connection name
Create a variable called INSTANCE_CONNECTION_NAME and set it to the exact string "my-project:us-central1:my-instance".
GCP
Need a hint?

The instance connection name looks like project:region:instance.

2
Set the service account key file path
Create a variable called SERVICE_ACCOUNT_KEY and set it to the exact string "service-account.json".
GCP
Need a hint?

The service account key file is a JSON file downloaded from Google Cloud Console.

3
Create the Cloud SQL Proxy command string
Create a variable called proxy_command and set it to f"./cloud_sql_proxy -instances={INSTANCE_CONNECTION_NAME}=tcp:5432 --credentials-file={SERVICE_ACCOUNT_KEY}".
GCP
Need a hint?

The proxy command uses the instance connection name and the credential file to open a secure TCP connection on port 5432.

4
Run the Cloud SQL Proxy command
Write the exact line to run the Cloud SQL Proxy using the proxy_command variable with the os.system() function.
GCP
Need a hint?

Use import os at the top and then run os.system(proxy_command) to start the proxy.