In my last blog about Serverless Applications with AWS Fargate
we looked at how to create a simple Flask/Python based application in AWS. The application is a Serverless Continuous Running
Application or ‘SCRA’. A SCRA application runs continuously, has virtually no limit on the code size and programming languages
that can be used and you pay only for what you use. Above all, with SCRA applications, you don’t manage servers.
This time we will deploy the application to Google App Engine (GAE). Lets take a look!
Google App Engine
GAE is a platform for serverless applications that provides development and hosting capabilities to
developers. Programs can be developed in most popular programming languages like Python, Go and Java.
GAE provides the infrastructure for running web applications at cloud scale. The architecture of GAE is fixed which
means that GAE is fit for purpose for certain applications like stateful web applications.
Example
The example project consists of the following files,
from which only app.yaml
, main.py
and requirements.txt
are the most important files.
.
├── LICENSE
├── Makefile
├── README.md
├── app.yaml
├── main.py
└── requirements.txt
The file app.yaml
is the deployment descriptor and contains a single line, the runtime:
runtime: python37
The requirements.txt
file contains the dependencies for the application. GAE will automatically download and install
the dependencies for use:
flask-basicauth
flask
The main application is defined in main.py
which will be examined by GAE in order to deploy the web application:
# [START gae_python37_app]
from flask import Flask, jsonify
from flask_basicauth import BasicAuth
app = Flask(__name__)
app.config['BASIC_AUTH_USERNAME'] = 'user'
app.config['BASIC_AUTH_PASSWORD'] = 'password'
app.config['BASIC_AUTH_FORCE'] = True
basic_auth = BasicAuth(app)
actors = [
{'id': 1, 'actor': 'William Shatner', 'role': 'James T'},
{'id': 2, 'actor': 'Leonard Nimoy', 'role': 'Spock'},
{'id': 3, 'actor': 'DeForest Kelley', 'role': 'Leonard McCoy'},
{'id': 4, 'actor': 'James Doohan', 'role': 'Montgomery Scott'},
{'id': 5, 'actor': 'George Takei', 'role': 'Hikaru Sulu'},
{'id': 6, 'actor': 'Walter Koenig', 'role': 'Pavel Chekov'},
{'id': 7, 'actor': 'Nichelle Nichols', 'role': 'Nyota Uhura'},
{'id': 8, 'actor': 'Majel Barrett', 'role': 'Christine Chapel'}
]
@app.route('/')
def hello():
return 'Hello World!'
@app.route('/actors', methods=['GET'])
def get_persons():
return jsonify(actors), 200
# [END gae_python37_app]
To deploy the example type make deploy
and to invoke the application type make browse
. To remove the application,
it must be disabled. A GAE can only be disabled by means of the web console. You have to login to console.cloud.google.com,
choose your project, navigate to GAE, go to settings and disable the application.
Conclusion
Because of the predefined architecture, managed infrastructure and developer focused workflow, serverless applications
are very easy to create in GAE. With a minimum of code you can create highly scalable web applications and web services.
The platform manages the life cycle of the applications, and upgrades. Logging and monitoring are provided by Google Stackdriver.
When compared to deploying the same solution in AWS Fargate,
a GAE application has a lot less configuration. Next time we’ll look at deploying a docker container on Google App Engine!