<?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[Stories by Krutika Pasalkar on Medium]]></title>
        <description><![CDATA[Stories by Krutika Pasalkar on Medium]]></description>
        <link>https://medium.com/@khpasalkar16?source=rss-56f3a93f281f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8YqvYRf19ej-2fzBq3-0ww.jpeg</url>
            <title>Stories by Krutika Pasalkar on Medium</title>
            <link>https://medium.com/@khpasalkar16?source=rss-56f3a93f281f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:12:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khpasalkar16/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[Using Cloud Armor to allow/block specific countries/regions from accessing application deployed on…]]></title>
            <link>https://khpasalkar16.medium.com/using-cloud-armor-to-allow-block-specific-countries-regions-from-accessing-application-deployed-on-596433ca1ca5?source=rss-56f3a93f281f------2</link>
            <guid isPermaLink="false">https://medium.com/p/596433ca1ca5</guid>
            <dc:creator><![CDATA[Krutika Pasalkar]]></dc:creator>
            <pubDate>Thu, 25 Mar 2021 21:24:30 GMT</pubDate>
            <atom:updated>2021-03-25T21:24:30.119Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Cloud Armor to allow/block specific countries/regions from accessing application deployed on GCP App Engine</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*eLoipRkYQrposwpt-W025w.png" /><figcaption>GCP App Engine</figcaption></figure><p>In the App engine, we have firewall rules to allow/block traffic based on IP ranges. But what if we want to allow/block traffic from specific countries/regions?</p><p>In order to achieve this we can use Cloud Armor. Cloud Armor helps protect your applications and websites against denial of service and web attacks. You can check the <a href="https://cloud.google.com/armor">GCP documentation</a> to learn more.</p><p><strong>Note</strong> : It is assumed that application is already deployed and running on App Engine.</p><p><strong>We need to follow 3 major steps:</strong></p><ol><li>Creating Load balancer which will serve App Engine application as backend</li></ol><p>2. Configure Cloud Armor policy to allow/block specific countries/region</p><p>3. Disable the default appspot url of App Engine</p><h3>Lets get started!</h3><h3>Step 1: Creating Load balancer which will serve App Engine application as backend</h3><p>Cloud Armor cannot directly be applied to App Engine endpoint. Hence, we will have to create a Google load balancer and add our app engine service as a backend. We will create serverless NEG for this purpose</p><p><strong>Tips</strong>: A serverless NEG is a backend that points to a Cloud Run, App Engine, or Cloud Functions service.</p><p>For more information, you can refer to this <a href="https://cloud.google.com/load-balancing/docs/negs/serverless-neg-concepts">GCP documentation</a></p><ol><li><strong>Create Serverless Neg</strong></li></ol><p>Use below gcloud command to create serverless Neg</p><pre>gcloud compute network-endpoint-groups create &lt;SERVERLESS_NEG_NAME&gt;\<br>             region=us-central1 \<br>             --network-endpoint-type=SERVERLESS \<br>             --app-engine-service=default</pre><p><strong>Note</strong>: default is the app engine service you want to have behind LB.</p><p>Us-central1 is the region where app engine is deployed</p><p><strong>2. Create a Backend Service that points to your Serverless NEG</strong></p><p>Create backend service for Load Balancer using below gcloud command</p><pre>gcloud compute backend-services create &lt;BACKEND_SERVICE_NAME&gt; \<br>              --global</pre><p>Add backend to service using below gcloud command</p><pre>gcloud compute backend-services add-backend --global \<br>            &lt;BACKEND_SERVICE_NAME&gt; \<br>            --network-endpoint-group=&lt;SERVERLESS_NEG_NAME&gt; \<br>            --network-endpoint-group-region=us-central1</pre><p><strong>3. Create a URL map to route incoming requests to the backend service</strong></p><p>Use below gcloud command to create url map</p><pre>gcloud compute url-maps create &lt;URL_MAP_NAME&gt; \ <br>             --default-service &lt;BACKEND_SERVICE_NAME&gt;</pre><p>If you want to create an HTTPS load balancer, you must have an SSL certificate resource to use in the HTTPS target proxy. To create a SSL certificate, you must have a domain (If you don’t have a domain, you can use a self signed SSL certificate).</p><p>We can create self managed or google managed SSL certificates.</p><p>For now, I will create an HTTP load balancer. Hence will not require any SSL certificate.</p><p><strong>4. Create target proxy</strong></p><p>Use below gcloud command to create target proxy</p><pre>gcloud compute target-http-proxies create &lt;TARGET_HTTP_PROXY_NAME&gt; \<br>             --url-map=&lt;URL_MAP_NAME&gt;</pre><p><strong>5. Create global forwarding rule</strong></p><p>Use below gcloud command to create global forwarding rule,</p><pre>gcloud compute forwarding-rules create &lt;HTTP_FORWARDING_RULE_NAME&gt; \<br>             --target-http-proxy=&lt;TARGET_HTTP_PROXY_NAME&gt; \<br>             --global \<br>             --ports=80</pre><p>Our Load balancer is set up now.</p><p>You can get the IP address at which your load balancer is serving either by going to GCP console in Load balancing under Frontends or you can use below command,</p><pre>gcloud beta compute forwarding-rules describe \        &lt;HTTP_FORWARDING_RULE_NAME&gt; --global</pre><p>It will print a field containing an IP address.</p><p>Eg.</p><p>IPAddress: xx.xx.xx.xx</p><h3>Step 2. Configure Cloud Armor policy to allow/block specific countries/region</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*oR4q6t5VTLJynCkQiB_Ahw.png" /><figcaption>Cloud Armor</figcaption></figure><p>Now as our Load balancer is set up. It’s time to configure security policies that will be applied to this load balancer. We will configure security policies on Cloud Armor to allow/block traffic from specific countries. (Apart from allow/block specific region traffic, there are many other features in cloud armor. You can refer to this <a href="https://cloud.google.com/armor/docs/configure-security-policies">GCP documentation</a> for more information)</p><ol><li>Go to Cloud Armor from GCP console</li><li>Click on Create Policy</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HWSzbPImBl2krJuzxFU0Rw.png" /><figcaption>Cloud Armor Policy</figcaption></figure><p>3. Give name and description to policy.</p><p>Select default rule action as deny. You can choose any Deny status code. I will choose 403 (Forbidden).</p><blockquote>The default rule action will have lowest priority. If you want to allow only specific countries, you can set a default action as deny. But if you want to allow all except some specific countries, you can set default as allow</blockquote><p>Here for eg, I will only allow US to access the application. Hence my policy default action will be Deny.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GkQJtf17rtulsZJ6TfNmQw.png" /><figcaption>Default rule in Cloud Armor policy</figcaption></figure><p>Click the next step.</p><p>4. On the second step (Add more rules), click Add rules</p><p>Here, since I want to allow only the US, I will create a rule for the US as follows.</p><p>Give description to rule. Select mode as Advanced mode. Click on Rule syntax help (You can refer to the picture)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*YgEF2q1QMaLzthzTHLy-iQ.png" /><figcaption>Policy rule syntax help in Cloud Armor</figcaption></figure><p>You can see the syntax for all the examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*u7x8pjeQ37FEgse2K55L-Q.png" /><figcaption>Syntax for all rule expression</figcaption></figure><p>Syntax rule based on country selection is</p><pre>origin.region_code == &#39;&lt;country_code&gt;&#39;</pre><p>Hence, for US is</p><pre>origin.region_code == &#39;US&#39;</pre><p>Click Action as Allow.</p><p>Priority as 100 (Priority is evaluated from 0 (highest) to 2,147,483,647 (lowest))</p><p>Click on Done</p><p>The summary will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*DIqCWBX0H4mmDGfF_VU9vg.png" /><figcaption>Summary of Policy rules in Cloud Armor</figcaption></figure><p>You can add multiple countries to allow traffic by adding clicking <strong>Add rule</strong></p><blockquote><strong>Note</strong>: If I had to allow all countries except the US, then the default rule would be Allow and in add more rules, I would have created a deny rule for the US.</blockquote><p>5. Once all rules are added, click on Next step</p><p>6. In Apply policy to targets, click on Add Target</p><p>Select Type as Load balancer and Target as the Load balancer just created above which is serving the App engine.</p><p>After select target, click Next step</p><p>7. Next, Advanced configurations are optional.</p><p>You can click Create Policy.</p><h3>Cloud Armor Policy is created !!!</h3><p>Now for all countries which we denied access will get 403 Forbidden error and they won’t be able to access our application.</p><p>We are not done yet. One main step is remaining.</p><h3>Step 3: Disable the default appspot URL of App Engine</h3><p>By default, App Engine applications serve requests at a URL of the form <a href="https://$project_id.appspot.com./">https://$PROJECT_ID.appspot.com.</a> This URL is automatically assigned when you create an App Engine app. We need to disable this appspot URL so that all user traffic goes through the load balancer. Otherwise, users can use the appspot URL to bypass the load balancer, including the Cloud Armor policy of allow/block traffic configured in above steps on the load balancer. Hence this is very important.</p><p>Update the default service of an App Engine app to accept traffic only from Cloud Load Balancing run below gcloud command:</p><pre>gcloud app services update default --ingress \<br>          internal-and-cloud-load-balancing</pre><h4>We are done!</h4><h3>Conclusion</h3><p>It was quite a long blog. I hope this was helpful for you all. It’s possible that I might have missed something. Please feel free to comment if so!</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=596433ca1ca5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Schedule the Start and Stop of GCP Compute Engine instances using Cloud Scheduler and Cloud…]]></title>
            <link>https://khpasalkar16.medium.com/schedule-the-start-and-stop-of-gcp-compute-engine-instances-using-cloud-scheduler-and-cloud-418e1da69045?source=rss-56f3a93f281f------2</link>
            <guid isPermaLink="false">https://medium.com/p/418e1da69045</guid>
            <category><![CDATA[cloud-scheduler]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Krutika Pasalkar]]></dc:creator>
            <pubDate>Sun, 13 Sep 2020 19:13:42 GMT</pubDate>
            <atom:updated>2020-09-13T19:13:42.389Z</atom:updated>
            <content:encoded><![CDATA[<h3>Schedule the Start and Stop of GCP Compute Engine instances using Cloud Scheduler and Cloud Function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*4dNUkbrJUG2ir-VtD3h9jw.png" /><figcaption>Google Cloud Platform</figcaption></figure><p>Google Cloud Platform is one of the fastest-growing cloud platforms. Compute Engine is an IaaS solution that GCP offers. Compute instances can be set up in the cloud to provide required amounts of computing power. Cloud allows you the pricing advantage of <strong>‘pay as you go’</strong>. Hence, we just have to pay for VMs based on the number of hours they are up and running. Most of the compute engine VMs of development and testing environments are idle after the working hours. Hence in order to save cost, we can spin down the instances when we have finished our work to avoid runaway cost. There can be situations where developers forgot to shut down the instances after work. In order to avoid such situations, we can automate the process of spinning down an instance after work hours and spin them up next morning.</p><p>In order to achieve this, we can create Cloud Function which will be triggered by Cloud Scheduler to shut down or start up instances.</p><p>The process can be illustrated using below Architecture Diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*2MbYWgE1rhggTzRS7OwWJA.png" /><figcaption>Architecture Diagram</figcaption></figure><p>We need two cloud scheduler jobs, <br><strong>Start_server_scheduler </strong>—<strong> </strong>To start a VM instance at required time in morning. Consider 9:00 AM.<br><strong>Stop_server_scheduler</strong> — To stop VM instances at required time in the evening. Consider 7:00 PM.</p><p>And, We need two cloud Functions, <br><strong>StartServer</strong> — Containing python code to start target server.<br><strong>StopServer</strong> — Containing python code to stop target server.<br>[ Here the target is only one instance. We can use metadata in order to target multiple instances ].</p><h3>Steps for implementation</h3><h4>Step 1: Create startserver Cloud Function</h4><p>Assuming that you already have a Google account. Go to the Google Cloud Console and login with your Google account.</p><p>Select a project where you want to create a scheduler or create a new project.</p><ol><li>Open the Cloud Functions Overview page in the Cloud Console</li><li>Click <strong>Create function</strong>.</li><li><strong>Name</strong> your function as <strong>StartServer</strong></li><li>Select <strong>Region</strong> as required. Suppose <strong>us-central1</strong></li><li>In the <strong>Trigger</strong> field, select <strong>HTTP</strong> <strong>Trigger</strong></li><li>In <strong>Authentication</strong>, Select <strong>Allow Unauthenticated invocations</strong></li><li>Click Save</li><li>No need to change Networking, Variables and Advance Settings</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*FH75zxM1Jp0hknE3-Q-RJg.png" /><figcaption>Steps to create StartServer Cloud Function</figcaption></figure><p>9. Configurations are set. Click on next to Add code.</p><p>10. In <strong>Runtime</strong>, Select <strong>Python3.7</strong></p><p>11. Select <strong>Source code</strong> as <strong>Inline Editor</strong>.</p><p>12. Select <strong>main.py</strong> file and click on edit. Add below lines of code.</p><pre>from google.auth.transport.requests import AuthorizedSession</pre><pre>from google import auth</pre><pre>PROJECT_ID=”<em>my-project</em>” # Update placeholder value</pre><pre>instance_zone=”<em>my-zone</em>” # Update placeholder value</pre><pre>instance_name=”<em>my-instance</em>” # Update placeholder value</pre><pre>def start_server(request):</pre><pre>    credentials, project = auth.default(scopes = [“https://www.googleapis.com/auth/cloud-platform&quot;])</pre><pre>    authed_session = AuthorizedSession(credentials)</pre><pre>    print(“starting server”)</pre><pre>    # you can call start multiple instance by calling below line passing different instance name</pre><pre>    response = authed_session.post(‘https://compute.googleapis.com/compute/v1/projects/{}/zones/{}/instances/{}/start&#39;.format(PROJECT_ID,instance_zone,instance_name))</pre><p>13. Select <strong>requirements.txt</strong> file and click on edit. Add below lines of code.</p><pre>google-auth==1.11.3</pre><p>14. In <strong>Entry point</strong>, specify <strong>start_server</strong></p><p>15. Click on <strong>Deploy</strong></p><h4>Step 2: Create stopserver Cloud Function</h4><ol><li>Open the Cloud Functions Overview page in the Cloud Console</li><li>Click <strong>Create function</strong>. [Assuming You have required permissions to create Cloud Function]</li><li><strong>Name</strong> your function as <strong>StopServer</strong></li><li>Select <strong>Region</strong> as required. Suppose <strong>us-central1</strong></li><li>In the <strong>Trigger</strong> field, select <strong>HTTP</strong> <strong>Trigger</strong></li><li>In <strong>Authentication</strong>, Select <strong>Allow Unauthenticated invocations</strong></li><li>Click Save</li><li>No need to change Networking, Variables and Advance Settings</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*GOsfeaDfwcKc4mBmjX5tLg.png" /><figcaption>Steps to create StopServer Cloud Function</figcaption></figure><p>9. Configurations are set. Click on next to Add code.</p><p>10. In <strong>Runtime</strong>, Select <strong>Python3.7</strong></p><p>11. Select <strong>Source code</strong> as <strong>Inline Editor</strong>.</p><p>12. Select <strong>main.py</strong> file and click on edit. Add below lines of code.</p><pre>from google.auth.transport.requests import AuthorizedSession</pre><pre>from google import auth</pre><pre>PROJECT_ID=”<em>my-project</em>” # Update placeholder value</pre><pre>instance_zone=”<em>my-zone</em>” # Update placeholder value</pre><pre>instance_name=”<em>my-instance</em>” # Update placeholder value</pre><pre>def stop_server(request):</pre><pre>    credentials, project = auth.default(scopes = [“https://www.googleapis.com/auth/cloud-platform&quot;])</pre><pre>    authed_session = AuthorizedSession(credentials)</pre><pre>    print(“stopping server”)</pre><pre>    # you can call stop multiple instance by calling below line passing different instance name</pre><pre>    response = authed_session.post(&#39;https://compute.googleapis.com/compute/v1/projects/{}/zones/{}/instances/{}/stop&#39;.format(PROJECT_ID,instance_zone,instance_name))</pre><p>13. Select <strong>requirements.txt</strong> file and click on edit. Add below lines of code.</p><pre>google-auth==1.11.3</pre><p>14. In <strong>Entry point</strong>, specify <strong>stop_server</strong></p><p>15. Click on <strong>Deploy</strong></p><h4>Step 3: Create start_server_scheduler Cloud Scheduler job</h4><ol><li>Go to Cloud Scheduler using this <a href="https://console.cloud.google.com/cloudscheduler">link</a> or go via navigation menu.</li><li>Click on Create Jobs. [Assuming You have required permissions to create Cloud Scheduler jobs]</li><li>Name your <strong>Job</strong> as <strong>start_server_scheduler</strong></li><li>Give <strong>Description</strong> to job. [optional]</li><li>Select frequency of Job as required. You have to specify the Cron expression for frequency.</li></ol><p>You can use <a href="https://crontab.guru/">crontab guru</a> to create cron expressions.</p><p>Eg. If you want to start server from Mon to Fri at 9 AM then specify as</p><pre>0 9 * * MON-FRI</pre><p>Here is the expression explanation on crontab guru.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*uNj-ICyTCy1xejTyzy9fJQ.png" /><figcaption>Cron expression</figcaption></figure><p>6. Select the <strong>timezone </strong>as<strong> </strong>applicable to you.</p><p>7. In <strong>Target</strong>, Select <strong>HTTP</strong>.</p><p>For URL,</p><p>Go to Cloud function Overview page in the Cloud Console</p><p>Click on <strong>StartServer</strong> cloud function</p><p>Go to <strong>Trigger</strong> tab</p><p>Copy the <strong>URL</strong> specified</p><p>Paste it in <strong>URL</strong></p><p>8. Click on <strong>Create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*2YHPbjzbncYeKCO6rxC7SA.png" /><figcaption>Step for Cloud SCheduler</figcaption></figure><p>9. Test the Scheduler by Clicking on <strong>Run Now</strong> button</p><p>10. Results should show success.</p><p>11. If the job failed, view logs and try troubleshooting</p><h4>Step 4: Create stop_server_scheduler Cloud Scheduler job</h4><ol><li>Go to Cloud Scheduler using this <a href="https://console.cloud.google.com/cloudscheduler">link</a> or go via navigation menu</li><li>Click on Create Jobs</li><li>Name your <strong>Job</strong> as <strong>stop_server_scheduler</strong></li><li>Give <strong>Description</strong> to job. [optional]</li><li>Select frequency of Job as required. You have to specify the Cron expression for frequency.</li></ol><p>You can use <a href="https://crontab.guru/">crontab guru</a> to create cron expressions.</p><p>Eg. If you want to stop server from Mon to Fri at 7:00 PM then specify as</p><pre>0 19 * * MON-FRI</pre><p>Here is the expression explanation on crontab guru.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*ncTrQWMQLSlptHttxMEXoA.png" /><figcaption>Cron expression</figcaption></figure><p>6. Select the <strong>timezone </strong>as<strong> </strong>applicable to you.</p><p>7. In <strong>Target</strong>, Select <strong>HTTP</strong>.</p><p>For URL,</p><p>Go to Cloud function Overview page in the Cloud Console</p><p>Click on <strong>StopServer</strong> cloud function</p><p>Go to <strong>Trigger</strong> tab</p><p>Copy the <strong>URL</strong> specified</p><p>Paste it in <strong>URL</strong></p><p>8. Click on <strong>Create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*kms0Nf9T26TQZJlVoO9pKw.png" /><figcaption>Steps for cloud scheduler</figcaption></figure><p>9. Test the Scheduler by Clicking on <strong>Run Now</strong> button</p><p>10. Results should show success.</p><p>11. If the job failed, view logs and try troubleshooting</p><h3>Done !</h3><p>Hope this was helpful and saved your time googling all this stuff. Please post any questions below in the comments section. I Will be glad to answer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=418e1da69045" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying an Angular Front-end with a Django Rest Framework Back-end on Google App engine]]></title>
            <link>https://khpasalkar16.medium.com/deploying-an-angular-front-end-with-a-django-rest-framework-back-end-on-google-app-engine-7a1ed4927f3d?source=rss-56f3a93f281f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a1ed4927f3d</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[app-engine]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Krutika Pasalkar]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 11:18:07 GMT</pubDate>
            <atom:updated>2021-06-18T14:06:20.071Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Deploying an Angular Front-end with a Django Rest Framework Back-end on Google App Engine</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*sVAkgWbSxar2gqEYcPmgUw.png" /><figcaption>App Engine</figcaption></figure><p>I was relatively new to <strong>Google cloud platform</strong> and had been struggling on how to deploy <strong>Angular</strong> + <strong>Django</strong> app on App Engine. Google App engine documentation and various other resources guides you how to deploy a Django app separately or an Angular app separately (running on a node server). Hence it might feel overwhelming to figure out how to deploy them together as a production ready application.</p><p>This article is for everyone who’s going through the same issue.The process is quite simple.</p><p>You can follow these <strong>11 steps</strong> in order to deploy your application on Google App Engine.</p><h3><strong>Let’s start</strong></h3><p>A little background first.</p><ul><li>App Engine is Platform-as-a-service i.e. <strong>PaaS</strong>. ( We need not worry about scaling. Google manages the infrastructure for you).</li><li>There are two environments — Standard and Flexible . We will deploy our application in the App Engine <strong>Standard</strong> environment.</li></ul><p><strong>Note</strong>. <em>This walk through will not be code centred. Deployment is what we are keen on.</em></p><h3><strong>Step 1: Designing your application</strong></h3><p>An App Engine app consists of <strong>one or more services</strong>. Each service can be configured to use different<strong> runtimes</strong> and to operate with different performance settings.</p><p>In our case, there will be two services. One for <strong>front-end </strong>and other for <strong>back-end</strong>.</p><p>The front-end service will have <strong>node</strong> runtime and the back-end service will have <strong>python3</strong> runtime.</p><p>Follow step 2 to 5 to deploy angular frontend service.</p><h3>Step 2: Change in <strong>baseurl</strong> in environment.ts file</h3><p>In src/environment/environment.ts</p><p>Change below lines</p><pre>export const environment = {<br>production: false,<br>urls: {<br>           baseUrl: &#39;<a href="https://restapi.net/&#39;">https://restapi.net/&#39;</a><br>      }<br>}</pre><p>Change it to,</p><pre>export const environment = {<br>production: false,<br>urls: {<br>            baseUrl: &#39;/api/&#39;<br>      }<br>}</pre><p><strong>baseUrl</strong> is the back-end server HTTP URL. As we will be deploying back-end in another service, the URL request should be routed to that service.</p><p>In step 11 we will configure a dispatch.yaml file for HTTP URL redirection to back-end service.</p><h3><strong>Step 3: Build your Angular App</strong></h3><p>Go to your angular app directory and run below command</p><blockquote>ng build</blockquote><p>This command will create a new <strong>dist</strong> folder which will contain minified CSS and JS files.</p><h3><strong>Step 4: Create Config file for front-end deployment</strong></h3><p>App engine uses a file called<strong> app.yaml</strong> to describe an app’s deployment configuration.</p><p>Create a blank file in your project directory and name it as app.yaml</p><p>Copy the below contents to your file,</p><pre>runtime: nodejs10<br>handlers:<br>- url: /<br>  static_files: dist/&lt;YOUR_APP_NAME&gt;/index.html<br>  upload: dist/&lt;YOUR_APP_NAME&gt;/index.html<br>  secure: always<br>- url: /<br>  static_dir: dist/&lt;YOUR_APP_NAME&gt;/<br>  secure: always</pre><p><em>( Using </em><strong><em>Secure: always </em></strong><em>is optional. You can remove that line. Please take care of indentation)</em></p><p><strong>Important</strong> — The directory structure should be the same as the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*u3XMpnvrcUzSb7hfUi3jaQ.png" /><figcaption>Directory structure for front-end</figcaption></figure><h3><strong>Step 5: Setting up GCP</strong></h3><p>Assuming that you already have a Google account. Go to the Google Cloud Console and login with your Google account.</p><p>create new project eg. application-deployment</p><p>In that project, create a <a href="https://console.cloud.google.com/storage/browser">Google Storage Bucket</a>. Name your bucket something e.g. application_code and leave the rest of things as default and click on create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*DMclJ9TXinU_LAONOVDbtw.png" /><figcaption>Create bucket UI in GCP console</figcaption></figure><p>Go to the bucket you just created (application_code) on the cloud console</p><p>upload your angular build code into this bucket by selecting the <strong>upload folder</strong> button.</p><h3><strong>Step 6: Deploy front-end in app engine</strong></h3><p>open the Google Cloud Interactive Shell. It is an in-browser terminal window provided by Google for your project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*jG9sRU2AY7B3ZCpsk9gcNw.png" /><figcaption>Cloud shell logo</figcaption></figure><p>Once you are connected to the Cloud Shell, create an app engine application.</p><blockquote>gcloud app create — project=&lt;PROJECT_NAME&gt;</blockquote><p>Create a directory for your app e.g. angular-app-gcp</p><blockquote>mkdir angular-app-gcp</blockquote><p>Sync data from bucket to this directory</p><blockquote>gsutil rsync -r gs://application_code ./angular-app-gcp</blockquote><p>Go inside the directory and deploy frontend</p><blockquote>cd angular-app-gcp</blockquote><blockquote>gcloud app deploy</blockquote><p>You will be asked for the<strong> zone/region</strong> where you’d like the App Engine to host your application. Select any zone.</p><p>After that, it will take a couple of minutes to deploy your application and will give you a link where you can access it. You can view your application link in the <a href="https://console.cloud.google.com/appengine">app engine console</a> as well.</p><p>Now our <strong>angular app is deployed</strong>.</p><p>Let’s start with <strong>Django</strong> deployment.</p><p>Follow step 7 to 10 to deploy django backend service</p><h3><strong>Step 7 : Changes in urls.py of all app in django project</strong></h3><p>Change all path in <strong>urlspatterns</strong> from</p><pre>path(“api1/”, method, name=”method”)</pre><p>To,</p><pre>path(“<strong>api</strong>/api1/”, method, name=”method”)</pre><p>Because we have changed the Baseurl by adding /api for url routing. Make sure to allow deployment url of frontend in django <strong>settings.py</strong></p><pre>ALLOWED_HOSTS = [‘&lt;project_name&gt;.&lt;region&gt;.appspot.com’]</pre><p>In the project directory, create <strong>main.py</strong> and paste below lines.</p><pre>from cosabackend.wsgi import application</pre><pre># App Engine by default looks for a main.py file at the root of the app directory with a WSGI-compatible object called app.</pre><pre># This file imports the WSGI-compatible object of the Django app, application from mysite/wsgi.py and renames it app so it is</pre><pre># discoverable by App Engine without additional configuration.</pre><pre>app = application</pre><h3><strong>Step 8: Create Config file for back-end deployment</strong></h3><p>Create a blank file in your project directory and name it as <strong>app.yaml</strong></p><p>Copy the below contents to your file</p><pre>runtime: python37</pre><pre>service: backend</pre><pre>handlers:</pre><pre>- url: /static</pre><pre>  static_dir: /static/</pre><pre>  secure: always</pre><pre>- url: /.*</pre><pre>  script: auto</pre><pre>  secure: always</pre><p><em>(Please take care of indentation)</em></p><p><strong>Important</strong> —<em> The directory structure should be the same as the image below</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*IXlCHMPiP4z5VJZan70B4A.png" /><figcaption>Directory structure of back-end app</figcaption></figure><h3><strong>Step 9 : Upload the back-end code to the gcs bucket and deploy the back-end app.</strong></h3><p>Delete the front-end code from the bucket (application_code) and upload this back-end code there.</p><p>Create a directory for your back-end code e.g. django-app-gcp</p><blockquote>mkdir django-app-gcp</blockquote><p>Sync data from bucket to this directory</p><blockquote>gsutil rsync -r gs://application_code ./django-app-gcp</blockquote><p>Go inside the directory and deploy frontend</p><blockquote>cd django-app-gcp</blockquote><blockquote>gcloud app deploy</blockquote><p>Deployment Url will be displayed in the console. This is the back-end server base URL.</p><h3><strong>Step 10: Troubleshooting if deployment fails.</strong></h3><p>You may get an error message specifying below reason,</p><blockquote>ERROR : This deployment has too many files.</blockquote><p>In that case, we have to specify<strong> .gcloudignore</strong> file to ignore the upload of any file or directory which we don’t want to deploy. The syntax is the same as the .gitignore file.</p><p>This below file might work for you.</p><pre>.gcloudignore</pre><pre># If you would like to upload your .git directory, .gitignore file or files</pre><pre># from your .gitignore file, remove the corresponding line</pre><pre># below:</pre><pre>.git</pre><pre>.gitignore</pre><pre># Python pycache:</pre><pre>__pycache__/</pre><pre># Ignored by the build system</pre><pre>/setup.cfg</pre><pre># IDEs and editors</pre><pre>/.idea</pre><pre>.project</pre><pre>.classpath</pre><pre>.c9/</pre><pre>*.launch</pre><pre>.settings/</pre><pre>*.sublime-workspace</pre><pre># IDE — VSCode</pre><pre>.vscode/*</pre><pre>!.vscode/settings.json</pre><pre>!.vscode/tasks.json</pre><pre>!.vscode/launch.json</pre><pre>!.vscode/extensions.json</pre><pre>.history/*</pre><h3><strong>Step 11: Configure dispatch.yaml</strong></h3><p>We are using dispatch.yaml to send incoming requests to our backend service based on the path (<strong>/api/</strong>) in the URL.</p><p>Create a dispatch.yaml file outside of our front-end or back-end app.</p><p>Paste below lines there.</p><pre># routing rules</pre><pre>dispatch:</pre><pre># api</pre><pre>- url: “*/api/*”</pre><pre>  service: backend</pre><p>To deploy the dispatch.yaml file, use the following command</p><blockquote>gcloud app deploy dispatch.yaml</blockquote><p><strong>Done ! Your application is deployed in the app engine.</strong></p><p>Hope this was helpful and saved your time googling all this stuff. Please post any questions below in the comments section. I Will be glad to answer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a1ed4927f3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>