Google Cloud Platform - Using Cloud Functions

December 02, 2017

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:

gcp func 1

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

gcp func 2

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:

gcp func 3

Testing

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

gcp func 4

References

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



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024