Learn how to deploy a sample app on App Engine standard environment
connected to a SQL Server instance by using the Google Cloud console and a client
application.
Assuming that you complete all the steps in a timely manner, the resources
created in this quickstart typically cost less than one dollar (USD).
Before you begin
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Click the following button to open Cloud Shell, which provides
command-line access to your Google Cloud resources directly from the browser.
Cloud Shell can be used to run the gcloud commands presented throughout this quickstart.
App Engine standard environment does not support connecting to
Cloud SQL for SQL Server over public IP using Unix sockets but
connections are possible using the Go, Java and Python connectors.
Console
In the Google Cloud console, go to the Cloud SQL Instances page.
Make sure that Enterprise Plus is selected as the Cloud SQL edition for your instance.
In the Instance ID field, enter
quickstart-instance.
In the Password field, enter a password for
the sqlserver user. Save this password for future use.
In the Choose region and zonal availability
section, select Single zone.
Click the Show configuration options menu.
Expand the Machine configuration node.
From the Machine shapes region, select the 4 vCPU, 32 GB shape.
Click Create instance and then wait
until the instance initializes and starts.
gcloud
Before running the command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
--database-version: The database engine type and version.
If left unspecified, the API default is used.
See the gcloud database versions
documentation to see the current available versions.
--cpu: The number of cores
desired in the machine.
--memory: Whole number value indicating how
much memory is desired in the machine. A size unit should be
provided (for example, 3072MB or 9GB). If no units are specified,
GB is assumed.
--region: Regional location of the instance
(for example asia-east1, us-east1). If left unspecified, the default
us-central is used.
gcloudcomputeaddressescreategoogle-managed-services-default\
--global--purpose=VPC_PEERING--prefix-length=16\
--description="peering range for Google"--network=default
Run the gcloud services vpc-peerings connect
command to create a private connection to the allocated IP address range. Replace YOUR_PROJECT_ID with your project's project ID.
Create an instance with private IP address and SSL enabled
Before running the command as follows, replace DB_ROOT_PASSWORD with the password of your database user.
Optionally, modify the values for the following parameters:
--database-version: The database engine type and version.
If left unspecified, the API default is used.
See the gcloud database versions
documentation to see the current available versions.
--cpu: The number of cores in the machine.
--memory: A whole number value indicating how
much memory to include in the machine. A size unit can be
provided (for example, 3072MB or 9GB). If no units are specified,
GB is assumed.
--region: The regional location of the instance
(for example asia-east1, us-east1). If left unspecified, the default
us-central1 is used.
See the full list of regions.
Deploy a sample app to App Engine standard environment
Create the App Engine application
Create the App Engine application in your Google Cloud project. This
enables the App Engine service, creates a default App Engine application
and creates a App Engine service account that will be used to connect to Cloud SQL.
Console
In the Google Cloud console, go to the App Engine page.
With a Cloud SQL instance, database, and service account with client
permissions, you can now configure and deploy a sample application to connect
to your Cloud SQL instance.
Public IP
App Engine standard environment supports connecting to
Cloud SQL for SQL Server over public IP using
the Go, Java and Python connectors.
Go
In Cloud Shell Editor, open the sample app's source code.
In the Open in Cloud Shell dialog box, click Confirm to
download the sample app code and open the sample app directory in Cloud Shell Editor.
At the Cloud Shell command prompt, run the following command to activate your project:
gcloudconfigsetprojectYOUR-PROJECT-ID
If an Authorize Cloud Shell dialog box appears, then click Authorize.
From the Explorer navigation menu of Cloud Shell Editor, navigate to and open the
golang-samples/cloudsql/sqlserver/database-sql/cmd/app/app.standard.yaml file.
Replace the placeholders for the environment variables in the
app.standard.yaml file with the following values:
<PROJECT-ID> with your project ID.
<INSTANCE-REGION> with us-central1.
<INSTANCE-NAME> with your instance's ID
that appears on the Cloud SQL instances
page in the Google Cloud console.
<YOUR_DB_USER_NAME> with sqlserver.
<YOUR_DB_PASSWORD> with the password of the
quickstart-user that you created in Create a
user.
<YOUR_DB_NAME> with quickstart-db.
At the Cloud Shell command prompt, in the
golang-samples/cloudsql/sqlserver/database-sql directory, run the following
gcloud app deploy
command to deploy the sample app to App Engine standard environment.
gcloudappdeploycmd/app/app.standard.yaml
If you're prompted to choose the region for creating the app,
then enter the numeric choice for us-central.
When prompted with Do you want to continue?, enter Y.
When the deploy command completes, run the
gcloud app browse
command:
gcloudappbrowse
Click the generated link to see the sample app running on
App Engine standard environment. This environment is connected to Cloud SQL.
Java
In Cloud Shell Editor, open the sample app's source code.
In the Open in Cloud Shell dialog box, click Confirm to
download the sample app code and open the sample app directory in Cloud Shell Editor.
At the Cloud Shell command prompt, run the following command to activate your project:
gcloudconfigsetprojectYOUR-PROJECT-ID
If an Authorize Cloud Shell dialog box appears, then click Authorize.
From the Explorer navigation menu of Cloud Shell Editor, navigate to and open the
java-docs-samples/cloud-sql/sqlserver/servlet/src/main/webapp/WEB-INF/appengine-web.xml file.
Replace the placeholders for the environment variables in the
appengine-web.xml file with the following values:
project-name:region-name:instance-name with your instance's Connection name
that appears on the Cloud SQL instances
page in the Google Cloud console.
my-db-user with quickstart-user.
my-db-password with the password of the
sqlserver that you created in Create a
user.
my_db with quickstart-db.
At the Cloud Shell command prompt, in the
java-docs-samples/cloud-sql/sqlserver/servlet directory, run the following
Apache Mavenmvn clean package command to deploy the sample app
to App Engine standard environment.
mvncleanpackageappengine:deploy-DskipTests
If you're prompted to choose the region for creating the app,
then enter the numeric choice for us-central.
When prompted with Do you want to continue?, enter Y.
When the deploy command completes, run the
gcloud app browse
command:
gcloudappbrowse
Click the generated link to see the sample app running on
App Engine standard environment. This environment is connected to Cloud SQL.
Python
In Cloud Shell Editor, open the sample app's source code.
In the Open in Cloud Shell dialog box, click Confirm to
download the sample app code and open the sample app directory in Cloud Shell Editor.
At the Cloud Shell command prompt, run the following command to activate your project:
gcloudconfigsetprojectYOUR-PROJECT-ID
If an Authorize Cloud Shell dialog box appears, then click Authorize.
From the Explorer navigation menu of Cloud Shell Editor, navigate to and open the
python-docs-samples/cloud-sql/sql-server/sqlalchemy/app.standard.yaml file.
Replace the placeholders for the environment variables in the
app.standard.yaml file with the following values:
<PROJECT-ID> with your project ID.
<INSTANCE-REGION> with us-central1.
<INSTANCE-NAME> with your instance's ID
that appears on the Cloud SQL instances
page in the Google Cloud console.
<YOUR_DB_USER_NAME> with sqlserver.
<YOUR_DB_PASSWORD> with the password of the
quickstart-user that you created in Create a
user.
<YOUR_DB_NAME> with quickstart-db.
At the Cloud Shell command prompt, in the
python-docs-samples/cloud-sql/sql-server/sqlalchemy directory, run the following
gcloud app deploy
command to deploy the sample app to App Engine standard environment.
gcloudappdeployapp.standard.yaml
If you're prompted to choose the region for creating the app,
then enter the numeric choice for us-central.
When prompted with Do you want to continue?, enter Y.
When the deploy command completes, run the
gcloud app browse
command:
gcloudappbrowse
Click the generated link to see the sample app running on
App Engine standard environment. This environment is connected to Cloud SQL.
Private IP
For private IP paths, your application connects directly to your
instance through Serverless VPC Access. This method uses a TCP socket to
connect directly to the Cloud SQL instance without using the Cloud SQL Auth Proxy.
Go
Create and download SSL server certificate
In the Google Cloud console, go to the Cloud SQL Instances page.
In the Open in Cloud Shell dialog box, click Confirm to
download the sample app code and open the sample app directory in Cloud Shell Editor.
At the Cloud Shell command prompt, run the following command to activate your project:
gcloudconfigsetprojectYOUR-PROJECT-ID
If an Authorize Cloud Shell dialog box appears, then click Authorize.
Upload the SSL server certificate file to the certs folder.
From the Explorer navigation menu of Cloud Shell Editor, navigate to the
golang-samples/cloudsql/sqlserver/database-sql/certs folder.
Right-click the certs folder in Cloud Shell Editor and select Upload Files.
Select the following file on your local machine: server-ca.pem.
With the SSL server certificate file selected, click Open to complete the process of uploading the file to Cloud Shell Editor.
From the Explorer navigation menu of Cloud Shell Editor, navigate to and open the
golang-samples/cloudsql/sqlserver/database-sql/cmd/app/app.standard.yaml file.
Copy and paste the following code into the file, replacing the existing file content:
INSTANCE-NAME with your instance's ID
that appears on the Cloud SQL instances
page in the Google Cloud console.
YOUR_DB_PASSWORD with the password of the
quickstart-user that you created in Create a
user.
INSTANCE_HOST with your instance's Private IP address
that appears on the Cloud SQL instances
page in the Google Cloud console.
At the Cloud Shell command prompt, in the
golang-samples/cloudsql/sqlserver/database-sql directory, run the following
gcloud app deploy
command to deploy the sample app to App Engine standard environment.
gcloudappdeploycmd/app/app.standard.yaml
If you're prompted to choose the region for creating the app,
then enter the numeric choice for us-central.
When prompted with Do you want to continue?, enter Y.
When the deploy command completes, run the
gcloud app browse
command:
gcloudappbrowse
Click the generated link to see the sample app running on
App Engine standard environment. This environment is connected to Cloud SQL.
Node.js
Create a Serverless VPC Connection for connections to the instance via Private IP
In the Google Cloud console, go to the Serverless VPC access - Create connector page.
In the Open in Cloud Shell dialog box, click Confirm to
download the sample app code and open the sample app directory in Cloud Shell Editor.
At the Cloud Shell command prompt, run the following command to activate your project:
gcloudconfigsetprojectYOUR-PROJECT-ID
If an Authorize Cloud Shell dialog box appears, then click Authorize.
From the Explorer navigation menu of Cloud Shell Editor, navigate to and open the
nodejs-docs-samples/cloud-sql/sqlserver/mssql/app.standard.yaml file.
Replace the placeholders for the environment variables in the
app.standard.yaml file with the following values:
CLOUD_SQL_INSTANCE_IP_ADDRESS with your instance's Private IP address
that appears on the Cloud SQL instances
page in the Google Cloud console.
MY_DB_USER with quickstart-user.
MY_DB_PASSWORD with the password of the
quickstart-user that you created in Create a
user.
MY_DATABASE with quickstart-db.
<MY-PROJECT> with your project ID.
<CONNECTOR_NAME> with quickstart-connector.
At the Cloud Shell command prompt, in the
nodejs-docs-samples/cloud-sql/sqlserver/mssql directory, run the following
gcloud app deploy
command to deploy the sample app to App Engine standard environment.
gcloudappdeployapp.standard.yaml
If you're prompted to choose the region for creating the app,
then enter the numeric choice for us-central.
When prompted with Do you want to continue?, enter Y.
When the deploy command completes, run the
gcloud app browse
command:
gcloudappbrowse
Click the generated link to see the sample app running on
App Engine standard environment. This environment is connected to Cloud SQL.
Python
Create and download SSL server certificate
In the Google Cloud console, go to the Cloud SQL Instances page.
In the Open in Cloud Shell dialog box, click Confirm to
download the sample app code and open the sample app directory in Cloud Shell Editor.
At the Cloud Shell command prompt, run the following command to activate your project:
gcloudconfigsetprojectYOUR-PROJECT-ID
If an Authorize Cloud Shell dialog box appears, then click Authorize.
Upload SSL server certificate file to the certs folder.
From the Explorer navigation menu of Cloud Shell Editor, navigate to the
python-docs-samples/cloud-sql/sql-server/sqlalchemy/certs folder.
Right-click the certs folder in Cloud Shell Editor and select Upload Files
Select following file on your local machine: server-ca.pem.
With the SSL server certificate file selected, click Open to complete the process of uploading the file to Cloud Shell Editor.
From the Explorer navigation menu of Cloud Shell Editor, navigate to and open the
python-docs-samples/cloud-sql/sql-server/sqlalchemy/app.standard.yaml file.
Copy and paste the following code into the file, replacing the
existing file content:
YOUR_DB_PASSWORD with the password of the
quickstart-user that you created in Create a
user.
INSTANCE_HOST with your instance's Private IP address
that appears on the Cloud SQL instances
page in the Google Cloud console.
PROJECT_ID with your project ID.
At the Cloud Shell command prompt, in the
python-docs-samples/cloud-sql/sql-server/sqlalchemy directory, run the following
gcloud app deploy
command to deploy the sample app to App Engine standard environment.
gcloudappdeployapp.standard.yaml
If you're prompted to choose the region for creating the app,
then enter the numeric choice for us-central.
When prompted with Do you want to continue?, enter Y.
When the deploy command completes, run the
gcloud app browse
command:
gcloudappbrowse
Click the generated link to see the sample app running on
App Engine standard environment. This environment is connected to Cloud SQL.
Clean up
To avoid incurring charges to your Google Cloud account for
the resources used on this page, follow these steps.
In the Google Cloud console, go to the Cloud SQL Instances page.
Select the quickstart-instance instance to open the Instance details
page.
In the icon bar at the top of the page, click Delete.
In the Delete instance dialog box, type quickstart-instance, and then
click Delete to delete the instance.
Disabling your app stops it from running instances and serving requests.
If your app is processing a request, your app completes the request before being
disabled.
To disable an App Engine app and retain its data, do the
following:
In the Google Cloud console, go to the Settings page:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-20 UTC."],[],[]]