Cloud
Cloud
Cloud
Cloud computing, in simple words, is accessing and storing data over the Internet
instead of doing it on your personal hard drive.
It offers services like storage, database, networking, and more over the Internet to
provide faster, innovative, and flexible resources to its customers. The customers get to
pay only for the resources they use, hence helping them lower their operating costs and
run their business
Now, among various cloud providers like AWS, Microsoft, VMWare, IBM, etc., Google
Cloud has been the talk of the town in recent years and there are enough reasons behind
it. Let’s begin with starters and understand what Google Cloud is.
Google Cloud is a suite of Cloud Computing services offered by Google. The platform
provides various services like compute, storage, networking, Big Data, and many more
that run on the same infrastructure that Google uses internally for its end users like
Google Search and YouTube.
Google server hasn’t gone down in years. So, if you are planning to run your application
on the Google Cloud infrastructure, then you can be assured of your applications being
safe and secure.
ABOUT GOOGLE CLOUD SERVICES (HTTPS://CLOUD.GOOGLE.COM/DOCS/OVERVIEW/CLOUD-PLATFORM-
SERVICES)
This overview introduces some of the commonly used Google Cloud services. For the full
list of services, see the Products and services page.
• Big data
• Machine learning
https://cloud.google.com/compute/docs/quickstart-linux )
1.Click the
to select your payment method. On the left is a panel populated with the
temporary
After tab.
is a temporary account).
o Do not sign up for free trials.
Start Lab
button. If you need to pay for the lab, a pop-up opens for you
1. In the Sign in page, paste the username that you copied from the
Connection Details panel. Then copy and paste the password.
page.
In the Cloud Console, in the top right toolbar, click theActivate Cloud Shell
button.
Click Continue.
You can list the active account name with the written commands in console :
Deploy a simple Apache web server to learn the basics of
Now you'll install an NGINX web server, one of the most popular web servers
in the world, to connect your virtual machine to something.
1. In the SSH terminal, to get root access, run the following command:
In the SSH terminal, to get root access, run the following command:
sudo su -
apt-get update
• Install NGINX:
content_copy
Click the
button. If you need to pay for the lab, a pop-up opens for
you to select your payment method. On the left is a panel populated with the
1. In the Sign in page, paste the username that you copied from the
Connection Details panel. Then copy and paste the password.
Important: You must use the credentials from the Connection Details
panel. Do not use your Qwiklabs credentials. If you have your own
Google Cloud account, do not use it for this lab (avoids incurring
charges).
is a temporary account).
o Do not sign up for free trials.
page.
In the Cloud Console, in the top right toolbar, click theActivate Cloud Shell
button.
your PROJECT_ID
. For example:
4. Click Enable.
Store and sync data with our NoSQL cloud database. Data is synced across
all clients in Realtime, and remains available when your app goes offline.
Database instance and automatically receive updates with the newest data.
iOS setup | Android setup | Web setup | REST API | C++ setup | Unity setup | Admin setup
1) You can add firebase to an app.
What is Firebase?
1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens
for you to select your payment method. On the left is a panel populated with
the temporary credentials that you must use for this lab.
Cloud Firestore is a flexible, scalable database for mobile, web, and server
development from Firebase and Google Cloud. Like Firebase Realtime Database, it keeps
your
data in sync across client apps through realtime listeners and offers offline support for
mobile
and web so you can build responsive apps that work regardless of network latency or
Internet
connectivity. Cloud Firestore also offers seamless integration with other Firebase and
Google
2. Copy the username, and then click Open Google Console. The lab spins
up resources, and then opens another tab that shows the Sign in page.
Account.
3. In the Sign in page, paste the username that you copied from the
Connection Details panel. Then copy and paste the password.
Important: You must use the credentials from the Connection Details
panel. Do not use your Qwiklabs credentials. If you have your own
Google Cloud account, do not use it for this lab (avoids incurring
charges).
Note: You can view the menu with a list of Google Cloud Products and Services by clicking the
Navigation menu at the top-
left.
In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell
button.
Click Continue.
web-start: The starting code that you'll build upon in this lab. web: The
complete code for the finished sample app.
This opens a new browser window with the Cloud Shell tab.
Register the app with the nickname Friendly Chat, then check the box next to
"Also set up Firebase Hosting for this app". Click Register app.
Click through the remaining steps. You don't need to follow the instructions
now, these will be covered in later steps.
• Click the Authentication tile > Get started > Sign-in method.
Now a user can sign into the app with their Google account credentials.
content_copy
Now set up the Firebase CLI to use your Firebase Project:
firebase use --add
content_copy
You'll be asked which project to add. Use the arrow keys to
select your Project ID, then press Enter. When prompted,
create an alias, such as staging.
Giving your project an alias is helpful if you are managing
multiple apps/projects. You can switch between aliases in
Cloud Shell with firebase use <alias_name>.
Stop the app by pressing
Ctrl + c
. This lab has laid out only the UI for you so far.
You also need to tell the Firebase SDK which project you're
using. A special script is also imported to do that.
<script src="scripts/main.js"></script>
Set up user sign in
The Firebase SDK was imported and initialized in the index.html file, so it's
ready to use. Next, implement user sign-in using Firebase Auth.
In the Cloud Console, from Navigation menu click on APIs & Services >
OAuth consent screen.
// Sign into Firebase using popup auth & Google as the identity provider.
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider);
content_copy
The signOut function is triggered when the user clicks Sign out. Update the
signOutfunction with:
firebase.auth().onAuthStateChanged(authStateObserver); }
content_copy
To display the users name and profile picture, update the profile pic and
display name functions to the following:
// Returns the signed-in user's profile pic URL. function
getProfilePicUrl() {
return firebase.auth().currentUser.photoURL ||
'/images/profile_placeholder.png';
}
return firebase.auth().currentUser.displayName; }
content_copy
If the user tries to send a messages when they are not signed in, the app
should display an error message. To detect if the user is actually signed in,
change
the isUserSignedIn function to:
// Returns true if a user is signed-in.
function isUserSignedIn() {
return !!firebase.auth().currentUser; }
content_copy
Save scripts/main.js.
content_copy
Click on the Hosting URL that is returned to open the application in your
browser.
Sign in using the Sign-In with Google button. Remember to use your
Qwiklabs credentials!
After Signing in the profile pic and name of the user will be displayed:
Data model
Firestore data is split into collections, documents, fields, and subcollections.
Each message of the chat is stored as a document in a top-level collection
called messages.
name: getUserName(),
text: messageText,
profilePicUrl: getProfilePicUrl(),
timestamp: firebase.firestore.FieldValue.serverTimestamp()
}).catch(function(error) {
console.error('Error writing new message to Firebase Database', error);
}); }
content_copy
content_copy
Click on the Hosting URL that is returned to open the application in your
browser.
After signing-in, enter a message such as “Hi there!”, then click SEND. This
will write the message into Firestore. However, you won't yet see the data in
your
actual web app because you still need to implement retrieving the data (the
next section of the lab).
You can see the newly added message in your Firebase Console. In the
Develop section click on Firestore and you should see the messages
collection with your newly added message:
Read messages
Synchronize Messages
To read messages on the application, add listeners that trigger when changes
are made to the data then creates a UI element that shows new messages.
// Loads chat messages history and listens for upcoming ones. function
loadMessages() {
// Create the query to load the last 12 messages and listen for new ones.
var query = firebase.firestore()
.collection('messages')
.orderBy('timestamp', 'desc')
.limit(12);
deleteMessage(change.doc.id);
} else {
message.imageUrl);
}
}); });
content_copy
message.text, message.profilePicUrl,
content_copy
Click on the Hosting URL that is returned to open the application in your
browser or refresh the Friendly Chat tab you're already signed into.
The messages you typed earlier and saw in the database should be displayed
in
the Friendly Chat UI. You can also write a new message, it should appear
instantly. You can also try manually deleting, modifying, or adding new
messages directly in the Firestoresection of the Firebase Console, the
changes should reflect in the UI.
Send Images
Now add a feature that shares images.
While the Cloud Firestore is good to store structured data, files are better
stored in Cloud Storage. Cloud Storage for Firebase is a file/blob storage
service. Use it to store the images the user shares.
• Creates a "placeholder" chat message into the chat feed, so that users
see a "Loading" animation while we upload the image.
• Upload the image file to Cloud Storage to the path:
/<uid>/<messageId>/<file_name>.
• Generate a publicly readable URL for the image file.
• Update the chat message with the newly uploaded image file's URL in
lieu
// 1 - We add a message with a loading icon that will get updated with the
shared image.
firebase.firestore().collection('messages').add({
name: getUserName(),
imageUrl: LOADING_IMAGE_URL,
profilePicUrl: getProfilePicUrl(),
timestamp: firebase.firestore.FieldValue.serverTimestamp()
}).then(function(messageRef) {
// 2 - Upload the image to Cloud Storage.
var filePath = firebase.auth().currentUser.uid + '/' + messageRef.id +
'/' + file.name;
return
firebase.storage().ref(filePath).put(file).then(function(fileSnapshot) {
// 3 - Generate a public URL for the file.
return fileSnapshot.ref.getDownloadURL().then((url) => {
// 4 - Update the chat message placeholder with the image's URL. return
messageRef.update({
imageUrl: url,
}); });
}).catch(function(error) {
console.error('There was an error uploading a file to Cloud Storage:',
error); });
content_copy
content_copy
Click the image upload button and select an image file from your computer
using the file picker. If you’re looking for an image, feel free to use this
nice pic of my gallery.
Create a sample web-based application using Python and deploy it on
AWS.
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your
payment method. On the left is a panel populated with the temporary credentials that you must
use for this lab.
Copy the username, and then click Open Google Console. The lab spins up resources, and then
opens another tab that shows the Sign in page.
In the Sign in page, paste the username that you copied from the Connection Details panel. Then
copy and paste the password.
Important: You must use the credentials from the Connection Details panel. Do not use your
Qwiklabs credentials. If you have your own Google Cloud account, do not use it for this lab (avoids
incurring charges).
1. Enter the following command to copy the Hello World sample app
repository to your Google Cloud instance:
Make a change
You can leave the development server running while you develop your
application. The development server watches for changes in your source files
and reloads them if necessary.
Let's try it. Leave the development server running. We'll open another
command line window, then edit main.py to change "Hello World!" to "Hello,
Cruel World!".
1. Click the (+) next to your Cloud Shell tab to open a new command line
session.
2. Enter this command to go to the directory that contains the sample code.
cd python-docs-samples/appengine/standard_python3/hello_world
nano main.py
4. Change "Hello World!" to "Hello, Cruel World!". Exit and save the file. 5.
Reload the Hello World! Browser or click the Web Preview > Preview
humans. This is why APIs are often described in the media as technology that allows
The client sends a request for specific information or functionality to another system. That
system
that it will be in a specific format that both sides can understand. That format is often very
• The electricity coming from the wall is a service. It can stop and start at any
time.
• The treadmill plugged into the wall uses the electricity to run.
• Since the treadmill does not have its own source of power, the treadmill is
outsourcing the power it needs to a service provider, for example, to one that
uses wind turbines or solar power.
While electrical sockets differ depending on where you are in the world, they
have predictable, standard patterns of openings; and the electrical plugs
attached to devices like treadmills are designed to fit those standard patterns.
Outsourcing
APIs help open up a plethora of opportunities. Here are ways that software,
customers, citizen integrators, developers, and their teams can benefit from using
In the name of repeatability, any compatible device (in this case, the gym equipment)
can easily outsource its electrical requirements to a service, and those devices can
Similarly, APIs allow you to outsource key data and functionality through a
customer experiences, not on figuring out how you’re going to get common, yet
nuanced information.
Increased Mobility
Consuming-devices are easily moved from one socket to another. For example, with
no plug, matching socket or specifications, the gym owner may have to hardwire
equipment into the walls of the building
Abstraction
When taking a look at the fitness club, the electrical socket is a layer of abstraction to
the underlying service, or electricity. What is abstraction you ask? It is a way of hiding
the working details of another system.
As long as the service delivers 120 volts of AC power to the wall socket in the
standard way, the service provider is free to change anything and everything from
just behind the socket all the way to the source of power. Any changes are opaque to
consuming devices.
For example, when applications connect to APIs from across the Internet, the
majority of API providers make these connections available over HTTP, or hypertext
transfer protocol, otherwise known as the World Wide Web.
API
While reusing existing code limits differentiation between applications, a reference to
the API (more commonly referred to as "calling" an API) can supply the program with
HTTP Verbs
Descriptions
POST
GET
PUT
DELETE
Update and replace existing data with new data being sent in the request
Of course, the above response isn’t very intuitive and would never be presented to
the treadmill user. It is formatted according to another standard called JSON
(JavaScript Object Notation) that is often used with HTTP.
Treadmill Interface
Once the treadmill receives a response, the user can see total calories burned, how
they're tracking against the most recent fitness challenge, and more.
Web has turned into a programmable platform that’s equally, if not more, powerful
APIs aren’t limited to what can be found in the same local network. Developers and
citizen integrators can also consume APIs offered by remote systems and devices.
The number and types of devices that can be plugged into electrical sockets are
limited only by the imaginations of inventors and the capacity of the utility.
API Economy
Depending on the volume of calls or some other way of breaking down different tiers
of service, a provider like Google might charge the application developer a fee for
using the API. This gives rise to the idea of an API economy.
Back in the days when Unix first came out, it was not uncommon for programmers to
remotely invoke business logic from another machine across a network through a
technology called RPC, or remote procedure call.