Cloud computing is becoming more ubiquitous and relevant - which is why a wide knowledge of it is important. "Platform as a Service" (PaaS) offers enterprises a powerful way to drive modern and cloud-based software development. In the first two parts of our PaaS blog series, we already gave you an overview of the general advantages of this model and looked at the possible uses of Django on Beanstalk. In the third part, we will then focus on what the Google App Engine offers in the area of Platform as a Service.
Google App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. It is possible to design and develop applications using a variety of popular languages, libraries, and frameworks, and then let Google App Engine handle provisioning servers and scaling application instances based on demand. (Source) In summary, Google App Engine is a Platform as a Service (PaaS) solution that simplifies application deployment within the cloud computing environment. Although Google App Engine may be used by small as well as large organizations, it is better suited to bigger corporations and organizations since it automates everything. (Source)
Google App Engine offers many more advantages than disadvantages as a Platform as a Service (PaaS) solution. App Engine is a cost-effective solution forlow-traffic applications as well as small organizations, and it has faster autoscaling capabilities. Management complications are reduced, so developers just have to worry about their application and not about managing VMs. Google App Engine also has built-in functionality for version control and traffic splitting, making these features quicker and more efficient. Access to the memcache is possible, while access to Datastore is much faster.
On the other hand, because instances are shorter, Google App Engine is more limited. This simplifies and speeds up autoscaling, although large applications may require larger virtual machine instances. In Combination with that, this Platform as a Service solution does not support networking. (Source)
There are several options for deploying Django Python applications within the Google Cloud Computing environment:
We will cover running Django on the Google App Engine standard environment. Django python apps operating on Google Cloud are powered by the same infrastructure that runs all of Google's products, which increases the app's capacity in order to adapt to a changing workload. (Source)
As prerequisites, you need to hold a Google Cloud account with billing, Cloud SQLAdmin API, Secret Manager and Cloud Build APIs enabled. Also, Google Cloud CLI has to be installed and initialized.
There are 5 general steps to follow inorder to run Django on the App Engine standard environment:
Step 1: Prepare the environment
Step 2: Create backing services
Step 3: Running the application on the local computer
Step 4: Using the Django management console
Step 5: Deploy the application to the App Engine default environment
For this Django sample app, clone the repository to your local machine and navigate to the sample code directory. You must also ensure that you have at least Python 3.7 installed, then create a Python virtual environment and install dependencies.
After that you are required to download Cloud SQL Authproxy to connect to Cloud SQL from your local machine. To do that, you need to authenticate and acquire credentials for the API and download and install the Cloud SQL Auth proxy, as shown in the images below. (Source)
All services should be deployed in the same region, and in this step, you will set up database, media storage, and secret storage.
To create a PostgreSQL instance, you have to go to Cloud Console and click on Create Instance in the Cloud SQL Instances section. After that, click on Create Instance and then on PostgreSQL. In the Instance ID field, enter your wanted instance name together with a password for the postgres user. Finally, click on Create.
Within your created instance page, go to the Databases tab and click on Create database. Define the database name and click Create.
To create a database user, go to the Users tab and click on Add User Account. Under Built-in Authentication add a user account to instance, enter database username and password and click Add. (Source)
In order to secure values about configured backing services, see the Store secret values in Secret Manager section.
In a separate terminal, start the Cloud SQL Auth proxy, set the Project ID locally, set an environment carriable to indicate you are using Cloud SQL Auth proxy.
Run the Django migrations to set up your models and assets, and finally start the Django webserver. In the browser, go to http://localhost:8000to display the text from the sample app. To stop the local web server, press Ctrl/ Cmd + C. (Source)
To use Django’s admin console, you need to create superuser and enter username, email, and password. Go to http://localhost:8000/adminand login with created credentials.(Source)
Firstly, upload and deploy the application, type yes when prompted to confirm the settings, and wait for the completion message. After that, open app.yaml and update the value of APPENGINE_URL with your deployed URL and update your configuration changes with deploying app again.
To run deployed application, open the deployed website or alternatively, display the URL and open manually. (Source)
For more information about updating your application, understanding the code, or cleaning up the Django python project see the official Google Cloud documentation.
Most cloud providers offer some form of Platform as a service (PaaS), making the above benefits available to any organization. Other PaaS examples include Microsoft Azure App Services and Elastic Beanstalk. Learn more about them in upcoming blog articles.