How to Create a Cloud Functions in 3min

# What is a Cloud Functions & How does it work?

Cloud Functions are used more and more by many companies and became a must-have for any application. If you create a product, you should definitely consider using them as they can automatically scale without any DevOps from you or your team. You will also pay only for what you use (that's a big +).

The concept is quite simple: it's the combination of an HTTP endpoint and a function execution. Every time the HTTP endpoint is hit, the function is called.

Even tho the concept is quite simple, the implementation might become a nightmare depending on the Cloud functions platform you are using. We will see here how Liteflow is making this process simple and much faster.

# Create a Cloud Functions

Let's get started and create our first Cloud Functions with Liteflow in less than 3 minutes 😉

# Step 1: Create your function

For this we will need two files:

# index.js

This file contains the source code of our function.

module.exports = ({ body, headers }) => {
  return "hello world";
};

# liteflow.yml

This file contains the logic to connect the HTTP to our function.

# liteflow.yml
workflows:
  my-cloud-function:
    steps:
      - type: trigger
        service: http
        eventKey: request
        endpointKey: my-cloud-function
      - type: task
        service: js-function
        taskKey: execute
        handler: ./index.js

This simple workflow creates an endpoint that will be used as a gateway for you to access your function.

# Step 2: Run your function

First, if you don't have it already, you need to install the Liteflow CLI.

npm i -g @liteflow/cli

Then in your project directory just run:

liteflow deploy

This will deploy an endpoint and your function. You can now access the Liteflow console, select your project, and visualize your functions' logs.

To trigger your function, you can call the HTTP endpoint created for you with the POST method

curl -XPOST https://gateway.liteflow.com/__REPLACE_WITH_YOUR_ENDPOINT__ -d '{}' -H "Content-Type: application/json"

Once called with your endpoint, you should see the log on the console.

# Conclusion

That's it you have created your first Cloud Functions with Liteflow, congratulations 😃 As you can see the process to create one with Liteflow is way easier and faster than the traditional method.

We would love to hear your feedback regarding this tutorial, and your experience with the creation of your first Cloud Functions. Don't hesitate to share it with us in the comment section below.

New to Liteflow? Code and launch your applications quickly with a backend framework and integrated cloud solution. Visualize and manage applications anytime with the console. Sign up for free and deploy your idea in seconds!



play icon developers icon

Liteflow is built for developers

Discover Liteflow

Increase your product development speed

Grow your business faster with the Liteflow Toolkit for Lean Software Development

Sign up for free

No credit card required