<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Romin Irani’s Blog - Medium]]></title>
        <description><![CDATA[Technical Tutorials, APIs, Cloud, Books and more. - Medium]]></description>
        <link>https://rominirani.com?source=rss----6fc063f083b1---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Romin Irani’s Blog - Medium</title>
            <link>https://rominirani.com?source=rss----6fc063f083b1---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 11 Mar 2023 10:11:51 GMT</lastBuildDate>
        <atom:link href="https://rominirani.com/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Google Cloud Shell — Resources to get started]]></title>
            <link>https://rominirani.com/google-cloud-shell-resources-to-get-started-ed02a78a5579?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/ed02a78a5579</guid>
            <category><![CDATA[google-cloud-shell]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 10:09:54 GMT</pubDate>
            <atom:updated>2021-09-27T10:09:14.820Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Cloud Shell — Resources to get started</h3><p>Let’s learn about Google Cloud Shell and how it can help you as a developer to get more productive working with Google Cloud Applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGxFAn86ChHWDtZFTxCq2A.png" /></figure><p><strong>Cloud Shell</strong> (<a href="https://lnkd.in/dcS444yp">https://lnkd.in/dcS444yp</a>) is an interactive shell environment for Google Cloud that makes it easy for you to learn and experiment with Google Cloud and manage your projects and resources from your web browser.</p><p>How much space does it give you and is it linked to a specific GCP Project ?<br><strong>Cloud Shell provisions 5 GB of free persistent disk storage</strong> mounted as your $HOME directory on the virtual machine instance. This storage is on a per-user basis and is available across projects.</p><p>What <strong>kind of tools does it come pre-installed with</strong>?<br>For a start, we have multiple editors, Google Cloud Tools (gcloud, gsutil), Build and Package Tools and more. For the entire list, check out: <a href="https://lnkd.in/dteQhK5N">https://lnkd.in/dteQhK5N</a></p><p>What kind of <strong>Programming Language SDK support</strong> can I get in Google Cloud Shell?<br>Check out the list of languages that are supported. <a href="https://lnkd.in/deX7wZHi">https://lnkd.in/deX7wZHi</a></p><p>Does it come with a Visual Editor?<br>Yes. Google Cloud Shell comes with an editor, based on <strong>Eclipse Thiea</strong>. You can launch it from within Cloud Shell or even directly via <a href="https://lnkd.in/dBWfMufS">https://lnkd.in/dBWfMufS</a>. It is <strong>integrated with Cloud Code</strong> (<a href="https://lnkd.in/drN_mm95">https://lnkd.in/drN_mm95</a>), that has integrated support for k8s, Cloud Run apps and exploring various Google APIs. Looking to learn about using the Cloud Shell Editor? Check out this playlist: <a href="https://lnkd.in/dVPpcuQ2">https://lnkd.in/dVPpcuQ2</a></p><p>How much does it cost?<br><strong>No additional cost</strong> for Google Cloud customers.</p><p>Can I upload and download files?<br>Yes. Check out <a href="https://lnkd.in/dZSw3sf8">https://lnkd.in/dZSw3sf8</a></p><p>Can I locally run web applications in Cloud Shell and preview/test them?<br>Absolutely. Check out <a href="https://lnkd.in/ds-MvM9u">https://lnkd.in/ds-MvM9u</a></p><p>I have never used Cloud Shell? Whats the quickest way to get started?<br><strong>Cloud Shell 101:</strong> <a href="https://lnkd.in/d5c9cYhS">https://lnkd.in/d5c9cYhS</a>. Once done with that, explore our other Quickstarts: <a href="https://lnkd.in/dBfRW3Q9">https://lnkd.in/dBfRW3Q9</a></p><h4>Any other cool features?</h4><p>1. <strong>Open in Cloud Shell:</strong> This allows you to publish a link that opens the Google Cloud Console with a Git repository cloned into Cloud Shell. Check out : <a href="https://lnkd.in/dpBPb3n9">https://lnkd.in/dpBPb3n9</a></p><p>2. <strong>Interactive Tutorials :</strong> Write interactive tutorials that takes a user step by step while still remaining within Cloud Shell and GCP console?<br>Check this <a href="https://lnkd.in/dZrVfk6c">https://lnkd.in/dZrVfk6c</a></p><p>3. <strong>Activate Google Cloud Shell within Documentation</strong> :<br>Now you can run code samples within documentation inside of Cloud Shell with single click. Read more: <a href="https://lnkd.in/dywbUS_h">https://lnkd.in/dywbUS_h</a></p><blockquote>What is/are your favourite feature(s)?</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed02a78a5579" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/google-cloud-shell-resources-to-get-started-ed02a78a5579">Google Cloud Shell — Resources to get started</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hands-on Guide to Scheduling VM Instances to Start and Stop]]></title>
            <link>https://rominirani.com/hands-on-guide-to-scheduling-vm-instances-to-start-and-stop-a079a50e16c6?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/a079a50e16c6</guid>
            <category><![CDATA[scheduling]]></category>
            <category><![CDATA[operations]]></category>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Sun, 18 Apr 2021 09:34:35 GMT</pubDate>
            <atom:updated>2021-04-18T09:34:24.885Z</atom:updated>
            <content:encoded><![CDATA[<p>We recently covered a 3-part series on Compute Engine Pricing, which I list down over here:</p><ul><li>Part 1 : <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-1-d71f2cf2bd14">Sustained Use Discounts and Committed Use Discounts</a></li><li>Part 2 : <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-2-78ee7ff783b8">Custom Machine Types</a></li><li>Part 3 : <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-3-7c0883681a7b">Preemptible VMs</a></li></ul><p>In Part 1 , we covered On-demand pricing , where you are charged for the time that you keep the Virtual Machine instances running. We also covered the scenario, that in development and testing environments, one of the recommendations is not to keep the instances running all the time. You can save a lot of money by identifying the block of time that you typically use these VMs and then keeping them in a Stopped state during other days.</p><p>An example scenario could be that you would like all your Development machines to be started at 9:00 AM and stopped at 5:00 PM everyday. This will result in you getting billed for just 8 hours a day instead of 24 hours a day. This will result in significant savings just in on-demand pricing for that VM. Just for numbers, cost of running a n1-standard-1 instance for 24 hrs / day and all days a week v/s running it for 8 hours a day and all days a week is shown below. You can see the cost of approx. $29 v/s $13 / month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*vmEculXDpraME4LNnOyv1w.png" /></figure><p><strong>Google Cloud recently announced the </strong><a href="https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop"><strong>ability to schedule start and stopping your Compute Engine instances</strong></a><strong> in GA and this article will show how we can do the same.</strong></p><h4>What is an Instance Schedule?</h4><p>To get started, we need to first understand the concept of an Instance Schedule. The Instance Schedule is meta information about when you want to start an instance, stop an instance, in which compute engine region it can be applied to, the time zone for the start/stop time and whether you want apply it daily/weekly/monthly with various combinations. Think of Cron expressions that specific when it can be applied.</p><p>Having said that, a sample Instance Schedule might have the following definition:</p><pre>Name + Description : &lt;Sample Name + Description&gt;<br>Compute Engine Region : asia-south1 (Mumbai) <br>Start Time : 9:00 AM<br>End Time : 5:00 PM<br>Time Zone : IST (UTC + 5:30)<br>Initiation Date (Optional) : Leave it empty<br>End Date (Optional) : Leave it empty<br>Frequency : Daily / Weekly / Monthly (Depending on that you can select days of the week and days of the month)</pre><p>So, if we go back to our plan of having an Instance Schedule, where we want our machines to be running only from 9:00 AM to 5:00 PM on all days of the week (daily) and apply it to various instances in Mumbai region, I would go with the following values:</p><pre>Name + Description : MyDevMachine-Instance-Schedule<br>Compute Engine Region : asia-south1 <br>Start Time : 9:00 AM<br>End Time : 5:00 PM<br>Time Zone : IST (UTC + 5:30)<br>Frequency : Daily</pre><p>That’s it. Before we get to the mechanics of setting this up, I suggest to read up on the <a href="https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop#limitations">limitations</a>, a few of which I reiterate below:</p><ul><li>An instance schedule is specific to a region and you can only attach it to instances in that region.</li><li>Each VM instance can be associate with only one instance schedule.</li><li>The instance schedule needs a window of about 15 minutes to the time that you have specified to complete the start and stop of the instance. In my sample runs, it took around 10 minutes after the stop time for example, for the instance to actually stop. So you might want to factor that but do it with care since you cannot predict it precisely.</li></ul><h4>Instance Schedules in Action</h4><p>To see the instance schedules work in action, we are going to go with our original requirement i.e. start the VM instances at 9:00 AM and stop them at 5:00 PM, on all days of the week.</p><p>Given that, I went ahead and created two Compute Engine VMs — nothing fancy here, just go with the n1-standard-1 or smaller VMs. In my case, I created them in the region = asia-south1.</p><p>If you are familiar with gcloud, you can use the following commands to create a couple of VM instances.</p><pre>gcloud compute instances create <strong>instance-1</strong> --machine-type=n1-standard-1 --zone=asia-south1-a</pre><pre>gcloud compute instances create <strong>instance-2</strong> --machine-type=n1-standard-1 --zone=asia-south1-a</pre><p>If you visit the Google Cloud Console and Compute Engine → VM Instances, you should see the two of them listed as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*9twQ-Sd1lSt7Rsqxhx2LOA.png" /></figure><p>If you notice, you see a tab <strong>INSTANCE SCHEDULE </strong>next to INSTANCES in the above screenshot. Simply click on that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQ3f41IkM2Zb_BTUc3BD_w.png" /></figure><p>At this point, we don’t have any instance schedules. Remember, all of the stuff that I am showing can be done via the <strong>gcloud </strong>utility or even the API, but I will use the Cloud Console here.</p><p>Let’s create our instance schedule now. Click on <strong>CREATE INSTANCE SCHEDULE </strong>and you will see the following screen. Go ahead and populate it as I have shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fedKluCXojzZM_jt9dwQcA.png" /></figure><p>Click on <strong>SUBMIT </strong>button and the schedule gets created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_HqC5j9EeUtjFj6D6qd2A.png" /></figure><p>The <strong>instance schedule is not yet</strong> <strong>associated</strong> (<strong>attached</strong>) to any Compute Engine VM Instances. So let’s apply it to both our VMs (<strong>instance-1</strong> and <strong>instance-2</strong>).</p><p>Click on the instance schedule record i.e. (<strong>dev-start-stop-schedule</strong> under the name column). You should see the screen below. It contains the definition of our instance schedule (<strong>dev-start-stop-schedule</strong>) and you can see that there are no attached instances yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*evWb9XamuaRwEuBe-fF5SQ.png" /></figure><p>Click on the <strong>ADD INSTANCES TO SCHEDULE </strong>link shown above and you will see the list of VMs that can be attached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISR_KqkEv2x325RWuVY2pA.png" /></figure><p>Select the VMs (<strong>instance-1</strong> and <strong>instance-2</strong> in our case) and click on the <strong>ADD </strong>button. You see that the instances are now attached to the instance schedule and it is in effect <strong><em>(if you get an error about service account permission, see the next section)</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rgf07ve7rqnteGzla3sK9Q.png" /></figure><h4>Service Account Permission</h4><p>Keep in mind that when we create an instance schedule and attach it to the Compute Engine instances, Compute Engine behind the scenes will need to have the permission to perform a <strong>start instance </strong>and <strong>stop instance </strong>operation on those compute resources (<strong>VM instances : instance-1 and instance-2</strong>).</p><p>For that to happen, you must ensure that the <a href="https://cloud.google.com/compute/docs/access/service-accounts#compute_engine_service_account">Google Managed Compute Engine System Service account</a> (not your default Compute Engine service account) has the permissions to start and stop the instance.</p><p>The Google Managed Compute Engine System Service Account is of the form:</p><pre>service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.com</pre><p>This account is not visible in the list of service accounts when you go to that section in the IAM or Service Accounts section. We will get to that in a while, but first up, we will create a Custom Role : Instance-Start-Stop-Role , which only has permissions to start and stop Compute Engine instances.</p><p>Go to <strong>IAM &amp; Admin → IAM </strong>section in the Google Cloud Console and click on <strong>CREATE ROLE </strong>at the top as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*LzOCN7nBHHMUu1BSYigXWg.png" /></figure><p>This will bring up a form, where you can fill it up with the Custom Role name (in my case, it is Instance-Start-Stop-Role):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzTRz2OV5ZByyL_l4cMOng.png" /></figure><p>Click on <strong>ADD PERMISSIONS</strong>. This will bring up the following screen , where you can filter by role by typing in Compute Instance Admin and selecting <strong>Compute Instance Admin (v1) </strong>as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSlsnkH_GcpkqwQioNQsTQ.png" /></figure><p>Then from the list of permissions, filter it first by compute.instances.start and then click on <strong>ADD</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x10-dEZ10l5RiSHZS5L7XQ.png" /></figure><p>Similarly, filter it again via <strong>compute.instances.stop </strong>and click on <strong>ADD.</strong></p><p>Ensure that you have both these permissions and then create the role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l6DoLjMnzqG-KXszjuLSnw.png" /></figure><p>This will create a Custom Role. Now, all we need to do is assign this role to the Google Managed Compute Engine System Service Account. Let’s do that.</p><p>Visit <strong>IAM and Admin → IAM</strong>. Select the checkbox for <strong>Include Google-provided role grants </strong>as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*caq7RmldK6HgtXQFtrS6JQ.png" /></figure><p>This will show the system accounts too and you should look out for the service account of the form:</p><pre>service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.com</pre><p>We can now edit this role by clicking on the Edit Pencil icon at the end. This will bring up the current list of roles assigned to this service account. Click on <strong>ADD ANOTHER ROLE </strong>and select our Custom Role that we just defined i.e. Instance-Start-Stop-Role. Click on Save. You will be brought back to the list of Accounts, just ensure that the new custom role is visible in addition to other roles for the service account.</p><p>Note : In case you got the permission error while attaching the instance schedule to the instance, go back now and try the same again. You should be able to move attach the same successfully.</p><p>That is pretty much what you have to do to schedule your instances to start and stop as per your pattern.</p><h4>Monitoring the Start / Stop Schedule in Action</h4><p>You can use Cloud Logging to view the start and stop schedule in Action. I created an instance schedule of just 30 minutes to test the same in action i.e. I defined the instance schedule to start at 12:00 PM and stop at 12:30 PM.</p><p>To view the same, I visited Cloud Logging → Logs Explore as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dFTSHpqBNPJpOtMq8w2Xqg.png" /></figure><p>Next up, click on <strong>Query builder</strong>. Then do the following:</p><ul><li>For the <strong>Resource </strong>dropdown, select VM Instances from the Resource Type as shown below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*imUjk8njqdalCv7nhppBWA.png" /></figure><ul><li>For Log name, we need to go to the Cloud Audit Log and Activity as shown below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*caA_S92VK0F0-UQ7BJ7Fjg.png" /></figure><p>Now run the log query again , and you see a lot more specific logs. I went back to the logs and noticed that the stop command was given as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xk0Pb_5_7dlCJJ8QI_cTlw.png" /></figure><p>You can see that the stop command was given a good 10 minutes after my instance schedule specified time i.e. 12:30 PM. So as I earlier mentioned and which the documentation states clearly, we should factor a 15 minute window after the start / stop time for the action to be performed.</p><p>Hope this was useful. Do note that we also have <a href="https://cloud.google.com/compute/docs/instances/suspend-resume-instance">available in beta, the ability to suspend/resume a VM</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a079a50e16c6" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/hands-on-guide-to-scheduling-vm-instances-to-start-and-stop-a079a50e16c6">Hands-on Guide to Scheduling VM Instances to Start and Stop</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A working guide to understanding Google Compute Engine Pricing Options — Part 3]]></title>
            <link>https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-3-7c0883681a7b?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/7c0883681a7b</guid>
            <category><![CDATA[pricing]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[compute-engine]]></category>
            <category><![CDATA[cost]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Thu, 15 Apr 2021 16:40:57 GMT</pubDate>
            <atom:updated>2021-04-15T16:40:44.399Z</atom:updated>
            <content:encoded><![CDATA[<h3>A working guide to understanding Google Compute Engine Pricing Options — Part 3</h3><p>In the <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-2-78ee7ff783b8">previous part</a>, we took a look at Custom Machine Types in Google Compute Engine and how you could provision a VM as per your specific vCPU / RAM requirements and save on the cost.</p><p>In this article, we are going to look at how you can save a lot more of the list price of a VM via what are know as <a href="https://cloud.google.com/preemptible-vms">Preemptible Virtual Machines</a>. We will also understand more importantly, where you can ideally use this type of a VM.</p><h4>What is a Preemptible Virtual Machine?</h4><p>I would like to present the definition via two points:</p><ul><li>This is an instance that you can get at a much lower price.</li><li>This is an instance that can be stopped if Compute Engine requires the infrastructure for some other tasks.</li></ul><p>Having defined the above, it means that these instances which could be stopped any time , at-least once across a 24 hour period, should not be used for any kind of workload. You cannot use this instance for a customer facing website or a critical workload that is not designed to survive an instance stopping, etc.</p><p>As a result, it is best suited for batch processing or fault tolerant jobs, where the Preemptible Virtual Machines (<strong>PVMs</strong>) are part of a cluster. Think of Big Data clusters, where the frameworks are fault-tolerant , can distribute their workloads across instances and can tolerate a few instances going up and down. It can be well suited to a Managed Instance Group too.</p><p>I won’t go too much into the finer aspects of how you will be notified if a PVM is going to be preempted, how to write a shutdown script to handle that for some work to be done before the VM terminates, etc. You should read up on all those details over <a href="https://cloud.google.com/compute/docs/instances/preemptible">here</a>. Google Cloud has also published a set of <a href="https://cloud.google.com/compute/docs/instances/create-start-preemptible-instance#best_practices">best practices</a> to reduce your chances of getting preempted, interesting … isn’t it?</p><h4>GCP Calculator for PVM Pricing</h4><p>Let’s continue with the example that we have been using so far for provisioning a n1-standard-1 instance type (1 vCPU and 3.75 GB RAM). Launch the GCP Calculator <a href="https://cloud.google.com/products/calculator">https://cloud.google.com/products/calculator</a> and use the following:</p><pre># instances : 1<br>What for? : Server-1<br>OS : Free<br>Series : N1<br>Machine Type : n1-standard-1<br>Region : Mumbai</pre><p>This comes to our standard pricing that we saw earlier as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*9Cp-jNGQqYG1QR2ryB3FMw.png" /></figure><p>Remember that I have chosen 24 hours per day and 7 days a week as running time for this instance.</p><p>Now, let’s see the cost if we go for a Preemptible version of the above. Go with the same settings, except that in the GCP Calculator, you will see a field called “Machine Class”. Click on that dropdown and select <strong>Preemptible </strong>instead of <strong>Regular.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFWTd0G356dYbsr1vy3ogw.png" /></figure><p>With all the other settings remaining the same, the pricing comes to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*iAG0CRfF8aPVKj3H7XCj5A.png" /></figure><p>See the big difference in cost? Use this knowledge and the fact that if you have fault tolerant workloads that are run across cluster of VMs, you could save tons of $$$ using PVMs. Just make sure that you understand the tradeoffs that are mentioned in the documentation.</p><h4>Conclusion</h4><p>I would like to highlight that there are a lot more things to consider from a total cost perspective, when provisioning a Virtual Machine and not just list price. My goal was to help you understand the list prices via the Google Cost Calculator and for you to better understand the following terms:</p><ul><li>Sustained Use Discounts</li><li>Committed Use Discounts</li><li>Custom Machine Types</li><li>Preemptible Virtual Machines</li></ul><p>Hope this series was useful to you. Look forward to any feedback and some lessons that you have learnt while juggling with these options.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c0883681a7b" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-3-7c0883681a7b">A working guide to understanding Google Compute Engine Pricing Options — Part 3</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A working guide to understanding Google Compute Engine Pricing Options — Part 2]]></title>
            <link>https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-2-78ee7ff783b8?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/78ee7ff783b8</guid>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[pricing]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 16:11:49 GMT</pubDate>
            <atom:updated>2021-04-15T16:41:58.974Z</atom:updated>
            <content:encoded><![CDATA[<h3>A working guide to understanding Google Compute Engine Pricing Options — Part 2</h3><p>In the <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-1-d71f2cf2bd14">previous part</a>, we took a look at understanding the basics of Sustained Use Discounts (SUD) and Committed Use Discounts (CUD) and how they are related to pricing a Virtual Machine in Google Compute Engine.</p><p>In this article, we are going to take a look at one of the biggest differentiators in Google Cloud Platform : <a href="https://cloud.google.com/custom-machine-types">Custom Virtual Machine Types</a>.</p><p>Before we get to that, let us continue with the Virtual Machine instance type that we used in the previous article i.e. <strong>n1-standard-1</strong> , which as per the documentation gives us <strong>1 vCPU and 3.75 GB RAM</strong>.</p><p>Google Compute Engine gives us a list of standard machine types, which come with a fixed vCPU and RAM combination and you have a variety of them to choose from. Let’s look at the n1-standard series and the different fixed machine types that we can choose from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Mr6TNmSUZH2gM9M3tmV3A.png" /><figcaption>Reference : <a href="https://cloud.google.com/compute/vm-instance-pricing#n1_predefined">https://cloud.google.com/compute/vm-instance-pricing#n1_predefined</a></figcaption></figure><p>This choice is good since your workloads might have varied requirements in terms of the vCPU and RAM that they need.</p><h4>We need a higher configuration !!!</h4><p>Now consider a scenario that you have been happily chugging along with our n1-standard-1 configuration and we are hitting limits in terms of performance. You are told to upgrade to more vCPU and RAM. The first thing that you might end up doing is to look at the list above and start matching the machine type that corresponds to the vCPU and Memory that you want. You have 2 options here:</p><ul><li>If you find a perfect match, you pick the machine type and we are done.</li><li>If you don’t find the perfect match, you are likely to choose the next higher configuration.</li></ul><p>Let’s concentrate on the 2nd option. You end up choosing the next higher configuration, which means that you have made a compromise and gone for a larger capacity in terms of vCPU and RAM. Nothing wrong with it but the first hit when you do that is going to be the cost ($$$) of running that instance.</p><p>We are talking about just one VM over here, but think about a medium sized deployment of 10s of VMs and you are likely to end up in this scenario a lot more than you expected, thereby over provisioning a lot more additional vCPU and RAM, and therefore paying a lot more.</p><h4>Enter Custom Machine Types</h4><p>Luckily , there is a 3rd option available in Google Cloud Platform and that is <a href="https://cloud.google.com/custom-machine-types">Custom Machine Types</a>. What if you could settle for something in the middle in terms of the vCPU and RAM that you need. What this means is that you come as close as possible to what you need and you end up paying less too. You pay less, because logically the configuration you want is now somewhere between the original configuration and the next higher configuration.</p><p>There will certain ratios that you need to maintain in terms of vCPU and RAM for Custom Machine configurations and you should check out the <a href="https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type">documentation</a> for the same.</p><p>Let’s work out the details for our example. We have the following scenario:</p><ul><li>We had our original VM i.e. n1-standard-1 (1 vCPU and 3.75 GB RAM)</li><li>We want to upgrade to a configuration where we need <strong>6 vCPUs and 24 GB RAM.</strong></li></ul><p>Question: Is the 6 vCPU and 24 GB RAM configuration available among the standard n1-standard-* machine types, as per the list below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*bDPRzcewmQnlUwm8Y_qo_Q.png" /></figure><p>It’s not an exact match and you might be tempted to go to the n1-standard-8 configuration for a start. Nothing wrong in that, but let’s see what happens when we use the GCP Calculator.</p><p>Visit the GCP Calculator at <a href="https://cloud.google.com/products/calculator">https://cloud.google.com/products/calculator</a> and use the following:</p><p>First, let’s look at our original pricing for n1-standard-1 for 24 hours a day and 7 days a week, which we did in the earlier article as shown below:</p><pre># instances : 1<br>What for? : Server-1<br>OS : Free<br>Series : N1<br>Machine Type : n1-standard-1<br>Region : Mumbai</pre><p>We get the following pricing as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*xQ7sh84eadOHDEsnSQVq8g.png" /></figure><p>Next, let’s look at the pricing for a <strong>n1-standard-8</strong> configuration as shown below:</p><pre># instances : 1<br>What for? : N1-Server2<br>OS : Free<br>Series : N1<br>Machine Type : n1-standard-8<br>Region : Mumbai</pre><p>We get the following pricing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*XykhsPsNJrYFMHpIOQpatg.png" /></figure><p>This is all fine but we would like to now use the option of custom machine types and see what it will cost us for provisioning exactly what we need:</p><p>Once again in the GCP Cost Calculator, enter the following to get the pricing for our custom configuration as per the specifications below:</p><pre># instances : 1<br>What for? : N1-CustomServer<br>OS : Free<br>Series : N1<br>Machine Type : &lt;&lt;&lt; How do we select this &gt;&gt;&gt; ??? <br>Region : Mumbai</pre><p>So, how do we select a custom machine type in the GCP Cost Calculator. In the form, click on the dropdown list for Machine Type and you will see <strong>Custom Machine Type </strong>right at the top, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2KdrH0rwLo34ifrrkJvz5w.png" /></figure><p>On selecting that, you will see a slider for selecting the vCPU and RAM combination as shown below and we will select the values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7QjfnCpfBOrJT4Pk4wCuA.png" /></figure><p>Once you add this to the estimate, you will see the pricing as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*uJbHJqjpSvuN9fhi3Mrk_Q.png" /></figure><p>You can see how the pricing dropped from nearly $230/month to $178/month. That is a lot of savings and this is true cloud pricing in terms of provisioning exactly what you want and getting charged for that.</p><h4>Additional considerations</h4><p>Like with everything else, it can’t be that simple, isn’t it ? There are additional things that you need to be aware about:</p><ul><li>There are certain minimum RAM per VCPU expected in different machine types.</li><li>The RAM that you can allocate needs to be a multiple of a certain amount i.e. 256MB.</li><li>Each machine type will be constrained in terms of max vCPUs and RAM supported.</li><li>There is a max vCPU to RAM ratio that can be supported across different machines. So if you need additional RAM , you will need to provision Extended Memory and some caveats are there to that too in terms of you not being able to make use of Committed Use Discounts on Extended Memory.</li></ul><p>Whew ! Don’t worry , just familiarize yourself with the <a href="https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#n1_custom_machine_types">documentation</a>.</p><p>This concludes the part on Custom Machine Types , a true differentiator available in Google Cloud. Next up, let us discuss <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-3-7c0883681a7b">Preemptible Virtual Machines</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ee7ff783b8" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-2-78ee7ff783b8">A working guide to understanding Google Compute Engine Pricing Options — Part 2</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A working guide to understanding Google Compute Engine Pricing Options — Part 1]]></title>
            <link>https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-1-d71f2cf2bd14?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/d71f2cf2bd14</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[pricing]]></category>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[cost-calculator]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 03:45:34 GMT</pubDate>
            <atom:updated>2021-04-15T17:50:07.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>A working guide to understanding Google Compute Engine Pricing Options — Part 1</h3><p>This is series of articles that I plan to write to help understand the various pricing levers that you have in Google Cloud Platform’s core compute offering : <a href="https://cloud.google.com/compute">Google Compute Engine</a>. I plan to explain this vis easy to understand and practical examples with the help of the Google Cloud Cost Calculator, that is available publicly.</p><p>Let’s get going.</p><p>Google Compute Engine provides a core infrastructure component : Virtual Machines (VM). These VMs are classified into different families</p><ul><li>General purpose</li><li>Memory Optimized</li><li>Compute Optimized</li></ul><p>Each family has various machine types. How do you select which machine type, what kind of workloads are they best suited for? You can use this guide as a start for the same:<a href="https://cloud.google.com/compute/docs/machine-types">https://cloud.google.com/compute/docs/machine-types</a> and I produce a screenshot from there that covers the various workloads that are best suited for which machine types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lQu3Fu5xPGo6ZjSl" /></figure><p>Each of the machine types (e.g. N1 general purpose) will have several <strong>*fixed*</strong> or <strong>*pre-defined*</strong> configurations (instance types) of VPU and RAM. You can choose the appropriate instance types depending on your requirements.</p><p>A set of instance types for N1 (General purpose) machine types is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_LaI_GDDpAVbe7B-" /></figure><blockquote>An important thing to consider when you choose a machine type is whether it is available in the GCP Region (actually zone) since VMs are zonal resources.</blockquote><p>Check out the list of regions that GCP is available in and more importantly, <strong>the availability of machine types per region</strong>. Bookmark this since this can change. <a href="https://cloud.google.com/compute/docs/regions-zones">https://cloud.google.com/compute/docs/regions-zones</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J0yqH9EGGCyMknb2" /></figure><p>VM is a rented resource and hence you are charged for the time that you use the Virtual VM. Let’s qualify that. You are charged for the amount of time that you keep a VM in running state. If a VM is stopped, you are not charged for it. <a href="https://cloud.google.com/compute/vm-instance-pricing">https://cloud.google.com/compute/vm-instance-pricing</a></p><p>Is there any minimum charge and then charged by second/minute/hour — whats the granularity by which you are charged? I reproduce this from the official documentation linked above:</p><ul><li>All vCPUs, GPUs, and GB of memory are charged a minimum of <em>1 minute</em>. For example, if you run your virtual machine for 30 seconds, you will be billed for 1 minute of usage.</li><li>After 1 minute, instances are charged in <em>1 second increments</em>.</li></ul><p>Each VM instance type has a pricing associated with it i.e. per hour pricing. As you consider higher vCPU and more RAM, the pricing inches upwards. Take a look at pricing for N1 instance types (<a href="https://cloud.google.com/compute/vm-instance-pricing#n1_predefined">https://cloud.google.com/compute/vm-instance-pricing#n1_predefined</a>).</p><blockquote>Remember* the prices are not the same in each region. When we get to using the Google Cloud Calculator in a while, ensure that you choose the correct region for the pricing to avoid any surprised.</blockquote><p>In the screenshot below, you will find that there is a dropdown for the region that you can select and see the prices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*se9ZwqHRtcHvFoiw" /></figure><p>The pricing is classified into:</p><ul><li>On-demand price</li><li>Preemptible price</li><li>1 year commitment price</li><li>3-year commitment price</li></ul><p>This can be confusing but let’s understand it with an example that we shall work through with the help of the GCP Cost Calculator. We will also throw in some other variations.</p><h4>Our Running Example</h4><p>First up, we will finalize that we are interested in provisioning a Compute Engine VM instance type (<strong>n1-standard-1</strong>), which has the following configuration:</p><pre>vCPU     : 1<br>RAM (GB) : 3.75 GB<br>Region   : Mumbai<br>OS       : Free (Linux)</pre><p>Remember that I mentioned that GCP charges you for duration that you keep the VM running. So you run it 24 x 7 i.e. 7 days a week and for 24 hours a day i.e. you keep the VM running. GCP charges you by the rate per hour for that instance type.</p><p>But do consider that not everything needs to run 24 x 7. For e.g. consider organizations that have a <strong>development , test and production environments</strong>. Sure the production environments run 24 x 7 but my development / test environment might only run for 5 days a week (Mon-Fri) and 8 hours a day (9:00AM — 5:00 PM).</p><p>So I should be charged less right ? Correct. Let’s go step by step.</p><p>First up, we will use the GCP Cost Calculator available at (<a href="https://cloud.google.com/products/calculator">https://cloud.google.com/products/calculator</a>) and see what it costs to run this VM.</p><p>Visit the <a href="https://cloud.google.com/products/calculator">URL</a> and enter the values as:</p><pre># instances : 1<br>OS : Free<br>Series : N1<br>Machine Type : n1-standard-1<br>Region : Mumbai</pre><p>Ensure that you select 24 hours per day and 7 days per week as shown below. Click on “Add to Estimate”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F8H0Pu3gplheWDeW" /></figure><p>This will show the pricing to you on the right side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C6FOqedK7KphymGG" /></figure><p>Note 3 things here first:</p><ul><li>The pricing is for the full month : 730 hours per month i.e. your VM is in running state throughout the month.</li><li>You can change the currency to one that you want. This is very useful to share with clients that would like to be billed or want to see what it costs for them in their currency of choice.</li><li>You can email this estimate or even click on Save Estimate to get a URL to share and keep collaborating on the pricing.</li></ul><p>Notice one of the entries in the billing details <strong>“Sustained Use Discount : 30%” </strong>. What is going on here? Google Cloud provides an automatic discount (upto a certain %) off the list price, when you use the VM for more time , in our case the <strong>full duration of the month</strong>.</p><p>The more you use, the more discount you get. Check this graph out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*T7mvERAvpZIzqt-l" /></figure><p>If you use it for just 15 days a month, we still give you a % discount. This is Sustained Use Discount (SUD) and it is covered here: <a href="https://cloud.google.com/compute/docs/sustained-use-discounts">https://cloud.google.com/compute/docs/sustained-use-discounts</a></p><p>That’s great , isn’t it ? No need to do complex calculations — we pass on the discount as per your usage.</p><h4>What about Developer and Test Environments?</h4><p>Next up, remember the dev and test environments? What if you wanted to run this for the following:</p><ul><li>5 days a week (Monday — Friday)</li><li>8 hours a day</li></ul><p>Let’s click on the Edit button for the pricing as shown below. This will populate the entries in the form of the GCP Calculator, where you can then tweak any settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TaEtMRR94d7APYbD" /></figure><p>Now go ahead and change the values as shown below:</p><ul><li>8 hours per day</li><li>5 days per week</li></ul><p>And click on <strong>“Add to Estimate”</strong> again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B0PZTl0z5lgxXJ6o" /></figure><p>This will bring up the revised pricing as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ruG8yh0I2Rddjr3_" /></figure><p>That’s a nice discount , isnt it ? So always plan out your different environments (Production, Development , Testing) and how long the VMs need to be running.</p><p>Don’t pay for resources that are idle and you are not using. Best Practice : <a href="https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop">https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop</a></p><h4>What are Committed Use Discounts (CUD)?</h4><p>Now, what let’s come to Committed Use Discounts (CUD). If you are willing to commit to running these instances all the time for a period of 1 yr or 3 yr, Google Cloud can give additional discounts. Read about CUD here (<a href="https://cloud.google.com/compute/docs/instances/signing-up-committed-use-discounts">https://cloud.google.com/compute/docs/instances/signing-up-committed-use-discounts</a> )</p><p>Let’s see how to do that in the calculator. Let’s edit the previous entry back to running it 24x7 , so that the total is shown as below. This time, we will also label this line item as : SUD Server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/0*HmfueBoo32814CVN" /></figure><p>Next up, add another VM resource with the following:</p><pre># instances : 1<br>What for : CUD-1yr<br>OS : Free<br>Series : N1<br>Machine Type : n1-standard-1<br>Region : Mumbai<br>Committed Use Discount : 1 yr</pre><p>Click on <strong>“Add to Estimate”</strong></p><p>Next up, add another VM resource with the following:</p><pre># instances : 1<br>What for : CUD-3yr<br>OS : Free<br>Series : N1<br>Machine Type : n1-standard-1<br>Region : Mumbai<br>Committed Use Discount : 3 yr</pre><p>Click on <strong>“Add to Estimate”</strong></p><p>This will bring up the following pricing and you can see how it is beneficial to go for CUD pricing, if you plan to commit to GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/0*EZGtrdFixa6xz8e2" /></figure><p>Hope this was useful.</p><p>I plan to cover more some nuances next on Compute Engine pricing vis-a-vis <a href="https://iromin.medium.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-2-78ee7ff783b8">Custom Machine Types</a> and <a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-3-7c0883681a7b">Preemptible VMs</a> in another thread.</p><p>Till then, Happy Pricing !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d71f2cf2bd14" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/a-working-guide-to-understanding-google-compute-engine-pricing-options-part-1-d71f2cf2bd14">A working guide to understanding Google Compute Engine Pricing Options — Part 1</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing in a Multilingual Agent in Dialogflow]]></title>
            <link>https://rominirani.com/writing-in-a-multilingual-agent-in-dialogflow-6ff9a43b9839?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/6ff9a43b9839</guid>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[multilingual]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[hindi]]></category>
            <category><![CDATA[dialogflow]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Thu, 16 Jul 2020 11:58:46 GMT</pubDate>
            <atom:updated>2020-07-16T12:03:45.798Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developing a multilingual Agent in Dialogflow</h3><p><a href="http://dialogflow.com">Dialogflow</a> is a great tool for designing and building out Agents that can run in a variety of Messaging Platforms. In my interactions with customers, a frequent request that comes up is about support for multiple languages. Not just that but complex scenarios like “Can an Agent support more than 1 language in a single utterance?”, etc.</p><p>The objective of this blog post is to show you step by step how you can start designing an Agent in Dialogflow that can support two languages. It will cover just about enough to give you a start and you can build upon it.</p><h3>Pre-requisites</h3><p>I shall assume that you know how to use Dialogflow to build out an Agent and are familiar with the environment and key building blocks like Intents, Entities, etc.</p><p>I am going to use English and Hindi as two languages that the Agent understands, so I will expect you to make sense of the Hindi that you see in this blog post.</p><h3>What are we going to build?</h3><p>We are going to build an Agent for a Hotel chain that lets you book a room in one of the cities that it has resorts in. We are not going to make things complex here since the idea is to show you the multilingual feature.</p><p>Here is a sample interaction with my Agent in <strong>Hindi</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*82MAT5_zHvAIqCaYahIt-g.png" /></figure><p>And here is the same interaction in English:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*770fgytRGhDp2ZxOwmLKfA.png" /></figure><h3>Let’s get started</h3><p>Log in to the Dialogflow flow console with your account and click on <strong>Create New Agent</strong>, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*3BwONcuyLWjbdof7jwWFZQ.png" /></figure><p>This will bring up a form as shown below. Provide a name to your Agent, go with all other defaults, including <strong>English </strong>as the default language and click on <strong>Create</strong>. Let’s assume that the name of the Agent for this tutorial is <strong>MyMultilingual Agent</strong>.</p><blockquote>You will see screenshots with the Agent name as <strong>Romin-MultilingualBot</strong> but for your reading, you can assume the name is <strong>MyMultilingual Agent</strong></blockquote><p>On successful creation, you will have the standard two intents : Default Fallback Intent and Default Welcome Intent created for you.</p><p>Go to the <strong>Settings </strong>page for the Agent and then to the Languages. You will only see <strong>English — en </strong>listed, which is the default language that we had selected at the time of creation of the Agent. Click on <strong>Select Additional Language </strong>and then select <strong>Hindi </strong>from the list.</p><blockquote>If you are upto it, pick another language that you are familiar with instead of Hindi and follow along accordingly.</blockquote><p>You should see something similar to the screen shown below. Also notice , how on the left-pane, you now see two chips indicating the two languages that the Agent now supports i.e. <strong>en </strong>and <strong>hi</strong>. Click on <strong>Save</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gachKQmlTL3oXbPeuUvfsg.png" /></figure><blockquote>Important → Every time that you have to work with a specific language, make sure to select the language chip from the Top Left. This way you know which language you are in and for which, you are now configuring Intents, Entities and so on.</blockquote><h3>Support for English</h3><p>For the default English language, we are not going to do anything special. If you are familiar with the default Intents (Welcome and Fallback) that are generated, we are good. We are not going to modify anything over there.</p><p>Ensure that you have select the English language <strong>en </strong>for the Agent. Then let’s do a couple of things for this Agent.</p><ul><li>Add a <strong>resort-location</strong> Entity</li></ul><p>We don’t want users to select any city in which this Hotel chain has resorts in. We would like to restrict it only to cities in which they have resorts. To do this, we are going to define a Custom Entity named <strong>resort-location </strong>and restrict the values over there.</p><p>Go ahead to Entities and create a Custom Entity <strong>resort-location </strong>as shown below and click on <strong>Save</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*d51SbdTLJ9KRdMf_m76jvw.png" /></figure><ul><li>Add a new Intent <strong>Book Holiday Intent</strong></li></ul><p>Click on <strong>Intents </strong>and then add a New Intent named <strong>Book Holiday Intent</strong>. In the sample phrases give the following and make sure that the custom entity <strong>@resort-location </strong>is detected currently for the parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*89QOlYcwfwavBiSF9rOF9Q.png" /></figure><p>Go to <strong>Actions and Parameters</strong> section and mark the <strong>resort-location </strong>parameter as <strong>required.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*eHhpyBxiFQuB5L9eCo_klw.png" /></figure><p>If the user does not provide us with the required parameter, we need to prompt them for the value. For that, I set the Prompt text for this variable (last column in the above table) as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*93ZnJ6gNAr1eOtBLxFUlpQ.png" /></figure><p>Finally, provide a simple Text Response that the Intent gives out as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*nipRPdpUaXZnfymitW34xQ.png" /></figure><p>Click <strong>Save </strong>and let the training get completed.</p><p>There we go ! We have our Agent ready and you can test it out in the Test console on the right. Remember that you have already selected the <strong>English Language (en) </strong>for the Agent, hence the Test console will assume an interaction in English language.</p><p>Give it a spin as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*EmJkLBFgupnvprK0WCGUpA.png" /></figure><p>We are looking good now for our English support. Let’s figure out Hindi language support now.</p><h3>Support for Hindi</h3><p>First thing that you need to do now (I am sure you know what that is…) is to switch to <strong>Hindi </strong>language. From just below the Agent name, switch to Hindi by choosing the language chip as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*o2My53uhdZzLPEYvvVzlYw.png" /></figure><p>Now, visit the Intents section and you will see all the 3 intents that we have so far:</p><ul><li>Default Welcome Intent</li><li>Default Fallback Intent</li><li>Book Holiday Intent</li></ul><p>Click on either the Welcome or the Fallback Intent and you will notice that Dialogflow has provided us with sample phrases in the language for both the intent. Wonderful, isn’t it? Sample screenshots for the two intents are given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*NAc7hb6VZkiIjZxACJb2Ow.png" /></figure><p>and the Fallback Intent is given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*ti0zaJjtmVkX-Usm1GVlMg.png" /></figure><p>This means that if you would like to test these two intents right away in the language, go ahead and test them out in the console.</p><p>Let’s get back to the two things that we need to modify for Hindi language:</p><ul><li><strong>resort-location </strong>entity</li><li>Book Holiday Intent</li></ul><p>First, up visit the <strong>Entities </strong>section. You will see that the <strong>resort-location </strong>entity is present but it will not have any values in Hindi language. So go ahead and enter the Hindi specific values as given below and remember to click the <strong>Save </strong>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*jSmtqQxNyYCH0SMwVWqfYw.png" /></figure><p>Next up, visit the <strong>Intents </strong>and click on Book Holiday Intent. The values will once again be empty, but let’s fill them up in the right sequence as given below.</p><p>First up, provide the sample phrases for booking a room as given below. You can use your own nuances too in Hindi (and please excuse my language skills).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Q3SnvLaK87J7rUkTE0veDw.png" /></figure><p>See how it is able to map the city value to the <strong>resort-location </strong>entity.</p><p>Next up, in the Actions and Parameters section, we need to provide a prompt for our parameter in Hindi language. Click on prompt for the <strong>resort-location </strong>parameter and provide some text. An example is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*6gL4GIhTFifmz1X6UBhlVw.png" /></figure><p>Finally, let’s provide the text response too as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*odRrzd9_D0ZRoFSbxiW5Zw.png" /></figure><p>Remember to Save. That’s it. We can now go and test the same in the console. Ensure that the language selected is still Hindi. A sample interaction in the Test Console is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*aiwyvYlMgSEchPrvBIq-eA.png" /></figure><p>and another interaction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*F10QL5mzM8Mz196CCnx0XQ.png" /></figure><h3>Testing the Integration</h3><p>You can even test it out in the <strong>Integrations → Dialogflow Messenger </strong>, which is in Beta:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*hgGC8-PQFnYRe_RTwSEwgw.png" /></figure><p>It will show you a snippet of code that you can insert into your web site or you can try it out there itself. For those of you with sharp eyes , you will notice that the language is indicated in the iframe snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*-7nfk6jGIzvcWzH4IpcDAQ.png" /></figure><p>Click on <strong>TRY IT NOW</strong> button and experience your Agent.</p><p>Hope you liked the tutorial. Let a thousand multilingual Agents bloom !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ff9a43b9839" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/writing-in-a-multilingual-agent-in-dialogflow-6ff9a43b9839">Writing in a Multilingual Agent in Dialogflow</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cloud Functions Tutorial : Using the Cloud Scheduler to trigger your functions]]></title>
            <link>https://rominirani.com/google-cloud-functions-tutorial-using-the-cloud-scheduler-to-trigger-your-functions-756160a95c43?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/756160a95c43</guid>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cron]]></category>
            <category><![CDATA[cloud-scheduler]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 10:18:22 GMT</pubDate>
            <atom:updated>2018-11-08T10:18:10.732Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Cloud Functions Tutorial : Using the Cloud Scheduler to trigger your functions</h3><blockquote>This is part of a <a href="https://rominirani.com/google-cloud-functions-tutorial-series-f04b2db739cd">Google Cloud Functions Tutorial Series</a>. Check out the series for all the articles.</blockquote><p>By now, you will be familiar with creating Cloud Functions (foreground and background) and associating the appropriate trigger i.e. HTTP Trigger, PubSub Trigger and others. We usually find that we have a need to trigger the Cloud Function at regular intervals.</p><p>Consider the following Cloud Functions that you might have written:</p><ol><li>A function that checks a Stock Price every 10 minutes and sends you an email.</li><li>A function that runs once a day at 3:00 AM to begin the process of taking a backup.</li></ol><p>You could even have complex scheduling like run a Cloud Function every Monday, Wednesday and Friday at 10:00 AM.</p><p>In all the above situations, you have the following requirements:</p><ol><li>A Service that will trigger your Cloud Function.</li><li>A Service that can accept simple to complex scheduling intervals. For e.g every NN minutes, every NN hours, every week on Friday at 10:00 PM and more. In other words, support a <a href="http://man7.org/linux/man-pages/man5/crontab.5.html">CRON like expression that we know from Unix world</a>.</li></ol><h3>Cloud Scheduler</h3><p>The <a href="https://cloud.google.com/scheduler/">Cloud Scheduler</a> now available in Beta helps us out in the above requirements.</p><p>As per the official documentation, Cloud Scheduler is an enterprise grade job scheduler that will help you automate your jobs across various Google Services in a standard fashion and comes with retry mechanisms that you can configure. It can also trigger your jobs in a variety of ways and currently supports invoking a HTTP endpoint, send a message to Cloud Pub/Sub and trigger an internal App Engine URL.</p><p>In our example here, we will be looking at <strong>triggering a sample Cloud Function every minute</strong>. Let’s go.</p><p>Before we begin, a few assumptions:</p><ol><li>You have an existing Google Cloud Platform project with Cloud Functions API enabled.</li><li>You have a sample Cloud Function ready with a HTTP Trigger associated with it. Let us assume that this Cloud Function is called <strong>function-1</strong>. <strong>Note down the HTTPs Trigger URL</strong> of the Cloud Function.</li><li>You need to enable the Cloud Scheduler API for your Google Cloud Platform project. From GCP console, visit APIs and search for Cloud Scheduler API as shown below:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*GsYub9MO8mKiH5DwZPLSWw.png" /></figure><p>Click on Cloud Scheduler API and click on Enable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*Ev88u2Wniaq0KSDkRffjQw.png" /></figure><blockquote>Once enabled, you might see a message that says that you will need to have credentials in order to use the API. That is fine for now, since we plan to do everything via the GCP console and Cloud Functions deployed inside the same GCP Project. The API credentials would be required in case you were making any requests to this API from external Apps.</blockquote><p>This completes our initial setup.</p><h3>Using the Cloud Scheduler</h3><p>We have completed the initial setup and have our Cloud Function <strong>function-1 </strong>ready. All we need to do now is to create a job in the Cloud Scheduler. All the details like the schedule, what to trigger and other parameters will be configured at the time of Job creation itself and are associated with the Job.</p><p>From the GCP Console main menu, visit the <strong>Cloud Scheduler </strong>page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*tUn9O93PMYyil_ERx-xxcQ.png" /></figure><p>Click on the <strong>Cloud Scheduler</strong> option. Since we do not have any jobs yet, we will see the message as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*BBoFZPtYZtM2YyRx0x6bTg.png" /></figure><p>Click on <strong>Create job</strong>. This will prompt you to select a region in which you would like to initialise the Cloud Scheduler. Select the appropriate region. You should see a message as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*Cs5kxr8HobBbvl1y8n4PiQ.png" /></figure><p>Once it is initialised, you will be led to a form to create a new job and you can provide the details as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*vNiLalmcaMu8VPjy8D1uTg.png" /></figure><p>The key things to note in the Job details form are:</p><ul><li><strong>Name</strong> : Give a unique name to your job.</li><li><strong>Frequency</strong> : Provide the cron expression. Since we want to trigger the function every minute, I use : * * * * *</li><li><strong>Timezone</strong> : You can select a specific timezone in which to execute the function. The Cloud Scheduler will use that.</li><li><strong>Target : </strong>As mentioned earlier, the Cloud Scheduler currently supports App Engine, HTTP and Pub/Sub. We will select HTTP i.e. ask the Cloud Scheduler to invoke a HTTP endpoint that we will specify next. This HTTP endpoint will be that of our HTTP Trigger based Cloud Function.</li><li><strong>URL</strong> : Provide the HTTPs endpoint of the Cloud Function i.e. <strong>function-1</strong>.</li><li><strong>HTTP method</strong> : This applies to HTTP invocations. You can choose from one of the HTTP methods like POST, GET, etc. In our case, we will use the POST method.</li></ul><p>Click on <strong>Create </strong>button. This will create the Job and you will see it listed in the list of jobs. You can either wait for the execution to happen (look at the <strong>Result </strong>column) since it is every 1 minute or if you want to invoke it directly click on <strong>Run now</strong>.</p><p>Once it has executed, you will see the status getting updated as shown below (only the specific columns are shown):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*RlE7MB9VkXDvLXO9ebNVIw.png" /></figure><p>Click on <strong>View</strong> button to see the logs. Here is the sample log statemens from one run of the job:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*t3oB5mxp1Lqn9kit6_9uaQ.png" /></figure><blockquote>Note that we could also have a Pub/Sub Trigger configured Cloud Function get triggered by the Scheduler by using the same steps given above to create a job. Except that in the target, you will select Pub/Sub and provide the Pub/Sub Topic name. At the scheduler trigger time, the Cloud Scheduler will publish a message to the topic with the message body that you specify.</blockquote><p>This completes our note on triggering a Cloud Function using the just released Cloud Scheduler service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=756160a95c43" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/google-cloud-functions-tutorial-using-the-cloud-scheduler-to-trigger-your-functions-756160a95c43">Google Cloud Functions Tutorial : Using the Cloud Scheduler to trigger your functions</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Book Review : The Fuzzy and the Techie]]></title>
            <link>https://rominirani.com/book-review-the-fuzzy-and-the-techie-b217468a24bd?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/b217468a24bd</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[liberal-arts]]></category>
            <category><![CDATA[book-review]]></category>
            <category><![CDATA[digital]]></category>
            <category><![CDATA[fuzzy]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Tue, 06 Nov 2018 10:35:08 GMT</pubDate>
            <atom:updated>2018-11-06T10:34:49.561Z</atom:updated>
            <content:encoded><![CDATA[<h3>Book Review : The Fuzzy and the Techie</h3><p>This is a book review of <a href="https://www.amazon.in/dp/B07CVJTD67/ref=dp-kindle-redirect?_encoding=UTF8&amp;btkr=1">The Fuzzy and the Techie : Why the Liberal Arts will Rule the Digital World</a> by Scott Hartley.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/0*ODGnUu9ZYXCB64Wn.jpg" /></figure><p>This book caught my attention a few months back since I am firmly of the belief that to create great products, it is not just about having technical prowess but a lot of other things and I specifically wanted to understand the role of liberal arts. It is this intersection of streams that is of deep interest to me.</p><p>The book is firm in its theme and gives numerous examples of how folks with either just a liberal arts background, or a combination of humanities + tech have been making significant contributions to digital products. This is not just from an ideating perspective but even working with technical folks to bring their ideas to reality.</p><p>The book is a good read. It gave me numerous examples of companies that either I had heard about or had no clue about. The latter was more interesting since I often found myself looking them up on the internet for precisely what they are doing. It was interesting to understand the background of the founders and honestly I have been humbled since I was not really sure if people with a very diverse background or completely unrelated background could go so deep and build a cutting edge or futuristic digital product. There are examples throughout the book and enough food for thought in multiple places.</p><p>What I would have liked to see more in the book would have been a deeper discussion into how specific diverse backgrounds played a role. I would have loved to hear more from the folks themselves. I do understand that a book might not be an effective format for that kind of discussion but I did feel like I wanted to understand the founder a bit more.</p><p>The book takes up multiple themes ranging from creating better learning outcomes, making technology work for humans, designing responsible products, the job skills needed for the future and more. Each of these themes can be a book in itself but it made me better understand that to effectively solve these problems would require a very different mindset and most likely a different stream that they took up instead of just engineering or medicine. I appreciated the fact that the author concluded that in the end , it is a partnership between the Techies and Fuzzies that will yield the best results.</p><p>The book is also a gentle reminder to parents, including myself (especially within the context of where I live … India) that we have to let go of current mentalities that push our kids only into Engineering and Medical streams. This book has been educating in multiple ways for me.</p><p>I give this book 3.5/5 stars.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b217468a24bd" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/book-review-the-fuzzy-and-the-techie-b217468a24bd">Book Review : The Fuzzy and the Techie</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cloud Functions Tutorial : Using Environment variables]]></title>
            <link>https://rominirani.com/google-cloud-functions-tutorial-using-environment-variables-20b4f0f82aa0?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/20b4f0f82aa0</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[google-cloud-functions]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Wed, 24 Oct 2018 14:53:11 GMT</pubDate>
            <atom:updated>2018-10-24T14:52:51.412Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Cloud Functions Tutorial : Using Environment variables</h3><blockquote>This is part of a <a href="https://rominirani.com/google-cloud-functions-tutorial-series-f04b2db739cd">Google Cloud Functions Tutorial Series</a>. Check out the series for all the articles.</blockquote><blockquote>At the time of writing this article, support for Environment variables in Google Cloud Functions is in Beta.</blockquote><p>As you start work your way through Cloud Functions, one of things that you will notice as you write them is that you often end up accessing other systems or define some constants, etc. You might want to connect to an external system for which you need to have a hostname, service name, etc.</p><p>The questions to ask are:</p><ol><li>Is it possible to define a Cloud Function and associate one or more Environment variables with it at the time of deployment?</li><li>Will the Cloud Functions runtime make it available to our function when it runs it?</li><li>Can we read these Environment variables directly in our code?</li><li>Can we use the standard gcloud functions command or the GCP Console to manage the Environment variables?</li></ol><p>The answer to all of the above questions is yes ! Enter Environment Variables in Cloud Functions.</p><h3>Using process.env</h3><p>Let us take a look at the existing environment variables that are already present. This is not something you want to do too much about but it comes in handy to understand which of these are reserved environment variables and used in some way or the other by Google Cloud Functions runtime.</p><pre>exports.helloEnvVariables = (req, res) =&gt; {<br> res.status(200).send(process.env);<br>};</pre><p>If you deploy the above Cloud Function, you should get an output that looks like this. It gives you an interesting amount of information.</p><pre>{<br> “X_GOOGLE_CODE_LOCATION”: “/user_code”,<br> “WORKER_PORT”: “8091”,<br> “X_GOOGLE_SUPERVISOR_INTERNAL_PORT”: “8081”,<br> “X_GOOGLE_WORKER_PORT”: “8091”,<br> “FUNCTION_IDENTITY”: “<a href="mailto:mygcpproject@appspot.gserviceaccount.com">mygcpproject@appspot.gserviceaccount.com</a>”,<br> “X_GOOGLE_LOAD_ON_START”: “false”,<br> “X_GOOGLE_FUNCTION_REGION”: “us-central1”,<br> “GCLOUD_PROJECT”: “mygcpproject”,<br> “FUNCTION_NAME”: “myEnvVarFunction”,<br> “X_GOOGLE_FUNCTION_MEMORY_MB”: “128”,<br> “SUPERVISOR_HOSTNAME”: “169.254.8.129”,<br> “X_GOOGLE_GCLOUD_PROJECT”: “mygcpproject”,<br> “PATH”: “/usr/local/bin:/usr/bin:/bin”,<br> “FUNCTION_REGION”: “us-central1”,<br> “PWD”: “/user_code”,<br> “FUNCTION_TRIGGER_TYPE”: “HTTP_TRIGGER”,<br> “FUNCTION_TIMEOUT_SEC”: “60”,<br> “X_GOOGLE_FUNCTION_TRIGGER_TYPE”: “HTTP_TRIGGER”,<br> “NODE_ENV”: “production”,<br> “SHLVL”: “1”,<br> “X_GOOGLE_FUNCTION_NAME”: “myEnvVarFunction”,<br> “X_GOOGLE_ENTRY_POINT”: “helloVersion”,<br> “X_GOOGLE_FUNCTION_IDENTITY”: “<a href="mailto:mygcpproject@appspot.gserviceaccount.com">mygcpproject@appspot.gserviceaccount.com</a>”,<br> “DEBIAN_FRONTEND”: “noninteractive”,<br> “CODE_LOCATION”: “/user_code”,<br> “X_GOOGLE_GCP_PROJECT”: “mygcpproject”,<br> “FUNCTION_MEMORY_MB”: “128”,<br> “GCP_PROJECT”: “mygcpproject”,<br> “X_GOOGLE_SUPERVISOR_HOSTNAME”: “169.254.8.129”,<br> “PORT”: “8080”,<br> “SUPERVISOR_INTERNAL_PORT”: “8081”,<br> “X_GOOGLE_FUNCTION_TIMEOUT_SEC”: “60”,<br> “ENTRY_POINT”: “helloVersion”,<br> “OLDPWD”: “/var/tmp/worker/”,<br> “_”: “/usr/bin/env”,<br> “HOME”: “/tmp”<br>}</pre><h3>Specifying your own Environment Variables</h3><p>To associate Environment Variables with your Cloud Function, you can do it in multiple ways:</p><ol><li>Use the GCP Console to define them at the time of creating/updating a Google Cloud Function</li><li>Use gcloud functions command to set and update them individually, a list of them or via a configuration file.</li></ol><p>In this tutorial, we will use the GCP Console, but if you would like to do the same via the gcloud functions command, you can read up the documentation here: <a href="https://cloud.google.com/functions/docs/env-var#setting_environment_variables">Using environment variables</a>.</p><p>Let us go ahead and create a Google Cloud Function via the GCP Console. I am assuming that you know that by now via this series and are able to bring up the Create Function form on your own.</p><p>If you scroll right down, you will find a <strong>More</strong> link. Click that and the Environment Variables section should show up as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*JxOUnpcJQwwXEO7NUBl6kw.png" /></figure><p>Click on the <strong>Add variable </strong>button to add variables as you want. We will define four variables as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*PGeWMzkrL6PpZeOeJFewkA.png" /></figure><p>To use any specific environment variable value in your Google Cloud Function, you will have to use the process.env statement as shown below:</p><pre>exports.helloEnvVariables = (req, res) =&gt; {<br>  let minVer = process.env.MIN_VER;<br>  let maxVer = process.env.MAX_VER;<br>  let maxResults = process.env.MAX_RESULTS;<br>  let hostName = process.env.HOSTNAME;<br>  res.status(200).send(&quot;Function version:&quot; + maxVer + &quot;.&quot; + minVer);<br>};</pre><p>If you deploy and run this function, it will send back the following response text:</p><pre>Function version:1.2</pre><h3>A few points around using Environment Variables</h3><p>Using Environment Variables in Google Cloud Functions is straight forward but there are a few things to keep in mind:</p><ol><li>The size of the variable names and values is limited to 32KiB. Additionally, there are reserved names for Environment variables and you saw that in the first example that we ran.</li><li>Once you have deployed a Google Cloud Function with Environment variables or you are associated Environment variables for the first time for an existing Google Cloud Function, you cannot just apply any changes to Environment variables without deploying the function. In other words, any change to Environment variables requires a full function deploy.</li><li>Extending point (2), keep in mind that when you deploy a new version of the function with updated Environment variables, the changes may not be immediately available on the next invocation of your function. I strongly recommend this talk by <a href="https://medium.com/u/fd9f69cf1fc2">Jason Polites</a> (Twitter: <a href="https://twitter.com/jplts">@jplts</a> ). If you are working with Google Cloud Functions — do spend time with this</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMBBQ6P3GauY%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMBBQ6P3GauY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMBBQ6P3GauY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/66081576ef88238ee8e405c5c8111d51/href">https://medium.com/media/66081576ef88238ee8e405c5c8111d51/href</a></iframe><p>4. The scope of the Environment variables is limited to your specific Cloud function. You cannot share it across multiple functions.</p><p>5. Environment variables are not the place to put sensitive data. So do not keep credentials (usernames, passwords, keys) or anything that you do not want others to get a hold off. Take a look at this article by <a href="https://medium.com/u/3bbb601727dc">Seth Vargo</a> (Twitter: <a href="https://twitter.com/sethvargo">@sethvargo</a>) on managing secrets in serverless.</p><p><a href="https://www.sethvargo.com/secrets-in-serverless/">Secrets in Serverless | Seth Vargo</a></p><p>Here is an excellent article on using process.env and specifically I would recommend the section “When to use it” to understand common use cases that are a good fit for Environment variables.</p><p><a href="https://codeburst.io/process-env-what-it-is-and-why-when-how-to-use-it-effectively-505d0b2831e7">process.env: What it is and why/when/how to use it effectively</a></p><p>6. In case you are providing Environment variables to your Cloud Functions via a configuration file at the time of gcloud functions deploy , do remember to add that file potentially to your .cloudignore and .gitignore files.</p><h4>Reference</h4><p>Official Documentation on Environment Variables → <a href="https://cloud.google.com/functions/docs/env-var#using_environment_variables">https://cloud.google.com/functions/docs/env-var#using_environment_variables</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20b4f0f82aa0" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/google-cloud-functions-tutorial-using-environment-variables-20b4f0f82aa0">Google Cloud Functions Tutorial : Using Environment variables</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cloud Functions Tutorial : Deploying from a Source Repository]]></title>
            <link>https://rominirani.com/google-cloud-functions-tutorial-deploying-from-a-source-repository-6cb0d4b81cd8?source=rss----6fc063f083b1---4</link>
            <guid isPermaLink="false">https://medium.com/p/6cb0d4b81cd8</guid>
            <category><![CDATA[cloud-repositories]]></category>
            <category><![CDATA[google-cloud-functions]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[faa]]></category>
            <dc:creator><![CDATA[Romin Irani]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 06:56:05 GMT</pubDate>
            <atom:updated>2018-10-23T06:56:05.333Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Cloud Functions Tutorial : Deploying from a Source Repository</h3><blockquote>This is part of a <a href="https://rominirani.com/google-cloud-functions-tutorial-series-f04b2db739cd">Google Cloud Functions Tutorial Series</a>. Check out the series for all the articles.</blockquote><p>In the series so far, we have deployed our source code directly. What I mean by that is that we either had the source code present in a local folder and then we used gcloud to deploy the function or we used the Cloud Console Web UI to paste our source code directly. If you have taken a closer look, you would have noticed that one of the options available for deploying your Function is to use a Source Code Repository like Git to host your function code and deploy it directly from there.</p><p>The ability to host our Source code in a Git repository and use that as a basis to deploy our function code has multiple benefits. It fits with a typical development workflow that we use today. Additionally, you can maintain versions of your function code and also have automatic builds done for you via the source code checkin trigger. Let’s learn the mechanics of how to do this now.</p><p>First up, if you visit the Cloud Console Web UI for creating a Cloud Function, you can see the option for Source Code Repository as shown below (only relevant sections from the <strong>Create Function</strong> form ):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*-kT89xtkuIzxynfQAuC_rw.png" /></figure><h3>Google Cloud Source Repositories</h3><p>Did you know that each Google Cloud Platform project comes with a Git repository ? This is available in the Cloud Console main menu via the Source Repositories option shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*56xjPQxRW6ZgoxNTNchTjQ.png" /></figure><p>What we shall be doing is the following:</p><ol><li>As mentioned earlier, all the code in this series is available at Github at <a href="https://github.com/rominirani/googlecloudfunctions-training">https://github.com/rominirani/googlecloudfunctions-training</a>. So we already have a Git repository created for us over there. <strong>I am assuming that you have cloned this repository under our own Github account. This is important and do not miss this step.</strong></li><li>We are going to initialize a repository in our GCP Project and connect it to the Github repository that we have created in Step 1. All code that you push / update to this Github repository will be kept in sync by the Google Cloud Source Repository.</li><li>At the time of deploying our function, we can refer to the Google Cloud Source Repository, specify the branch and the folder in which the specific function source is present and the deployment then happens automatically for us.</li></ol><p>Let’s do it.</p><p>Google Cloud Source Repositories has been revamped significantly and a Beta version is available, at the time of writing this blog post. I shall use the Beta version and in case you see a message asking you to use the Beta version, please do so.</p><p>The Beta version available at <a href="https://source.cloud.google.com/">https://source.cloud.google.com/</a> looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Je2f_gHaIx-mfrHifLaxvg.png" /></figure><p>If you click on <strong>View All Repositories</strong>, you will see all your GCP Projects and the associated repositories for the same. We shall go ahead and create a new respository. To do that, click on the <strong>New repository </strong>button in the top right corner.</p><p>You have a couple of options as shown below and I am choosing the 2nd option since I would like to connect this repository to an already initialized and available repository that I have for this series at Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*5BDrJknQgbg5ElB6HYaa_A.png" /></figure><p>Click on <strong>Continue. </strong>This will bring up a screen below where you should select your existing GCP Project and choose the provider as Github. Give the appropriate consent and complete the formalities of connecting to Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*vhHCnDlkvFz8BnyKEWNMjQ.png" /></figure><p>Once you click on <strong>Connect to Github</strong>, you will need to authorize Google Cloud Platform to access your Github account and repositories that you have under it and select the particular repository on Github to connect to. Please do that. You should see a message similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*6QVpLzXNNB_6kjyGm0XhOQ.png" /></figure><p>If all goes well, your Github repository will be available under Source Repositories as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AZTob6pZ2GGBbsEffXnIOA.png" /></figure><p>We are able to see our README.md file and that is a good thing ! :-)</p><p>This completes our section of connecting an existing Github repository to Cloud Source Repositories. You can continue to use your standard Git workflow to checkin files into Github repository and the same will get mirrored into the Cloud Source Repositories. The synchronisation is done for you.</p><p>The important thing to note from the above screen is the repository name and the branch name. An example is shown below. This should also help you understand that a GCP Project can have one or more repositories (a default one and multiple others like these as shown below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*zJIwTWsG8Qp9nqOHOAzPtA.png" /></figure><p>You can click on the Repository and Branch drop down arrows to view the details. What I particularly liked was that you could look at various branches, tags, commits and everything that has happened in Github directly from Cloud Source Repositories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*kwCvQKcwW1QP7PQXo6IXjg.png" /></figure><h3>Deploying our function from Cloud Source Repository</h3><p>We are going to deploy a HTTP Trigger based function that is present in the helloworld-http folder of our repository as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*uI8nOzh5QorhIoWamhTCdg.png" /></figure><p>Few things to note here:</p><ol><li>Repository Name : <a href="https://source.cloud.google.com/mindstormclouddemo/github_rominirani_googlecloudfunctions-training">github_rominirani_googlecloudfunctions-training</a></li><li>Branch/Tag : Branch</li><li>Branch Name : master</li><li>Folder in which the index.js file is present : helloworld-http</li><li>Function to execute : helloGET</li></ol><p>Once ,we have this information, we can visit the GCP Console for New Function and provide the information as given above and click on Create Function. Your function should deploy successfully and ready to be invoked!</p><blockquote>This is part of a <a href="https://rominirani.com/google-cloud-functions-tutorial-series-f04b2db739cd">Google Cloud Functions Tutorial Series</a>. Check out the series for all the articles.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cb0d4b81cd8" width="1" height="1" alt=""><hr><p><a href="https://rominirani.com/google-cloud-functions-tutorial-deploying-from-a-source-repository-6cb0d4b81cd8">Google Cloud Functions Tutorial : Deploying from a Source Repository</a> was originally published in <a href="https://rominirani.com">Romin Irani’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>