Skip to Content

Google Professional Cloud Developer: How to Test App Engine Application Locally with Cloud SQL for PostgreSQL?

Learn how to set up your local development environment for testing an App Engine application with Cloud SQL for PostgreSQL while keeping traffic encrypted and authenticated.

Table of Contents

Question

You are using App Engine and Cloud SQL for PostgreSQL to develop an application. You want to test your application code locally before deploying new application versions to the development environment that is shared with other developers. You need to set up your App Engine local development environment to test your application while keeping all traffic to Cloud SQL instances encrypted and authenticated to Cloud IAM and PostgreSQL. What should you do before starting the local development server?

A. Install PostgreSQL on your local workstation. Run a local PostgreSQL database on your workstation. Configure the application to connect to a PostgreSQL instance on localhost.
B. Download and install the Cloud SQL Auth Proxy to your local development environment. Configure the Cloud SQL Auth Proxy to connect to the Cloud SQL instance and run the proxy. Configure the application to connect to a PostgreSQL instance on localhost.
C. Deploy a Compute Engine instance, and install HAProxy on the instance. Configure Cloud SQL Auth Proxy on the instance, and use the instance’s service account to authenticate to Cloud SQL. Configure the application to connect to the Compute Engine instance’s IP address.
D. Configure your local development server to connect to the private IP address of the Cloud SQL instance. Encrypt database entries with a cryptographic library before submitting them to the database. Store the decryption key as an environment variable in App Engine.

Answer

B. Download and install the Cloud SQL Auth Proxy to your local development environment. Configure the Cloud SQL Auth Proxy to connect to the Cloud SQL instance and run the proxy. Configure the application to connect to a PostgreSQL instance on localhost.

Explanation

To test your App Engine application locally before deploying to a shared development environment, while keeping all traffic to your Cloud SQL for PostgreSQL instance encrypted and authenticated using Cloud IAM, you should:

Download and install the Cloud SQL Auth Proxy on your local development machine. The Cloud SQL Auth Proxy allows you to connect to your Cloud SQL instance without having to whitelist IP addresses or configure SSL. It authenticates using the credentials of the user running the proxy.

Configure the Cloud SQL Auth Proxy to connect to your Cloud SQL instance by specifying the instance connection name and the port to use for local connections. Then run the proxy process, which will establish a secure tunnel to your Cloud SQL instance.

Configure your application code to connect to the PostgreSQL database using localhost and the port specified when starting the Cloud SQL Auth Proxy, rather than connecting directly to the Cloud SQL instance.

The Cloud SQL Auth Proxy handles encryption of traffic to the database and authenticates the connection using Cloud IAM permissions. This allows you to securely access your Cloud SQL instance from your local development environment for testing, before deploying the application code to App Engine.

Using the Cloud SQL Auth Proxy is the recommended way to test App Engine applications locally with Cloud SQL. It keeps your database access secure without having to manage SSL certificates or IP whitelists, and without the need to deploy additional infrastructure like a separate Compute Engine instance running a proxy.

Google Professional Cloud Developer certification exam assessment practice question and answer (Q&A) dump including multiple choice questions (MCQ) and objective type questions, with detail explanation and reference available free, helpful to pass the Google Professional Cloud Developer exam and earn Google Professional Cloud Developer certification.