Build your first serverless function in 10 minutes

Max Katz - Jun 17 '19 - - Dev Community

My teammate Upkar Lidder published a great tutorial on how to create your first serverless function very fast⚡️. I wanted to give it a try and share the step with you here. There is nothing to download, install or configure. You can finish this tutorial in under 10 minutes ⏳.

Tutorial steps

You will complete the following steps:

  1. Create a new IBM Cloud account or sign into an existing account
  2. Create a new cloud functions
  3. Test the function
  4. Invoking as a REST API

Let’s go! 🏃🏻‍♀️🏃🏻‍♂️

Sign-up for an IBM Cloud account

In this first step you will sign-up for a new account or log-in into an existing account.

serverless-helloworld-signin

  1. Sign-up for an IBM Cloud account or sign-in into an existing account
    • You will get a completely free account where you can try and use cloud 40 services. You can keep it forever. That’s pretty nice!
  2. That’s it

Creating a cloud function

In this step you will create a new cloud function.

  1. After you sign-in, open the = menu in the top-right and select Functions serverless-helloworld-menu
  2. From the IBM Cloud Functions main page click Start Creating button serverless-helloworld-startcreating
  3. From the Create page, select Create Action option serverless-helloworld-createaction
  4. On the Create Action page
    • For Action Name enter myfirstaction
    • Keep default values for Enclosing Package and Runtime
      serverless-helloworld-actionname
  5. Click Create button to create the Serverless function

All done. You should see the function code now.

serverless-helloworld-code

Testing the function

In this step we will test the function.

  1. To make it super simple, click the Invoke button (upper right). You are done. serverless-hellowrold-invoke1

Now, to make it just a little bit more interesting, let’s make a super small change to the function.

  1. Change the message the function returns to I built this in 10 minutes!
  2. Click the Save button
  3. Click the Invoke button. You should see the updated message 🤩 ### Invoking as a REST API

In this last step you will learn how to invoke the function as a REST API.

  1. On the left-hand side menu click Endpoints
  2. In Web Action section, check Enable as Web Action. Click Save
    serverless-helloworld-webaction
  3. Copy the URL below. Open a new browser window and paste the URL into the address bar
  4. You should see the result from the function serverless-hellowworld-browserrun

That’s it. It was fast, right?

Summary

In this blog post you learned how to create your first serverless function. If you want to learn more and cover more advanced serverless topics, please check out the serverless Code Patterns we have available.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .