Step by Step guide for setup google cloud functions

  1. Open the Google Cloud Console and select your project.
  2. Click on the “Navigation menu” (☰) and navigate to “Cloud Functions”.
  3. Click “Create Function” to create a new function.
  4. In the “Create Function” page, enter a name for your function and select a region.
  5. Choose “HTTP” as the trigger type and set the authentication to “Allow unauthenticated invocations” for simplicity.
  6. In the “Source code” section, select the “Inline editor” option and choose the desired runtime environment. For this example, we will use Node.js.
  7. Copy and paste the following code into the “index.js” file:
exports.helloWorld = (req, res) => {
  let name = req.query.name || 'World';
  res.send(`Hello, ${name}!`);
};

This code defines a simple HTTP function that returns a “Hello, World!” message, which can also be customized with a name query parameter.

  1. In the “Function to execute” field, enter the name of the exported function (helloWorld in this case).
  2. Click “Create” to create your function.

Once your function is deployed, you can test it by clicking the “Testing” tab and entering a value for the name query parameter. You should see the message “Hello, <name>!” returned in the response.

Here’s an example of how to call the function using a simple HTTP GET request:

https://[REGION]-[PROJECT-ID].cloudfunctions.net/[FUNCTION-NAME]?name=John

Replace [REGION], [PROJECT-ID], and [FUNCTION-NAME] with the appropriate values for your project and function.

That’s it! You’ve successfully created and deployed a simple Google Cloud Function using the Cloud Console. From here, you can explore more advanced features such as Cloud Pub/Sub triggers, Cloud Storage integrations, and more.

Leave a Reply

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