Azure vs GCP part 14: Functions (GCP)
Tags: azure, gcp, cloud
Published: 2018-03-22 03:31:34

---
title: "Azure vs GCP part 14: Functions (GCP)"
published: true
description: In this series, I compare Azure and GCP as C# developer
tags: azure,gcp,cloud
cover_image: https://thepracticaldev.s3.amazonaws.com/i/m57mmv4hgz9xrskaital.PNG
---

In [previous article](https://dev.to/kenakamu/azure-vs-gcp-part-13-functions-azure-1moj), I hands on Azure Functions App. In this article, I look into GCP functions.

However, the thing is, it doesn't support C#. Javascript on Node.js is the only supported language and execution environment at this moment.

# GCP
GCP also offers "Cloud Functions" service to support function technology. 

- One language support: At this moment, Cloud Function supports Javascript on Node.js 6.11.5
- Support multiple triggers: HTTP request, several web service webhook, several storage triggers. See [here](https://cloud.google.com/functions/docs/concepts/events-triggers) for detail.
- Scaling: It's support multiple scaling options. See [here](https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale) for detail.
- Flexible pricing: See [here](https://cloud.google.com/functions/pricing-summary/) for detail.
- Integrate with platform: Security, Monitoring, Other services, etc.


# Write a code

As explained above, Javascript is the only option for now.

### Basic function

1\. Go to [Google cloud console](https://console.cloud.google.com) and click cloud shell icon.

![function](https://thepracticaldev.s3.amazonaws.com/i/1xz2t4o57gdue6qrnjut.PNG)

2\. Create a directory and change directory to it.

```shell
mkdir cloudcomparefunction
cd cloudcomparefunction

```

3\. Create index.js and add following code.

```javascript
exports.cloudcomparefunction = (req, res) => {
  res.send('Hello World!');
};
```

4\. Run the following command to deploy. If this is first time to use Cloud Functions, it asks you to enable Cloud Functions API. Type yes to enable it.

```shell
gcloud beta functions deploy cloudcomparefunction --trigger-http
```

5\. Once it's deployed, check the url and invoke it using tools such as postman or curl. I used postman here.

![function](https://thepracticaldev.s3.amazonaws.com/i/gwpk1jxls4zoa4fqgki9.PNG)

### Local Debugging Experience

Though I didn't explain the local debugging experience for Azure, as it's really the same as other .NET application, I try debugging for Cloud Storage. I can use Functions local emulator and Visual Studio Code to debug it.

1\. First of all, install the local emulator. It says npm version 6.11.5 is supported so I installed the version for test.

```shell
npm install -g @google-cloud/functions-emulator
```
2\. Though I can download the code I already created, I just do it from scrach on the local pc. Create folder, add file and initialize npm project. 

```shell
cd <to anywhere you want>
mkdir function_demo
cd function_demo
npm init --yes
```
3\. Open the folder via Visual Studio Code and add index.js in the folder and add the following code.

```javascript
exports.cloudcomparefunction = (req, res) => {
   
     res.send('Hello World!');
};
```
4\. Run the functions emulator, and deploy locally.

```shell
functions start
functions deploy cloudcomparefunction --trigger-http --local-path=<path to the project folder>
```

5\. Once deploy completed, I can see the deployed URL.

![debug](https://thepracticaldev.s3.amazonaws.com/i/5v5ln4sqn05ocmiajhw1.PNG)

6\. Access to the URL to confirm it's working.

7\. Go back to Visual Studio Code, and select debug menu. Then click "gear icon" and select "Node.js"

![debug](https://thepracticaldev.s3.amazonaws.com/i/9064ti7fupe08cg8tk2d.PNG)

8\. By default, it adds "launch" config. Add "attach" type by start typing it.

![debug](https://thepracticaldev.s3.amazonaws.com/i/kc6571pphoj6bg5qn5ke.PNG)

9\. Run the following command to start debugger.

```shell
functions debug cloudcomparefunction
```

10\. It should show you the debugger port. It was 5858 for me, so change the port to 5858.

![debug](https://thepracticaldev.s3.amazonaws.com/i/a85dhmv8t1xfbssamzwx.PNG)

11\. Then, in Visual Studio Code, npm --select "Attach" from the dropdown and hit F5. Then set breakpoint to index.js and test it.

![debug](https://thepracticaldev.s3.amazonaws.com/i/rxy6c9oa8smx4f6l197f.PNG)

### Other debug options
GCP provides great tool called "Stack Driver" which enables break point on the production. It simply shows me the snapshot of the context and it didn't stop the application, which is very cool.

# Summary

From my experience, I think GCP needs more time to provide full feature to compete with Azure. Azure has a huge lead for functions technology at the moment, because:

- Azure supports multiple languages, whereas GCP supports Node.js only.
- Azure supports more variety of triggers.
- Azure offers "binding" to easily work with input/output
- Azure provides more IDE integration to GCP.
- Debugging experience is easier for Azure.
- Durable Functions: very unique capability

On the other hand, GCP also provides very attracted features such as:

- Stack Driver, the debugger works with any services.
- Simple UI (for my own opinion)
- Bunch of Cloud SDKs for Node.js

By the way, both cloud provides similar yet interesting features.

- Cloud Shell inside portal
- Online editor, which you can write code like IDE but in the browser.
- Integration with other services
- Monitoring, auto-scale, etc

In the next article, I look into micro services.

# Reference
[Debugging with Visual Studio Code](https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Debugging-with-Visual-Studio-Code)
[Cloud Functions Emulator ](https://github.com/GoogleCloudPlatform/cloud-functions-emulator)