Chapter 52 – Utilise Google Cloud Platform to Implement Python Script Automation with Cloud Function and Cloud Scheduler

This python tutorial is relevant to coach how to automate your Python applications with the Google cloud platform. Compared to local device crontab and cron jobs, Cloud platforms like Google can allow your application 24 hours and 7 days stand-by and run by triggering preset events. You need to either keep the laptop running 24 hours or sit beside the device to monitor. I will take the trending topic bot for example and walk you through all components and script codings.

google cloud platform

This chapter is relevant to coaching on how to automate your Python applications with the Google cloud platform. Compared to local device crontab and cron jobs, Cloud platforms like Google can allow your application 24 hours and 7 days stand-by and run by triggering preset events. You need to either keep the laptop running for 24 hours or sit beside the device to monitor. I will take the trending topic bot for example and walk you through all components and script codings.

Table of Contents: Use Google Cloud Platform to Automate Web Applications

Google Cloud Platform – How does it work and why do we need it?

Basically, the Google Cloud Platform allows us to deploy a Python script to run automatically based on the schedule and workflow settings. Depending on the work volume, it can either be free or not. And even if you need to pay for some excess volume, it’s the pay-as-you-go model.

Python automation has great business and marketing value. It’s because it makes it possible to real-time optimize the advertising campaign, update the dashboard to grab intelligent data, and refresh the latest trending content automatically. Previously I tried to write some articles regarding APIs, price trackers, and trending topics. If you are interested in some application scenarios, please feel free to check them out

Meta Ads API – Break Through Platform Ceiling and Implement Practical Dynamic Content and Targeting Ads Strategies

Chapter 47: Product Price Trackers of Google Shopping, Walmart, HomeDepot Product Using Easy2Digital APIs

Chapter 51 – Trending News Bot with Twitter and Easy2Digital News APIs

Sign up for a Google Cloud Account and Create a Billing Account

Compared to the Google APIs console account, we need to add a credit card to sign up for a Google cloud account, although both are in the same interface. It’s because Google needs us to enable the billing account for the Cloud function, App engine, or computer engine. If your usage exceeds the free tier, GCP would automatically charge you based on the actual volume. And as well as activating Google APIs, we need to create a project as well using the account with a billing account.

Cloud Functions provides a perpetual free tier for compute-time resources, which includes an allocation of both GB-seconds and GHz-seconds. In addition to the 2 million invocations, the free tier provides 400,000 GB seconds, 200,000 GHz seconds of computing time, and 5GB of Internet egress traffic per month.

The free tier is measured as a dollar equivalent to the Tier 1 pricing. The equivalent dollar amount is provided whether you run your functions in a region with Tier 1 pricing or Tier 2 pricing or both. However, the deduction of usage of the free tier will be based on whether the region in which the function is running is in Tier 1 or Tier 2

Google Cloud Platform – Configure, Deploy and Set up Google Cloud Function

The most complex step is the Python script you are going to upload to GCP, and in terms of the function, deployment is not difficult. There are basically 4 steps.

Create a Function

Here we need to select the server we’re going to store our application and scripts and the methods of triggers. There are several options that we could select based on the project’s needs. In terms of operational automation and marketing automation, Cloud Pub/Sub can be the best one. It’s because it’s much easier to deploy with all user authentication done internally, so the credentials are not necessary.

google cloud platform

Set up Runtime Environment Variables in the Function Section

In a Python script, it might include and involve some sensitive data and numbers, such as the password, etc. This section called runtime environment variables gives people to create some variables that have sensitive data value instead of putting them onto the script directly.

Upload the Python Script and Requirement TXT

In the Cloud function script interface, Google sets to start with a def with two arguments. It’s mandatory whether you use them or not. If you don’t have any arguments, just leave them both there as what it is.

The other thing you need to be aware of is the entry point name must be the same as your function name. For example, here I name it the trendingNews2022, and the def function name is also the same.

Then, we need to tell Google what Python modules the script requires. So we can add the module and version bylines in the requirement.txt.

Deploy and Test the Script

When things are ready, we can click the deploy button, and Google would take some time to process. When you see a green light turning on on the left-hand side of your function. That means the script doesn’t have outstanding issues at the moment.

However, the green light doesn’t mean that your automation is working properly and correctly. We need to test the function and check the logs and see if there are some bugs or something else before launching.

Google Cloud Platform – Set up Cloud Scheduler Connecting with the Specific Cloud Function Topics

We have finished the most difficult part, but it seems it’s not that difficult in fact. Here we need to create a cloud schedule and connect the function topic we just created.

The thing we need to do here is to set up the frequency using the cron methodology. I’m not going to go into details in this section as I have another article relevant to this topic. If you are interested, please check out this.

Chapter 18: Utilize Macbook Crontab to Automate Running Amazon Competitor Price Tracker and Updating P&L Calculator and Product Market Value

Full Python Application Scripts that can be enhanced with the automation capability

If you are interested in the full script of Chapter 52 – Utilise Google Cloud Platform to Implement Python Script Automation with Cloud Function and Cloud Scheduler, please subscribe to our newsletter by adding the message “Chapter 53”. We would send you the script immediately to your mailbox.

I hope you enjoy reading Chapter 52 – Utilise Google Cloud Platform to Implement Python Script Automation with Cloud Function and Cloud Scheduler. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

  • Support and donate to our channel through PayPal (paypal.me/Easy2digital)
  • Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
  • Follow and like my page Easy2Digital Facebook page
  • Share the article on your social network with the hashtag #easy2digital
  • Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
  • You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount codes
  • Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)