<?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 Dixit Goyal on Medium]]></title>
        <description><![CDATA[Stories by Dixit Goyal on Medium]]></description>
        <link>https://medium.com/@dixitgoyal?source=rss-28c7311132d9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*tgggphqEod86F67yQvzK4g.jpeg</url>
            <title>Stories by Dixit Goyal on Medium</title>
            <link>https://medium.com/@dixitgoyal?source=rss-28c7311132d9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 16:24:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dixitgoyal/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[Creating google cloud function with Pub/Sub topic trigger using python]]></title>
            <link>https://medium.com/@dixitgoyal/creating-google-cloud-function-with-pub-sub-topic-trigger-using-python-7f4a56c4a7a2?source=rss-28c7311132d9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f4a56c4a7a2</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[google-pubsub]]></category>
            <dc:creator><![CDATA[Dixit Goyal]]></dc:creator>
            <pubDate>Sun, 06 Sep 2020 08:53:20 GMT</pubDate>
            <atom:updated>2020-09-06T08:53:20.646Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*y2vym4h3ERGCgbwgV3Tw2g.png" /></figure><p>In today’s world, every tech organization is moving to a serverless architecture. So I thought of writing this article to help developers/architects who are still new to this. There are multiple options available to deploy serverless applications. Most popular nowadays are google cloud functions &amp; AWS Lambda. In this article, I will explain how to create a cloud function and call it from the <strong>Pub/Sub topic </strong>service offered by <strong>Google Cloud Platform.</strong></p><p>What is Google Cloud function?</p><p>It is <strong>Google’s</strong> serverless compute solution for creating event-driven applications where you can deploy any routine/function to be executed after some event that may be created by the user or from your application’s rest API.</p><p>What is the Pub/Sub topic?</p><p>It’s a simple queue where you can publish any message with some parameters. There will be one or more publishers who will publish to the topic and one or more consumers who will subscribe to the topics. <strong>For example, in this article, we will see how the Pub/Sub topic message will trigger google cloud function.</strong></p><p><strong>Prerequisites:-</strong></p><ol><li>You should have a google cloud platform active account.</li><li>Basic knowledge of python</li></ol><p><strong>Here’s how I did it:</strong></p><ol><li><strong>Create a GCP Service Account and assign it the role “Pub/Sub Publisher”. This will be a Google-managed service account.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORCBgPs0Kr3A3aqn-XGd8A.png" /><figcaption><a href="https://console.cloud.google.com/iam-admin/serviceaccounts/create">https://console.cloud.google.com/iam-admin/serviceaccounts/create</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rBMQsYqjtfWySAWmsnUtQ.png" /><figcaption><strong>Give Pub/Sub permission to the account</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wDl2ctYdwyG1xi44g1_o3g.png" /><figcaption><strong>You can leave these options blank</strong></figcaption></figure><p>2. <strong>Create an API key in the same service account and download the JSON key</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aZTS_4xnUv3vghXbKQY2UQ.png" /><figcaption>Generate new JSON key from the ADD KEY option on the service account details page</figcaption></figure><p>JSON file with service credentials will be automatically downloaded after creating. Keep it safe, we will use this to publish a message to <strong>Pub/Sub topic</strong>.</p><p>3. <strong>Create a Pub/Sub topic</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s31dq7rbB1YOxyj7jC_I3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vYLNBnOoDujUeGHBI1pLAw.png" /></figure><p>Now the <strong>Pub/Sub topic</strong> is ready. We will move on to the next step where we will create <strong>cloud function</strong>.</p><p>4. <strong>Create a cloud function</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*BauxS1XMlyOmw950ZgnGJA.png" /></figure><p>Choose the pub/sub in the trigger section and select the same topic we created in the last step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*5PvVj0E0ZyE8350JM9TLpw.png" /></figure><p>in the next step: Choose any language you are comfortable in. I’m choosing Python 3.7 in this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7kHFF2QnvJIdHQaB64tkw.png" /></figure><p>now our cloud function is ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOW6wK53CEP_wCO2kRhWnw.png" /></figure><p>5. <strong>Publish a new message to Pub/Subtopic using service credentials generated in Step-2.</strong></p><p>put the content of API key JSON generated in step-2 into credentials.json and change pub/sub topic and project ids as per your account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*uTKD9pLj2h5l1KMC9oy1xQ.png" /><figcaption>Note: Install google cloud library of python to run the above function.</figcaption></figure><p>After publishing the message to the <strong>Pub/Sub topic</strong>, we will check whether it successfully executed our cloud functions or not.</p><p>6. <strong>Verify execution of cloud function after publishing of message to Pub/Sub.</strong></p><p>Go to view logs option from the cloud functions list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FXEQYi3AkNZNjN15gYUzkQ.png" /></figure><p>You will see in the logs that our function is successfully executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rrd2GLAZTUnarH--GBEgtg.png" /></figure><p>I hope, it will be useful to get an overall understanding of how we can user GCP cloud function and pub/sub trigger to develop a serverless solution. I will soon write an article on AWS Lambda as well. Please like, share this article so that it can reach to needful.</p><p>Fell free to ask any questions in the comments section and also can directly contact at <a href="https://dixitgoyal.in/">https://dixitgoyal.in/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f4a56c4a7a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>