<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Google Cloud Platform - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Google Cloud Platform - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 23 May 2026 19:41:38 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/google-cloud-platform/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Use Google Dataproc – Example with PySpark and Jupyter Notebook ]]>
                </title>
                <description>
                    <![CDATA[ In this article, I'll explain what Dataproc is and how it works. Dataproc is a Google Cloud Platform managed service for Spark and Hadoop which helps you with Big Data Processing, ETL, and Machine Learning. It provides a Hadoop cluster and supports H... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-google-dataproc/</link>
                <guid isPermaLink="false">66d460f6d1ffc3d3eb89de60</guid>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ hadoop ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ spark ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sameer Shukla ]]>
                </dc:creator>
                <pubDate>Tue, 03 May 2022 15:14:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/My-project.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article, I'll explain what Dataproc is and how it works.</p>
<p>Dataproc is a Google Cloud Platform managed service for Spark and Hadoop which helps you with Big Data Processing, ETL, and Machine Learning. It provides a Hadoop cluster and supports Hadoop ecosystems tools like Flink, Hive, Presto, Pig, and Spark.</p>
<p>Dataproc is an auto-scaling cluster which manages logging, monitoring, cluster creation of your choice and job orchestration. You'll need to manually provision the cluster, but once the cluster is provisioned you can submit jobs to Spark, Flink, Presto, and Hadoop.</p>
<p>Dataproc has implicit integration with other GCP products like Compute Engine, Cloud Storage, Bigtable, BigQuery, Cloud Monitoring, and so on. The jobs supported by Dataproc are MapReduce, Spark, PySpark, SparkSQL, SparkR, Hive and Pig.</p>
<p>Apart from that, Dataproc allows native integration with Jupyter Notebooks as well, which we'll cover later in this article.</p>
<p>In the article, we are going to cover:</p>
<ol>
<li><p>Dataproc cluster types and how to set Dataproc up</p>
</li>
<li><p>How to submit a PySpark job to Dataproc</p>
</li>
<li><p>How to create a Notebook instance and execute PySpark jobs through Jupyter Notebook.</p>
</li>
</ol>
<h2 id="heading-how-to-create-a-dataproc-cluster">How to Create a Dataproc Cluster</h2>
<p>Dataproc has three cluster types:</p>
<ol>
<li><p>Standard</p>
</li>
<li><p>Single Node</p>
</li>
<li><p>High Availability</p>
</li>
</ol>
<p>The Standard cluster can consist of 1 master and N worker nodes. The Single Node has only 1 master and 0 worker nodes. For production purposes, you should use the High Availability cluster which has 3 master and N worker nodes.</p>
<p>For our learning purposes, a single node cluster is sufficient which has only 1 master Node.</p>
<p>Creating Dataproc clusters in GCP is straightforward. First, we'll need to enable Dataproc, and then we'll be able to create the cluster.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-185.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Start Dataproc cluster creation</em></p>
<p>When you click "Create Cluster", GCP gives you the option to select Cluster Type, Name of Cluster, Location, Auto-Scaling Options, and more.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-199.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Parameters required for Cluster</em></p>
<p>Since we've selected the Single Node Cluster option, this means that auto-scaling is disabled as the cluster consists of only 1 master node.</p>
<p>The Configure Nodes option allows us to select the type of machine family like Compute Optimized, GPU and General-Purpose.</p>
<p>In this tutorial, we'll be using the General-Purpose machine option. Through this, you can select Machine Type, Primary Disk Size, and Disk-Type options.</p>
<p>The Machine Type we're going to select is n1-standard-2 which has 2 CPU’s and 7.5 GB of memory. The Primary Disk size is 100GB which is sufficient for our demo purposes here.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-200.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Master Node Configuration</em></p>
<p>We've selected the cluster type of Single Node, which is why the configuration consists only of a master node. If you select any other Cluster Type, then you'll also need to configure the master node and worker nodes.</p>
<p>From the Customise Cluster option, select the default network configuration:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-201.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Use the option "Scheduled Deletion" in case no cluster is required at a specified future time (or say after a few hours, days, or minutes).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/5_ml_resize_x2_colored_toned_light_ai-1.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Schedule Deleting Setting</em></p>
<p>Here, we've set "Timeout" to be 2 hours, so the cluster will be automatically deleted after 2 hours.</p>
<p>We'll use the default security option which is a Google-managed encryption key. When you click "Create", it'll start creating the cluster.</p>
<p>You can also create the cluster using the ‘gcloud’ command which you'll find on the ‘EQUIVALENT COMMAND LINE’ option as shown in image below.</p>
<p>And you can create a cluster using a POST request which you'll find in the ‘Equivalent REST’ option.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-203.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>gcloud and REST option for Cluster creation</em></p>
<p>After few minutes the cluster with 1 master node will be ready for use.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-204.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Cluster Up and Running</em></p>
<p>You can find details about the VM instances if you click on "Cluster Name":</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-205.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-206.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-submit-a-pyspark-job">How to Submit a PySpark Job</h2>
<p>Let’s briefly understand how a PySpark Job works before submitting one to Dataproc. It’s a simple job of identifying the distinct elements from the list containing duplicate elements.</p>
<pre><code class="lang-python"><span class="hljs-comment">#! /usr/bin/python</span>

<span class="hljs-keyword">import</span> pyspark

<span class="hljs-comment">#Create List</span>
numbers = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">4</span>,<span class="hljs-number">6</span>]

<span class="hljs-comment">#SparkContext</span>
sc = pyspark.SparkContext()

<span class="hljs-comment"># Creating RDD using parallelize method of SparkContext</span>
rdd = sc.parallelize(numbers)

<span class="hljs-comment">#Returning distinct elements from RDD</span>
distinct_numbers = rdd.distinct().collect()

