Google Cloud Platform – Using Cloud Functions

In this post and this post I wrote about how you might create a basic Azure function. In this post, I’ll do the same thing using the Google Cloud Platform (GCP).

Google Cloud Functions

This is what google refer to as their serverless function offering. The feature is, at the time of writing, still in Beta, and only allows JavaScript functions (although after the amount of advertising they have been doing on Dot Net Rocks, I did look for a while for the C# switch).

As with many of the Google features, you need to enable functions for the project that you’re in:

Once the API is enabled, you’ll have the opportunity to create a new function; doing so should present you with this screen:

Since the code has to be in JavaScript, you could use the following (which is a cut down version of the default code):

exports.helloWorld = function helloWorld(req, res) {
    
    console.log(req.body.message);
    res.status(200).send('Test function');

};

Once you create the function, you’ll see it spin for a while before it declares that you’re ready to go:

Testing

In order to test that this works, simply navigate to the URL given earlier on:

References

https://cloud.google.com/functions/docs/writing/http

One thought on “Google Cloud Platform – Using Cloud Functions

  1. Pingback: A C# Programmer's Guide to Google Cloud Pub Sub Messaging - The Long Walk

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.