loading...

Google Cloud Platform – Google Cloud Functions

How to install Ubuntu Server 19.10

Google Cloud Functions is a serverless environment for building and connecting cloud services. Developers and users write simple-purpose functions that are executed in response to an event that may be generated from your cloud instances or infrastructure. When the event being watched is triggered, the cloud function executes in a fully managed environment. This kind of approach saves a lot of time because a developer need not worry about having to deploy the underlying infrastructure that is required to run their code. Cloud functions remove the additional overhead of managing the environment and give a developer a fully managed execution environment that can readily be used.

Cloud functions are written in JavaScript and execute in a Node.js v6.11.5 environment. Because cloud functions execute in a Node.js environment, you can easily build and test the function on any Node.js environment before deploying.

Some examples of using cloud functions are file upload events to cloud storage, an incoming message on a specific application that triggers an event, or a simple log change. Events can also include database changes, files added to storage, or even new virtual machines being created.

We will briefly look at deploying a sample function using the GCP console:

  1. Click on the top menu and select Cloud Functions.
  2. Click on Create function:
  1. Google creates a sample function with code for you to test the functionality. Ideally you would use the gcloud tool or the SDK to create and deploy functions:
  1. Select a name and the Memory allocated for the function. Depending on the complexity of the function, you may need to allocate more memory.
  2. Choose a Trigger for the function. You can pick from an  HTTP trigger, C loud Pub/Sub topic, or a C loud Storage bucket. We will discuss C loud Pub/Sub topics and C loud Storage buckets in the upcoming chapters.
  3. The URL is how you can access this function.
  4. The Javascript code is pre-written to test the function. The code here responds to an HTTP request that can provide a message field in its body.
  5. Click Save to create the function:
  1. Click on the function to open its dashboard. Here you can look at many aspects of this function including its invocations per second, memory usage, and execution time:
Functions on Dashboard
  1. You can click EDIT to change the code of the function. Once saved your updated function is ready to be run. An additional feature is the ability to copy the function into a new function.
  2. It is easy to test this function. Click on Test function to test the function:
  1. Enter "message":"hello world" in the { } and click Test the function:

Comments are closed.

loading...