This repository contains workshops as part of a presentation on Google Cloud Platform. Use this README to follow along with the workshops. Sections will be added as we progress through the workshop.
In this workshop, you will create a Google Cloud Platform project. A project organizes all your Google Cloud Platform resources.
- Navigate to Cloud Console.
- Sign in with a personal or @cornell.edu account.
- If you already have an active Google Cloud Platform trial or credit, skip ahead to the "Environment" section.
- If you have not activated a free trial, you should see the following image:
If you would like, you can sign up for this free trial. Doing this will require a credit card for identification purposes.
- If you cannot or do not wish to activate the free trial, ask a Googler for a credit key and redeem it here. Make sure you are applying it to your @cornell.edu account!
- If you have a partner, add them to your coupon's billing account as a Billing Account Administrator (Top-left menu -> Billing -> Add Members/Select a role -> Add). This will allow them to continue to the Environment section in their own console with their own project.
You can choose to run this either in Cloud Shell (recommended) or on your own machine. If you choose to run on your own machine, follow the additional instructions under "Using your own machine".
Navigate to Cloud Shell by clicking on the following button (outlined in red) in the Cloud Console:
Clone this repository with the following command:
git clone https://github.com/TrevorEdwards/gcp-workshop
Navigate to the repository directory:
cd gcp-workshop
Run the following interactive utility to set up billing, API access, and authentication:
./bin/init-project
NOTE: This utility requires Node.js.
If at any time you get stuck, re-run the command and skip the steps you have already done.
Don't worry if you don't completely understand what's happening here -- this is something you would normally do through the web UI. In essence, the script:
- Creates a new project, which is where your application will live.
- Links a billing account to the project, which allows you to use Google APIs.
- Enables the Cloud APIs necessary for this workshop.
- Creates a service account, which is essentially a Google account for your application, and allows it to access the APIs.
- As part of this step, you'll download a key file. This key is used in lieu of a password for the account.
- Instructs you to add the key to your environment, which allows your application to find it.
Before doing the above, you'll need to download gcloud
first. As an extra step, you'll need to login with:
gcloud auth login
You will also need to download and install Node.js 8.
After that, you should be all set to continue as if you were running in the Cloud Shell in the instructions above.
This workshop will take you through building a Google Translate-like web service using the Google Cloud Translate API and Node.js. You'll be able to launch your app on Google App Engine (GAE) to deploy it to the world!
Navigate to the gae-translate
directory in your terminal:
cd gae-translate
Then, run npm install
(npm
is Node's package manager) to install the
dependencies you'll need for this application:
npm install # This installs dependencies, such as the Google Translate API, as specified by the package.json file in this directory.
We've already provided most of the code for you. Start the application by typing the following at the command line:
node server.js
This starts a long-running application that will serve browser requests on port 8080 of the local machine. To see what this looks like, click the "Web Preview" button in the top right of your cloud shell (outlined in red in the below image) -- which will automatically open up a new tab showing your running web app.
(If you have the menu on the left of the screen open, you will have to minimize it before you can see this icon.)
Though barebones, the interface should seem pretty familiar. However, there's only two languages in the drop-down menu -- English and Spanish. This is because the server implementation is incomplete. Open up server.js
and take a look at the code. See if you can fill in the missing part of the code (the part that fetches languages), using the other portions of the code as an example!
Hint: Using your browser's developer console can be helpful for figuring out what exactly is happening under the hood. In Chrome, you can open it by right-clicking anywhere on the web page, clicking, "Inspect", and then changing to the "Sources" or "Network" tab in the console.
Once you've filled up the missing part and tinkered around with the code, it's time to deploy the application on Google App Engine. Simply type the following command:
gcloud app deploy
Feel free to pick any region here.
It'll take a few minutes, but in the end you'll see your application deployed to a real production environment!
Why this works: A configuration file named app.yaml
sits in your working directory. This is the config file used for Google App Engine. It contains just enough information for App Engine to know that you want to use Node.js (runtime
) on App Engine Flex, the Docker-based version of App Engine (flex
). See this page for more details.
In this workshop, you will implement a Google Cloud Function which translates a sentence to a target language and back, then returns the similarity between the original sentence and its translated version.
- Enable the Google Cloud Translation API if you have not already here.
- Navigate to your Google Cloud Functions console.
- Create a new HTTP function called
case1
. Leave all options to their defaults. - Replace the existing
package.json
with this template. - Replace the existing
index.js
function with this template. - Implement all four TODOs in
index.js
. - Test your function using the testing tab with this test case.
- Do more tests as desired. Keep an eye on the scoreboard for your project! Feel free to ask for help!
In this workshop, you will implement a Google Cloud Function that calculates the number of triplets in a sequence. Given a sequence s
a triplet is three indices a
, b
, and c
such that a
< b
< c
and s[a]
< s[b]
< s[c]
.
- Navigate to your Google Cloud Functions console.
- Create a new HTTP function called
case2
. Leave all options to their defaults. - Replace the existing
index.js
function with this template. - Implement both TODOs in
index.js
. - Test your function using the testing tab with this test case.
- Do more tests as desired. Keep an eye on the scoreboard for your project! Feel free to ask for help!