<span class="hljs-comment">#Print</span>
print(<span class="hljs-string">'Distinct Numbers:'</span>, distinct_numbers)
</code></pre>
<p>Upload the .py file to the GCS bucket, and we'll need its reference while configuring the PySpark Job.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-21.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Job GCS Location</em></p>
<p>Submitting jobs in Dataproc is straightforward. You just need to select “Submit Job” option:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-209.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Job Submission</em></p>
<p>For submitting a Job, you'll need to provide the Job ID which is the name of the job, the region, the cluster name (which is going to be the name of cluster, "first-data-proc-cluster"), and the job type which is going to be PySpark.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-223.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Parameters required for Job Submission</em></p>
<p>You can get the Python file location from the GCS bucket where the Python file is uploaded – you'll find it at gsutil URI.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-24.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>No other additional parameters are required, and we can now submit the job:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-224.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>After execution, you should be able to find the distinct numbers in the logs:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-213.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Logs</em></p>
<h2 id="heading-how-to-create-a-jupyter-notebook-instance">How to Create a Jupyter Notebook Instance</h2>
<p>You can associate a notebook instance with Dataproc Hub. To do that, GCP provisions a cluster for each Notebook Instance. We can execute PySpark and SparkR types of jobs from the notebook.</p>
<p>To create a notebook, use the "Workbench" option like below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-26.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Make sure you go through the usual configurations like Notebook Name, Region, Environment (Dataproc Hub), and Machine Configuration (we're using 2 vCPUs with 7.5 GB RAM). We're using the default Network settings, and in the Permission section, select the "Service account" option.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-225.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Parameters required for Notebook Cluster Creation</em></p>
<p>Click Create:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-216.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Notebook Cluster Up &amp; Running</em></p>
<p>The "OPEN JUPYTYERLAB" option allows users to specify the cluster options and zone for their notebook.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-226.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-227.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Once the provisioning is completed, the Notebook gives you a few kernel options:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-27.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Click on PySpark which will allow you to execute jobs through the Notebook.</p>
<p>A SparkContext instance will already be available, so you don't need to explicitly create SparkContext. Apart from that, the program remains the same.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/image-220.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Code snapshot on Notebook</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Working on Spark and Hadoop becomes much easier when you're using GCP Dataproc. The best part is that you can create a notebook cluster which makes development simpler.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Google Cloud Platform Tutorial: From Zero to Hero with GCP ]]>
                </title>
                <description>
                    <![CDATA[ By Sergio Fuentes Navarro Do you have the knowledge and skills to design a mobile gaming analytics platform that collects, stores, and analyzes large amounts of bulk and real-time data? Well, after reading this article, you will. I aim to take you fr... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/google-cloud-platform-from-zero-to-hero/</link>
                <guid isPermaLink="false">66d460ee33b83c4378a5183d</guid>
                
                    <category>
                        <![CDATA[ Cloud Computing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ google cloud ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 09 Oct 2020 15:24:46 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/10/gcp.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sergio Fuentes Navarro</p>
<p>Do you have the knowledge and skills to design a mobile gaming analytics platform that collects, stores, and analyzes large amounts of bulk and real-time data?</p>
<p>Well, after reading this article, you will.</p>
<p>I aim to take you <strong>from zero to hero in Google Cloud Platform (GCP) in just one article</strong>. I will show you how to:</p>
<ul>
<li>Get started with a GCP account for free</li>
<li>Reduce costs in your GCP infrastructure</li>
<li>Organize your resources</li>
<li>Automate the creation and configuration of your resources</li>
<li>Manage operations: logging, monitoring, tracing, and so on.</li>
<li>Store your data</li>
<li>Deploy your applications and services</li>
<li>Create networks in GCP and connect them with your on-premise networks</li>
<li>Work with Big Data, AI, and Machine Learning</li>
<li>Secure your resources</li>
</ul>
<p>Once I have explained all the topics in this list, I will share with you a solution to the system I described. </p>
<p>If you do not understand some parts of it, you can go back to the relevant sections. And if that is not enough, visit the links to the documentation that I have provided.</p>
<p><strong>Are you up for a challenge?</strong> I have selected a few questions from old GCP Professional Certification exams. They will test your understanding of the concepts explained in this article.</p>
<p>I recommend trying to solve both the design and the questions <em>on your own</em>, going back to the guide if necessary. Once you have an answer, compare it to the proposed solution.</p>
<p>Try to go beyond what you are reading and ask yourself what would happen if requirement X changed:</p>
<ul>
<li>Batch vs streaming data</li>
<li>Regional vs global solution</li>
<li>A small number of users vs huge volume of users</li>
<li>Latency is not a problem vs real-time applications</li>
</ul>
<p>And any other scenarios you can think of.</p>
<p>At the end of the day, you are not paid just for what you know but for your thought process and the decisions you make. That is why it is vitally important that you exercise this skill.</p>
<p>At the end of the article, I'll provide more resources and next steps if you want to continue learning about GCP.</p>
<h2 id="heading-how-to-get-started-with-google-cloud-platform-for-free"><strong>How to get started with G</strong>oogle <strong>C</strong>loud <strong>P</strong>latform <strong>for</strong> free</h2>
<p>GCP currently offers a <a target="_blank" href="https://cloud.google.com/free">3 month free trial</a> with $300 US dollars of free credit. You can use it to get started, play around with GCP, and run experiments to decide if it is the right option for you. </p>
<p><strong>You will NOT</strong> <strong>be charged</strong> <strong>at the end of your trial</strong>. You will be notified and your services will stop running unless you decide to upgrade your plan.</p>
<p>I strongly recommend using this trial to practice. To learn, you have to <strong>try things on your own</strong>, face problems, break things, and fix them. It doesn't matter how good this guide is (or the official documentation for that matter) if you do not try things out.</p>
<h2 id="heading-why-would-you-migrate-your-services-to-google-cloud-platform"><strong>Why would you migrate your services to Google Cloud Platform?</strong></h2>
<p>Consuming resources from GCP, like storage or computing power, provides the following benefits:</p>
<ul>
<li>No need to spend a lot of money upfront for hardware</li>
<li>No need to upgrade your hardware and migrate your data and services every few years</li>
<li>Ability to scale to adjust to the demand, paying only for the resources you consume</li>
<li>Create proof of concepts quickly since provisioning resources can be done very fast</li>
<li>Secure and manage your <a target="_blank" href="https://cloud.google.com/endpoints/docs">APIs</a></li>
<li>Not just infrastructure: data analytics and machine learning services are available in GCP</li>
</ul>
<p>GCP makes it easy to experiment and use the resources you need in an economical way.</p>
<h2 id="heading-how-to-optimize-your-vms-to-reduce-costs-in-gcp">How to optimize your VMs to reduce costs in GCP</h2>
<p>In general, you will only be <strong>charged for the time your instances are running</strong>. Google will not charge you for stopped instances. However, if they consume resources, like disks or reserved IPs, you might incur charges.</p>
<p>Here are some ways you can optimize the cost of running your applications in GCP.</p>
<h3 id="heading-custom-machine-types">Custom Machine Types</h3>
<p>GCP provides different <a target="_blank" href="https://cloud.google.com/compute/docs/machine-types">machine families</a> with predefined amounts of RAM and CPUs:</p>
<ul>
<li><strong>General-purpose</strong>. Offers the best price-performance ratio for a variety of workloads.</li>
<li><strong>Memory-optimized</strong>. Ideal for memory-intensive workloads. They offer more memory per core than other machine types.</li>
<li><strong>Compute-optimized</strong>. They offer the highest performance per core and and are optimized for compute-intensive workloads</li>
<li><strong>Shared-core</strong>. These machine types timeshare a physical core. This can be a cost-effective method for running small applications.</li>
</ul>
<p>Besides, you can create your custom machine with the amount of RAM and CPUs you need.</p>
<h3 id="heading-preemptible-vms">Preemptible VM's</h3>
<p>You can use preemptible virtual machines to save up to 80% of your costs. They are ideal <strong>for fault-tolerant, non-critical applications</strong>.  You can save the progress of your job in a persistent disk using a shut-down script to continue where you left off.</p>
<p>Google may stop your instances at any time (with a 30-second warning) and will always stop them after 24 hours.</p>
<p>To reduce the chances of getting your VMs shut down, Google recommends:</p>
<ul>
<li>Using <strong>many small instances</strong> and</li>
<li>Running your jobs during <strong>off-peak</strong> times.</li>
</ul>
<p><strong>Note</strong>: Start-up and shut-down scripts apply to non-preemptible VMS as well. You can use them the control the behavior of your machine when it starts or stops. For instance, to install software, download data, or backup logs.</p>
<p>There are two options to define these scripts:</p>
<ul>
<li>When you are creating your instance in the Google Console, there is a field to paste your code.</li>
<li>Using the metadata server URL to point your instance to a script stored in Google Cloud Storage.</li>
</ul>
<p>This latter is preferred because it is easier to create many instances and to manage the script.</p>
<h3 id="heading-sustained-use-discounts">Sustained Use Discounts</h3>
<p>The longer you use your virtual machines (and Cloud SQL instances), the higher the discount - up to 30%. Google does this automatically for you.</p>
<h3 id="heading-committed-use-discounts">Committed Use Discounts</h3>
<p>You can get up to 57% discount if you commit to a certain amount of CPU and RAM resources for a period of 1 to 3 years.</p>
<p>To estimate your costs, use the <a target="_blank" href="https://cloud.google.com/products/calculator">Price Calculator</a>. This helps prevent any surprises with your bills and create <a target="_blank" href="https://cloud.google.com/billing/docs/how-to/budgets">budget alerts</a>.</p>
<h2 id="heading-how-to-manage-resources-in-gcphttpscloudgooglecomresource-managerdocs"><strong><a target="_blank" href="https://cloud.google.com/resource-manager/docs">How to manage resources in GCP</a></strong></h2>
<p>In this section, I will explain how you can manage and administer your Google Cloud resources.</p>
<h3 id="heading-resource-hierarchyhttpscloudgooglecomresource-managerdocscloud-platform-resource-hierarchy"><strong><a target="_blank" href="https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy">Resource Hierarchy</a></strong></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/resource-manager.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>There are four types of resources that can be managed through Resource Manager:</p>
<ul>
<li><strong>The organization resource</strong>. It is the root node in the resource hierarchy. It represents an organization, for example, a company.</li>
<li><strong>The projects resource</strong>. For example, to separate projects for production and development environments. They are <strong>required</strong> to create resources.</li>
<li><strong>The folder resource</strong>. They provide an extra level of project isolation. For example, creating a folder for each department in a company.</li>
<li><strong>Resources</strong>. Virtual machines, database instances, load balancers, and so on.</li>
</ul>
<p>There are <strong>quotas</strong> that limit the maximum number of resources you can create to prevent unexpected spikes in billing. However, most quotas can be increased by opening a support ticket.</p>
<p>Resources in GCP follow a <strong>hierarchy</strong> via a parent/child relationship, similar to a traditional file system, where:</p>
<ul>
<li><strong>Permissions are inherited as we descend the hierarchy</strong>. For example, permissions granted and the organization level will be propagated to all the folders and projects.</li>
<li>More permissive parent policies always overrule more restrictive child policies.</li>
</ul>
<p>This hierarchical organization helps you manage common aspects of your resources, such as access control and configuration settings.</p>
<p>You can create super admin accounts that have access to every resource in your organization. Since they are very powerful, make sure you follow <a target="_blank" href="https://cloud.google.com/resource-manager/docs/super-admin-best-practices">Google's best practices</a>.</p>
<h3 id="heading-labels">Labels</h3>
<p>Labels are key-value pairs you can use to organize your resources in GCP. Once you attach a label to a resource (for instance, to a virtual machine), you can filter based on that label. This is useful also to break down your bills by labels.</p>
<p>Some common use cases:</p>
<ul>
<li>Environments: prod, test, and so on.</li>
<li>Team or product owners</li>
<li>Components: backend, frontend, and so on.</li>
<li>Resource state: active, archive, and so on.</li>
</ul>
<h3 id="heading-labels-vs-network-tags">Labels vs Network tags</h3>
<p>These two similar concepts seem to generate some confusion. I have summarized the differences in this table:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Labels</td><td>Network tags</td></tr>
</thead>
<tbody>
<tr>
<td>Applied to any GCP resource</td><td>Applied only for VPC resources</td></tr>
<tr>
<td>Just organize resources</td><td>Affect how resources work (ex: through application of firewall rules)</td></tr>
</tbody>
</table>
</div><h3 id="heading-cloud-iamhttpscloudgooglecomiamdocs"><strong><a target="_blank" href="https://cloud.google.com/iam/docs">Cloud IAM</a></strong></h3>
<p>Simply put, Cloud IAM controls <strong>who can do what on which resource</strong>. A resource can be a virtual machine, a database instance, a user, and so on. </p>
<p>It is important to notice that permissions are not directly assigned to users. Instead, they are bundled into <em>roles</em>, which are assigned to <em>members</em>. A <em>policy</em> is a collection of one or more bindings of a set of members to a role.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/IAM.svg" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-identities">Identities</h3>
<p>In a GCP project, identities are represented by Google accounts, created outside of GCP, and defined by an email address (not necessarily @gmail.com). There are different types:</p>
<ul>
<li><strong>Google accounts*</strong>. To represent people: engineers, administrators, and so on.</li>
<li><strong>Service accounts</strong>. Used to identify non-human users: applications, services, virtual machines, and others. The authentication process is defined by <em>account keys</em>, which can be managed by Google or by users (only for user-created service accounts).</li>
<li><strong>Google Groups</strong> are a collection of Google and service accounts.</li>
<li><strong>G Suite Domain*</strong> is the type of account you can use to identify organizations. If your organization is already using <a target="_blank" href="https://en.wikipedia.org/wiki/Active_Directory">Active Directory</a>, it can be synchronized with Cloud IAM using <a target="_blank" href="https://cloud.google.com/identity/docs">Cloud Identity</a>.</li>
<li><strong>allAuthenticatedUsers</strong>. To represent any authenticated user in GCP.</li>
<li><strong>allUsers</strong>. To represent anyone, authenticated or not.</li>
</ul>
<p>Regarding service accounts, some of Google's best practices include:</p>
<ul>
<li>Not using the default service account</li>
<li>Applying the <a target="_blank" href="https://en.wikipedia.org/wiki/Principle_of_least_privilege">Principle of Least Privilege</a>. For instance:  </li>
<li>Restrict who can act as a service account  </li>
<li>Grant only the minimum set of permissions that the account needs  </li>
<li>Create service accounts for each service, only with the permissions the account needs</li>
</ul>
<h3 id="heading-roles">Roles</h3>
<p>A role is a <strong>collection of permissions</strong>. There are three types of roles:</p>
<ul>
<li><strong>Primitive</strong>. Original GCP roles that apply to the entire project. There are three concentric roles: <strong>Viewer</strong>, <strong>Editor</strong>, and <strong>Owner</strong>. Editor contains Viewer and Owner contains Editor.</li>
<li><strong>Predefined</strong>. Provides access to specific services, for example, storage.admin.</li>
<li><strong>Custom</strong>. lets you create your own roles, combining the specific permissions you need.</li>
</ul>
<p>When assigning roles, follow the principle of least privilege, too. In general, <strong>prefer predefined over primitive roles</strong>.</p>
<h3 id="heading-cloud-deployment-managerhttpscloudgooglecomdeployment-managerdocs"><strong><a target="_blank" href="https://cloud.google.com/deployment-manager/docs">Cloud Deployment Manager</a></strong></h3>
<p>Cloud Deployment Manager automates repeatable tasks like provisioning, configuration, and deployments for any number of machines. </p>
<p>It is Google's <em>Infrastructure as Code</em> service, similar to Terraform - although you can deploy only GCP resources. It is used by <a target="_blank" href="https://cloud.google.com/marketplace">GCP Marketplace</a> to create pre-configured deployments.</p>
<p>You define your configuration in YAML files, listing the resources (created through API calls) you want to create and their properties. Resources are defined by their <strong>name</strong> (VM-1, disk-1), <strong>type</strong> (compute.v1.disk, compute.v1.instance) and <strong>properties</strong> (zone:europe-west4, boot:false).</p>
<p>To increase performance, resources are deployed in parallel. Therefore you need to <strong>specify any dependencies using references</strong>. For instance, do not create virtual machine VM-1 until the persistent disk disk-1 has been created. In contrast, Terraform would figure out the dependencies on its own.</p>
<p>You can modularize your configuration files using templates so that they can be independently updated and shared. Templates can be defined in Python or Jinja2. The contents of your templates will be inlined in the configuration file that references them.</p>
<p>Deployment Manager will create a manifest containing your original configuration, any templates you have imported, and the expanded list of all the resources you want to create.</p>
<h2 id="heading-cloud-operations-formerly-stackdriverhttpscloudgooglecomstackdriverdocs"><strong><a target="_blank" href="https://cloud.google.com/stackdriver/docs">Cloud Operations (formerly Stackdriver)</a></strong></h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/stackd.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Operations provide a set of tools for monitoring, logging, debugging, error reporting, profiling, and tracing of resources in GCP (AWS and even on-premise).</p>
<h3 id="heading-cloud-logging"><strong>Cloud Logging</strong></h3>
<p>Cloud Logging is GCP's centralized solution for real-time log management. For each of your projects, it allows you to store, search, analyze, monitor, and alert on logging data:</p>
<ul>
<li>By default, data will be stored for a certain period of time. The retention period varies depending on the type of log. You cannot retrieve logs after they have passed this retention period.</li>
<li>Logs can be exported for different purposes. To do this, you create a <strong>sink</strong>, which is composed of a <strong>filter</strong> (to select what you want to log) and a <strong>destination</strong>: Google Cloud Storage (GCS) for long term retention, BigQuery for analytics, or Pub/Sub to stream it into other applications.</li>
<li>You can create log-based metrics in Cloud Monitoring and even get alerted when something goes wrong.</li>
</ul>
<p>Logs are a named collection of <strong>log entries</strong>. Log entries record status or events and includes the name of its log, for example, compute.googleapis.com/activity. There are two main types of logs:</p>
<p><strong>First, User Logs:</strong></p>
<ul>
<li>These are generated by your applications and services. </li>
<li>They are written to Cloud Logging using the Cloud Logging API, client libraries, or <a target="_blank" href="https://cloud.google.com/logging/docs/agent">logging agents</a> installed on your virtual machines. </li>
<li>They stream logs from common third-party applications like MySQL, MongoDB, or Tomcat.</li>
</ul>
<p><strong>Second, Security logs, divided into:</strong></p>
<ul>
<li>Audit logs, for administrative changes, system events, and data access to your resources. For example, who created a particular database instance or to log a <a target="_blank" href="https://cloud.google.com/compute/docs/instances/live-migration">live migration</a>. Data access logs must be explicitly enabled and may incur additional charges. The rest are enabled by default, cannot be disabled, and are free of charges.</li>
<li>Access Transparency logs, for actions taken by Google staff when they access your resources for example to investigate an issue you reported to the support team.</li>
</ul>
<h4 id="heading-vpc-flow-logs">VPC Flow Logs</h4>
<p>They are specific to VPC networks (which I will introduce later). VPC flow logs record a <strong>sample of network flows</strong> sent from and received by VM instances, which can be later access in Cloud Logging. </p>
<p>They can be used to monitor network performance, usage, forensics, real-time security analysis, and expense optimization.</p>
<p><strong>Note</strong>: you may want to log your billing data for analysis. In this case, you do <em>not</em> create a sink. You can directly export your reports to BigQuery.</p>
<h3 id="heading-cloud-monitoring"><strong>Cloud Monitoring</strong></h3>
<p>Cloud Monitoring lets you monitor the performance of your applications and infrastructure, visualize it in dashboards, create <a target="_blank" href="https://cloud.google.com/monitoring/uptime-checks">uptime checks</a> to detect resources that are down and <a target="_blank" href="https://cloud.google.com/monitoring/alerts">alert</a> you based on these checks so that you can fix problems in your environment. You can monitor resources in GCP, AWS, and even on-premise.</p>
<p>It is recommended to create a separate project for Cloud Monitoring since it can keep track of resources across multiple projects. </p>
<p>Also, it is recommended to install a monitoring agent in your virtual machines to send application metrics (including many third-party applications) to Cloud Monitoring. Otherwise, Cloud Monitoring will only display CPU, disk traffic, network traffic, and uptime metrics.</p>
<h4 id="heading-alerts">Alerts</h4>
<p>To receive alerts, you must declare an <strong>alerting policy</strong>. An alerting policy defines the <strong>conditions</strong> under which a service is considered unhealthy. When the conditions are met, a new incident will be created and notifications will be sent (via email, Slack, SMS, PagerDuty, etc). </p>
<p>A policy belongs to an individual workspace, which can contain a maximum of 500 policies.</p>
<h4 id="heading-trace">Trace</h4>
<p>Trace helps <strong>find bottlenecks in your services</strong>. You can use this service to figure out how long it takes to handle a request, which microservice takes the longest to respond, where to focus to reduce the overall latency, and so on.</p>
<p>It is enabled by default for applications running on Google App Engine (GAE) - Standard environment - but can be used for applications running on GCE, GKE, and Google App Engine Flexible.</p>
<h4 id="heading-error-reporting">Error Reporting</h4>
<p>Error Reporting will aggregate and display errors produced in services written in Go, Java, Node.js, PHP, Python, Ruby, or .NET. running on GCE, GKE, GAP, Cloud Functions, or Cloud Run.</p>
<h4 id="heading-debug">Debug</h4>
<p>Debug lets you inspect the application's state without stopping your service. Currently supported for Java, Go, Node.js and Python. It is automatically integrated with GAE but can be used on GCE, GKE, and Cloud Run.</p>
<h4 id="heading-profile">Profile</h4>
<p>Profiler that continuously gathers CPU usage and memory-allocation information from your applications. To use it, you need to install a profiling agent.</p>
<h2 id="heading-how-to-store-data-in-gcp"><strong>How to store data in GCP</strong></h2>
<p>In this section, I will cover both Google Cloud Storage (for any type of data, including files, images, video, and so on), the different database services available in GCP, and how to decide which storage option works best for you.</p>
<h3 id="heading-google-cloud-storage-gcshttpscloudgooglecomstoragedocs"><strong><a target="_blank" href="https://cloud.google.com/storage/docs">Google Cloud Storage (GCS)</a></strong></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/gcs.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>GCS is Google's <strong>storage service for unstructured data</strong>: pictures, videos, files, scripts, database backups, and so on. </p>
<p>Objects are placed in <strong>buckets</strong>, from which they inherit permissions and storage classes. </p>
<p><a target="_blank" href="https://cloud.google.com/storage/docs/storage-classes">Storage classes</a> provide different SLAs for storing your data to minimize costs for your use case. A bucket's storage class can be changed (under some restrictions), but it will affect new objects added to the bucket only.</p>
<p>In addition to Google's console, you can interact with GCS from your command line, using <a target="_blank" href="https://cloud.google.com/storage/docs/gsutil">gsutil</a>. You can use specify:</p>
<ul>
<li><strong>Multithreaded updates</strong> when you need to upload a large number of small files. The command looks like gsutil -m cp files gs://my-bucket)</li>
<li><strong>Parallel updates</strong> when you need to upload large files. For more details and restrictions, visit this <a target="_blank" href="https://cloud.google.com/storage/docs/gsutil/commands/cp#parallel-composite-uploads">link</a>.</li>
</ul>
<p>Another option to upload files to GCS is <a target="_blank" href="https://cloud.google.com/storage-transfer/docs">Storage Transfer Service (STS)</a>, a service that imports data to a GCS bucket from:</p>
<ul>
<li>An AWS S3 bucket</li>
<li>A resource that can be accessed through HTTP(S)</li>
<li>Another Google Cloud Storage bucket</li>
</ul>
<p>If you need to upload huge amounts of data (from hundreds of terabytes up to one petabyte) consider <a target="_blank" href="https://cloud.google.com/transfer-appliance/docs/2.2">Data Transfer Appliance</a>: ship your data to a Google facility. Once they have uploaded the data to GCS, the process of <a target="_blank" href="https://cloud.google.com/transfer-appliance/docs/2.0/data-rehydration">data rehydration</a> reconstitutes the files so that they can be accessed again.</p>
<h4 id="heading-object-lifecycle-managementhttpscloudgooglecomstoragedocslifecycle"><a target="_blank" href="https://cloud.google.com/storage/docs/lifecycle">Object lifecycle management</a></h4>
<p>You can define rules that determine what will happen to an object (will it be archived or deleted) when a certain condition is met. </p>
<p>For example, you could define a policy to automatically change the storage class of an object from Standard to Nearline after 30 days and to delete it after 180 days.</p>
<p>This is the way a rule can be defined:</p>
<pre><code class="lang-js">{
   <span class="hljs-string">"lifecycle"</span>:{
      <span class="hljs-string">"rule"</span>:[
         {
            <span class="hljs-string">"action"</span>:{
               <span class="hljs-string">"type"</span>:<span class="hljs-string">"Delete"</span>
            },
            <span class="hljs-string">"condition"</span>:{
               <span class="hljs-string">"age"</span>:<span class="hljs-number">30</span>,
               <span class="hljs-string">"isLive"</span>:<span class="hljs-literal">true</span>
            }
         },
         {
            <span class="hljs-string">"action"</span>:{
               <span class="hljs-string">"type"</span>:<span class="hljs-string">"Delete"</span>
            },
            <span class="hljs-string">"condition"</span>:{
               <span class="hljs-string">"numNewerVersions"</span>:<span class="hljs-number">2</span>
            }
         },
         {
            <span class="hljs-string">"action"</span>:{
               <span class="hljs-string">"type"</span>:<span class="hljs-string">"Delete"</span>
            },
            <span class="hljs-string">"condition"</span>:{
               <span class="hljs-string">"age"</span>:<span class="hljs-number">180</span>,
               <span class="hljs-string">"isLive"</span>:<span class="hljs-literal">false</span>
            }
         }
      ]
   }
}
</code></pre>
<p>It will be applied through gsutils or a REST API call. Rules can be created also through the Google Console.</p>
<h4 id="heading-permissions-in-gcs">Permissions in GCS</h4>
<p>In addition to IAM roles, you can use Access Control Lists (ACLs) to manage access to the resources in a bucket. </p>
<p>Use IAM roles when possible, but remember that <strong>ACLs</strong> grant access to buckets and <strong>individual objects</strong>, while <strong>IAM roles are project or bucket wide</strong> permissions. Both methods work in tandem.</p>
<p>To grant temporary access to users outside of GCP, use <a target="_blank" href="https://cloud.google.com/storage/docs/access-control/signed-urls">Signed URLs</a>.</p>
<h4 id="heading-bucket-lock">Bucket lock</h4>
<p>Bucket locks allow you to enforce a <strong>minimum retention period</strong> for objects in a bucket. You may need this for auditing or legal reasons.</p>
<p><strong>Once a bucket is locked, it cannot be unlocked</strong>. To remove, you need to first remove all objects in the bucket, which you can only do after they all have reached the retention period specified by the retention policy. Only then, you can delete the bucket. </p>
<p>You can include the retention policy when you are creating the bucket or add a retention policy to an existing bucket (it retroactively applies to existing objects in the bucket too).</p>
<p>Fun fact: the maximum retention period is 100 years.</p>
<h3 id="heading-relational-managed-databases-in-gcp"><strong>Relational Managed Databases in GCP</strong></h3>
<p>Cloud SQL and Cloud Spanner are two managed database services available in GCP. If you do not want to deal with all the work necessary to maintain a database online, they are a great option. You can always spin a virtual machine and manage your own database.</p>
<h4 id="heading-cloud-sqlhttpscloudgooglecomsqldocs"><a target="_blank" href="https://cloud.google.com/sql/docs">Cloud SQL</a></h4>
<p>Cloud SQL provides access to a managed MySQL or PostgreSQL database instance in GCP. Each instance is limited to a <strong>single region</strong> and has a <strong>maximum capacity of 30 TB</strong>. </p>
<p>Google will take care of the installation, backups, scaling, monitoring, failover, and read replicas. For availability reasons, replicas must be defined in the same region but a different zone from the primary instances.</p>
<p>Data can be easily imported (first uploading the data to Google Cloud Storage and then to the instance) and exported using SQL dumps or CSV files format. Data can be compressed to reduce costs (you can directly import .gz files). For "lift and shift" migrations, this is a great option.</p>
<p>If you need global availability or more capacity, consider using Cloud Spanner.</p>
<h4 id="heading-cloud-spannerhttpscloudgooglecomspannerdocs"><a target="_blank" href="https://cloud.google.com/spanner/docs">Cloud Spanner</a></h4>
<p>Cloud Spanner is globally available and can scale (horizontally) very well. </p>
<p>These two features make it capable of supporting different use cases than Cloud SQL and more expensive too. Cloud Spanner is not an option for lift and shift migrations.</p>
<h3 id="heading-nosql-managed-databases-in-gcp"><strong>NoSQL Managed Databases in GCP</strong></h3>
<p>Similarly, GCP provides two managed NoSQL databases, Bigtable and Datastore, as well as an in-memory database service, Memorystore.</p>
<h4 id="heading-datastorehttpscloudgooglecomdatastoredocs"><a target="_blank" href="https://cloud.google.com/datastore/docs">Datastore</a></h4>
<p>Datastore is a completely no-ops, highly-scalable document database ideal for web and mobile applications: game states, product catalogs, real-time inventory, and so on. It's great for:</p>
<ul>
<li>User profiles - mobile apps</li>
<li>Game save states</li>
</ul>
<p>By default, Datastore has a built-in <strong>index</strong> that improves performance on simple queries. You can create your own indices, called <strong>composite indexes</strong>, defined in YAML format.</p>
<p>If you need extreme throughput (huge number of reads/writes per second), use Bigtable instead.</p>
<h4 id="heading-bigtablehttpscloudgooglecombigtabledocs"><a target="_blank" href="https://cloud.google.com/bigtable/docs">Bigtable</a></h4>
<p>Bigtable is a NoSQL database ideal for analytical workloads where you can expect a very high volume of writes, reads in the milliseconds, and the ability to store terabytes to petabytes of information. It's great for:</p>
<ul>
<li>Financial analysis</li>
<li>IoT data</li>
<li>Marketing data</li>
</ul>
<p>Bigtable requires the creation and configuration of your nodes (as opposed to the fully-managed Datastore or BigQuery). You can add or remove nodes to your cluster with zero downtime. The simplest way to interact with Bigtable is the command-line tool <a target="_blank" href="https://cloud.google.com/bigtable/docs/cbt-overview">cbt</a>.</p>
<p>Bigtable's performance will depend on the design of your database schema.</p>
<ul>
<li>You can only define one key per row and must keep all the information associated with an entity in the same row. Think of it as a hash table.</li>
<li>Tables are sparse: if there is no information associated with a column, no space is required.</li>
<li>To make reads more efficient, try to store related entities in adjacent rows.</li>
</ul>
<p>Since this topic is worth an article on its own, I recommend you read the <a target="_blank" href="https://cloud.google.com/bigtable/docs/performance">documentation</a>.</p>
<h4 id="heading-memorystorehttpscloudgooglecommemorystoredocs"><a target="_blank" href="https://cloud.google.com/memorystore/docs">Memorystore</a></h4>
<p>It provides a managed version of Redis and Memcache (in-memory databases), resulting in very fast performance. Instances are regional, like Cloud SQL, and have a capacity of up to 300 GB.</p>
<h3 id="heading-how-to-choose-your-database"><strong>How to choose your database</strong></h3>
<p>Google loves decision trees. This one will help you choose the right database your your projects. For unstructured data consider GCS or process it using Dataflow (discussed later).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/choose-db.svg" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-does-networking-work-in-gcp"><strong>How does networking work in GCP?</strong></h2>
<h3 id="heading-virtual-private-cloud-vpc-see-the-docs-herehttpscloudgooglecomvpcdocs"><strong>Virtual Private Cloud (VPC) - <a target="_blank" href="https://cloud.google.com/vpc/docs/">see the docs here</a></strong></h3>
<p>You can use the same network infrastructure that Google uses to run its services: YouTube, Search, Maps, Gmail, Drive, and so on. </p>
<p>Google infrastructure is divided into:</p>
<ul>
<li><strong>Regions</strong>: Independent geographical areas, at least 100 miles apart from each other, where Google hosts datacenters. It consists of 3 or more zones. For example, us-central1.</li>
<li><strong>Zones</strong>: Multiple individual datacenters within a region. For example, us-central1-a.</li>
<li><strong>Edge Points of Presence</strong>: points of connection between Google's network and the rest of the internet.</li>
</ul>
<p>GCP infrastructure is designed in a way that all traffic between regions travels through a global private network, resulting in better security and performance.</p>
<p>On top of this infrastructure, you can build networks for your resources, Virtual Private Clouds. They are <strong>software-defined networks</strong>, where all the traditional network concepts apply:</p>
<ul>
<li><a target="_blank" href="https://cloud.google.com/vpc/docs/vpc#subnets_vs_subnetworks">Subnets</a>. Logical partitions of a network defined using <a target="_blank" href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing">CIDR notation</a>. They belong to one region only but can span multiple zones. If you have multiple subnets (including your on-premise networks if they are connected to GCP), make sure the CIDR ranges do not overlap.</li>
<li><strong>IP addresses</strong>. Can be internal (for private communication within GCP) or external (to communicate with the rest of the internet). For external IP addresses, you can use an <strong>ephemeral IP</strong> or pay for a <strong>static IP</strong>. In general, you need an external IP address to connect to GCP services. However, in some cases, you can configure <a target="_blank" href="https://cloud.google.com/vpc/docs/private-access-options">private access</a> for instances that only have an internal IP.</li>
<li><a target="_blank" href="https://cloud.google.com/vpc/docs/firewalls">Firewalls rules</a>, to allow or deny traffic to your virtual machines, both incoming (ingress) and outgoing (egress). By default, all ingress traffic is denied and all egress traffic is allowed. Firewall rules are defined at the VPC level but they <strong>apply to individual instances or groups of instances</strong> using <strong>network tags</strong> or <strong>IP ranges</strong>.<br><strong>Common issue</strong>: If you know your VMs are working correctly but you cannot access them through HTTP(s) or cannot SSH into them, have a look at your firewall rules.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/vpc.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can create <strong>hybrid networks</strong> connecting your on-premise infrastructure to your VPC.</p>
<p>When you create a project, a <strong>default network</strong> will be created with subnets in each region (auto mode). You can delete this network, but you need to create at least one network to be able to create virtual machines. </p>
<p>You can also create your <strong>custom networks</strong>, where no subnets are created by default and you have full control over subnet creation (custom mode).</p>
<p>The main goal of a VPC is the <strong>separation of network resource</strong>s. A GCP project is a way to organize resources and manage permissions. </p>
<p>Users of project A need permissions to access resources in project B. All users can access any VPC defined in any project to which they belong. Within the same VPC, resources in subnet 1 need to be granted access to resources in subnet 2.</p>
<p>In terms of IAM roles, there is a distinction between who can create network resources (Network admin, to create subnets, virtual machines, and so on) and who is responsible for the security of the resources (Security Admin, to create firewall rules, SSL certificates, and so on). </p>
<p>The Compute Instance Admin role combines both roles.</p>
<p>As usual, there are quotas and limits to what you can do in a VPC, amongst them:</p>
<ul>
<li>The maximum number of VPCs in a project.</li>
<li>The maximum number of virtual machines per VPC.</li>
<li>No broadcast or multicast.</li>
<li>VPCs cannot use IPv6 to communicate internally, although global load balancers support IPv6 traffic.</li>
</ul>
<h3 id="heading-how-to-share-resources-between-multiple-vpcs"><strong>How to share resources between multiple VPCs</strong></h3>
<h4 id="heading-shared-vpchttpscloudgooglecomvpcdocsshared-vpc"><a target="_blank" href="https://cloud.google.com/vpc/docs/shared-vpc">Shared VPC</a></h4>
<p>Shared VPCs are a way to share resources between different projects within the same organization. This allows you to control billing and manage access to the resources in different projects, following the principle of least privilege. Otherwise you'd have to put all the resources in a single project.</p>
<p>To design a shared VPC, projects fall under three categories:</p>
<ul>
<li><strong>Host project</strong>. It is the project that hosts the common resources. There can only be one host project.</li>
<li><strong>Service project</strong>: Projects that can access the resources in the host project. A project cannot be both host and service.</li>
<li><strong>Standalone project</strong>. Any project that does not make use of the shared VPC.</li>
</ul>
<p>You will only be able to communicate between resources created <strong>after</strong> you define your host and service projects. Any existing resources before this will not be part of the shared VPC.</p>
<h4 id="heading-vpc-network-peeringhttpscloudgooglecomvpcdocsvpc-peering"><a target="_blank" href="https://cloud.google.com/vpc/docs/vpc-peering">VPC Network Peering</a></h4>
<p>Shared VPCs can be used when all the projects belong to the same organization. However, if:</p>
<ul>
<li>You need <strong>private communication</strong> across VPCs.</li>
<li>The VPCs are in projects that may belong to <strong>different organizations</strong>.</li>
<li>Want <strong>decentralized</strong> control, that is, no need to define host projects, server projects, and so on.</li>
<li>Want to reuse existing resources.</li>
</ul>
<p>VPC Network peering is the right solution.</p>
<p>In the next section, I will discuss how to connect your VPC(s) with networks outside of GCP.</p>
<h2 id="heading-how-to-connect-on-premise-and-gcp-infrastructures">How to connect on-premise and GCP infrastructures</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/interc.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>There are three options to connect your on-premise infrastructure to GCP:</p>
<ul>
<li>Cloud VPN</li>
<li>Cloud Interconnect</li>
<li>Cloud Peering</li>
</ul>
<p>Each of them with different capabilities, use cases, and prices that I will describe in the following sections.</p>
<h3 id="heading-cloud-vpnhttpscloudgooglecomnetwork-connectivitydocsvpn"><a target="_blank" href="https://cloud.google.com/network-connectivity/docs/vpn">Cloud VPN</a></h3>
<p>With Cloud VPN, your traffic travels through the public internet over an encrypted tunnel. Each tunnel has a maximum capacity of 3 Gb per second and you can use a maximum of 8 for better performance. These two characteristics make VPN the cheapest option.</p>
<p>You can define two types of routes between your VPC and your on-premise networks:</p>
<ul>
<li><strong>Static routes</strong>. You have to manually define and update them, for example when you add a new subnet. This is not the preferred option.</li>
<li><strong>Dynamic routes</strong>. Routes are automatically handled (defined and updated) for you using <a target="_blank" href="https://cloud.google.com/network-connectivity/docs/router">Cloud Router</a>. This is the preferred option when <a target="_blank" href="https://en.wikipedia.org/wiki/Border_Gateway_Protocol">BGP</a> is available.</li>
</ul>
<p>Your traffic gets encrypted and decrypted by VPN Gateways (in GCP, they are regional resources). </p>
<p>To have a more robust connection, consider using multiple VPN gateways and tunnels. In case of failure, this redundancy guarantees that traffic will still flow.</p>
<h3 id="heading-cloud-interconnecthttpscloudgooglecomnetwork-connectivitydocsinterconnect"><a target="_blank" href="https://cloud.google.com/network-connectivity/docs/interconnect">Cloud Interconnect</a></h3>
<p>With Cloud VPN, traffic travels through the public internet. With Cloud Interconnect, there is a <strong>direct physical connection</strong> between your on-premises network and your VPC. This option will be more expensive but will provide the best performance.</p>
<p>There are two types of interconnect available, depending on how you want your connection to GCP to materialize:</p>
<ul>
<li><strong>Dedicated interconnect</strong>. There is "a direct cable" connecting your infrastructure and GCP. This is the fastest option, with a capacity of 10 to 200 Gb per second. However, it is not available everywhere: at the time of this writing, only in 62 locations in the world.</li>
<li><strong>Partner interconnect</strong>. You connect through a service provider. This option is more geographically available, but the not as fast as a dedicated interconnects: from 50 Mb per second to 10 Gb per second.</li>
</ul>
<h3 id="heading-cloud-peeringhttpscloudgooglecomvpcdocsusing-vpc-peering"><a target="_blank" href="https://cloud.google.com/vpc/docs/using-vpc-peering">Cloud Peering</a></h3>
<p>Cloud peering is not a GCP service, but you can use it to connect your network to Google's network and access services like Youtube, Drive, or GCP services. </p>
<p>A common use case is when you need to connect to Google but don't want to do it over the public internet.</p>
<h3 id="heading-other-networking-services"><strong>Other networking services</strong></h3>
<h4 id="heading-load-balancers-lbhttpscloudgooglecomload-balancingdocsload"><a target="_blank" href="https://cloud.google.com/load-balancing/docs/load">Load Balancers (LB)</a></h4>
<p>In GCP, load balancers are pieces of software that distribute user requests among a group of instances. </p>
<p>A load balancer may have multiple backends associated with it, having rules to decide the appropriate backend for a given request.</p>
<p>There are different types of load balancers. They differ in the type of traffic (HTTP vs TCP/UDP - Layer 7 or Layer 4), whether they handle external or internal traffic, and whether their scope is regional or global:</p>
<ul>
<li><strong>HTTP(s)</strong>. Global LB that handles HTTP(s) requests, distributing traffic to multiple regions based on user location (to the closest region with available instances) or URL maps (the LB can be configured to forward requests to <em>URL/news</em> to a backend service and <em>URL/videos</em> to a different one). It can receive both IPv4 and IPv6 traffic (but this one is terminated at the LB level and proxied as IPv4 to the backends) and has native support for WebSockets.</li>
<li><strong>SSL Proxy LB</strong>. <strong>Global</strong> LB that handles encrypted TCP traffic, managing SSL certificates for you.</li>
<li><strong>TCP Proxy LB</strong>. <strong>Global</strong> LB that handles unencrypted TCP traffic. Like SSL Proxy LB, by default, it will not preserve the client's IP, but this can be changed.</li>
<li><strong>Network Load Balancer</strong>. Regional LB that handles TCP/UDP external traffic, based on IP address and port.</li>
<li><strong>Internal Load Balancer</strong>. Like a Network LB, but for internal traffic.</li>
</ul>
<p>For the visual learners:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/lb.svg" alt="Image" width="600" height="400" loading="lazy"></p>
<h4 id="heading-cloud-dnshttpscloudgooglecomdnsdocs"><a target="_blank" href="https://cloud.google.com/dns/docs">Cloud DNS</a></h4>
<p>Cloud DNS is Google's managed <a target="_blank" href="https://en.wikipedia.org/wiki/Domain_Name_System">Domain Name System (DNS)</a> host, both for internal and external (public) traffic. It will map URLs like <a target="_blank" href="https://www.freecodecamp.org/">https://www.freecodecamp.org/</a> to an IP address. It is the only service in GCP with 100% SLA - it is available 100% of the time.</p>
<h4 id="heading-google-cloud-cdnhttpscloudgooglecomcdndocs"><a target="_blank" href="https://cloud.google.com/cdn/docs">Google Cloud CDN</a></h4>
<p>Cloud DNS is Google's <a target="_blank" href="https://en.wikipedia.org/wiki/Content_delivery_network">Content Delivery Network</a>. If you have data that does not change often (images, videos, CSS, etc.) it makes sense to cache it close to your users. Cloud CDN provides 90 Edges Point of Presence (POP) to cache the data close to your end-users.</p>
<p>After the first request, static data can be stored in a POP, usually much closer to your user than your main servers. Thus, in subsequent requests, you can retrieve the data faster from the POP and reduce the load on your backend servers.</p>
<h2 id="heading-where-can-you-run-your-applications-in-gcp"><strong>Where can you run your applications in GCP?</strong></h2>
<p>I will present 4 places where your code can run in GCP:</p>
<ul>
<li>Google Compute Engine</li>
<li>Google Kubernetes Engine</li>
<li>App Engine</li>
<li>Cloud Functions</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/gce.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Note</strong>: there is a 5th option: Firebase is Google's mobile platform that helps you quickly develop apps.</p>
<h3 id="heading-compute-engine-gcehttpscloudgooglecomcomputedocs"><strong><a target="_blank" href="https://cloud.google.com/compute/docs">Compute Engine (GCE)</a></strong></h3>
<p>Compute engine allows you to spin up virtual machines in GCP. This section will be longer since GCE provides the infrastructure where GKE and GAE run.</p>
<p>In the introduction, I talked about the different types of VMs you can create in GCE. Now, I will cover where to store the data, how to back it up, and how to create instances with all the data and configuration you need.</p>
<h4 id="heading-where-to-store-your-vms-data-disks">Where to store your VM's data: disks</h4>
<p>Your data can be stored in <strong>Persistent disks</strong>, <strong>Local SSDs</strong>, or in <strong>Cloud Storage</strong>.</p>
<h5 id="heading-persistent-diskhttpscloudgooglecompersistent-disk"><strong><a target="_blank" href="https://cloud.google.com/persistent-disk">Persistent Disk</a></strong></h5>
<p>Persistent disks provide durable and reliable block storage. They are not local to the machine. Rather, they are networked attached, which has its pros and cons:</p>
<ul>
<li>Disks can be resized, attached, or detached from a VM even if the instance is in use.</li>
<li>They have high reliability.</li>
<li>Disks can survive the instance after its deletion.</li>
<li>If you need more space, simply attach more disks.</li>
<li>Larger disks will provide higher performance.</li>
<li>Being networked attached, they are less performant than local options. SSD persistent disks are also available for more demanding workloads.</li>
</ul>
<p>Every instance will need one boot disk and it must be of this type.</p>
<h5 id="heading-local-ssdhttpscloudgooglecomlocal-ssd"><strong><a target="_blank" href="https://cloud.google.com/local-ssd">Local SSD</a></strong></h5>
<p>Local SSDs are attached to a VM to which they provide high-performance ephemeral storage. As of now, you can attach up to eight 375GB local SSDs to the same instance. However, this data will be lost if the VM is killed.</p>
<p>Local SSDs can only be attached to a machine when it is created, but you can attach both local SSDs and persistent disks to the same machine.</p>
<p>Both types of disks are zonal resources.</p>
<h5 id="heading-cloud-storage"><strong>Cloud Storage</strong></h5>
<p>We have extensively covered GCS in a previous section. GCS is not a filesystem, but you can use <a target="_blank" href="https://cloud.google.com/storage/docs/gcs-fuse">GCS-Fuse</a> to mount GCS buckets as filesystems in Linux or macOS systems. You can also let apps download and upload data to GCS using standard filesystem semantics.</p>
<h4 id="heading-how-to-back-up-your-vms-data-snapshots">How to back up your VM's data: Snapshots</h4>
<p>Snapshots are backups of your disks. To reduce space, they are created incrementally:</p>
<ul>
<li>Back up 1 contains all your disk content</li>
<li>Back up 2 only contains the data that has changed since back up 1</li>
<li>Back up 3 only contains the data that has changed since back up 2, and so on</li>
</ul>
<p>This is enough to restore the state of your disk.</p>
<p>Even though snapshots can be taken without stopping the instance, it is best practice to at least reduce its activity, stop writing data to disk, and flush buffers. This helps you make sure you get an accurate representation of the content of the disk.</p>
<h4 id="heading-imageshttpscloudgooglecomcomputedocsimages"><a target="_blank" href="https://cloud.google.com/compute/docs/images">Images</a></h4>
<p>Images refer to the operating system images needed to create boot disks for your instances. There are two types of images:</p>
<ul>
<li><strong>Public images</strong>. They are provided and maintained by Google, open-source communities, and third-party vendors. Ready for you to use as soon as you create your project. Available to anyone</li>
<li><strong>Custom images</strong>. Images that you have created.</li>
<li>They are linked to the project in which you created them but you can share them with other projects.</li>
<li>You can create images from <strong>persistent disks</strong> and <strong>other images</strong>, both from the same project or shared from another project.</li>
<li>Related images can be grouped in <strong>image families</strong> to simplify the management of the different image versions.</li>
<li>For Linux-based images, you can share them also by exporting them to Cloud Storage as a tar.gz file.</li>
</ul>
<p>You might be asking yourself what is the difference between an image and a snapshot. Mainly, <strong>their purpose</strong>. Snapshots are taken as incremental backups of a disk while images are created to spin up new virtual machines and configure instance templates.</p>
<p><strong>Note on images vs startup scripts:</strong></p>
<p>For simple setups, startup scripts are also an option. They can be used to test changes quickly, but the VMs will take longer to be ready compared to using an image where all the needed software is installed, configured, and so on.</p>
<h4 id="heading-instance-groups">Instance groups</h4>
<p>Instance groups let you treat a group of instances as a single unit and they come in two flavors:</p>
<ul>
<li><strong>Unmanaged instance group</strong>. Formed by a heterogeneous group of instances that required individual configuration settings.</li>
<li><strong>Managed instance group (MIG).</strong> This is the preferred option when possible. All the machines look the same, making it easy to configure them, create them in multiple zones (high availability), replace them if they become unhealthy (auto-healing), balance the traffic among them, and create new instances if they traffic increases (horizontal scaling).</li>
</ul>
<p>To create a MIGs, you need to define an <strong>instance template</strong>, specifying your machine type, zone, OS image, startup and shutdown scripts, and so on. Instance templates are immutable.</p>
<p>To update a MIG, you need to create a new template and use the <strong>Managed Instance Group Updated</strong> to deploy the new version to every machine in the group. </p>
<p>This functionality can be used to create <a target="_blank" href="https://martinfowler.com/bliki/CanaryRelease.html">canary tests</a>, deploying your changes to a small fraction of your machines first.</p>
<p>Visit this <a target="_blank" href="https://cloud.google.com/compute/docs/instance-groups/distributing-instances-with-regional-instance-groups">link</a> to know more about Google's recommendations to ensure an application deployed via a managed instance group can handle the load even if an entire zone fails.</p>
<h4 id="heading-security-best-practices-for-gce">Security best practices for GCE</h4>
<p>To increase the security of your infrastructure in GCE, have a look at:</p>
<ul>
<li><a target="_blank" href="https://cloud.google.com/security/shielded-cloud/shielded-vm">Shielded VMs</a></li>
<li><a target="_blank" href="https://cloud.google.com/solutions/connecting-securely">Prevent instances from being reached from the public internet</a></li>
<li>[Trusted images](https://cloud.google.com/compute/docs/images/restricting-image-access#:~:text=Use the Trusted image feature,images%2C disks%2C and snapshots.) to make sure your users can only create disks from images in <strong>specific projects</strong></li>
</ul>
<h3 id="heading-app-enginehttpscloudgooglecomappenginedocs"><strong><a target="_blank" href="https://cloud.google.com/appengine/docs">App Engine</a></strong></h3>
<p>App Engine is a great choice when you want to focus on the code and let Google handle your infrastructure. You just need to choose the region where your app will be deployed (this cannot be changed once it is set). Amongst its main use cases are websites, mobile apps, and game backends.</p>
<p>You can easily update the version of your app that is running via the command line or the Google Console. </p>
<p>Also, if you need to deploy a risky update to your application, you can split the traffic between the old and the risky versions for a canary deployment. Once you are happy with the results, you can route all the traffic to the new version.</p>
<p>There are two App Engine environments:</p>
<ul>
<li><strong>Standard</strong>. This version can quickly scale up or down (even to zero instances) to adjust to the demand. Currently, only a few programming languages are supported (Go, Java, PHP, and Python) and you do not have access to a VPC (including VPN connections). It can be scaled down to zero instances.</li>
<li><strong>Flexible.</strong> Your code runs in Docker containers in GCE, hence more flexible than the Standard environment. However, creating new instances is slower and it cannot be scaled down to zero instances. It is suited for more consistent traffic.</li>
</ul>
<p>Regardless of the environment, there are no up-front costs and you only pay for what you use (billed per second).</p>
<p><strong>Memcache</strong> is a built-in App Engine, giving you the possibility to choose between a <strong>shared</strong> cache (default, free option) or a <strong>dedicated</strong> cache for better performance. </p>
<p>Visit this link to know more about the <a target="_blank" href="https://cloud.google.com/appengine/docs/standard/java/memcache#best_practices">best practices</a> you should follow to maximize the performance of your app.</p>
<h3 id="heading-google-kubernetes-engine-gkehttpscloudgooglecomkubernetes-enginedocs"><strong><a target="_blank" href="https://cloud.google.com/kubernetes-engine/docs">Google Kubernetes Engine (GKE)</a></strong></h3>
<p><a target="_blank" href="https://kubernetes.io/">Kubernetes</a> is an open-source <strong>container orchestration system</strong>, developed by Google. </p>
<p>Kubernetes is a very extensive topic in itself and I will not cover here. You just need to know that GKE makes it easy to run and manage your Kubernetes clusters on GCP. </p>
<p>Google also provides <a target="_blank" href="https://cloud.google.com/container-registry">Container Registry</a> to store your container images - think of it as your private Docker Hub.</p>
<p><strong>Note</strong>: You can use <a target="_blank" href="https://cloud.google.com/cloud-build/docs">Cloud Build</a> to run your builds in GCP and, among other things, produce Docker images and store them in Container Registry. Cloud Build can import your code from Google Cloud Storage, <a target="_blank" href="https://cloud.google.com/source-repositories/docs">Cloud Source Repository</a>, GitHub, or Bitbucket.</p>
<h3 id="heading-cloud-functionshttpscloudgooglecomfunctionsdocs"><strong><a target="_blank" href="https://cloud.google.com/functions/docs">Cloud Functions</a></strong></h3>
<p>Cloud Functions are the equivalent of Lambda functions in AWS. Cloud functions are <strong>serverless</strong>. They let you focus on the code and not worry about the infrastructure where it is going to run.</p>
<p>With Cloud Functions it is <strong>easy to respond to events</strong> such as uploads to a GCS bucket or messages in a Pub/Sub topic. You are only charged for the time your function is running in response to an event.</p>
<h2 id="heading-how-to-work-with-big-data-in-gcp"><strong>How to work with Big Data in GCP</strong></h2>
<h3 id="heading-bigqueryhttpscloudgooglecombigquerydocs"><strong><a target="_blank" href="https://cloud.google.com/bigquery/docs/">BigQuery</a></strong></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/bigq.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>BigQuery is Google's serverless data warehousing and provides analytics capabilities for petabyte-scale databases. </p>
<p>BigQuery automatically backs up your tables, but you can always export them to GCS to be on the safe side - incurring extra costs. </p>
<p>Data can be ingested in batches (for instance, from a GCS bucket) or from a stream in multiple formats: CSV, JSON, Parquet, or Avro (most performant). Also, you can query data that resides in external sources, called federated sources, for example, GCS buckets.</p>
<p>You can interact with your data in BigQuery using SQL via the</p>
<ul>
<li>Google Console.</li>
<li><a target="_blank" href="https://cloud.google.com/bigquery/docs/bq-command-line-tool">Command-line</a>, running commands like <code>bq query 'SELECT field FROM ....</code></li>
<li>REST API.</li>
<li>Code using client libraries.</li>
</ul>
<p><a target="_blank" href="https://cloud.google.com/bigquery/docs/reference/standard-sql/user-defined-functions">User-Defined Functions</a> allow you to combine SQL queries with JavaScript functions to create complex operations.</p>
<p>BigQuery is a columnar data store: records are stored in columns. Tables are collections of columns and datasets are collections of tables. </p>
<p>Jobs are actions to load, export, query, or copy data that BigQuery runs on your behalf. </p>
<p>Views are virtual tables defined by a SQL query and are useful sharing data with others when you want to control exactly what they have access to.</p>
<p>Two important concepts related to tables are:</p>
<ul>
<li><strong>Partitioned tables</strong>. To limit the amount of data that needs to be queried, tables can be divided into partitions. This can be done based on ingest time or including a timestamp or date column or an integer range. This way it is easy to query for certain periods without querying the full table. To reduce costs, you can define an expiration period after which the partition will be deleted.</li>
<li><a target="_blank" href="https://cloud.google.com/bigquery/docs/clustered-tables"><strong>Clustered tables</strong></a>. Data are clustered by column (for instance, order_id). When you query your table, only the rows associated with this column will be read. BigQuery will perform this clustering automatically based on one or more columns.</li>
</ul>
<p>Using IAM roles, you can control access at a project, dataset, or view level, but <em>not at the table level</em>. Roles are complex for BigQuery, so I recommend checking the <a target="_blank" href="https://cloud.google.com/bigquery/docs/access-control#predefined_roles_comparison_matrix">documentation</a>. </p>
<p>For instance, the jobUser role only lets you run jobs while the user role lets you run jobs and create datasets (but not tables).</p>
<p>Your costs depend on how much data you store and stream into BigQuery and how much data you query. To reduce costs, BigQuery automatically caches previous queries (per user). This behavior can be disabled.</p>
<p>When you don't edit data for 90 days, it automatically moves to a cheaper storage class. You pay for what you use, but it is possible to opt for a flat rate (only if you need more than the 2000 <a target="_blank" href="https://cloud.google.com/bigquery/docs/slots">slots</a> that are allocated by default). </p>
<p>Check these links to see how to <a target="_blank" href="https://cloud.google.com/bigquery/docs/best-practices-performance-overview">optimize your performance</a> and <a target="_blank" href="https://cloud.google.com/blog/products/data-analytics/cost-optimization-best-practices-for-bigquery">costs</a>.</p>
<h3 id="heading-cloud-pubsubhttpscloudgooglecompubsubdocs"><strong><a target="_blank" href="https://cloud.google.com/pubsub/docs">Cloud Pub/Sub</a></strong></h3>
<p>Pub/Sub is Google's <strong>fully-managed message queue</strong>, allowing you to decouple publishers (adding messages to the queue) and subscribers (consuming messages from the queue).</p>
<p>Although it is similar to <a target="_blank" href="https://kafka.apache.org/">Kafka</a>, Pub/Sub is not a direct substitute. They can be combined in the same pipeline (Kafka deployed on-premise or even in GKE). There are open-source plugins to connect Kafka to GCP, like <a target="_blank" href="https://www.confluent.io/hub/confluentinc/kafka-connect-gcp-pubsub">Kafka Connect</a>.</p>
<p>Pub/Sub guarantees that every message will be delivered at least once but it does not guarantee that messages will be processed in order. It is usually connected to Dataflow to process the data, ensure that the messages are processed in order, and so on.</p>
<p>Pub/Sub support both push and pull modes:</p>
<ul>
<li><strong>Push.</strong> Messages are sent to subscribers, resulting in lower latency.</li>
<li><strong>Pull.</strong> Subscribers pull messages from topics, better suited for a large volume of messages.</li>
</ul>
<h3 id="heading-cloud-pubsub-vs-cloud-task"><strong>Cloud Pub/Sub vs Cloud Task</strong></h3>
<p><a target="_blank" href="https://cloud.google.com/tasks/docs">Cloud Tasks</a> is another fully-managed service to execute tasks asynchronously and manage messages between services. However, there are differences between Cloud Tasks and Pub/Sub:</p>
<ul>
<li>In Pub/Sub, publishers and subscribers are decoupled. Publishers know nothing about their subscribers. When they publish a message, they implicitly cause one or multiple subscribers to react to a publishing event.</li>
<li>In Cloud Tasks, the publisher stays in control of the execution. Besides, Cloud Tasks provide other features unavailable for Pub/Sub like scheduling specific delivery times, delivery rate controls, configurable retries, access and management of individual tasks in a queue, task/message creation deduplication.</li>
</ul>
<p>For more details, check out this <a target="_blank" href="https://cloud.google.com/tasks/docs/comp-pub-sub">link</a>.</p>
<h3 id="heading-cloud-dataflowhttpscloudgooglecomdataflowdocs"><strong><a target="_blank" href="https://cloud.google.com/dataflow/docs/">Cloud Dataflow</a></strong></h3>
<p>Cloud Dataflow is Google's managed service for <strong>stream and batch data processing</strong>, based on <a target="_blank" href="https://beam.apache.org/documentation/">Apache Beam</a>. </p>
<p>You can define pipelines that will transform your data, for example before it is ingested in another service like BigQuery, BigTable, or Cloud ML. The same pipeline can process both stream and batch data.</p>
<p>A common pattern is to stream data into Pub/Sub, let's say from <a target="_blank" href="https://cloud.google.com/solutions/iot">IoT devices</a>, process it in Dataflow, and store it for analysis in BigQuery. </p>
<p>But Pub/Sub does not guarantee that the order in which messages are pushed to the topics will be the order in which the messages are consumed. However, this can be done with Dataflow.</p>
<h3 id="heading-cloud-dataprochttpscloudgooglecomdataprocdocs"><strong><a target="_blank" href="https://cloud.google.com/dataproc/docs">Cloud Dataproc</a></strong></h3>
<p>Cloud Dataproc is Google's managed the Hadoop and Spark ecosystem. It lets you create and manage your clusters easily and turn them off when you are not using them, to reduce costs. </p>
<p>Dataproc can only be used to process batch data, while Dataflow can handle also streaming data.</p>
<p>Google recommends using Dataproc for a lift and leverage migration of your on-premise Hadoop clusters to the cloud:</p>
<ul>
<li>Reduce costs turning your cluster off when you are not using it.</li>
<li>Leverage Google's infrastructure</li>
<li>Use some preemptible virtual machines to reduce costs</li>
<li>Add larger (SSD) persistent disks to improve performance</li>
<li>BigQuery can replace Hive and BigTable can replace HBase</li>
<li>Cloud Storage replaces HDFS. Just upload your data to GCS and change the prefixes hdfs:// to gs://</li>
</ul>
<p>Otherwise, you should choose Cloud Dataflow.</p>
<h3 id="heading-dataprephttpscloudgooglecomdataprepdocs"><strong><a target="_blank" href="https://cloud.google.com/dataprep/docs">Dataprep</a></strong></h3>
<p>Cloud Dataprep provides you with a <strong>web-based interface to clean and prepare your data</strong> before processing. The input and output formats include, among others, CSV, JSON, and Avro.</p>
<p>After defining the transformations, a Dataflow job will run. The transformed data can be exported to GCS, BigQuery, etc.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/proc.svg" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-cloud-composerhttpscloudgooglecomcomposerdocs"><strong><a target="_blank" href="https://cloud.google.com/composer/docs">Cloud Composer</a></strong></h3>
<p>Cloud Composer is Google's fully-managed <a target="_blank" href="https://airflow.apache.org/">Apache Airflow</a> service to create, schedule, monitor, and manage workflows. It handles all the infrastructure for you so that you can concentrate on combining the services I have described above to create your own workflows.</p>
<p>Under the hood, a GKE cluster will be created with Airflow in it and GCS will be used to store files.</p>
<h3 id="heading-ai-and-machine-learning-in-gcphttpscloudgooglecomproductsai"><strong><a target="_blank" href="https://cloud.google.com/products/ai">AI and Machine Learning in GCP</a></strong></h3>
<p>Covering the basics of machine learning would take another article. So here, I assume you are familiar with it and will show you how to train and deploy your models in GCP. </p>
<p>We'll also look at what APIs are available to leverage Google's machine learning capabilities in your services, even if you are not an expert in this area.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/AI.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<h4 id="heading-ai-platformhttpscloudgooglecomai-platformdocs"><a target="_blank" href="https://cloud.google.com/ai-platform/docs">AI Platform</a></h4>
<p>AI Platform provides you with a <strong>fully-managed platform</strong> to use machine learning libraries like <a target="_blank" href="https://www.tensorflow.org/">Tensorflow</a>. You just need to focus on your model and Google will handle all the infrastructure needed to train it. </p>
<p>After your model is trained, you can use it to get online and batch predictions.</p>
<h4 id="heading-cloud-automlhttpscloudgooglecomautoml"><a target="_blank" href="https://cloud.google.com/automl">Cloud AutoML</a></h4>
<p>Google lets you use <strong>your data to train their models</strong>. You can leverage models to build applications that are based on natural language processing (for example, document classification or sentiment analysis applications), speech processing, machine translation, or video processing (video classification or object detection).</p>
<h2 id="heading-how-to-explore-and-visualize-your-data-in-gcp"><strong>How to explore and visualize your data in GCP</strong></h2>
<h3 id="heading-cloud-data-studiohttpscloudgooglecombigquerydocsvisualize-data-studio"><strong><a target="_blank" href="https://cloud.google.com/bigquery/docs/visualize-data-studio">Cloud Data Studio</a></strong></h3>
<p>Data Studio lets you create <strong>visualizations and dashboards</strong> based on data that resides in Google services (YouTube Analytics, Sheets, AdWords, local upload), Google Cloud Platform (BigQuery, Cloud SQL, GCS, Spanner), and many third-party services, storing your reports in Google Drive.</p>
<p>Data Studio is not part of GCP, but <strong>G-Suite</strong>, thus its permissions are not managed using IAM. </p>
<p>There are no additional costs for using Data Studio, other than the storage of the data, queries in BigQuery, and so on. <strong>Caching</strong> can be used to improve performance and reduce costs.</p>
<h3 id="heading-cloud-datalabhttpscloudgooglecomdatalabdocs"><strong><a target="_blank" href="https://cloud.google.com/datalab/docs">Cloud Datalab</a></strong></h3>
<p>Datalab lets you <strong>explore, analyze, and visualize data</strong> in BigQuery, ML Engine, Compute Engine, Cloud Storage, and Stackdriver. </p>
<p>It is based on Jupyter notebooks and supports Python, SQL, and Javascript code. Your notebooks can be shared via the Cloud Source Repository.</p>
<p>Cloud Datalab itself is free of charge, but it will create a virtual machine in GCE for which you will be billed.</p>
<h2 id="heading-security-in-gcphttpscloudgooglecomsecurity"><strong><a target="_blank" href="https://cloud.google.com/security/">Security in GCP</a></strong></h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/10/sec.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-encryption-on-google-cloud-platform"><strong>Encryption on Google Cloud Platform</strong></h3>
<p>Google Cloud encrypts data both at rest (data stored on disk) and in transit (data traveling in the network), using <a target="_blank" href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a> implemented via <a target="_blank" href="https://boringssl.googlesource.com/boringssl/">Boring SSL</a>. </p>
<p>You can manage the encryption keys yourself (both storing them in GCP or on-premise) or let Google handle them.</p>
<h4 id="heading-encryption-at-resthttpscloudgooglecomsecurityencryption-at-restdefault-encryption"><a target="_blank" href="https://cloud.google.com/security/encryption-at-rest/default-encryption">Encryption at rest</a></h4>
<p>GCP encrypts data stored at rest <strong>by default</strong>. Your data will be divided into chunks. Each chunk is distributed across different machines and encrypted with a unique key, called a <strong>data encryption key (DEK)</strong>. </p>
<p>Keys are generated and managed by Google but you can also manage the keys yourself, as we will see later in this guide.</p>
<h4 id="heading-encryption-in-transithttpscloudgooglecomsecurityencryption-in-transit"><a target="_blank" href="https://cloud.google.com/security/encryption-in-transit">Encryption in Transit</a></h4>
<p>To add an extra security layer, all communications between two GCP services or from your infrastructure to GCP are encrypted at one or more network layers. Your data would not be compromised if your messages were to be intercepted.</p>
<h3 id="heading-cloud-key-management-service-kmshttpscloudgooglecomkmsdocs"><strong><a target="_blank" href="https://cloud.google.com/kms/docs">Cloud Key Management Service (KMS)</a></strong></h3>
<p>As I mentioned earlier, you can let Google manage the keys for you or you can manage them yourself. </p>
<p>Google KMS is the service that allows you to <strong>manage your encryption keys</strong>. You can create, rotate, and destroy symmetric encryption keys. All keys related activity is registered in logs. These keys are referred to as <strong>customer-managed encryption keys</strong>. </p>
<p>In GCS, they are used to <a target="_blank" href="https://cloud.google.com/storage/docs/encryption/customer-managed-keys#:~:text=Data%20Encryption%20Options.-,Overview,are%20stored%20within%20Cloud%20KMS.">encrypt</a>:</p>
<ul>
<li>The object's data.</li>
<li>The object's CRC32C checksum.</li>
<li>The object's MD5 hash.</li>
</ul>
<p>And Google uses server-side keys to handle the rest of the metadata, including the object's name.</p>
<p>The DEKs used to encrypt your data are also encrypted using key encryption keys (KEKs), in a process called envelope encryption. By default, KEKs are rotated every 90 days.</p>
<p>It is important to note that KMS does not store secrets. KMS is a central repository for KEKs. Only the keys that GCP needs to encrypt secrets that are stored somewhere else, for instance in <a target="_blank" href="https://cloud.google.com/solutions/secret-manager/">Secrets management</a>.</p>
<p><strong>Note</strong>: For GCE and GCS, you have the possibility of keeping your keys on-premise and let Google retrieve them to encrypt and decrypt your data. These are known as <strong>customer-supplied keys</strong>.</p>
<h3 id="heading-identity-aware-proxy-iaphttpscloudgooglecomiapdocs"><strong><a target="_blank" href="https://cloud.google.com/iap/docs">Identity-Aware Proxy (IAP)</a></strong></h3>
<p>Identity-Aware Proxy allows you to <strong>control the access</strong> GCP applications via HTTPs without installing any VPN software or adding extra code in your application to handle login. </p>
<p>Your applications are visible to the public internet, but only accessible to authorized users, implementing a zero-trust security access model. </p>
<p>Furthermore, with TCP forwarding you can prevent services like SSH to be exposed to the public internet.</p>
<h3 id="heading-cloud-armorhttpscloudgooglecomarmordocs"><strong><a target="_blank" href="https://cloud.google.com/armor/docs">Cloud Armor</a></strong></h3>
<p>Cloud Armor protects your infrastructure from <a target="_blank" href="https://en.wikipedia.org/wiki/Denial-of-service_attack">distributed denial of service (DDoS)</a> attacks. You define rules (for example to whitelist or deny certain IP addresses or CIDR ranges) to create security policies, which are enforced at the Point of Presence level (closer to the source of the attack).</p>
<p>Cloud Armor gives you the option of previewing the effects of your policies before activating them.</p>
<h3 id="heading-cloud-data-loss-preventionhttpscloudgooglecomdlpdocs"><strong><a target="_blank" href="https://cloud.google.com/dlp/docs">Cloud Data Loss Prevention</a></strong></h3>
<p>Data Loss Prevention is a fully-managed service designed to help you discover, classify, and protect sensitive data, like:</p>
<ul>
<li><strong>Personable Identifiable Information (PII)</strong>: name, Social Security number, driver's license number, bank account number, passport number, email address, and so on.</li>
<li><strong>Secrets</strong></li>
<li><strong>Credentials</strong></li>
</ul>
<p>DLP is integrated with GCS, BigQuery, and Datastore. Also, the source of the data can be outside of GCP. </p>
<p>You can specify what type of data you're interested in, called info type, define your own types (based on dictionaries of words and phrases or based on regex expressions), or let Google use the default which can be time-consuming for large amounts of data.</p>
<p>For each result, DLP will return the likelihood of that piece of data matches a certain info type: LIKELIHOOD_UNSPECIFIED, VERY_UNLIKELY, UNLIKELY, POSSIBLE, LIKELY, VERY_LIKELY.</p>
<p>After detecting a piece of PII, DLP can transform it so that it cannot be mapped back to the user. DLP uses multiple techniques to de-identify your sensitive data like tokenization, bucketing, and date shifting. DLP can detect and redact sensitive data in images too.</p>
<h3 id="heading-vpc-service-controlhttpscloudgooglecomvpc-service-controlsdocsoverview"><strong><a target="_blank" href="https://cloud.google.com/vpc-service-controls/docs/overview">VPC Service Control</a></strong></h3>
<p>VPC Service Control helps prevent data exfiltration. It allows you to define a perimeter around resources you want to protect. You can define what services and from what networks these resources can be accessed.</p>
<h3 id="heading-cloud-web-security-scannerhttpscloudgooglecomsecurity-command-centerdocsconcepts-web-security-scanner-overview"><strong><a target="_blank" href="https://cloud.google.com/security-command-center/docs/concepts-web-security-scanner-overview">Cloud Web Security Scanner</a></strong></h3>
<p>Cloud Web Security Scanner scanner applications running in Compute Engine, GKE, and App Engine for common vulnerabilities such as passwords in plain text, invalid headers, outdated libraries, and <a target="_blank" href="https://en.wikipedia.org/wiki/Cross-site_scripting">cross-site scripting attacks</a>. It simulates a real user trying to click on your buttons, inputting text in your text fields, and so on.</p>
<p>It is part of <a target="_blank" href="https://cloud.google.com/security-command-center/docs">Cloud Security Command Center</a>.</p>
<h2 id="heading-more-gcp-resources"><strong>More GCP resources</strong></h2>
<ul>
<li><a target="_blank" href="https://gcp.solutions/">Google Cloud Solutions Architecture Reference</a></li>
<li><a target="_blank" href="https://cloud.google.com/solutions/#section-1">GCP solutions by industry</a></li>
<li><a target="_blank" href="https://www.youtube.com/user/googlecloudplatform">GCP Youtube channel</a></li>
<li><a target="_blank" href="https://cloud.google.com/training/free-labs">GCP Labs</a></li>
</ul>
<p>If you're interested in learning more about GCP, I recommend checking the free practice exams for the different certifications. Whether you are preparing for a GCP or not you can use them to find gaps in your knowledge:</p>
<ul>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/cloud-developer">Professional Cloud Developer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/clouddata-engineer">Professional Cloud Data Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/cloud-network-engineer">Professional Cloud Network Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/cloud-security-engineer">Professional Cloud Security Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/cloud-devops-engineer">Professional Cloud DevOps Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/cloud-devops-engineer">Professional Cloud Machine Learning Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/sample-questions/cloud-architect">Professional Cloud Architect</a></li>
</ul>
<p><strong>Note:</strong> Some questions are based on case studies. Links to the case studies will be provided in the exams so that you have the full context to properly understand and answer the question.</p>
<h2 id="heading-time-to-test-your-knowledge"><strong>Time to test your knowledge</strong></h2>
<p>I've extracted 10 questions from some of the exams above. Some of them are pretty straightforward. Others require deep thought and deciding what is the best solution when more than one option is a viable solution.</p>
<h3 id="heading-question-1"><strong>Question 1</strong></h3>
<p>Your customer is moving their corporate applications to Google Cloud. The security team wants detailed visibility of all resources in the organization. You use the Resource Manager to set yourself up as the Organization Administrator. </p>
<p>Which Cloud Identity and Access Management (Cloud IAM) roles should you give to the security team while following Google's recommended practices?</p>
<p>A. Organization viewer, Project owner</p>
<p>B. Organization viewer, Project viewer</p>
<p>C. Organization administrator, Project browser</p>
<p>D. Project owner, Network administrator</p>
<h3 id="heading-question-2"><strong>Question 2</strong></h3>
<p>Your company wants to try out the cloud with low risk. They want to archive approximately 100 TB of their log data to the cloud and test the serverless analytics features available to them there, while also retaining that data as a long-term disaster recovery backup. </p>
<p>Which two steps should they take? (Choose two)</p>
<p>A. Load logs into BigQuery.</p>
<p>B. Load logs into Cloud SQL.</p>
<p>C. Import logs into Cloud Logging.</p>
<p>D. Insert logs into Cloud Bigtable.</p>
<p>E. Upload log files into Cloud Storage.</p>
<h3 id="heading-question-3"><strong>Question 3</strong></h3>
<p>Your company wants to track whether someone is present in a meeting room reserved for a scheduled meeting. </p>
<p>There are 1000 meeting rooms across 5 offices on 3 continents. Each room is equipped with a motion sensor that reports its status every second. </p>
<p>You want to support the data ingestion needs of this sensor network. The receiving infrastructure needs to account for the possibility that the devices may have inconsistent connectivity. </p>
<p>Which solution should you design?</p>
<p>A. Have each device create a persistent connection to a Compute Engine instance and write messages to a custom application.</p>
<p>B. Have devices poll for connectivity to Cloud SQL and insert the latest messages on a regular interval to a device-specific table.</p>
<p>C. Have devices poll for connectivity to Cloud Pub/Sub and publish the latest messages on a regular interval to a shared topic for all devices.</p>
<p>D. Have devices create a persistent connection to an App Engine application fronted by Cloud Endpoints, which ingest messages and write them to Cloud Datastore.</p>
<h3 id="heading-question-4"><strong>Question 4</strong></h3>
<p>To reduce costs, the Director of Engineering has required all developers to move their development infrastructure resources from on-premises virtual machines (VMs) to Google Cloud. </p>
<p>These resources go through multiple start/stop events during the day and require the state to persist. </p>
<p>You have been asked to design the process of running a development environment in Google Cloud while providing cost visibility to the finance department. </p>
<p>Which two steps should you take? (Choose two)</p>
<p>A. Use persistent disks to store the state. Start and stop the VM as needed.</p>
<p>B. Use the --auto-delete flag on all persistent disks before stopping the VM.</p>
<p>C. Apply the VM CPU utilization label and include it in the BigQuery billing export.</p>
<p>D. Use BigQuery billing export and labels to relate cost to groups.</p>
<p>E. Store all state in a Local SSD, snapshot the persistent disks and terminate the VM.</p>
<h3 id="heading-question-5"><strong>Question 5</strong></h3>
<p>The database administration team has asked you to help them improve the performance of their new database server running on Compute Engine. </p>
<p>The database is used for importing and normalizing the company’s performance statistics. It is built with MySQL running on Debian Linux. They have an n1-standard-8 virtual machine with 80 GB of SSD zonal persistent disk which they can't restart until the next maintenance event. </p>
<p>What should they change to get better performance from this system as soon as possible and in a cost-effective manner?</p>
<p>A. Increase the virtual machine’s memory to 64 GB.</p>
<p>B. Create a new virtual machine running PostgreSQL.</p>
<p>C. Dynamically resize the SSD persistent disk to 500 GB.</p>
<p>D. Migrate their performance metrics warehouse to BigQuery.</p>
<h3 id="heading-question-6"><strong>Question 6</strong></h3>
<p>Your organization has a 3-tier web application deployed in the same Google Cloud Virtual Private Cloud (VPC). </p>
<p>Each tier (web, API, and database) scales independently of the others. Network traffic should flow through the web to the API tier, and then on to the database tier. Traffic should not flow between the web and the database tier. </p>
<p>How should you configure the network with minimal steps?</p>
<p>A. Add each tier to a different subnetwork.</p>
<p>B. Set up software-based firewalls on individual VMs.</p>
<p>C. Add tags to each tier and set up routes to allow the desired traffic flow.</p>
<p>D. Add tags to each tier and set up firewall rules to allow the desired traffic flow.</p>
<h3 id="heading-question-7"><strong>Question 7</strong></h3>
<p>You are developing an application on Google Cloud that will label famous landmarks in users’ photos. You are under competitive pressure to develop a predictive model quickly. You need to keep service costs low. </p>
<p>What should you do?</p>
<p>A. Build an application that calls the Cloud Vision API. Inspect the generated MID values to supply the image labels.</p>
<p>B. Build an application that calls the Cloud Vision API. Pass client image locations as base64-encoded strings.</p>
<p>C. Build and train a classification model with TensorFlow. Deploy the model using the AI Platform Prediction. Pass client image locations as base64-encoded strings.</p>
<p>D. Build and train a classification model with TensorFlow. Deploy the model using the AI Platform Prediction. Inspect the generated MID values to supply the image labels.</p>
<h3 id="heading-question-8"><strong>Question 8</strong></h3>
<p>You set up an autoscaling managed instance group to serve web traffic for an upcoming launch. </p>
<p>After configuring the instance group as a backend service to an HTTP(S) load balancer, you notice that virtual machine (VM) instances are being terminated and re-launched every minute. The instances do not have a public IP address. </p>
<p>You have verified that the appropriate web response is coming from each instance using the curl command. You want to ensure that the backend is configured correctly. </p>
<p>What should you do?</p>
<p>A. Ensure that a firewall rule exists to allow source traffic on HTTP/HTTPS to reach the load balancer.</p>
<p>B. Assign a public IP to each instance and configure a firewall rule to allow the load balancer to reach the instance public IP.</p>
<p>C. Ensure that a firewall rule exists to allow load balancer health checks to reach the instances in the instance group.</p>
<p>D. Create a tag on each instance with the name of the load balancer. Configure a firewall rule with the name of the load balancer as the source and the instance tag as the destination.</p>
<h3 id="heading-question-9"><strong>Question 9</strong></h3>
<p>You created a job that runs daily to import highly sensitive data from an on-premises location to Cloud Storage. You also set up a streaming data insert into Cloud Storage via a Kafka node that is running on a Compute Engine instance. </p>
<p>You need to encrypt the data at rest and supply your own encryption key. Your key should not be stored in the Google Cloud. </p>
<p>What should you do?</p>
<p>A. Create a dedicated service account and use encryption at rest to reference your data stored in Cloud Storage and Compute Engine data as part of your API service calls.</p>
<p>B. Upload your own encryption key to Cloud Key Management Service and use it to encrypt your data in Cloud Storage. Use your uploaded encryption key and reference it as part of your API service calls to encrypt your data in the Kafka node hosted on Compute Engine.</p>
<p>C. Upload your own encryption key to Cloud Key Management Service and use it to encrypt your data in your Kafka node hosted on Compute Engine.</p>
<p>D. Supply your own encryption key, and reference it as part of your API service calls to encrypt your data in Cloud Storage and your Kafka node hosted on Compute Engine.</p>
<h3 id="heading-question-10"><strong>Question 10</strong></h3>
<p>You are designing a relational data repository on Google Cloud to grow as needed. The data will be transactionally consistent and added from any location in the world. You want to monitor and adjust node count for input traffic, which can spike unpredictably. </p>
<p>What should you do?</p>
<p>A. Use Cloud Spanner for storage. Monitor storage usage and increase node count if more than 70% utilized.</p>
<p>B. Use Cloud Spanner for storage. Monitor CPU utilization and increase node count if more than 70% utilized for your time span.</p>
<p>C. Use Cloud Bigtable for storage. Monitor data stored and increase node count if more than 70% is utilized.</p>
<p>D. Use Cloud Bigtable for storage. Monitor CPU utilization and increase node count if more than 70% utilized for your time span.</p>
<h4 id="heading-answers">Answers</h4>
<ol>
<li>B</li>
<li>A, E</li>
<li>C</li>
<li>A, D</li>
<li>C</li>
<li>D</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>B</li>
</ol>
<h2 id="heading-back-to-the-initial-proposition"><strong>Back to the initial proposition</strong></h2>
<p>At the beginning of this article, I said you'd learn how to design a mobile gaming analytics platform that collects, stores, and analyzes vast amounts of player-telemetry both from bulks of data and real-time events.</p>
<p>So, do you think you can do it?</p>
<p>Take a pen and a piece of paper and try to come up with your own solution based on the services I have described here. If you get stuck, the following questions might help:</p>
<ul>
<li>The platform needs to collect real-time events from the game:</li>
<li>Where might be the game running?</li>
<li>How can you ingest streaming data from the game into GCP?</li>
<li>How can you store it?</li>
<li>How can you collect and store the uploads of batches of data?</li>
<li>Can you analyze all the ingested data as it comes? Does it need to be processed?</li>
<li>What services can you use to analyze the data? How would this change if low-latency was now a new requirement?</li>
</ul>
<p>I have purposely defined the problem in a very vague way. This is what you can expect when you are facing this sort of challenge: uncertainty. It is part of your job to gather requirements and document your assumptions.</p>
<p>Do not worry if your solution does not look like <a target="_blank" href="https://cloud.google.com/solutions/mobile/mobile-gaming-analysis-telemetry">Google's</a>. This is just one possible solution. Learning to design complex systems is a skill that takes a lifetime to master. Luckily, you're headed in the right direction.</p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>This guide will help you get started on GCP and give you a broad perspective of what you can do with it. </p>
<p>By no means will you be an expert after finishing this guide, or any other guide for that matter. The only way to really learn is by practicing. </p>
<p><strong>You are going to learn infinitely more by doing than by reading or watching</strong>. I strongly recommend using your free trial and Code Labs if you are serious about learning.  </p>
<p>You can visit my blog <a target="_blank" href="https://www.yourdevopsguy.com/">www.yourdevopsguy.com</a>  and <a target="_blank" href="https://twitter.com/CodingLanguages">follow me on Twitter</a> for more high-quality technical content.</p>
<p><strong>Disclaimer:</strong> At the time of publishing this article, I don't work or have ever worked for Google. I wanted to organize and summarize the knowledge I have acquired learned via the Google documentation, YouTube videos, the courses that I have taken and most importantly through hands-on practice using GCP daily on my job. </p>
<p>All of this information is free out there. The figures, numbers, and versions that you see here come from the documentation at the time I am publishing this article. To make sure you are using up-to-date data, please visit the official documentation.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Pass Almost Every Google Cloud Platform Professional Certification Exam ]]>
                </title>
                <description>
                    <![CDATA[ By Ivam Luz Are you interested in becoming a Google Cloud Platform certified professional? Last year, I took five out of the seven (at the time of this writing) of the GCP professional exams: Professional Cloud Architect Professional Data Engineer P... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-pass-almost-every-google-cloud-professional-certification-exam/</link>
                <guid isPermaLink="false">66d45f3133b83c4378a517dc</guid>
                
                    <category>
                        <![CDATA[ google cloud ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ professional development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ self-improvement  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 15 Jun 2020 19:59:54 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/06/cloud-developer-7.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ivam Luz</p>
<p>Are you interested in becoming a Google Cloud Platform certified professional?</p>
<p>Last year, I took five out of the seven (at the time of this writing) of the GCP professional exams:</p>
<ul>
<li><a target="_blank" href="https://cloud.google.com/certification/cloud-architect">Professional Cloud Architect</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/data-engineer">Professional Data Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/cloud-security-engineer">Professional Cloud Security Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/cloud-network-engineer">Professional Cloud Network Engineer</a></li>
<li><a target="_blank" href="https://cloud.google.com/certification/cloud-developer">Professional Cloud Developer</a></li>
</ul>
<p>In this post, I'll share some information about the exams, my strategies for passing them, as well as a link to the study guides I created along the way. These guides have been battle tested by more than a hundred professionals (so far) who successfully got certified with their help.</p>
<h1 id="heading-about-the-certification-exams">About the certification exams</h1>
<h3 id="heading-professional-cloud-architect">Professional Cloud Architect</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/cloud-architect-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Professional Cloud Architect certification logo</em></p>
<ul>
<li><strong>Length:</strong> 2 hours</li>
<li><strong>Registration fee:</strong> $200 (plus tax where applicable)</li>
<li><strong>Languages:</strong> English, Japanese.</li>
<li><strong>Exam format:</strong> Multiple choice and multiple select, taken remotely or in person at a test enter. <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Exam Delivery Method:</strong><br>• Take the online-proctored exam from a remote location, review the online testing <a target="_blank" href="https://www.webassessor.com/wa.do?page=certInfo&amp;branding=GOOGLECLOUD&amp;tabs=13">requirements</a>.<br>• Take the onsite-proctored exam at a testing center, <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">locate a test center near you</a>.</li>
<li><strong>Prerequisites:</strong> None</li>
<li><strong>Recommended experience:</strong> 3+ years of industry experience including 1+ years designing and managing solutions using GCP.</li>
</ul>
<p><strong>Reference:</strong> <a target="_blank" href="https://cloud.google.com/certification/cloud-architect">https://cloud.google.com/certification/cloud-architect</a></p>
<h3 id="heading-professional-data-engineer">Professional Data Engineer</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/data-engineer-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Professional Data Engineer certification logo</em></p>
<ul>
<li><strong>Length:</strong> 2 hours</li>
<li><strong>Registration fee:</strong> $200 (plus tax where applicable)</li>
<li><strong>Languages:</strong> English, Japanese.</li>
<li><strong>Exam format:</strong> Multiple choice and multiple select taken remotely or in person at a test center. <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Exam Delivery Method:</strong><br>•  Take the online-proctored exam from a remote location, review the online testing <a target="_blank" href="https://www.webassessor.com/wa.do?page=certInfo&amp;branding=GOOGLECLOUD&amp;tabs=13">requirements</a>.<br>• Take the onsite-proctored exam at a testing center, <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Prerequisites:</strong> None</li>
<li><strong>Recommended experience:</strong> 3+ years of industry experience including 1+ years designing and managing solutions using GCP.</li>
</ul>
<p><strong>Reference:</strong> <a target="_blank" href="https://cloud.google.com/certification/data-engineer">https://cloud.google.com/certification/data-engineer</a></p>
<h3 id="heading-professional-cloud-security-engineer">Professional Cloud Security Engineer</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/security-engineer-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Professional Cloud Security Engineer certification logo</em></p>
<ul>
<li><strong>Length:</strong> 2 hours</li>
<li><strong>Registration fee:</strong> $200 (plus tax where applicable)</li>
<li><strong>Languages:</strong> English.<br><strong>Exam format:</strong> Multiple choice and multiple select, taken in person at a test center. <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Prerequisites:</strong> None</li>
<li><strong>Recommended experience:</strong> 3+ years of industry experience including 1+ years designing and managing solutions using GCP.</li>
</ul>
<p><strong>Reference:</strong> <a target="_blank" href="https://cloud.google.com/certification/cloud-security-engineer">https://cloud.google.com/certification/cloud-security-engineer</a></p>
<h3 id="heading-professional-cloud-network-engineer">Professional Cloud Network Engineer</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/network-engineer-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Professional Cloud Network Engineer certification logo</em></p>
<ul>
<li><strong>Length:</strong> 2 hours</li>
<li><strong>Registration fee:</strong> $200 (plus tax where applicable)</li>
<li><strong>Languages:</strong> English.</li>
<li><strong>Exam format:</strong> Multiple choice and multiple select, taken in person at a test center. <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Prerequisites:</strong> None</li>
<li><strong>Recommended experience:</strong> 3+ years of industry experience including 1+ years designing and managing solutions using GCP.</li>
</ul>
<p><strong>Reference:</strong> <a target="_blank" href="https://cloud.google.com/certification/cloud-network-engineer">https://cloud.google.com/certification/cloud-network-engineer</a></p>
<h3 id="heading-professional-cloud-developer">Professional Cloud Developer</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/cloud-developer-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Professional Cloud Developer certification logo</em></p>
<p>Honestly, this one caught me by surprise. Back in December 2019, when I took the exam, <strong>there wasn't anything saying it was in beta</strong>. By that time, this was the information available at the exam page:</p>
<ul>
<li><strong>Length</strong>: 2 hours</li>
<li><strong>Registration fee</strong>: $200 (plus tax where applicable)</li>
<li><strong>Languages</strong>: English, Japanese.</li>
<li><strong>Exam format</strong>: Multiple choice and multiple select, taken in person at a test center. <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Prerequisites</strong>: None</li>
<li><strong>Recommended experience</strong>: 3+ years of industry experience including 1+ years designing and managing solutions using GCP.</li>
</ul>
<p>At the time of this writing, though, the information available on the exam page is very different, as you can see below:</p>
<p>Beta certification exams are newly developed assessments. We gather performance statistics on the questions and use these statistics to create the certification standards for the final exams. If you pass, you are Google Cloud Certified.</p>
<ul>
<li>Save 40% on the cost of certification</li>
<li>Prove early adoption by claiming a low certificate number if you pass</li>
<li>Get exclusive Google-branded apparel</li>
<li>Refer to our <a target="_blank" href="https://cloud.google.com/certification/faqs#1">FAQs</a> for more details</li>
</ul>
<p><strong>Specifics about the beta</strong></p>
<ul>
<li><strong>Length</strong>: 4 hours</li>
<li><strong>Registration fee</strong>: $120 USD (40% discount on retail price of $200 USD) (plus tax where applicable)</li>
<li><strong>Languages</strong>: English.</li>
<li><strong>Exam format</strong>: Multiple choice and multiple select, taken in person at a test center. <a target="_blank" href="https://www.kryteriononline.com/Locate-Test-Center">Locate a test center near you</a>.</li>
<li><strong>Prerequisites</strong>: None</li>
<li><strong>Recommended experience</strong>: 3+ years of industry experience including 1+ years designing and managing solutions using GCP.</li>
<li><strong>Beta exam preparation resources</strong>:  </li>
<li>To take the upcoming beta exam, use <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-developer-2">the revised exam guide</a>.</li>
</ul>
<p><strong>Reference:</strong> <a target="_blank" href="https://cloud.google.com/certification/cloud-developer">https://cloud.google.com/certification/cloud-developer</a></p>
<h2 id="heading-the-preparation-process">The Preparation Process</h2>
<p>Now that you have all the basic information about the exams, it's time to study and get ready to pass them. My preparation process for the five exams I took involved the following steps:</p>
<ol>
<li><p>Read the exam overviews:<br>•  <a target="_blank" href="https://cloud.google.com/certification/cloud-architect">Professional Cloud Architect exam overview</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/data-engineer">Professional Data Engineer exam overview</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/cloud-security-engineer">Professional Cloud Security Engineer exam overview</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/cloud-network-engineer">Professional Cloud Network Engineer exam overview</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/cloud-developer">Professional Cloud Developer exam overview</a>  </p>
</li>
<li><p>Read the exam guides:<br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-architect">Professional Cloud Architect exam guide</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/data-engineer">Professional Data Engineer exam guide</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-security-engineer">Professional Cloud Security Engineer exam guide</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-network-engineer">Professional Cloud Network Engineer exam guide</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-developer">Professional Cloud Developer exam guide</a>  </p>
</li>
<li><p>Next, visit the products page of the platform and identify each product that may be related to the topics listed on the exam guides. For GCP, you can find this list <a target="_blank" href="https://cloud.google.com/products/">here</a>.  </p>
</li>
<li><p>For each of the products identified in the prior step, visit its <strong>Documentation/Concepts</strong> <strong>page</strong> and start reading about each of the concepts that are relevant for the given product. Check the <a target="_blank" href="https://cloud.google.com/compute/docs/concepts">GCE concepts page</a>, for example.  </p>
</li>
<li><p>You’ll probably notice some products seem to overlap with each other, and you might find it difficult to know when to use one or the other. Google Search is your best friend here. :)  </p>
</li>
<li><p>For the <strong>Cloud Architect</strong> exam, after going through each product and its concepts, read the sample study cases provided by Google and try to design potential solutions that could address the requirements described on them.<br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-architect/casestudy-mountkirkgames-rev2">Mountkirk games study case</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-architect/casestudy-dress4win-rev2">Dress4Win study case</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/guides/cloud-architect/casestudy-terramearth-rev2">TerramEarth study case</a>  </p>
</li>
</ol>
<p>For the <strong>Data Engineer</strong> exam, the sample study cases have been recently removed and weren't part of the exam anymore, at least until June 2019.  </p>
<p><strong>All the other exams</strong> didn't make use of sample study cases, as of 2019.  </p>
<ol start="7">
<li><p>Finally, take the practice exams. The practice exams provide an explanation for each of the questions after you finish them. They also help you get an idea of the format of the questions you’ll face on each exam and will help you know how prepared you are.<br>•  <a target="_blank" href="https://cloud.google.com/certification/practice-exam/cloud-architect">Professional Cloud Architect practice exam</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/practice-exam/data-engineer">Professional Data Engineer practice exam</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/practice-exam/cloud-security-engineer">Professional Cloud Security Engineer practice exam</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/practice-exam/cloud-network-engineer">Professional Cloud Network Engineer practice exam</a><br>•  <a target="_blank" href="https://cloud.google.com/certification/practice-exam/cloud-developer">Professional Cloud Developer practice exam</a>  </p>
</li>
<li><p>After finishing the practice exams, take notes of the topics that didn’t go well and re-read the relevant documentation collected on <strong>step 4</strong> above.  </p>
</li>
<li><p>Take the practice exams again (you can take them as many times as you want) and keep <strong>repeating steps from 6 to 8</strong> until you feel confident to take the real exams.</p>
</li>
</ol>
<h1 id="heading-study-guides">Study guides</h1>
<p>From my own experience, I can tell you <strong>it's a lot of work</strong>. For this reason, I decided to <strong>contribute back to the community and share the study guides</strong> I created throughout my preparation process.</p>
<p>The study guides are contained in the spreadsheet linked below, each on a separate tab.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://docs.google.com/spreadsheets/d/1LUtqhOEjUMySCfn3zj8Arhzcmazr3vrPzy7VzJwIshE/edit#gid=0">https://docs.google.com/spreadsheets/d/1LUtqhOEjUMySCfn3zj8Arhzcmazr3vrPzy7VzJwIshE/edit#gid=0</a></div>
<p>To use it, create your own copy. Once you do it, the spreadsheet will be made writable to you and you’ll be able to update the <strong>Status</strong> column, which you’ll help you to track your progress through the material:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/image-43.png" alt="Image" width="600" height="400" loading="lazy">
<em>A screenshot of the spreadsheet with reference material for both professional certification exams.</em></p>
<p>You can freely copy, change and distribute this material. The only thing I kindly ask from you is that you keep a reference to the original material and give me proper credits, if you feel it's helpful.</p>
<p>Even though the Cloud Developer exam is back in beta, I believe the guide I created is still relevant, as it covers a lot of the topics (probably even more than what's needed_.</p>
<h2 id="heading-disclaimer">Disclaimer</h2>
<p>I'm sharing these guides with the only intent of helping people aiming to take the <strong>Google Cloud Professional certification exams</strong>. Be advised there is no guarantee that following the guides will make you pass the exams. Use them at your own discretion.</p>
<h1 id="heading-tips-for-taking-your-exams">Tips for taking your exams</h1>
<ol>
<li>Know what each product does, what it’s good for and what it’s not good for, as well as its billing characteristics.</li>
<li>As you can see above, except for the Cloud Developer exam, which seems to be back in beta, you have <strong>2 hours to finish the exams</strong>. Keep in mind that <strong>good time management is crucial for your success</strong>.</li>
<li><strong>Don’t spend too much time on questions you don’t know</strong>. If you aren’t sure about an answer, mark the question to be reviewed later and move on to the next questions.</li>
<li><strong>Practice as much as possible using the practice exams</strong>.</li>
</ol>
<h1 id="heading-conclusion">Conclusion</h1>
<p>In my opinion, the <strong>greatest </strong>value of a certification<em>**</em> is to help you know which subjects are important to learn as a professional, if you are willing to work with a specific technology. </p>
<p>The <strong>Professional Cloud Security Engineer</strong> certification exam helped me a lot in guiding my studies to learn more about the security aspects of the Google Cloud Platform. It helped me <strong>learn about specific </strong>concerns<em>**</em> we should have when considering or using many of the platform products from a security standpoint.</p>
<p>The Cloud Network Engineer certification was the hardest one I took out of the five. I believe it’s due to the fact my whole career was focused on Software Development so far. </p>
<p>I recognize that, just because I got certified, it <strong>doesn’t mean I am</strong> now <strong>a network specialist</strong> (and, honestly, I don’t really intend to be). As some people say, a certification is just a “piece of paper”, right? On the other hand, I certainly learned a lot during this process and <strong>having some networking skills in my belt certainly makes me a better professional</strong>. </p>
<p>In fact, some of these skills have already helped me solve some infrastructure issues from one of my clients.</p>
<p>Besides all that, certifications are still highly valued by the market and may help you stand out from the crowd.</p>
<p>As a final tip, if you aren't sure which certification you should take first, this is the order I'd recommend (unless you have specific needs related to your job or are strongly focused on a specific area):</p>
<ol>
<li>Professional Cloud Architect</li>
<li>Professional Cloud Security Engineer</li>
<li>Professional Data Engineer</li>
<li>Professional Cloud Network Engineer</li>
<li>Professional Cloud Developer (because it's back in beta, otherwise it would probably be number 3 in this list)</li>
</ol>
<p>I hope this article and the referenced study guides help you in your journey to become a <strong>Google Cloud certified professional</strong> and I <strong>wish you all the success</strong> in your career!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-168.png" alt="Image" width="600" height="400" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/@mahdigp?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Mahdi Dastmard / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm<em>campaign=api-credit)</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to use Google Cloud Tasks in Laravel PHP ]]>
                </title>
                <description>
                    <![CDATA[ By Errol Fernandes Deploying a Laravel application on Google App Engine is a fairly easy task thanks to the documentation available. But setting up asynchronous task processing (Laravel Eventing) on Google Cloud effectively is not that simple. One of... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/using-google-cloud-tasks-in-laravel-php-24985db107b/</link>
                <guid isPermaLink="false">66c36466da3c91501890b9d7</guid>
                
                    <category>
                        <![CDATA[ google app engine ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 22 Feb 2019 11:10:14 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*pGJLCV_d77eyLshIDIVCdQ.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Errol Fernandes</p>
<p>Deploying a Laravel application on Google App Engine is a fairly easy task thanks to the documentation available. But setting up asynchronous task processing (Laravel Eventing) on Google Cloud effectively is not that simple.</p>
<p>One of the ways we can do this is by using the supervisord.conf file to set up the Laravel <code>queue:listen</code> command. But this is only available for Google App Engine Flexible Environment. So if you need a solution for Google App Engine Standard Environment, then you need to use Google Cloud Tasks to process async jobs.</p>
<p>Google Cloud Tasks is a fully managed service that allows you to manage the execution, dispatch, and delivery of a large number of distributed tasks. Using Cloud Tasks, you can perform work asynchronously outside of a user or service-to-service request.</p>
<p><strong>Step 1:</strong></p>
<p>Create a task queue to handle the tasks. Here we use the queue.yaml file to specify the configuration of the queue to be created in Google Cloud. The target parameter contains the name of the application deployed on app engine.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/cqgEZ5IU7zeQ-NiFA60HC4AHlIbvjJyzcVn1" alt="Image" width="800" height="104" loading="lazy"></p>
<p><strong>Step 2:</strong></p>
<p>Deploy the queue.yaml file in Google Cloud using the command <code>gcloud app deploy queue.yaml</code> The below image is of a Google Task queue created in Google Cloud.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/pLbVCTFBu-PMu1MOQrKXJqlczqPonw2d456T" alt="Image" width="800" height="161" loading="lazy"></p>
<p><strong>Step 3:</strong></p>
<p>We need to pass the route of the API and the payload object for the task. In the below example, we will pass the required data to an <code>initTask()</code> function:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Bu9p27rXvAA4sHalnZHVrvgSrkMaWXSH6SAQ" alt="Image" width="800" height="106" loading="lazy"></p>
<p><strong>Step 4:</strong></p>
<p>Create the initTask() function:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/9oBdKkfhFjJbbCEB0nuSBr9w3yOp89N1zfIH" alt="Image" width="800" height="161" loading="lazy"></p>
<p>We pass the userID of the current user in the payload for authentication reasons. Now that the payload is ready, we pass all the required details to the task builder function</p>
<p><strong>Step 5:</strong></p>
<p>Create the create_task() method. This method will use the Google API to build a Cloud Task and pass it to the task queue. The gAppCreds.json file is the Google Service Account created for defining the roles of the application.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/VCBtOQ8jdrE-Xp9bVZP8Ec9jkZJkjbRmVDi5" alt="Image" width="800" height="557" loading="lazy"></p>
<p><strong>Step 6:</strong></p>
<p>Now we create the API routes using the RouteServiceProvider in api.php:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3ELikvkitL6Oyv9u-jB-7IkdEck1xM-3o3xL" alt="Image" width="800" height="222" loading="lazy"></p>
<p><strong>Step 7:</strong></p>
<p>Now we create a TaskController which will route the different API to the specific function. So in the below example we create an <code>associateApp()</code> function:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/N9zDssAevMKOPAljdNo6Kk9rD7xV1oHhOU6-" alt="Image" width="800" height="165" loading="lazy"></p>
<p>In the above function, we json_decode the payload that we sent in <strong>Step 4</strong> and pass it to the respective event for processing. The userID that we passed in <strong>Step 4</strong> is used to validate the authenticity of the incoming API request.</p>
<h4 id="heading-final-verdict">Final Verdict:</h4>
<p>Normally in Laravel, we call the event from the respective controller directly. But for using Google cloud tasks, we create a Task API which in turn calls the route that in turn calls the event to process our data. So in short we create multiple APIs for our Laravel events and jobs which are then called (<strong>by Google Task API</strong>) based on the route that you pass in <strong>Step 3</strong> and <strong>Step 6</strong>.</p>
<p>Since I am using Google Cloud Tasks, I don’t need to worry about the supervisor or managing the jobs in the queue table, as everything is taken care by the Google Task Queue. All I have to do is monitor the Task Queue if there is any failed task.</p>
<p>Using Google Cloud API, I can create multiple queues for different target applications I deploy on Google App Engine irrespective of whether the environment is Standard or Flexible.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to secure and manage secrets using Google Cloud KMS ]]>
                </title>
                <description>
                    <![CDATA[ By Ramesh Lingappa Let’s jump right in. We all know it’s a bad idea to store application secrets within our code. So why we are storing there it still? Let’s take an example. We could store those secrets in a file and add it to the gitignore so it’s ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/securing-managing-secrets-using-google-cloud-kms-3fe08c69f499/</link>
                <guid isPermaLink="false">66c35e67e4cb1ff6521c823a</guid>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 07 Jan 2019 22:22:23 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*_Cf1p5h7nfoNfo4wNswuNw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ramesh Lingappa</p>
<p>Let’s jump right in. We all know it’s a bad idea to store application secrets within our code. So why we are storing there it still? Let’s take an example.</p>
<p>We could store those secrets in a file and add it to the <strong>gitignore</strong> so it’s not added to version control. But there are a couple of hurdles:</p>
<ul>
<li>How do we manage those secrets?</li>
<li>What happens when the local copy is deleted?</li>
<li>How do we share it with other developers?</li>
<li>How do we manage versioning of those secrets during changes and an audit log of who changed what?</li>
</ul>
<p>A lot of questions! So we end up storing it within the code, since it’s too much complexity to deal with.</p>
<p>For a big application or application which needs a higher level of security, we can use Production grade secret management services like <a target="_blank" href="https://www.vaultproject.io/">Hashicorp Vault</a>.</p>
<p>In this article, we will look at a decent approach in dealing with secrets while still achieving better security. We are going to achieve this using <strong>Google KMS + Git + IAM+ automation.</strong></p>
<p>The idea is not new. This is what we are going to do:</p>
<ul>
<li>We are going to store the encrypted version of plaintext in version control using Google KMS</li>
<li>We will use KMS IAM to allow appropriate users to manage secrets for each environment by granting encrypt/decrypt roles</li>
<li>We’ll deploy the application with encrypted secret files</li>
<li>We will allow permission for the server to decrypt secrets for each environment</li>
<li>At runtime, we’ll load encrypted files, decrypt using KMS APIs and use it.</li>
</ul>
<blockquote>
<p><a target="_blank" href="https://cloud.google.com/kms"><strong><em>Cloud KMS</em></strong></a> <em>is a <strong>cloud-hosted key management service</strong> that lets you manage cryptographic keys for your cloud services. You can generate, use, rotate, and destroy cryptographic keys. Cloud KMS is integrated with Cloud IAM and Cloud Audit Logging so that you can manage permissions on individual keys and monitor how these are used.</em></p>
</blockquote>
<p>So Cloud KMS will encrypt and decrypt our secrets so we don’t have to store the keys. Only an authorised <strong>user</strong> or <strong>a service account</strong> can perform encrypt or decrypt operations.</p>
<p>Let’s get started!</p>
<h3 id="heading-step1-preparing-secrets">Step1: Preparing Secrets</h3>
<p>For our use-case, we are going to have application secrets for each environment, <code>prod</code> <code>stag</code> and <code>dev</code> . We do so by creating a new folder called <code>credentials</code> under the root project folder and then create one folder for each environment.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*19_SnZ3De1o9XGv34P-oQg.png" alt="Image" width="288" height="147" loading="lazy">
<em>credentials per each environment</em></p>
<p>Make sure this folder is not tracked under version control by adding the following line in the <code>.gitignore</code> file:</p>
<pre><code>/credentials/
</code></pre><p>Here I am using a <strong>properties</strong> file, but it could be anything like JSON, YAML etc. Now you can add any sensitive information in these files. I have added the following:</p>
<pre><code># dev credentialsoauth_client_id=<span class="hljs-number">1234</span>oauth_client_secret=abcdapi_key=api_123# ...
</code></pre><p>Okay, our secrets are ready for hiding.</p>
<h3 id="heading-step2-creating-kms-secret-keys">Step2: Creating KMS Secret Keys</h3>
<p>We need to create encryption keys for each environment in order to use this service. For us, each environment will be a different google cloud project (recommended). It’s better this way since it gives isolation and access control (more on this later).</p>
<p>So go ahead and create a key for each environment using this link <a target="_blank" href="https://cloud.google.com/kms/docs/creating-keys#kms-create-keyring-console"><strong>Creating Symmetric Keys(recommended)</strong></a>. It has step by step instructions (different ways) to create those keys. We are creating those keys using the command line like below:</p>
<pre><code><span class="hljs-comment">// create key-ring (think of this as grouping)gcloud kms keyrings create [KEYRING_NAME] \--location [LOCATION] \--project live-project-id</span>
</code></pre><pre><code><span class="hljs-comment">// create the encryption keygcloud kms keys create [KEY_NAME] \--location [LOCATION] \--keyring [KEYRING_NAME] \--purpose encryption \--project live-project-id</span>
</code></pre><p>Here I am creating a key for production using the production project id. Repeat this process for each environment by replacing the <strong>Project ID</strong> for <em>stag and other environments</em><strong>.</strong></p>
<p><strong>Note</strong>: You need to have four pieces of information for each key: <code>location</code> <code>keyring</code> <code>cryptokey</code> and <code>project</code>. This information is not sensitive so you can store it in your code or build scripts</p>
<h3 id="heading-step3-assigning-permission-to-use-these-keys">Step3: Assigning Permission to use these keys</h3>
<p>Here comes the beauty of the KMS IAM system: in order to use each key, we need to explicitly grant access for an individual user or a service account. This makes it very powerful since now we can define who can manage secrets, who can view those secrets, and more.</p>
<p>Check out <a target="_blank" href="https://cloud.google.com/kms/docs/iam">Using IAM with Cloud KMS</a> for more information. With this, we can achieve the following:</p>
<h4 id="heading-production-environment"><strong>Production Environment:</strong></h4>
<p>No one should be able to see the secrets except the few people who can make changes to secrets. We can do so by granting them the role:</p>
<pre><code>cloudkms.cryptoKeyEncrypterDecrypter
</code></pre><p>So in this way, even though the encrypted credentials are stored in version control, other developers won't be able to use them. Note, even those developers can make live deployments without ever needing to know the secrets (more on this later).</p>
<h4 id="heading-staging-environment"><strong>Staging Environment:</strong></h4>
<p>Every developer can see the secrets and use them in development, but only a few people can make changes to secrets. We can do so by granting them the role:</p>
<pre><code><span class="hljs-comment">// for read onlycloudkms.cryptoKeyDecrypter</span>
</code></pre><pre><code><span class="hljs-comment">// for managingcloudkms.cryptoKeyEncrypterDecrypter</span>
</code></pre><p>Likewise, you can grant key roles for different environments depending on the need. For the exact commands, refer to <a target="_blank" href="https://cloud.google.com/kms/docs/iam#granting_permissions_to_use_keys">Granting Permission</a> in the docs.</p>
<h3 id="heading-step4-encrypting-secrets">Step4: Encrypting Secrets</h3>
<p>We are done with prep work, and now it’s time to hide some secrets. Assuming you have the <em>encrypter</em> role, with that you can encrypt a file using the following command:</p>
<pre><code>gcloud kms encrypt --location <span class="hljs-built_in">global</span> \  --keyring secrets-key-ring --key quickstart \  --plaintext-file credentials/stag/credentials.properties \  --ciphertext-file credentials-encrypted/stag/credentials.properties.encrypted
</code></pre><p>Since it’s a shell gcloud command, you can easily integrate it with any build system to encrypt all files under the <strong>credentials</strong> folder. For example, I am using <strong>gradle</strong> for this:</p>
<p>Basically, there are two helper functions:</p>
<ul>
<li><strong>kmsEncryptSecrets</strong> takes the <strong>src folder</strong> to encrypt each file within it and write it to the <strong>target folder</strong> with <strong>.enc</strong> (encrypted) extension, and</li>
<li><strong>kmsDecryptSecrets</strong> which does the reverse process.</li>
</ul>
<p>So each time we modify secrets, you can call the encrypt helper method with a simple task:</p>
<p>Now the encrypted folder will look like below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*fNdCMqpw8-uVglH_mIfHHQ.png" alt="Image" width="281" height="108" loading="lazy">
<em>encrypted credential files</em></p>
<p>This folder can be added to version control so each time an authorised user changes secrets, a new encrypted file is generated and logs the history in version control.</p>
<p>Similarly, there is a <a target="_blank" href="https://gist.github.com/ramesh-dev/3ba47732591c4b9e1bae7b99ed2b67a9">Decrypt Task</a> for the reverse process.</p>
<h3 id="heading-step4-using-encrypted-secrets-in-deployment">Step4: Using Encrypted Secrets in deployment</h3>
<p>Now that we are done encrypting secrets and properly managing them in version control, let's look at how it can be used at runtime, meaning when the app is actually running in staging or production. We can do that in two ways:</p>
<h4 id="heading-1-decrypting-secrets-and-passing-during-deployment"><strong>1. Decrypting secrets and passing during deployment:</strong></h4>
<p>So during deployment, an authorised user can simply decrypt those encrypted secrets and add it to the deployment (eg: build directory), thus making it available for the code at runtime. We are not going to cover this deeply.</p>
<blockquote>
<p><em>This approach is good when <strong>deployer</strong> needed to be very restrictive or process is automated using CD pipeline.</em></p>
</blockquote>
<h4 id="heading-2-passing-encrypted-secrets-during-deployment-and-decrypting-at-runtime"><strong>2. Passing encrypted secrets during deployment and decrypting at runtime:</strong></h4>
<p>Here we are not going to decrypt and send raw secrets during deployment. Instead, we are simply passing encrypted secrets. And during runtime we will decrypt those secrets and use them.</p>
<p><strong>Note:</strong> this works best within the Google Cloud Platform. Otherwise you need to generate a service account so you can use this approach with external providers.</p>
<p>This approach is even more secure since we are not relying on any intermediate user action or a pipeline, but instead only on authorised servers that can decrypt content at runtime.</p>
<p>For example, we can allow the staging server (service account) the ability to decrypt staging secrets and not the ability to decrypt production secrets.</p>
<blockquote>
<p><em>With this approach, even any developer who doesn’t have access to decrypt production secrets can able to perform production deployment and everything still works fine.</em></p>
</blockquote>
<h3 id="heading-step-5-using-secrets-at-runtime">Step 5: Using secrets at runtime</h3>
<p>We are going to use the second approach (passing encrypted secrets).</p>
<p>For the demo, assume we are going to deploy to <strong>AppEngine</strong> since it has a default service account generated already. We will grant it the access to decrypt secrets like below:</p>
<pre><code>gcloud kms keys add-iam-policy-binding secrets-enc-key \ --project kms-demo \--location <span class="hljs-built_in">global</span> \--keyring secrets-key-ring \--member serviceAccount:kms-demo@appspot.gserviceaccount.com \--project kms-demo \--role roles/cloudkms.cryptoKeyDecrypter
</code></pre><p>Thus when the server starts, we could simply load the encrypted file and use the <a target="_blank" href="https://cloud.google.com/kms/docs/reference/libraries">KMS client libraries</a> to decrypt its content.</p>
<h3 id="heading-step6-kms-audit-logshttpscloudgooglecomkmsdocslogging">Step6: <a target="_blank" href="https://cloud.google.com/kms/docs/logging">KMS Audit Logs</a></h3>
<p>Finally, you can see audit logs for operations on each key by enabling KMS audit logging (not enabled by default). Thus we can now keep track of all operations performed for future auditing.</p>
<p>You can enable the audit log using gcloud, but we have seen enough of the command line way. Alternatively, we can enable this configuration using the Cloud Console UI. From the left menu, choose <strong>IAM &amp; admin -&gt; Audit Lo</strong>gs.</p>
<p>Click <strong>Cloud Key Management Service</strong> and enable <strong>Data Read</strong> and <strong>Data Write</strong> and hit Save.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*8FblhXekEI-E0hmmKGQEqA.png" alt="Image" width="800" height="441" loading="lazy">
<em>Google IAM Audit Log Console</em></p>
<p>That's it! Now if any encrypt, decrypt or any other sorts of operations are performed, an audit log is generated and you can check those in the Logging section under <strong><em>Cloud KMS CryptoKey.</em></strong></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*X2F511jz2h5VoX5v0N6SNg.png" alt="Image" width="800" height="275" loading="lazy">
<em>Audit Logs for IAM operations</em></p>
<p>As you can see, it has audit logs for all sorts of operations including failures like Invalid permissions, or requests etc. It shows which user performed what operation using which key (or if it was done under a service account). That's a pretty neat solution. For more info, read <a target="_blank" href="https://cloud.google.com/kms/docs/logging">Using Cloud Audit Logging with Cloud KMS</a>.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>With this approach, we can store, manage and use application secrets or any sensitive information securely and also track changes using version control. The techniques discussed in this article can be used with any language, and it can use used fully or partially in other platforms as well like iOS, Android, external servers etc.</p>
<p>For a list of kms commands, refer to <a target="_blank" href="https://gist.github.com/ramesh-dev/5042ef29946f570c906a082ec67cb5dc">KMS Commands</a>. Also, check out the sample application for the complete code:</p>
<p><a target="_blank" href="https://github.com/ramesh-dev/gae-dynamic-config-demo/tree/kms_demo"><strong>ramesh-dev/gae-dynamic-config-demo</strong></a><br><a target="_blank" href="https://github.com/ramesh-dev/gae-dynamic-config-demo/tree/kms_demo">_AppEngine Dynamic Configuration Demo. Contribute to ramesh-dev/gae-dynamic-config-demo development by creating an…_github.com</a></p>
<p>Here are some reference links:</p>
<ul>
<li><a target="_blank" href="https://cloud.google.com/kms/">Google Cloud KMS</a></li>
<li><a target="_blank" href="https://cloud.google.com/kms/docs/creating-keys#kms-create-keyring-console">Creating Symmetric Keys in KMS</a></li>
<li><a target="_blank" href="https://cloud.google.com/kms/docs/quickstart">Google Cloud KMS Quick Start</a></li>
<li><a target="_blank" href="https://cloud.google.com/kms/docs/iam">Using IAM with Cloud KMS</a></li>
<li><a target="_blank" href="https://medium.com/swlh/dynamic-appengine-configurations-using-gradle-part-2-49a30eb87672">Dynamic AppEngine Configurations using Gradle Part 2</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The voice memo’s BFF — how to make Speech2Text easy with Machine Learning ]]>
                </title>
                <description>
                    <![CDATA[ By Rafael Belchior Do you think recording voice memos is inconvenient because you have to transcribe them? Do you waste your precious voice memos because you never write them down? Do you feel like you are not unlocking the full potential of what you... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-voice-memos-bff-speech-to-text-powered-by-machine-learning-1dbc7a6c65f1/</link>
                <guid isPermaLink="false">66c362d41a1cf73cbc81f136</guid>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ writing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 19 Dec 2018 17:07:43 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*9NU-RPt9yreyuqqOLQKQYA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Rafael Belchior</p>
<p>Do you think recording voice memos is inconvenient because you have to transcribe them? Do you waste your precious voice memos because you never write them down? Do you feel like you are not unlocking the full potential of what you record?</p>
<p>Yeah, that sucks. ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Ldug-95Ai5jva-tYYx4uQTcqzRj7bAFHqdsa" alt="Image" width="800" height="473" loading="lazy">
<em>Write, write, write.</em></p>
<p>I’m a Computer Science masters student. As I think that all work and no play makes me a dull boy, I’ve decided to invest some time in doing something different. Where? In the <a target="_blank" href="http://www.gce-neiist.org">student’s group to which I belong</a>, <a target="_blank" href="http://www.gce-neiist.org/articles">by interviewing a professor.</a></p>
<p>I’ve talked to professor Rui Henriques, a teacher assistant @ Técnico Lisboa and researcher @ INESC-ID. He is an expert in Data Mining and Bioinformatics. The 20 minutes interview turned into almost a full hour conversation.</p>
<p>Rui is not only a brilliant academic but also a very honest, cheerful and easy going person, which made it very easy. I learned a lot while talking to him, and I’m sure you also can. The interview will be online soon enough. ?</p>
<p>Anyway, I had a problem and a need. I wanted to save time by not having to transcribe the whole interview. The idea was to invest only twenty to sixty minutes in order to skyrocket performance when it comes to transcribing. This is not limited to interviews, of course. You can transcribe audio notes taken from several sources like classes, writing notes, thoughts, your shopping list, or your most philosophical pieces.</p>
<h3 id="heading-so-how-do-we-do-that">So, how do we do that?</h3>
<p>I’m also lecturing on <a target="_blank" href="https://fenix.tecnico.ulisboa.pt/disciplinas/AGISIT/2018-2019/1-semestre"><em>It Infrastructure Management and Administration</em></a> <em>@ <a target="_blank" href="https://tecnico.ulisboa.pt/en/">Técnico Lisboa</a>.</em> In classes, we have used Google Cloud Engine. I remembered a service called <a target="_blank" href="https://cloud.google.com/speech-to-text/´">Google Speech-To-Text</a>, which we could use in this case. And no, <a target="_blank" href="https://www.freecodecamp.org/news/the-voice-memos-bff-speech-to-text-powered-by-machine-learning-1dbc7a6c65f1/undefined">Google</a> is not paying me to write this ?</p>
<p>So, how to turn an interview of 55 minutes into easily editable text? How to reduce our efforts and focus on what matters? ?</p>
<p>? By the way, to make the most out of this method, please cut noise and try to record with a loud, clear voice. ?</p>
<h3 id="heading-step-1-installing-the-required-software">Step 1: Installing the required software</h3>
<p>I use Vagrant to manage virtual machines. The advantage is that to use the environment you need to instantiate the Speech-To-Text service. <a target="_blank" href="https://hackernoon.com/devops101-vagrant-6737c8c29904">In this article, I show step by step how to configure these tools</a> (read it up to the section “The Experiment”). If you prefer to do this on your local machine, go directly to the third step.</p>
<h3 id="heading-step-2-start-the-virtual-machine">Step 2: Start the virtual machine</h3>
<p>Now, open your console and run:</p>
<pre><code>$ vagrant up --provision &amp;&amp; vagrant ssh
</code></pre><p>The virtual machine is booting, installing all the required dependencies. This may take a while.</p>
<p>Wait a bit. Done. Nice. Kudos to you ?</p>
<h3 id="heading-step-3-getting-the-support-files">Step 3: Getting the support files</h3>
<p><a target="_blank" href="https://github.com/RafaelAPB/gce-speech2text">Fork this repository containing the support files</a> and then clone it to your computer. Put it in the folder that is being synced with your guest machine.</p>
<h3 id="heading-step-4-creating-an-account-at-google-cloud-engine">Step 4: Creating an account at Google Cloud Engine</h3>
<p>You can <a target="_blank" href="https://cloud.google.com/free/">require a free grant ($300)</a> for this experiment ? After creating the account, go to G<a target="_blank" href="https://goo.gl/jo2qQL">oogle Console.</a> Create a project. You can name it “easy-interview” if you are confident enough. You should see something like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/bjkBeRT3UGJIqilASbqpnwHS5amzLE4D5thc" alt="Image" width="800" height="344" loading="lazy"></p>
<p>After that, go to “APIs &amp; Services”, in order to activate the API we need to get the job done.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/6zhTG1GyeUS59a7hg5lCPUgytLIB6wr0Dky3" alt="Image" width="800" height="347" loading="lazy"></p>
<p>Click on “Create Credentials”. Choose “Cloud Speech API”. On “Are you planning to use this API with App Engine or Compute Engine?” say “No”. On step 2, “Create a service account” name the service “transcribing”. The role is Project =&gt; Owner. Key type: JSON.</p>
<p>By now, you should have downloaded a file called “file.txt”. It contains the credentials you need to use the service. Rename the file to “terraform-credentials.json”. Copy it to the folder containing the support files. As that folder is synced with your virtual machine, you will have access to those files from the guest machine. Now, run:</p>
<pre><code>$ gcloud auth login
</code></pre><p>Follow the instructions. Authenticate yourself following the link that is shown. Now, analyze the request.json file:</p>
<pre><code>{  <span class="hljs-string">"config"</span>: {      <span class="hljs-string">"encoding"</span>:<span class="hljs-string">"FLAC"</span>,      <span class="hljs-string">"sampleRateHertz"</span>: <span class="hljs-number">16000</span>,      <span class="hljs-string">"languageCode"</span>: <span class="hljs-string">"en-US"</span>,      <span class="hljs-string">"enableWordTimeOffsets"</span>: <span class="hljs-literal">false</span>  },  <span class="hljs-string">"audio"</span>: {      <span class="hljs-string">"uri"</span>:<span class="hljs-string">"gs://cloud-samples-tests/speech/brooklyn.flac"</span>  }}
</code></pre><p>Make sure to tune the parameters to fit your case. Beware that there are limitations on the encoding that you can use. If your file is in a different format than <em>flac</em> or <em>wav</em>, you will need to convert it. You can convert audio files with <a target="_blank" href="https://www.audacityteam.org/">Audacity</a>, a free, open-source audio software. After converting the audio, you have to upload it to Google Storage. For that, <a target="_blank" href="https://console.cloud.google.com/storage/">you have to create a bucket</a>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3TefQe9BJtLH7UJrI87F2cgaAIA2f3mSBabD" alt="Image" width="800" height="346" loading="lazy"></p>
<p>The settings may be:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/s3XAjTQlz1H3VEQLaWnM9Xw1fFBwQb3kgq5H" alt="Image" width="800" height="344" loading="lazy"></p>
<p>After that, upload your file to the bucket. On the Bucket menu, you should be able to access the URI associated with your file. The format is <em>gs://BUCKET/FILE.EXTENSION</em>. Take that URI and replace it on the file <em>my-request.json</em>.</p>
<p>Your file should look something like this:</p>
<pre><code>{  <span class="hljs-string">"config"</span>: {      <span class="hljs-string">"encoding"</span>:<span class="hljs-string">"FLAC"</span>,      <span class="hljs-string">"sampleRateHertz"</span>: <span class="hljs-number">16000</span>,      <span class="hljs-string">"languageCode"</span>: <span class="hljs-string">"pt-PT"</span>,      <span class="hljs-string">"enableWordTimeOffsets"</span>: <span class="hljs-literal">false</span>  },  <span class="hljs-string">"audio"</span>: {      <span class="hljs-string">"uri"</span>:<span class="hljs-string">"gs://easy-interview/interview.flac"</span>  }}
</code></pre><p>Before we use the API, we need to load the credentials. Run the script load-credentials.sh to load them:</p>
<pre><code>$ source load-credentials.sh
</code></pre><p>This has set the GOOGLE_APPLICATION_CREDENTIAL environment variable. Next, to test if the connection is successful, run:</p>
<pre><code>$ curl -s -H <span class="hljs-string">"Content-Type: application/json"</span> \    -H <span class="hljs-string">"Authorization: Bearer "</span>$(gcloud auth application-<span class="hljs-keyword">default</span> print-access-token) \    https:<span class="hljs-comment">//speech.googleapis.com/v1/speech:recognize \    -d @test-request.json</span>
</code></pre><p>You should be able to see a response with some transcribed text. Note that we ran <em>test-request.json,</em> which is just for testing purposes. Now, to make the call with your data, run:</p>
<pre><code>$ curl -s -H <span class="hljs-string">"Content-Type: application/json"</span> \    -H <span class="hljs-string">"Authorization: Bearer "</span>$(gcloud auth application-<span class="hljs-keyword">default</span> print-access-token) \    https:<span class="hljs-comment">//speech.googleapis.com/v1/speech:longrunningrecognize \    -d @my-request.json &gt;&gt; name.out</span>
</code></pre><p>If you run <em>more name.out,</em> you will see that the response contains a field called name. That name corresponds to the operation name that was created to meet the request. Now you have to wait a bit until the operation completes. Run (replace NAME with your operation’s name):</p>
<pre><code>$ curl -H <span class="hljs-string">"Authorization: Bearer "</span>$(gcloud auth application-<span class="hljs-keyword">default</span> print-access-token) \     -H <span class="hljs-string">"Content-Type: application/json; charset=utf-8"</span> \     <span class="hljs-string">"https://speech.googleapis.com/v1/operations/NAME"</span> &gt;&gt; result.out
</code></pre><p>While the operation doesn’t finish, your <em>result.out</em> will have a content similar to this:</p>
<p>{<br> “name”: “8254262642733152416”,<br> “metadata”: {<br> “<a target="_blank" href="http://twitter.com/type">@type</a>”: “type.googleapis.com/google.cloud.speech.v1.LongRunningRecognizeMetadata”,<br> “progressPercent”: 33,<br> “startTime”: “2018–12–08T01:15:08.969852Z”,<br> “lastUpdateTime”: “2018–12–08T01:19:25.105683Z”<br> }<br>}</p>
<p>For a 60mb file, encoded with <em>flac</em> , it took about 12 minutes. You will have a file called <em>results.out</em> with your precious content. It will be in your host machine as well. I’ve written a very simple Python script that parses <em>results.out.</em> The script redirects the output to a file named <em>results-parsed.out</em>. To execute it, run:</p>
<pre><code>$ python parse.py
</code></pre><p>If you don’t like the results, tune the parameters and try again.</p>
<p>Enjoy your content! You are done ? To finish this experiment, exit the machine:</p>
<pre><code>$ gcemgmt: exit
</code></pre><p>Now, stop the virtual machine:</p>
<pre><code>$ vagrant halt
</code></pre><p><strong>Don’t forget to delete the files that you uploaded to Google Cloud.</strong></p>
<p>Well done!?</p>
<p>Well, this took me several hours to write, but at least I didn’t have to transcribe the whole interview. ?</p>
<h3 id="heading-bottomline">Bottomline</h3>
<p>Firstly, I would ❤️to hear your opinion! Do you record lots of voice memos? Do you find this procedure useful? Do you have a different one?</p>
<p>If you <strong>liked this article</strong>, please click the ? button on the left. D<strong>o you have a friend or family member that would benefit from this solution? Share this article!</strong></p>
<p><em>Keep Rocking</em> ?</p>
<p>Entrepreneurship <a target="_blank" href="https://emojipedia.org/fire/">?</a></p>
<p><a target="_blank" href="https://blog.startuppulse.net/top-8-lessons-ive-learned-in-european-innovation-academy-2017-50eeb82d74b4"><strong>Top 8 lessons I’ve learned in European Innovation Academy 2017</strong></a><br><a target="_blank" href="https://blog.startuppulse.net/top-8-lessons-ive-learned-in-european-innovation-academy-2017-50eeb82d74b4">_Imagine you are seeing the opportunity to improve yourself at every level. Would you take it?_blog.startuppulse.net</a></p>
<p><strong>DevOps101</strong> ☄️</p>
<p><a target="_blank" href="https://hackernoon.com/devops101-vagrant-6737c8c29904"><strong>DevOps101 — Improve Your Workflow! First Steps on Vagrant</strong></a><br><a target="_blank" href="https://hackernoon.com/devops101-vagrant-6737c8c29904">_And make clients and developers happier._hackernoon.com</a><a target="_blank" href="https://hackernoon.com/devops101-itinfrastructure-54337d6a148b"><strong>DevOps101 — Infrastructure as Code With Vagrant</strong></a><br><a target="_blank" href="https://hackernoon.com/devops101-itinfrastructure-54337d6a148b">_And deploying a simple IT infrastructure (Two LAMP web servers and a client machine)._hackernoon.com</a></p>
<p>Blockchain For Students ⛓️</p>
<p><a target="_blank" href="https://hackernoon.com/blockchain-for-students-101-the-basics-part-1-f39b8201a7d5"><strong>Blockchain For Students 101 -The Basics (Part 1)</strong></a><br><a target="_blank" href="https://hackernoon.com/blockchain-for-students-101-the-basics-part-1-f39b8201a7d5">_Are you ready to dig deep into this life-changing technology?_hackernoon.com</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to set up JHipster microservices with Istio service mesh on Kubernetes ]]>
                </title>
                <description>
                    <![CDATA[ By Deepu K Sasidharan You can find a more up to date version of this post that uses JHipster 6 and latest Istio & Kubernetes versions here. Istio is the coolest kid on the DevOps and Cloud block now. For those of you who aren’t following close enoug... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/jhipster-microservices-with-istio-service-mesh-on-kubernetes-a7d0158ba9a3/</link>
                <guid isPermaLink="false">66c3593ac5e11f7a9c406844</guid>
                
                    <category>
                        <![CDATA[ Azure ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Kubernetes ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Productivity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 17 Nov 2018 16:01:37 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*sed7vszGYvi40oa1F7iVzg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Deepu K Sasidharan</p>
<p>You can find a more up to date version of this post that uses JHipster 6 and latest Istio &amp; Kubernetes versions <a target="_blank" href="https://dev.to/deepu105/how-to-set-up-java-microservices-with-istio-service-mesh-on-kubernetes-5bkn">here</a>.</p>
<hr>
<p>Istio is the coolest kid on the DevOps and Cloud block now. For those of you who aren’t following close enough — <a target="_blank" href="https://istio.io/docs/concepts/what-is-istio/">Istio is a service mesh</a> for distributed application architectures, especially the ones that you run on the cloud with Kubernetes. Istio plays extremely nice with Kubernetes, so nice that you might think that it’s part of Kubernetes.</p>
<p>If you are still wondering, what the heck is a service mesh or Istio? then let's have an overview of Istio.</p>
<p>Istio provides the following functionality in a distributed application architecture:</p>
<ul>
<li>Service discovery — Traditionally provided by platforms like <a target="_blank" href="https://github.com/Netflix/eureka/wiki">Netflix Eureka</a> or <a target="_blank" href="https://www.consul.io/">Consul</a>.</li>
<li>Automatic load balancing — You might have used <a target="_blank" href="https://github.com/Netflix/zuul/wiki">Netflix Zuul</a> for this.</li>
<li>Routing, circuit breaking, retries, fail-overs, fault injection — Think of <a target="_blank" href="https://github.com/Netflix/ribbon/wiki">Netflix Ribbon</a>, <a target="_blank" href="https://github.com/Netflix/Hystrix">Hytrix</a> and so on.</li>
<li>Policy enforcement for access control, rate limiting, A/B testing, traffic splits, and quotas — Again you might have used Zuul to do some of these.</li>
<li>Metrics, logs, and traces — Think of <a target="_blank" href="https://www.elastic.co/elk-stack">ELK</a> or <a target="_blank" href="https://cloud.google.com/stackdriver/">Stack driver</a></li>
<li>Secure service-to-service communication</li>
</ul>
<p>Below is the architecture of Istio.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*_STCerKXb4L3Hutyn4P5Gw.png" alt="Image" width="800" height="282" loading="lazy">
<em>Istio architecture</em></p>
<p>It can be classified into 2 distinct planes.</p>
<p><strong>Data plane</strong>: Is made of <a target="_blank" href="https://www.envoyproxy.io/">Envoy</a> proxies deployed as sidecars to the application containers. They control all the incoming and outgoing traffic to the container.</p>
<p><strong>Control plane</strong>: It uses Pilot to manages and configure the proxies to route traffic. It also configures Mixer to enforce policies and to collect telemetry. It also has other components like Citadel, to manage security, and Galley, to manage configurations.</p>
<p>Istio also configures an instance of <a target="_blank" href="https://grafana.com/">Grafana</a>, <a target="_blank" href="https://prometheus.io/">Prometheus</a> and <a target="_blank" href="https://www.jaegertracing.io/">Jaeger</a> for Monitoring and Observability. You can use this or use your existing monitoring stack as well.</p>
<p>I hope this provides an overview of Istio, now let's focus on the goal of this article.</p>
<h3 id="heading-devoxx-2018">Devoxx 2018</h3>
<p>I did a talk at <a target="_blank" href="https://dvbe18.confinabox.com/talk/XCM-6395/JHipster_5_-_What's_new_and_noteworthy">Devoxx 2018</a> along with <a target="_blank" href="https://www.julien-dubois.com/">Julien Dubois</a> doing the same demo and promised that I’d write a detailed blog about it.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/deepu105/status/1063010906777497600?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed&amp;ref_url=https%3A%2F%2Fcdn.embedly.com%2Fwidgets%2Fmedia.html%3Ftype%3Dtext%252Fhtml%26key%3Da19fcc184b9711e1b4764040d3dc5c07%26schema%3Dtwitter%26url%3Dhttps%253A%2F%2Ftwitter.com%2Fdeepu105%2Fstatus%2F1063010906777497600%26image%3Dhttps%253A%2F%2Fi.embed.ly%2F1%2Fimage%253Furl%253Dhttps%25253A%25252F%25252Fpbs.twimg.com%25252Fprofile_images%25252F1056590953132244993%25252F0FGRfVeQ_400x400.jpg%2526key%253Da19fcc184b9711e1b4764040d3dc5c07"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>You can watch the video to see JHipster + Istio in action.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/NPToZd0PxbI" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>You can watch the slides on Speaker Deck as well.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://speakerdeck.com/deepu105/jhipster-5-whats-new-and-noteworthy">https://speakerdeck.com/deepu105/jhipster-5-whats-new-and-noteworthy</a></div>
<h3 id="heading-preparing-the-kubernetes-cluster">Preparing the Kubernetes cluster</h3>
<p>First, let us prepare a Kubernetes cluster to deploy Istio and our application containers. Follow the instructions for any one of the platforms you prefer.</p>
<h4 id="heading-prerequisites">Prerequisites</h4>
<p><a target="_blank" href="https://kubernetes.io/docs/tasks/tools/install-kubectl/"><strong>kubectl</strong></a>: The command line tool to interact with Kubernetes. Install and configure it.</p>
<h4 id="heading-create-a-cluster-on-azure-kubernetes-serviceaks">Create a cluster on Azure Kubernetes Service(AKS)</h4>
<p>If you are going to use Azure, then install <a target="_blank" href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest"><strong>Azure CLI</strong></a> to interact with Azure. Install and log in with your Azure account (you can create a <a target="_blank" href="https://azure.microsoft.com/en-us/free/">free account</a> if you don’t have one already).</p>
<p>First let us create a resource group. You can use any region you like here instead of East US.</p>
<pre><code class="lang-bash">$ az group create --name eCommerceCluster --location eastus
</code></pre>
<p>Create the Kubernetes cluster:</p>
<pre><code class="lang-bash">$ az aks create \
--resource-group eCommerceCluster \
--name eCommerceCluster \
--node-count 4 \
--kubernetes-version 1.11.4 \
--enable-addons monitoring \
--generate-ssh-keys
</code></pre>
<p>The <code>node-count</code> flag is important as the setup requires at least four nodes with the default CPU to run everything. You can try to use a higher <code>kubernetes-version</code> if it is supported, else stick to 1.11.4</p>
<p>The cluster creation could take while so sit back and relax. ?</p>
<p>Once the cluster is created, fetch its credentials to be used from <code>kubectl</code> by running the below command. It automatically injects the credentials to your <code>kubectl</code> configuration under <strong><em>~/.kube/config</em></strong></p>
<pre><code class="lang-bash">$ az aks get-credentials \
--resource-group eCommerceCluster \
--name eCommerceCluster
</code></pre>
<p>You can view the created cluster in the Azure portal:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*yfLnHHc_N7VCkEY9vjNciQ.png" alt="Image" width="800" height="132" loading="lazy">
<em>Kubernetes cluster in AKS</em></p>
<p>Run <code>kubectl get nodes</code> to see it in the command line and to verify that kubectl can connect to your cluster.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*k8xsRqQsvnquUhGPAh9TsA.png" alt="Image" width="642" height="119" loading="lazy">
<em>Cluster Nodes</em></p>
<p>Proceed to the <strong>Install and setup Istio</strong> section.</p>
<h4 id="heading-create-a-cluster-on-google-kubernetes-enginegke">Create a cluster on Google Kubernetes Engine(GKE)</h4>
<p>If you are going to use Google Cloud Platform(GCP) then install <a target="_blank" href="https://cloud.google.com/sdk/docs/"><strong>Gcloud CLI</strong></a>to interact with GCP. Install and log in with your GCP account (you can create a <a target="_blank" href="https://console.cloud.google.com/freetrial">free account</a> if you don’t have one already).</p>
<p>First, we need a GCP project, you can either use an existing project that you have or create a new one using GCloud CLI with below command:</p>
<pre><code class="lang-bash">$ gcloud projects create jhipster-demo-deepu
</code></pre>
<p>Set the project you want to use as the default project:</p>
<pre><code class="lang-bash">$ gcloud config <span class="hljs-built_in">set</span> project jhipster-demo-deepu
</code></pre>
<p>Now let us create a cluster for our application with the below command:</p>
<pre><code class="lang-bash">$ gcloud container clusters create hello-hipster \

   --cluster-version 1.10 \

   --num-nodes 4 \

   --machine-type n1-standard-2
</code></pre>
<p>The <code>num-nodes</code> and <code>machine-type</code> flags are important as the setup requires at least four nodes with a bigger CPU to run everything. You can try to use a higher <code>cluster-version</code> if it is supported, else stick to 1.10.</p>
<p>The cluster creation could take while so sit back and relax.</p>
<p>Once the cluster is created, fetch its credentials to be used from <code>kubectl</code> by running the below command. It automatically injects the credentials to your <code>kubectl</code> configuration under <strong><em>~/.kube/config</em></strong></p>
<pre><code class="lang-bash">$ gcloud container clusters get-credentials hello-hipster
</code></pre>
<p>You can view the created cluster in the GCP GUI.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ZxNbIG4vqWJymTLweJpPyQ.png" alt="Image" width="800" height="196" loading="lazy">
<em>Kubernetes cluster on GKE</em></p>
<p>Run <code>kubectl get nodes</code> to see it in the command line and to verify that kubectl can connect to your cluster.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*F5Qcd_GS_GSuA1PsJE7gvA.png" alt="Image" width="800" height="110" loading="lazy">
<em>Cluster Nodes</em></p>
<h3 id="heading-install-and-setup-istio">Install and setup Istio</h3>
<p>Install Istio on your machine by following these steps:</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">cd</span> ~/

$ <span class="hljs-built_in">export</span> ISTIO_VERSION=1.0.2

$ curl -L https://git.io/getLatestIstio | sh -

$ ln -sf istio-<span class="hljs-variable">$ISTIO_VERSION</span> istio

$ <span class="hljs-built_in">export</span> PATH=~/istio/bin:<span class="hljs-variable">$PATH</span>
</code></pre>
<p>Make sure to use version <strong>1.0.2</strong> since the latest version seems to have issues connecting to the MySQL database containers.</p>
<p>Now let us install Istio on our Kubernetes cluster by applying the provided Kubernetes manifests and helm templates from Istio.</p>
<pre><code class="lang-bash">$ kubectl apply -f ~/istio/install/kubernetes/helm/istio/templates/crds.yaml
$ kubectl apply -f ~/istio/install/kubernetes/istio-demo.yaml \
    --as=admin --as-group=system:masters
</code></pre>
<p>Wait for the pods to run, these will be deployed to the <code>istio-system</code> namespace.</p>
<pre><code class="lang-bash">$ watch kubectl get pods -n istio-system
</code></pre>
<p>Once the pods are in running status, exit the watch loop and run the below to get the Ingress gateway service details. This is the only service that is exposed to an external IP.</p>
<pre><code class="lang-bash">$ kubectl get svc istio-ingressgateway -n istio-system

NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP
istio-ingressgateway   LoadBalancer   10.27.249.83   35.195.81.130
</code></pre>
<p>The external IP is very important here, let us save this to an environment variable so that we can use it in further commands.</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">export</span> \
  INGRESS_IP=$(kubectl -n istio-system get svc \
  istio-ingressgateway \
  -o jsonpath=<span class="hljs-string">'{.status.loadBalancer.ingress[0].ip}'</span>)
</code></pre>
<p>Now our Kubernetes cluster is ready for Istio. ?</p>
<p><em>For advanced Istio setup options refer to</em> <a target="_blank" href="https://istio.io/docs/setup/kubernetes/"><em>https://istio.io/docs/setup/kubernetes/</em></a></p>
<h3 id="heading-creating-the-microservice-application-stack">Creating the microservice application stack</h3>
<p>In one of my <a target="_blank" href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">previous posts</a>, I showcased how to create a full stack microservice architecture using <strong>JHipster</strong> and <strong>JDL</strong>. You can read the post <a target="_blank" href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">here</a> if you want to learn more details about it. For this exercise, we will use the same application but we will not use the Eureka service discovery option we used earlier. Also, note that the store application is further split into Gateway and Product applications.</p>
<h4 id="heading-architecture">Architecture</h4>
<p>Here is the architecture of the microservice that we are going to create and deploy today.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*UmNJ-Ue362-OltPOxt-OFQ.png" alt="Image" width="800" height="518" loading="lazy">
<em>Microservice architecture with Istio</em></p>
<p>It has a gateway application and three microservice applications. Each of them has its own database. You can see that each application has an Envoy proxy attached to the pod as a sidecar. Istio control plane components are also deployed to the same cluster along with Prometheus, Grafana, and Jaeger.</p>
<p>The Ingress gateway from Istio is the only entry point for traffic and it routes traffic to all microservices accordingly. Telemetry is collected from all the containers running in the cluster, including the applications, databases, and Istio components.</p>
<p>Compared to the architecture of the original application <a target="_blank" href="https://medium.com/@deepu105/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba">here</a>, you can clearly see that we replaced the JHipster registry and Netflix OSS components with Istio. The ELK monitoring stack is replaced with Prometheus, Grafana and Jaeger configured by Istio. Here is the original architecture diagram without Istio for a quick visual comparison.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*H-6_dz1-aYXQ-fzWEuJcRw.png" alt="Image" width="800" height="452" loading="lazy">
<em>Microservice architecture with Netflix OSS</em></p>
<h4 id="heading-application-jdl">Application JDL</h4>
<p>Let’s take a look at the modified JDL declaration. You can see that we have declared <code>serviceDiscoveryType no</code> here since we will be using Istio for that.</p>
<pre><code>
application {
  config {
    baseName store
    applicationType gateway
    packageName com.jhipster.demo.store
    serviceDiscoveryType no
    authenticationType jwt
    prodDatabaseType mysql
    cacheProvider hazelcast
    buildTool gradle
    clientFramework react
    useSass <span class="hljs-literal">true</span>
    testFrameworks [protractor]
  }
  entities *
}


application {
  config {
    baseName product
    applicationType microservice
    packageName com.jhipster.demo.product
    serviceDiscoveryType no
    authenticationType jwt
    prodDatabaseType mysql
    cacheProvider hazelcast
    buildTool gradle
    serverPort <span class="hljs-number">8081</span>
  }
  entities Product, ProductCategory, ProductOrder, OrderItem
}

application {
  config {
    baseName invoice
    applicationType microservice
    packageName com.jhipster.demo.invoice
    serviceDiscoveryType no
    authenticationType jwt
    prodDatabaseType mysql
    buildTool gradle
    serverPort <span class="hljs-number">8082</span>
  }
  entities Invoice, Shipment
}

application {
  config {
    baseName notification
    applicationType microservice
    packageName com.jhipster.demo.notification
    serviceDiscoveryType no
    authenticationType jwt
    databaseType mongodb
    cacheProvider no
    enableHibernateCache <span class="hljs-literal">false</span>
    buildTool gradle
    serverPort <span class="hljs-number">8083</span>
  }
  entities Notification
}

<span class="hljs-comment">/**
 * Entities for Store Gateway
 */</span>

<span class="hljs-comment">// Customer for the store</span>
entity Customer {
    firstName <span class="hljs-built_in">String</span> required
    lastName <span class="hljs-built_in">String</span> required
    gender Gender required
    email <span class="hljs-built_in">String</span> required pattern(<span class="hljs-regexp">/^[^@\s]+@[^@\s]+\.[^@\s]+$/</span>)
    phone <span class="hljs-built_in">String</span> required
    addressLine1 <span class="hljs-built_in">String</span> required
    addressLine2 <span class="hljs-built_in">String</span>
    city <span class="hljs-built_in">String</span> required
    country <span class="hljs-built_in">String</span> required
}

enum Gender {
    MALE, FEMALE, OTHER
}

relationship OneToOne {
    Customer{user(login) required} to User
}

service Customer <span class="hljs-keyword">with</span> serviceClass
paginate Customer <span class="hljs-keyword">with</span> pagination


<span class="hljs-comment">/**
 * Entities for product microservice
 */</span>


<span class="hljs-comment">// Product sold by the Online store </span>
entity Product {
    name <span class="hljs-built_in">String</span> required
    description <span class="hljs-built_in">String</span>
    price BigDecimal required min(<span class="hljs-number">0</span>)
    size Size required
    image ImageBlob
}

enum Size {
    S, M, L, XL, XXL
}

entity ProductCategory {
    name <span class="hljs-built_in">String</span> required
    description <span class="hljs-built_in">String</span>
}

entity ProductOrder {
    placedDate Instant required
    status OrderStatus required
    code <span class="hljs-built_in">String</span> required
    invoiceId Long
    customer <span class="hljs-built_in">String</span> required
}

enum OrderStatus {
    COMPLETED, PENDING, CANCELLED
}

entity OrderItem {
    quantity Integer required min(<span class="hljs-number">0</span>)
    totalPrice BigDecimal required min(<span class="hljs-number">0</span>)
    status OrderItemStatus required
}

enum OrderItemStatus {
    AVAILABLE, OUT_OF_STOCK, BACK_ORDER
}

relationship ManyToOne {
    OrderItem{product(name) required} to Product
}

relationship OneToMany {
   ProductOrder{orderItem} to OrderItem{order(code) required} ,
   ProductCategory{product} to Product{productCategory(name)}
}

service Product, ProductCategory, ProductOrder, OrderItem <span class="hljs-keyword">with</span> serviceClass
paginate Product, ProductOrder, OrderItem <span class="hljs-keyword">with</span> pagination
microservice Product, ProductOrder, ProductCategory, OrderItem <span class="hljs-keyword">with</span> product


<span class="hljs-comment">/**
 * Entities for Invoice microservice
 */</span>


<span class="hljs-comment">// Invoice for sales</span>
entity Invoice {
    code <span class="hljs-built_in">String</span> required
    date Instant required
    details <span class="hljs-built_in">String</span>
    status InvoiceStatus required
    paymentMethod PaymentMethod required
    paymentDate Instant required
    paymentAmount BigDecimal required
}

enum InvoiceStatus {
    PAID, ISSUED, CANCELLED
}

entity Shipment {
    trackingCode <span class="hljs-built_in">String</span>
    date Instant required
    details <span class="hljs-built_in">String</span>
}

enum PaymentMethod {
    CREDIT_CARD, CASH_ON_DELIVERY, PAYPAL
}

relationship OneToMany {
    Invoice{shipment} to Shipment{invoice(code) required}
}

service Invoice, Shipment <span class="hljs-keyword">with</span> serviceClass
paginate Invoice, Shipment <span class="hljs-keyword">with</span> pagination
microservice Invoice, Shipment <span class="hljs-keyword">with</span> invoice


<span class="hljs-comment">/**
 * Entities for notification microservice
 */</span>


entity Notification {
    date Instant required
    details <span class="hljs-built_in">String</span>
    sentDate Instant required
    format NotificationType required
    userId Long required
    productId Long required
}

enum NotificationType {
    EMAIL, SMS, PARCEL
}

microservice Notification <span class="hljs-keyword">with</span> notification

<span class="hljs-comment">/**
 * Deployments
 */</span>

deployment {
  deploymentType kubernetes
  appsFolders [store, invoice, notification, product]
  dockerRepositoryName <span class="hljs-string">"deepu105"</span>
  serviceDiscoveryType no
  istio <span class="hljs-literal">true</span>
  kubernetesServiceType Ingress
  kubernetesNamespace jhipster
  ingressDomain <span class="hljs-string">"34.90.236.124.nip.io"</span>
}
</code></pre><h4 id="heading-deployment-jdl">Deployment JDL</h4>
<p>JHipster version 5.7.0 introduced support for deployment declaration straight in the JDL</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/deepu105/status/1056588722769195018?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed&amp;ref_url=https%3A%2F%2Fcdn.embedly.com%2Fwidgets%2Fmedia.html%3Ftype%3Dtext%252Fhtml%26key%3Da19fcc184b9711e1b4764040d3dc5c07%26schema%3Dtwitter%26url%3Dhttps%253A%2F%2Ftwitter.com%2Fdeepu105%2Fstatus%2F1056588722769195018%26image%3Dhttps%253A%2F%2Fi.embed.ly%2F1%2Fimage%253Furl%253Dhttps%25253A%25252F%25252Fpbs.twimg.com%25252Fprofile_images%25252F1056590953132244993%25252F0FGRfVeQ_400x400.jpg%2526key%253Da19fcc184b9711e1b4764040d3dc5c07"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>We have the below in our JDL which declares our Kubernetes deployment:</p>
<pre><code>deployment {
  deploymentType kubernetes
  appsFolders [store, invoice, notification, product]
  dockerRepositoryName <span class="hljs-string">"deepu105"</span>
  serviceDiscoveryType no
  istio autoInjection
  istioRoute <span class="hljs-literal">true</span>
  kubernetesServiceType Ingress
  kubernetesNamespace jhipster
  ingressDomain <span class="hljs-string">"35.195.81.130.nip.io"</span>
}
</code></pre><p>The <code>serviceDiscoveryType</code> is disabled and we have enabled Istio with <code>autoInjection</code> support — the Envoy sidecars are injected automatically for the selected applications. Istio routes are also generated for the applications by enabling <code>istioRoute</code> option.</p>
<p>The <code>kubernetesServiceType</code> is set as <code>Ingress</code>, which is very important as Istio can only work with an Ingress controller service type. For Ingress, we need to set the domain DNS and this is where the Istio ingress gateway IP is needed. Now we need a DNS for our IP. For real usecases, you should map a DNS for the IP, but for testing and demo purposes we can use a wildcard DNS service like <a target="_blank" href="http://nip.io/"><strong>nip.io</strong></a> to resolve our IP. Just append <code>nip.io</code> to our IP and use that as the ingress domain.</p>
<h4 id="heading-generate-the-applications-and-deployment-manifests">Generate the applications and deployment manifests</h4>
<p>Now that our JDL is ready, let us scaffold our applications and Kubernetes manifests. Create a new directory and save the above JDL in the directory. Let us name it <strong><em>app-istio.jdl</em></strong> and then run the import-jdl command.</p>
<pre><code class="lang-bash">$ mkdir istio-demo &amp;&amp; <span class="hljs-built_in">cd</span> istio-demo
$ jhipster import-jdl app-istio.jdl
</code></pre>
<p>This will generate all the applications and install the required NPM dependencies in each of them. Once the applications are generated the deployment manifests will be generated and some useful instruction will be printed to the console.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*ROg2XrRkHVHA4Xib" alt="Image" width="800" height="325" loading="lazy">
<em>Generation output</em></p>
<p>Open the generated code in your favorite IDE/Editor and explore the code.</p>
<h3 id="heading-deploy-to-kubernetes-cluster-using-kubectl">Deploy to Kubernetes cluster using Kubectl</h3>
<p>Now let us build and deploy our applications. Run the <code>./gradlew bootWar -Pprod jibDockerBuild</code> command in the store, product, invoice, and notification folders to build the docker images. Once the images are built, push them to the docker repo with these commands:</p>
<pre><code class="lang-bash">$ docker image tag store deepu105/store

$ docker push deepu105/store

$ docker image tag invoice deepu105/invoice

$ docker push deepu105/invoice

$ docker image tag notification deepu105/notification

$ docker push deepu105/notification

$ docker image tag product deepu105/product

$ docker push deepu105/product
</code></pre>
<p>Once the images are pushed, navigate into the generated Kubernetes directory and run the provided startup script. (If you are on windows you can run the steps in <strong><em>kubectl-apply.sh</em></strong> manually one by one.)</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">cd</span> kubernetes
$ ./kubectl-apply.sh
</code></pre>
<p>Run <code>watch kubectl get pods -n jhipster</code> to monitor the status.</p>
<h3 id="heading-deployed-applications">Deployed applications</h3>
<p>Once all the pods are in running status we can explore the deployed applications</p>
<h4 id="heading-application-gateway">Application gateway</h4>
<p>The store gateway application is the entry point for our microservices. Get the URL for the store app by running <code>echo store.$INGRESS_IP.nip.io</code>, we already stored the INGRESS_IP to environment variables while creating the Istio setup. Visit the URL in your favorite browser and explore the application. Try creating some entities for the microservices:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*Qd6y_H-ObCeorQkg" alt="Image" width="800" height="490" loading="lazy">
<em>Store gateway application</em></p>
<h4 id="heading-monitoring">Monitoring</h4>
<p>Istio setup includes Grafana and Prometheus configured to collect and show metrics from our containers. Let's take a look.</p>
<p>By default, only the Ingress gateway is exposed to external IP and hence we will use kubectl port forwarding to set up a secure tunnel to the required services</p>
<p>Let us create a tunnel for Grafana:</p>
<pre><code class="lang-bash">$ kubectl -n istio-system \
port-forward $(kubectl -n istio-system get pod \

-l app=grafana -o jsonpath=<span class="hljs-string">'{.items[0].metadata.name}'</span>) 3000:3000
</code></pre>
<p>Open <a target="_blank">localhost:3000</a> to view the Grafana dashboard.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*zaX0S8relpT4q__T" alt="Image" width="800" height="490" loading="lazy">
<em>Grafana dashboard for the Store application</em></p>
<p>Grafana uses the metrics scrapped by Prometheus. We can look at Prometheus directly by creating a tunnel for it and opening <a target="_blank">localhost:9090</a>:</p>
<pre><code class="lang-bash">$ kubectl -n istio-system \
port-forward $(kubectl -n istio-system get pod -l \

app=prometheus -o jsonpath=<span class="hljs-string">'{.items[0].metadata.name}'</span>) 9090:9090
</code></pre>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*W4obHNne_wQJfAuU" alt="Image" width="800" height="490" loading="lazy">
<em>Prometheus dashboard</em></p>
<h4 id="heading-observability">Observability</h4>
<p>Istio configures Jaeger for distributed tracing and service graph for service observability. Let us take a look at them.</p>
<p>Create a tunnel for Jaeger and open <a target="_blank">localhost:16686</a></p>
<pre><code class="lang-bash">$ kubectl -n istio-system \
port-forward $(kubectl -n istio-system get pod -l \

app=jaeger -o jsonpath=<span class="hljs-string">'{.items[0].metadata.name}'</span>) 16686:16686
</code></pre>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*cyhS1_B0LFO54e48" alt="Image" width="800" height="490" loading="lazy">
<em>Jaeger tracing dashboard</em></p>
<p>You can make some requests in the application and find it in the tracing dashboard by querying for the service. Click on the request to see tracing details:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*X4XtKtIeMapPEyt_nfvftA.png" alt="Image" width="800" height="224" loading="lazy">
<em>Tracing for product category listing request</em></p>
<p>Let us now create a tunnel for the service graph and open it in <a target="_blank">localhost:8080/force/forcegraph.html</a>:</p>
<pre><code class="lang-bash">$ kubectl -n istio-system \
port-forward $(kubectl -n istio-system get pod -l \

app=servicegraph -o jsonpath=<span class="hljs-string">'{.items[0].metadata.name}'</span>) 8088:8088
</code></pre>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*4nQUsagF6TVupK-5" alt="Image" width="800" height="483" loading="lazy">
<em>Istio service graph</em></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Istio provides building blocks to build distributed microservices in a more Kubernetes-native way and takes the complexity and responsibility of maintaining those blocks away from you. This means you do not have to worry about maintaining the code or deployments for service discovery, tracing and so on.</p>
<p>Istio documentation says</p>
<blockquote>
<p>Deploying a microservice-based application in an Istio service mesh allows one to externally control service monitoring and tracing, request (version) routing, resiliency testing, security and policy enforcement, etc., in a consistent way across the services, for the application as a whole.</p>
</blockquote>
<p>Werner Vogels (CTO of AWS) quoted at AWS Re:Invent</p>
<blockquote>
<p>“In the future, all the code you ever write will be business logic.”</p>
</blockquote>
<p>Istio Service mesh helps with that statement. This lets you worry only about the applications that you are developing and with JHipster that future is truly here and you just need to worry about writing your business logic.</p>
<p>While this is great, it is not a silver bullet. Keep in mind that Istio is fairly new compared to other stable and battle-tested solutions like JHipster Registry (Eureka) or Consul.</p>
<p>Also, another thing to keep in mind is the resource requirements. The same microservices with JHipster Registry or Consul can be deployed to a 2 node cluster with 1 vCPU and 3.75 GB of memory per node in GCP while you need a 4 node cluster with 2 vCPUs and 7.5 GB of memory per node for Istio enabled deployments. The default Kubernetes manifest from Istio doesn’t apply any request limits for resources, and by adding and tuning those, the minimum requirement could be reduced. But still I don’t think you can get it as low as that is needed for the JHipster registry option.</p>
<p>In a real-world use case, the advantages of not having to maintain the complex parts of your infra vs having to pay for more resources might be a decision that has to be taken based on your priorities and goals.</p>
<p>A huge shout out to <a target="_blank" href="https://twitter.com/saturnism">Ray Tsang</a> for helping me figure out an optimal cluster size for this application. Also a huge thank you from myself and the community to both Ray and <a target="_blank" href="https://twitter.com/humourmind">Srinivasa Vasu</a> for adding the Istio support to JHipster.</p>
<p>JHipster provides a great Kubernetes setup to start with which you can further tweak as per your needs and platform. The Istio support is recent and will improve further over time, but it's still a great starting point especially to learn.</p>
<p>To learn more about JHipster and Full stack development, check out my book “<em>Full Stack Development with JHipster</em>” on <a target="_blank" href="https://www.amazon.com/Stack-Development-JHipster-Deepu-Sasidharan/dp/178847631X">Amazon</a> and <a target="_blank" href="https://www.packtpub.com/application-development/full-stack-development-jhipster">Packt</a>.</p>
<p>There is a great Istio tutorial from Ray Tsang <a target="_blank" href="https://docs.google.com/document/d/1Qo8o5C4UpGwMF7Mg02kLTaU4-xCSfJjLcnIFNveMEEA">here</a>.</p>
<p>If you like JHipster don’t forget to give it a star on <a target="_blank" href="https://github.com/jhipster/generator-jhipster">Github</a>.</p>
<p>If you like this article, please leave some claps (Did you know that you can clap multiple times in Medium? ?) I hope to write more about Istio in the near future.</p>
<p>You can follow me on <a target="_blank" href="https://twitter.com/deepu105">Twitter</a> and <a target="_blank" href="https://www.linkedin.com/in/deepu05/">LinkedIn</a>.</p>
<p>My other related posts:</p>
<ol>
<li><a target="_blank" href="https://medium.com/@deepu105/create-full-microservice-stack-using-jhipster-domain-language-under-30-minutes-ecc6e7fc3f77">Create full Microservice stack using JHipster Domain Language under 30 minutes</a></li>
<li><a target="_blank" href="https://medium.com/@deepu105/deploying-jhipster-microservices-on-azure-kubernetes-service-aks-fb46991746ba">Deploying JHipster Microservices on Azure Kubernetes Service (AKS)</a></li>
</ol>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Continuous Deployment for Node.js on the Google Cloud Platform ]]>
                </title>
                <description>
                    <![CDATA[ By Gautam Arora Google Cloud Platform (GCP) provides a host of options for Node developers to easily deploy our apps. Want a managed hosting solution like Heroku? App Engine, check! Want to host a containerized app? Kubernetes Engine, check! Want to ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/continuous-deployment-for-node-js-on-google-cloud-platform-751a035a28d5/</link>
                <guid isPermaLink="false">66c347d9790a62b5fbf7b8ae</guid>
                
                    <category>
                        <![CDATA[ Continuous Integration ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 15 Aug 2018 01:19:51 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*PsecxPuZQn0kVxC04OPU8Q.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Gautam Arora</p>
<p><a target="_blank" href="https://cloud.google.com/">Google Cloud Platform (GCP)</a> provides a host of options for <a target="_blank" href="https://nodejs.org/en/">Node</a> developers to easily deploy our apps. Want a managed hosting solution like Heroku? <a target="_blank" href="https://cloud.google.com/appengine/">App Engine</a>, check! Want to host a containerized app? <a target="_blank" href="https://cloud.google.com/kubernetes-engine/">Kubernetes Engine</a>, check! Want to deploy serverless app? <a target="_blank" href="https://cloud.google.com/functions/">Cloud Functions</a>, check!</p>
<p>Recently at work, I’ve been enjoying using our <a target="_blank" href="https://technology.condenast.com/story/departures-building-a-docker-container-based-deployment-platform-at-conde-nast">in-house continuous deployment service</a> that quickly builds, tests, and deploys new commits pushed to GitHub. So when I read about Google’s new <a target="_blank" href="https://techcrunch.com/2018/07/24/google-announces-cloud-build-its-new-continuous-integration-continuous-delivery-platform/">Cloud Build</a> service, I wanted to take it for a spin and see if I could recreate a similar seamless deployment experience for myself. Further, in a conversation with <a target="_blank" href="https://twitter.com/fhinkel">Fransizka</a> from the Google Cloud team, she identified this as an area where a tutorial would be helpful. So here we go…</p>
<h3 id="heading-but-wait-what-is-cloud-build">But wait, what is Cloud Build?</h3>
<p>Cloud Build is a managed build service in GCP that can pull code from a variety of sources, run a series of build steps to create a build image for the application, and then deploy this image to a fleet of servers.</p>
<p>Cloud Build works well with Google’s own source code repository, Bit Bucket or GitHub. It can create a build image using a Docker configuration file (<code>Dockerfile</code>) or Cloud Build’s own configuration file (<code>cloudconfig.yaml</code>). It can deploy applications (and APIs) to App Engine, Kubernetes Engine, and Cloud Functions. A really cool feature is Build Triggers. These can be setup to watch for a new commit in the code repository and trigger a new build and deploy.</p>
<h4 id="heading-before-we-jump-into-the-deep-end">Before we jump into the deep end…</h4>
<p>This post shares the detailed steps and code to setup the continuous deployment for Node apps on GCP. It assumes that you’re familiar with developing simple Node applications, working with the command line, and have some high level understanding of deploying apps to cloud services like Heroku, AWS, Azure or GCP.</p>
<p>For each of the sections, a companion GitHub code repository is provided for you to follow along. Don’t sweat it though — feel free to skim over the article to learn about the high level ideas, and you can bookmark it and come to it later if you plan to set this up. The real fun of having a setup like this is that you get to deploy applications quickly.</p>
<h3 id="heading-continuous-deployment-for-app-engine-standard">Continuous Deployment for App Engine Standard</h3>
<p>Deploying a Node app to App Engine is quite simple. Create a new project in Google Cloud Console, add an <code>app.yaml</code> configuration file in our code directory (which describes the node runtime we want to use — I’ve used Node 8), and run <code>gcloud app deploy</code> on our terminal — and done!</p>
<p>If you want to try this out for yourself, here are a couple of resources:</p>
<ul>
<li><a target="_blank" href="https://github.com/gautamarora/gae-node-hello-world">Sample App for App Engine</a></li>
<li><a target="_blank" href="https://cloud.google.com/appengine/docs/standard/nodejs/quickstart">Quickstart Guide for Node on App Engine</a></li>
</ul>
<p>So, what we’ve done so far by following the quickstart guide above:</p>
<ol>
<li>Created a new project in Google Cloud Console</li>
<li>Deployed our Node app to App Engine using <em>gcloud app deploy</em></li>
</ol>
<p>….now how can we automate setup such that code changes get deployed automatically on push to GitHub?</p>
<p>Here is what we need to do:</p>
<ol>
<li><p>Put our code on GitHub</p>
</li>
<li><p>Head over to GitHub to create a new repository</p>
</li>
<li><p>Then follow the instructions to push code from your machine to GitHub</p>
</li>
<li><p>Enable Cloud Build</p>
</li>
<li><p><a target="_blank" href="https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com&amp;redirect=https://cloud.google.com/cloud-build/docs/quickstart-gcloud&amp;_ga=2.113783623.-1976915987.1533866140">Enable the Cloud Build API</a> for our project</p>
</li>
<li><a target="_blank" href="https://console.cloud.google.com/flows/enableapi?apiid=appengine.googleapis.com&amp;_ga=2.114826311.-1976915987.1533866140">Enable the App Engine API</a> for for our project.</li>
<li><p>Grant App Engine IAM to Cloud Build Service account by going to the <a target="_blank" href="https://console.cloud.google.com/iam-admin/iam">IAM page</a>, find this service account <code>&lt;project-id&gt;@cloudbuild.gserviceaccou</code>nt.com, edit it and give it the App Engine Admin role.</p>
</li>
<li><p>Create a <a target="_blank" href="https://cloud.google.com/cloud-build/docs/build-config">Cloud Build configuration file</a></p>
</li>
<li><p>Create a new file <code>cloudbuild.yaml</code> that looks like this:</p>
</li>
</ol>
<pre><code>steps:- name: <span class="hljs-string">'gcr.io/cloud-builders/npm'</span>  args: [<span class="hljs-string">'install'</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/npm'</span>  args: [<span class="hljs-string">'test'</span>]- name: <span class="hljs-string">"gcr.io/cloud-builders/gcloud"</span>  args: [<span class="hljs-string">"app"</span>, <span class="hljs-string">"deploy"</span>]timeout: <span class="hljs-string">"1600s"</span>
</code></pre><p>This configuration has three build steps (each line starting with a hyphen is a build step) that will run <code>npm install</code>, then <code>npm test</code> and if all looks good then deploy our code to App Engine.</p>
<p>Each build step is just like a command we run on our machine. But in this case, since this file is in yaml and each step is split over 2 lines of name and args, it can look like a bit of a mind-bender.</p>
<p>Let’s try this: for the line starting with “name”, read its last word and then read the values in the “args” line. I hope this file makes more sense now!</p>
<ol start="4">
<li><p>Run a Build manually (optional, just for verification)</p>
</li>
<li><p>We can now deploy our application from our machine using Cloud Build</p>
</li>
<li>Run the cloud build command on your terminal: <code>gcloud builds submit — config cloudbuild.yaml .</code>This command starts a build on Cloud Build using the configuration file we created above.</li>
<li>Head over to the <a target="_blank" href="https://console.cloud.google.com/cloud-build/builds">Cloud Builds page</a> to see the build being kicked off.</li>
<li>Wait for the build to end, and then test out your Node application using the App Engine URL for this app.</li>
<li><p>You can make changes to your Node app and call this command again and to start more builds if you would like.</p>
</li>
<li><p>Create a Build Trigger</p>
</li>
<li><p>Head over to the <a target="_blank" href="https://console.cloud.google.com/cloud-build/triggers">Cloud Build Triggers page</a> and select Create Trigger</p>
</li>
<li>On the Build Trigger setup page, choose GitHub as the Source Code Repository. This will require you to authorize GCP to access your GitHub repositories, which you will need to approve. Once done, select the GitHub repository for your Node app that you had pushed to GitHub earlier.</li>
<li>Create a trigger named <code>continuous deployment</code>, and for the trigger type choose Branch with regex for branch name as <code>master</code>. This will ensure that the builds, test, and deploy will only run for push to the master branch and not any branch.</li>
<li>For the build configuration file, select <code>cloudbuild.yaml</code></li>
<li><p>Now click the Build Trigger button</p>
</li>
<li><p>Run a Build automatically by pushing a commit to GitHub</p>
</li>
<li><p>With our build trigger created, make a simple commit to your node application, like change “Hello, World!” to “Hello, GCP!” and commit and push this code to GitHub</p>
</li>
<li>Head back the the <a target="_blank" href="https://console.cloud.google.com/cloud-build/builds">Cloud Builds page</a> and you will notice that a build was automatically triggered (if it isn’t, give it a few more seconds or click the refresh button on the page)</li>
<li>Once the build is complete and you see a green check, you can visit your application using its App Engine URL and see that your changes are now live!</li>
</ol>
<p>Here is a screenshot for builds being triggered through a GitHub push for our app:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/BwblpfTf5PSxQ4rXkzWshokcpg5iQJJEsThF" alt="Image" width="800" height="188" loading="lazy"></p>
<p>Too good to be true?? Run this last step a few times times to test it out a few more times. Our first application now gets deployed to App Engine on every commit to master ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/U057rpI1bqLVgfjn5DFIEZV-niVp6HY05VQ9" alt="Image" width="800" height="599" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/photos/g5FyZvIzUS4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="_blank" title=""&gt;Willian Justen de Vasconcellos on &lt;a href="https://unsplash.com/search/photos/shipping?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="<em>blank" title=")</em></p>
<h3 id="heading-continuous-deployment-for-kubernetes-engine">Continuous Deployment for Kubernetes Engine</h3>
<p>Great, so we’ve setup our application to deploy to App Engine on GitHub push, but what if we wanted the same setup for our containerized applications? Let’s give it a spin!</p>
<p>At a high level, deploying a Node app to Kubernetes engine has two main tasks. First, get our app ready: Containerize the application with Docker, build it, and push the Docker image to Google Container Registry. Then, setup things on the GCP end: create a Kubernetes Cluster, create a Deployment with your application image, and then create a Service to allow access to your running application.</p>
<p>If you want to try this out for yourself, here are a few resources:</p>
<ul>
<li><a target="_blank" href="https://github.com/gautamarora/gke-node-hello-world">Sample App for Kubernetes Engine</a></li>
<li><a target="_blank" href="https://nodejs.org/en/docs/guides/nodejs-docker-webapp/">Containerize a Node App with Docker</a></li>
<li><a target="_blank" href="https://github.com/gautamarora/gke-node-hello-world/blob/master/DEPLOY.md#deploy-a-containerized-hello-world-application-to-kubernetes-engine">Deploy a Containerized Hello World App to Kubernetes Engine</a></li>
</ul>
<p>So, what we’ve done so far by using the guides above:</p>
<ol>
<li>Created another new project in Google Cloud Console</li>
<li>Created a Kubernetes Cluster, Deployment, and Service</li>
<li>Deployed our Containerized Node app to Kubernetes Engine using <em>kubectl</em></li>
</ol>
<p>…but what we want is an continuous deployment setup such that a new commit kicks off a build and deployment.</p>
<p>Here is what we need to do:</p>
<ol>
<li><p>Put our code on GitHub</p>
</li>
<li><p>We will follow the same steps as we did in the section earlier on App Engine. Create a new repository and push code from our machine to GitHub.</p>
</li>
<li><p>Enable Cloud Build</p>
</li>
<li><p><a target="_blank" href="https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com&amp;redirect=https://cloud.google.com/cloud-build/docs/quickstart-gcloud&amp;_ga=2.113783623.-1976915987.1533866140">Enable the Cloud Build API</a> for our project</p>
</li>
<li><a target="_blank" href="https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com&amp;_ga=2.147807223.-1976915987.1533866140">Enable the Kubernetes Engine API</a> for our project</li>
<li><p>Grant Kubernetes Engine IAM to Cloud Service account by going to the I<a target="_blank" href="https://console.cloud.google.com/iam-admin/iam">AM page</a> for this service account <code>&lt;project-id&gt;@cloudbuild.gserviceaccou</code>nt.com, edit it, and give it the Kubernetes Engine Admin role</p>
</li>
<li><p>Create a Cloud Build Configuration file</p>
</li>
<li><p>Create a new file <code>cloudbuild.yaml</code> that looks like this:</p>
</li>
</ol>
<pre><code>steps:- name: <span class="hljs-string">'gcr.io/cloud-builders/npm'</span>  args: [<span class="hljs-string">'install'</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/npm'</span>  args: [<span class="hljs-string">'test'</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/docker'</span>  args: [<span class="hljs-string">"build"</span>, <span class="hljs-string">"-t"</span>, <span class="hljs-string">"gcr.io/$PROJECT_ID/my-image:$REVISION_ID"</span>, <span class="hljs-string">"."</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/docker'</span>  args: [<span class="hljs-string">"push"</span>, <span class="hljs-string">"gcr.io/$PROJECT_ID/image:$REVISION_ID"</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/kubectl'</span> args: - <span class="hljs-string">'set'</span> - <span class="hljs-string">'image'</span> - <span class="hljs-string">'deployment/my-deployment'</span> - <span class="hljs-string">'my-container=gcr.io/$PROJECT_ID/image:$REVISION_ID'</span> env: - <span class="hljs-string">'CLOUDSDK_COMPUTE_ZONE=us-east1-b'</span> - <span class="hljs-string">'CLOUDSDK_CONTAINER_CLUSTER=my-cluster'</span>
</code></pre><p>This configuration has five build steps that will run <code>npm install</code> and then <code>npm test</code> to make sure our application works, then it will create a Docker image and push to GCR and then deploy our application to our Kubernetes cluster. The values <code>_my-cluster, my-deployment and my-container_</code> in this file refer to resources in the Kubernetes cluster we have created (as per the guide we followed above). <code>_$REVISION_ID_</code> is a variable value that Cloud Build injects into the configuration based on GitHub commit that triggers this build.</p>
<ol start="4">
<li><p>Run a Build manually (optional, for verification)</p>
</li>
<li><p>We can now deploy our application from our machine using Cloud Build</p>
</li>
<li>Run the cloud build command on your terminal: <code>gcloud builds submit — config cloudbuild.yaml --substitutions=REVISION_ID=1 .</code></li>
</ol>
<p>We’re also passing the revision id in this command, since we are manually running this build vs it being triggered by GitHub.</p>
<ul>
<li>Head over to the <a target="_blank" href="https://console.cloud.google.com/cloud-build/builds">Cloud Builds page</a> to see the build in action.</li>
<li>At the end of the build, you can test out your Node application using the Kubernetes Service URL</li>
<li><p>You can make changes to your Node app and call this command again to kickoff more builds if you would like</p>
</li>
<li><p>Create a Build Trigger</p>
</li>
<li><p>The steps for setting this up are the same as that from the section above for App Engine. Go to <a target="_blank" href="https://console.cloud.google.com/cloud-build/triggers">Cloud Build Triggers page</a> for this project, select the right GitHub repository, create a trigger called <code>continuous deployment</code> just for the <code>master</code> branch and you’re done.</p>
</li>
<li>Run a Build automatically by pushing to GitHub</li>
<li>This is also the same as the section above for App Engine — make a change, add, commit and push to GitHub which will kickoff a build that you can see on your <a target="_blank" href="https://console.cloud.google.com/cloud-build/builds">Cloud Builds</a> page. Once the builds completes, you will be able to see the updated app using the Kubernetes Service URL.</li>
</ul>
<p>Here is a screenshot for a build being triggered through a GitHub push for our app:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/lhzzRfcvgfRJaV-NXGSZw6KvyrwTjKVj-WZA" alt="Image" width="800" height="130" loading="lazy"></p>
<p>The steps in this section were pretty much the same as the App Engine section. The main differences were that we had to containerize our application with Docker, spin up our Kubernetes cluster, and then have a Cloud Build configuration with just a few more steps.</p>
<p>But at its core, Cloud Build and its Build Triggers work pretty much the same and give us a seamless deployment experience. Our second application now gets deployed to Kubernetes Engine on every commit to master ??</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/jIX1ztshIMTpBiKNuw-YruekKbP0LIuxV6pB" alt="Image" width="800" height="534" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/photos/Esq0ovRY-Zs?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="_blank" title=""&gt;Maximilian Weisbecker on &lt;a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="<em>blank" title=")</em></p>
<h3 id="heading-continuous-deployment-for-cloud-functions">Continuous Deployment for Cloud Functions</h3>
<p>Sure, App Engine and Kubernetes Engine are great, but how about automated deployments for our Serverless app? I mean, having no servers to manage at all is really the best, right? Let’s do this!</p>
<p>Deploying a Node app to Cloud functions will require us to create a new project. No configuration files are needed, and once GCloud functions deploy on our terminal, our functions are deployed!</p>
<p>If you want to try this out for yourself, here are the resources you will need:</p>
<ul>
<li><a target="_blank" href="https://github.com/gautamarora/gae-node-hello-world">Sample App for Cloud Functions</a></li>
<li><a target="_blank" href="https://cloud.google.com/functions/docs/quickstart">Quickstart Guide for Node on Cloud Functions</a></li>
<li><a target="_blank" href="https://cloud.google.com/functions/docs/emulator">Locally Testing Cloud Functions using Node emulator</a></li>
</ul>
<p>If you’ve been following along, you can probably already picture what steps we need to do:</p>
<ol>
<li><p>Put our code on GitHub</p>
</li>
<li><p>We already know how to do this</p>
</li>
<li><p>Enable Cloud Build</p>
</li>
<li><p><a target="_blank" href="https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com&amp;redirect=https://cloud.google.com/cloud-build/docs/quickstart-gcloud&amp;_ga=2.113783623.-1976915987.1533866140">Enable the Cloud Build API</a> for our project</p>
</li>
<li><a target="_blank" href="https://console.cloud.google.com/flows/enableapi?apiid=cloudfunctions&amp;_ga=2.84807769.-1976915987.1533866140">Enable the Cloud Functions API</a> for our project.</li>
<li><p>Grant Cloud Functions IAM to Cloud Build Service account by going to the <a target="_blank" href="https://console.cloud.google.com/iam-admin/iam">IAM page</a>, find this service account <code>&lt;project-id&gt;@cloudbuild.gserviceaccou</code>nt.com, edit it and give it the Project Editor role.</p>
</li>
<li><p>Create a Cloud Build Configuration file</p>
</li>
<li><p>Create a new file <code>cloudbuild.yaml</code> that looks like this:</p>
</li>
</ol>
<pre><code>steps:- name: <span class="hljs-string">'gcr.io/cloud-builders/npm'</span>  args: [<span class="hljs-string">'install'</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/npm'</span>  args: [<span class="hljs-string">'test'</span>]- name: <span class="hljs-string">'gcr.io/cloud-builders/gcloud'</span> args: - beta - functions - deploy - helloWorld - -- source=. - -- runtime=nodejs8 - -- trigger-http
</code></pre><p>Similar to the App Engine configuration, this configuration has 3 steps to install. Then test the build, and if all is good, then deploy it to Cloud Functions.</p>
<ol start="4">
<li><p>Run the Build manually (optional, for verification)</p>
</li>
<li><p>We can now deploy our function from our machine using Cloud Build</p>
</li>
<li>Run this in your terminal: <code>gcloud builds submit — config cloudbuild.yaml .</code></li>
<li>Head over to the <a target="_blank" href="https://console.cloud.google.com/cloud-build/builds">Cloud Builds page</a> to see the build in action.</li>
<li><p>At the end of the build, you can test out your serverless app using the Cloud Function URL</p>
</li>
<li><p>Create a Build Trigger</p>
</li>
<li><p>The steps for setting this up are the same as that from the section above for App Engine and Kubernetes Engine. Go to <a target="_blank" href="https://console.cloud.google.com/cloud-build/triggers">Cloud Build Triggers page</a> for this project, select the right GitHub repository, create a trigger called <code>continuous deployment</code> just for the <code>master</code> branch, and you’re done.</p>
</li>
<li><p>Run a Build automatically by pushing to GitHub</p>
</li>
<li><p>This is also the same as the section above for App Engine &amp; Kubernetes Engine: make a change, add, commit and push to GitHub, which will kickoff a build that you can see on your <a target="_blank" href="https://console.cloud.google.com/cloud-build/builds">Cloud Builds</a> page. Once the build completes, you will be able to see the updated app using the Cloud Functions URL</p>
</li>
</ol>
<p>Here is a screenshot for build being triggered through a GitHub push for our sample app:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/UVSiRQerOS6aBhi8XUTJTxuVX976dsMDFgX5" alt="Image" width="800" height="160" loading="lazy"></p>
<p>Cloud Functions were super easy to setup with automated builds and makes the “code → build → test → push → deploy” workflow really really fast! Our third application now gets deployed to Cloud functions on every commit to master ???</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/41hLHGgzW9-5Np9cXWpgoltzPVltTqLNCfY0" alt="Image" width="800" height="450" loading="lazy">
_Photo by [Unsplash](https://unsplash.com/photos/kAjrml-a8R0?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="_blank" title=""&gt;Jassim Vailoces on &lt;a href="https://unsplash.com/search/photos/shipping?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="<em>blank" title=")</em></p>
<h3 id="heading-wrapping-up">Wrapping Up</h3>
<p>Phew! We covered a lot of ground in this post. If this was your first time trying out GCP for Node, hopefully you got to see how easy and straightforward it is to try out the various options. If you were most eager to understand how to setup continuous deployment for apps on GCP, I hope you weren’t disappointed either!</p>
<p>Before you go, I just wanted to make sure that you didn’t miss the fact that all the sections had a sample app: <a target="_blank" href="https://github.com/gautamarora/gae-node-hello-world">Hello World for App Engine</a>, <a target="_blank" href="https://github.com/gautamarora/gke-node-hello-world">Hello World for Kubernetes Engine</a> and <a target="_blank" href="https://github.com/gautamarora/gcf-node-hello-world">Hello World for Cloud Functions</a>.</p>
<p>That’s it for now! Let’s go ship some code! ?</p>
<p>Thanks for following along. If you have any questions or want to report any mistakes in this post, do leave a comment.</p>
<p>If you found this article helpful, don’t be shy to ?</p>
<p>And you can <a target="_blank" href="http://twitter.com/gautam">follow me on Twitter here.</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Decentralize your application with Google Cloud Platform ]]>
                </title>
                <description>
                    <![CDATA[ By Simeon Kostadinov When first starting a new software project, you normally choose a certain programming language, a specific framework and libraries. Then you begin coding. After 2 - 3 months you end up with a nicely working single application. Bu... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/decentralize-your-application-with-google-cloud-platform-7149ec6d0255/</link>
                <guid isPermaLink="false">66c348c0a7aea9fc97bdfaf2</guid>
                
                    <category>
                        <![CDATA[ decentralized apps ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Flask Framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Cloud Platform ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Microservices ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software architecture ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 21 Dec 2017 22:57:25 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*Z68F4SMRusBjJ7Q8ox4Waw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Simeon Kostadinov</p>
<p>When first starting a new software project, you normally choose a certain programming language, a specific framework and libraries. Then you begin coding. After 2 - 3 months you end up with a nicely working single application.</p>
<p><strong>But, as the project grows and more functionalities are added, you quickly realize the disadvantages of a centralized system.</strong> Difficult to maintain and unscalable are some of the reasons which will make you search for a better solution. Here is where Microservices come in help.</p>
<h4 id="heading-what-are-microservices">What are Microservices?</h4>
<p>Microservices are independently built systems, each running in their own process and often communicating with REST API. Representing different parts of your application, they are separately deployable and each part can be written in any language.</p>
<p>You can easily see how, by dealing with the problems of a monolithic system, Microservices have become a requirement for any state-of-the-art software.</p>
<p>I strongly recommend reading <a target="_blank" href="https://martinfowler.com/articles/microservices.html">Microservices (by James Lewis)</a> and <a target="_blank" href="https://dev.otto.de/2015/09/30/on-monoliths-and-microservices/">On Monoliths and Microservices</a> if you want to understand more in depth what are the key concepts in this architectural style.</p>
<h4 id="heading-what-are-you-going-to-build">What are you going to build?</h4>
<p>This article will walk you through the process of implementing a Microservice using <a target="_blank" href="https://cloud.google.com/">Google Cloud Platform</a>.</p>
<p>Imagine you’re developing an application that accepts a text input from a user and determine the category of the key words within the input.</p>
<p>We’ll use an example to illustrate the functionality of the App. Consider the sample text below from the <a target="_blank" href="https://cloud.google.com/natural-language/">GCP Cloud Natural Language API website</a>:</p>
<blockquote>
<p>“Google, headquartered in Mountain View, unveiled the new Android phone at the Consumer Electronic Show. Sundar Pichai said in his keynote that users love their new Android phones.”</p>
</blockquote>
<p>Our web App would accept the text above as input, and return the category that the key words belong to, as in the figure below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*SAeCcBhjaEY-JqaRzOaskA.png" alt="Image" width="800" height="587" loading="lazy">
_Source: [GCP Cloud Natural Language API website](https://cloud.google.com/natural-language/" rel="noopener" target="<em>blank" title=")</em></p>
<p>This feature is quite likeable and people use it hundreds of times each day. Now, if you’re going to offer this functionality as a service that receives a high amount of daily traffic, you want to respond with a stable and reliable system.</p>
<p>That’s why we’ll build a lightweight Flask App, hosted on <a target="_blank" href="https://cloud.google.com/appengine/docs/flexible/python/">Google App Engine</a>. Integrating it with <a target="_blank" href="https://cloud.google.com/pubsub/docs/">Google Cloud Pub/Sub</a> will help us handle all the asynchronous requests we receive and help us assure that users don’t wait too long for a response.</p>
<h4 id="heading-create-and-deploy-the-application">Create and deploy the application</h4>
<p>Let’s first start with the Flask app (you can also choose Django, Node.js, Go or anything used to build server-side applications). If you’re not very familiar with developing a Flask App, this <a target="_blank" href="https://damyanon.net/post/flask-series-environment/">Flask Series</a> can show you step-by-step how to set up an application.</p>
<p>For the purpose of this tutorial we will use this simple example:</p>
<p><strong>This embed is from an external site and no longer seems to be available</strong></p>
<p>First you need to install the dependencies <code>pip install Flask gunicorn</code>. You will be using <code>**gunicorn**</code> to run the application on Google App Engine. For local access you can run <code>python text.py</code> in the console and find the app on port 8080.</p>
<p>To deploy the app to Google App Engine, you need to take these steps:</p>
<ul>
<li>Create a project (follow the <a target="_blank" href="https://cloud.google.com/appengine/docs/flexible/python/quickstart">‘Before you begin’ instructions from the documentation</a>). <strong>Save the project id for later.</strong></li>
<li>Create <code>app.yaml</code> file (shown below), which is used by the Google App Engine to recognize the application.</li>
<li>Run <code>gcloud app deploy</code> in the console.</li>
</ul>
<p>The <code>app.yaml</code> file looks like this:</p>
<p><strong>This embed is from an external site and no longer seems to be available</strong></p>
<p>Line 3 is important, where you use <code>**gunicorn**</code> to tell Google App Engine to run the application <code>**app**</code> from a file called <code>text.py</code> (the Flask app)<em>.</em> You can learn more about the <code>.yaml</code> file structure <a target="_blank" href="https://cloud.google.com/appengine/docs/standard/python/config/appref">here</a>. After deployment you should be able to access your project from <code>https://[YOUR_PROJECT_ID].appspot.com</code>.</p>
<p>When building production ready applications, you often want to test your code before pushing it live. One way to do this is to run your App within a server locally. A better approach is to have a development version of the app which can be tested not only from your local machine but also from a hosted environment. You can use <a target="_blank" href="https://cloud.google.com/appengine/docs/admin-api/deploying-apps">Google App Engine versions</a> for this.</p>
<p>Just deploy your App with <code>gcloud app deploy -v textdev</code> (for development) or <code>gcloud app deploy -v textprod</code> (for production).</p>
<p>Then navigate to <code>https://textdev.[YOUR_PROJECT_ID].appspot.com</code> or <code>https://textprod.[YOUR_PROJECT_ID].appspot.com</code> to access the specific version.</p>
<h4 id="heading-scale-to-infinity">Scale to infinity</h4>
<p>So far so good. You have a working application, hosted on the Google Cloud Platform. Now you need to add <a target="_blank" href="https://cloud.google.com/pubsub/docs/">Google Cloud Pub/Sub</a> and <a target="_blank" href="https://cloud.google.com/natural-language/">Google Natural Language API</a>.</p>
<p>But first, let’s explain the architecture.</p>
<p>Once a request is received, the Flask app will publish a message with the text to a topic (created below). Then a subscriber (Python script) will pull this message and apply the Google Natural Language API to each text. Finally, the result will be saved to a database.</p>
<p>For multiple requests, the app asynchronously publishes them to the topic and the subscriber starts executing the first one. When ready, it picks the second one and so on.</p>
<p>Now you need to modify <code>text.py</code> file:</p>
<p><strong>This embed is from an external site and no longer seems to be available</strong></p>
<p>The code on line 15 and 16 creates the publisher. On line 18 it publishes a message containing the user email and text input.</p>
<p>You only need to fill in the <code>project_id</code> and <code>topic_id</code> (line 6 and 7).</p>
<p>Since the <code>project_id</code> was used earlier, just add it here.</p>
<p>For the <code>topic_id</code> you need to do the following:</p>
<ul>
<li><a target="_blank" href="https://console.cloud.google.com/apis/dashboard">Enable Google Cloud Pub/Sub API</a></li>
<li><a target="_blank" href="https://console.cloud.google.com/cloudpubsub/topicList">Go to the Pub/Sub page of your project</a></li>
<li>Create a topic and a subscription</li>
<li>Use the topic name as your <code>topic_id</code></li>
<li>Keep the subscription name for later.<br>You will need it as your <code>subscription_id</code></li>
</ul>
<p>Wonderful! Now you have a working publisher.</p>
<p>Let’s jump into setting up the subscriber. There are two files that need to be created: <code>worker.py</code> and <code>startup-script.sh</code>.</p>
<p>The <code>worker.py</code> looks like this:</p>
<p><strong>This embed is from an external site and no longer seems to be available</strong></p>
<p>The file is slightly larger but we will examine it step-by-step, starting from the bottom.</p>
<p>When the file is executed, the code on line 44 runs <code>main()</code>. This function sets the subscriber with your <code>project_id</code> and <code>subscription_id</code> and assigns a callback to it.</p>
<p>The <code>callback</code> (initialized on line 7) is going to receive all messages and perform the required task (to determine the category of a text). If you follow the code from the <code>callback</code>, you can easily see how the Google Natural Language API is being used.</p>
<p>The interesting line is 11 where <code>message.ack()</code> acknowledges the current message. You can see this is as if the worker is saying: “I am done with this message and ready to handle the next one”.</p>
<p>Now, you need to implement <code>startup-script.sh</code>.</p>
<p>This is a shell script with several commands:</p>
<p><strong>This embed is from an external site and no longer seems to be available</strong></p>
<p>Before explaining the code above, I need to clarify the process.</p>
<p>Basically, <a target="_blank" href="https://console.cloud.google.com/compute">Google Cloud Compute Engine</a> gives you the ability to scale an application by providing as many virtual machines (VM) as needed to run several workers simultaneously.</p>
<p>You just need to add the code for the worker, which you already have, and set the configurations of the VM. Together with the <code>worker.py</code>, you also need to add a <code>startup-script.sh</code> which will run every time a new VM boots up.</p>
<p>New VM instances are booted up to prevent delay in responses when a high number of messages is received.</p>
<p>For a deeper and more technical explanation of this process check out the <a target="_blank" href="https://cloud.google.com/compute/docs/">documentation</a>.</p>
<p>Now, let me walk you through the script:</p>
<ul>
<li><strong>Line 1</strong>: means that the script should always be run with bash, rather than another shell.</li>
<li><strong>Lines 2 and 3</strong>: creates and enters into a new directory where all of the files will be stored.</li>
<li><strong>Line 4</strong>: copies the <code>worker.py</code> file from <a target="_blank" href="https://cloud.google.com/storage/docs/">Google Cloud Storage</a> into the VM (I will explain how to upload your files to the storage below).</li>
<li><strong>Line 5</strong>: here you need to specify a JSON string of your key so that Google can verify your credentials. In order to get this string you need to <a target="_blank" href="https://console.cloud.google.com/iam-admin/iam/project">create a service account</a>. Select <code>**Furnish a new private key**</code> and for <code>**Key type**</code> use <code>JSON</code>. A file will be downloaded to your computer. Copy the content and turn it into a JSON string (using <code>JSON.stringify(key_in_json_format)</code> in a browser console). Paste it instead of <code>SERVICE_ACCOUNT_KEY</code><em>.</em></li>
<li><strong>Line 6</strong>: exports the key as an <a target="_blank" href="https://developers.google.com/identity/protocols/application-default-credentials">environment variable</a> which will be used by the Google APIs to verify your credentials.</li>
<li><strong>Lines 7 - 12</strong>: sets up configurations and installs the python libraries.</li>
<li><strong>Line 15</strong>: runs the worker.</li>
</ul>
<p>Now you need to upload <code>worker.py</code> and <code>startup-script.sh</code> to your storage and set up the VM. To upload the files just go <a target="_blank" href="https://console.cloud.google.com/storage/">here</a> and create a new bucket with the same name as your project id. Create a folder called <em>workers</em> and upload the scripts inside. <strong>Make sure to change the <code>worker.py</code> to a ‘Public link<em>’</em> and edit the permissions of the <code>_startup-script.sh_</code></strong> <strong>to</strong> have your service account as an owner.</p>
<h4 id="heading-configurations-and-testing">Configurations and testing</h4>
<p>The final step is to set up the configurations of the VM and test the system. Just follow the <a target="_blank" href="https://cloud.google.com/solutions/media-processing-pub-sub-compute-engine">‘Create an instance template’ instructions from the documentation</a> and you are good to go!</p>
<p>Once the VM boots up, you can try sending requests to your application and examine how it reacts by checking the <a target="_blank" href="https://console.cloud.google.com/logs/viewer">logs</a>.</p>
<h4 id="heading-final-thoughts">Final thoughts</h4>
<p>Going through Google’s documentation may help you a lot. Also check out this <a target="_blank" href="https://cloud.google.com/solutions/media-processing-pub-sub-compute-engine">tutorial</a> - you may find it useful while implementing some of the steps above.</p>
<p>I want to express my gratefulness to <a target="_blank" href="https://www.freecodecamp.org/news/decentralize-your-application-with-google-cloud-platform-7149ec6d0255/undefined">Logan Allen</a> for helping me better understand this process. I hope you find it useful.</p>
<p>Leave any questions or suggestions in the comment section.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
