As Cloud computing continues to expand, I'm always looking to learn new things, and looking out for the next big thing on the web. But from time to time, I like to come back to Google to see how its Cloud Platform is doing - and I must say, Google seems to always have everything figured out.

A few years ago, I had my first experience with Google App Engine (GAE) working on a powerful bookkeeping platform, and I remember how simple it was to get everything up and running. I didn't have to do any additional work, such as setting user groups, network, and security - all I had to do was write code, unit tests, and get it running on GAE. Awesome, right?

App Engine is a platform provided by Google as a service (PaaS) to leverage the easy development of cloud applications with flexibility and reliability. It abstracts away infrastructure, so you can focus solely on code, and also offers automatic scaling for web applications. In App Engine, applications are sandboxed and run across multiple servers. 

Google offers a free plan, that enables the basic usage of almost every Google Cloud feature. If you want to learn more, check out this link: https://cloud.google.com/free/docs/always-free-usage-limits.

First Things First

I'd recommend these articles if you're not used to GO packaging/configuration:

  1. https://www.golang-book.com/books/intro/11
  2.  https://golang.org/doc/code.html#GOPATH

Last but not least, you will need Google Cloud SDK, which can be downloaded here: https://cloud.google.com/sdk.

Setting Up Your Cloud Project

If you already know how to create an App Engine project, you can jump right to 
Creating Your App. If you're still learning, then the very first step is to open Google Cloud Consolethen:

 

1. Click on 'Select a project':

blog_post_1.png

 

2. Click on '+' to add a new project:

blog_post_2.png

 

3. Set your project name, which may differ from your project ID:

blog_post_3.png 

4. Now, your project is being created. It can take up to 5 minutes, so keep your eyes on the notification panel. As soon as the project is ready, you should be able to select it:

blog_post_4.gif5. Now, open the App Engine dashboard (https://console.cloud.google.com/AppEngine), and select Go as the project language:

blog_post_5.png

 

Then, you will be redirected to the location page. Select any location (I usually go with us-east1). After that, you will need to execute backend creation, which can take up to 5 minutes to execute. 

Creating Your Basic App

As usual, to be sure that the GAE project is working, we'll create a basic Hello World! app. In order to do that, go ahead, and create a Github repo for your code. Within this repo, I'll add two files:

  1. app.yaml
    runtime: go
    api_version: go1.8
    handlers:
    - url: /.*
      script: _go_app
    This file tells the App Engine service which runtime to use, including language and API versions. It also defines which URLs should be handled by this Go program. In other words, it requests that URLs that match this regex (/.*) be handled by this specific program. The _go_app is used only for the development server, which means it's ignored in production servers.
  2. main.go
    package main
    
    import (
    	"fmt"
    	"net/http"
    )
    
    // This will be the entry point for _GAE_, we'e using GO default http package to pass the request to a handler func
    func init() {
    	http.HandleFunc("/", handler)
    }
    
    // This will handle requests on the default path and return Hello World on the response
    func handler(w http.ResponseWriter, r *http.Request) {
    	fmt.Fprint(w, "Hello, world!!!")
    }
    This file is super straightforward. Like the comments state, we're passing requests on the root level of our app to the handler func, and returning a Hello World from there.

Google Cloud SDK

Configuring Your GCloud SDK

Assuming you have already installed Google Cloud SDK on your machine, you should be able to run the following command from your terminal:

    • gcloud init

This will start a command-line wizard that will ask you to authenticate via your Google Account, and set your project. The third step should ask you to select the GAE project, or select the project created earlier.

Running Your Project Locally

Now, it's finally time to test your app. In order to do that, first run this command from your project's root directory.

    • dev_appserver.py app.yaml

If everything worked, you should see an output similar to this one:

INFO     2017-09-21 02:50:22,725 devappserver2.py:692] Skipping SDK update check.
INFO     2017-09-21 02:50:22,771 api_server.py:272] Starting API server at: http://localhost:52474
INFO     2017-09-21 02:50:22,774 dispatcher.py:205] Starting module "default" running at: http://localhost:8080
INFO     2017-09-21 02:50:22,776 admin_server.py:116] Starting admin server at: http://localhost:8000

Now, go ahead and check your http://localhost:8080. You should see the Hello World!!! message.

Deploying Your App to the Cloud

Now that the app is working, we can deploy it to see it run on GAE effectively. Run this command from your terminal:

  1. gcloud app deploy (You will be asked to confirm if you want to deploy the app, go with Yes

That's it! If you're error free on the last command, then you should see the app URL. Alternatively, you can run this command to open your browser on the app URL:

    • gcloud app browse

Conclusion

As I mentioned at the beginning of this post, Google makes it easy for you to get your services up and running on its platform. The project setup is super straight-forward, and the outcome is pretty amazing. I hope I was able to help you create your basic project on GAE. I'll be publishing a new article in the near future showing how to create a basic REST service and put it onto GAE, so stay tuned!


Author

Pedro Costa

Programming isn’t about the language, it’s about the solution. In my 10+ years working in the software industry, I've had great opportunities to work on all types of applications. I've developed a couple of mobile apps and a few Java systems. I've also had the opportunity to write automated tests for a couple of applications. I’m always eager to learn new technologies/methodologies. My motivation is to wake up every day and be better than I was the day before.


Building Accessible Web Applications

READ MORE

Create a Tunnel from Anypoint Platform to GCP Using an HA VPN

READ MORE

Create a Classic Tunnel from GCP to Anypoint Platform

READ MORE

How to Make an Android Splash Screen

READ MORE