Build your first serverless function in 10 minutes

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

Continue reading “Build your first serverless function in 10 minutes”

Knative, Serverless, CouchDB, Machine Learning and IA in gaming – May 2019 online meetup recordings

IBM Developer SF team hosts weekly online meetups on various topics. Online events are one of the best ways to scale your Developer Relations program and reach developers anywhere, anytime and for a long time after the event.

The following online meetups we hosted in April 2019 with links to watch the recordings.  I also encourage you to join our meetup so you will always know when our online meetups are scheduled. Our meetups are hosted by the wonderful Lisa Jung 👋.

💡Edge computing and IoT devices (May 1, 2019) 

In this online meetup with Marek Sadowski developers learned:

  • Dive into concepts and architecture behind this solution
  • Show you how to add a voice user interface
  • Send and analyze sensor data in the cloud
  • Manage devices from the cloud
  • Teach you how you can make your Raspberry Pi to tell you a joke

Watch the recording 📺

Continue reading “Knative, Serverless, CouchDB, Machine Learning and IA in gaming – May 2019 online meetup recordings”

Chatbots, AI, Kubernetes, GraphQL, AI for IoT devices and more – online meetup recordings, April 2019

IBM Developer SF team hosts weekly online meetups on various topics. Online events are one of the best ways to scale your Developer Relations program and reach developers anywhere, anytime and for a long time after the event.

The following online meetups we hosted in April 2019 with links to watch the recordings.  I also encourage you to join our meetup so you will always know when our online meetups are scheduled. Our meetups are hosted by the wonderful Lisa Jung 👋.

💡Docker, Kubernetes, Istio and Knative (April 3, 2019)

In this online meetup Baruch Sadogursky from JFrog and Marek Sadowski discuss architecture of a real-world application running of Kubernetes as use-cases. Whether you are a beginner in containers, or an advanced user, you will get a good review on the current trends.

Watch the recording 📺

Continue reading “Chatbots, AI, Kubernetes, GraphQL, AI for IoT devices and more – online meetup recordings, April 2019”

GraphQL, Application Modernization, Serverless, Blockchain and more – March 2019 Online Meetups Recordings

IBM Developer SF team hosts weekly online meetups on various topics. Online events is one of the best ways to scale your Developer Relations program and reach developers anywhere, anytime and for a long time after the event.

The following online meetups we hosted in the month of March with links to watch the recordings.  I also encourage you to join our meetup so you will always know when our online meetups are scheduled. All online meetups are hosted by the wonderful Lisa Jung 👋.

✔️ Serverless Java – Mobile Serverless Backend as a Service (March 6, 2019)

In this online meetup Marek Sadowski taught developers about:

  • Who are the players in the Serverless ecosystem?
  • What are some use cases for Serverless solutions – with MBaaS as one of them
  • Best practices for the Serverless architecture for MBaaS
  • Whether going Serverless is really faster, better, cheaper for developers and organizations
  • Live coding examples using Java and Android

Watch the recording 📺

Continue reading “GraphQL, Application Modernization, Serverless, Blockchain and more – March 2019 Online Meetups Recordings”

Should you migrate an existing enterprise Java application to serverless architecture?

Last week Marek Sadowski and I presented Introduction to Serverless with IBM Cloud Functions: a new way to build modern apps at Silicon Valley JUG. 

One of the questions from the audience was how do you take an existing large enterprise Java application and migrate it to serverless architecture? 

The short answer is you probably shouldn’t do it.  

But let’s look at the long answer. 

Unless there is a very good reason, there is little value in taking a large existing enterprise Java application and migrating it to serverless architecture. I think serverless should be considered for new applications in most cases.  Now, if you need to add a small new feature to an existing application, you could look at serverless.

For example, if you are running a large loyalty application (airlines, hotels, etc) and you have a new requirement where you need to process new members once a day. Once a file is received/uploaded, a function can be executed to process the new members.  

Or, you can migrate small bits from an existing application like a cron job or a queue process. But again, there is probably little value in doing a complete re-write. 

Serverless cold start is not a problem – and here is why (for most applications)

When you start with serverless you will very soon learn/hear about functions cold start (I believe serverless = cloud functions + APIs). A cold start happens when a cloud function is invoked for the first time or after a long time of no invocations. Basically, it takes the server (yes – there are servers!) a little bit longer to get the function ready the first time, so it’s ready to accept and process the request. If a function is invoked a second time, it will execute faster. There is a time period during which a function stays warm. If a function is invoked again during that time period – it will be executed fast.

If a function is not invoked within some period, it becomes cold again and the next time it’s invoked, it will be a little bit slower again (cold start).

This makes sense. When you launch an app on your phone or computer for the first time – it takes a little bit longer the first time. When you launch it again very soon, it usually starts faster.

For many applications cold starts are not a problem. It’s very important we consider the type of application we are building. If we are building a business application or an internal backend application – then cold starts are not a problem. It’s not going to make a difference if an application starts a fraction of a second slower or responds to a request a fraction of a second slower. Type of an application is important when talking about cold starts. It’s only a problem for some applications and probably in those cases serverless is not the best fit.

Continue reading “Serverless cold start is not a problem – and here is why (for most applications)”

Video: Serverless – a new way to build modern applications

Curious about serverless/function-as-a-service/cloud functions technologies, but haven’t had a chance to dig in? Wondering what all the excitement is about? Serverless doesn’t mean no servers. It’s a new way to build modern applications. Watch this video to learn more about this new approach to building modern applications. The video covers:

  • The current state of the serverless ecosystem & major players
  • Recognized ideal use cases for serverless solutions
  • Best practices for serverless architecture
  • Good sources of information to keep abreast of new developments
  • Live coding example

If you want to learn more about this topic, please read this blog post: Serverless – simply an approach to building modern applications?

Serverless – simply an approach to building modern applications?

If you search for “serverless” you find that serverless is a new popular way to build modern applications. Is serverless really new?

Serverless refers to the notion that you don’t need to worry about servers – you don’t need to provision, deploy, maintain servers. Obviously there are servers but you don’t need to think or worry about them, the cloud or the platform where you run the code will take care of that for you. Another major benefit is that a serverless function (cloud functions or function as a service) will automatically scale when demand increases.

Interestingly, the idea of executing code in the cloud has existed for a long time as part of Backend as a Service (BaaS) or Mobile Backend as a Service (mBaas). Companies such as Parse (Founded in 2011. Acquired by Facebook and now lives as an open source project), StackMob (acquired by PayPal), Kinvey (acquired by Progress), Appery.io (my previous company) and many others.

In addition to providing a server-side environment where a developer can write and execute code, these companies provided additional services such as a database, integration with 3rd party API and services, push notifications (for mobile), analytics, file storage, integration with login providers and other capabilities. They also provided various client SDK to work with their backend services.

I think serverless is simply an approach to building modern applications. It’s not a particular feature, but an approach. As for naming, I personally prefer the name cloud functions or functions-as-a-service.

Continue reading “Serverless – simply an approach to building modern applications?”

How to Pass Parameters to a Cloud Function

In my previous blog post I showed how to invoke an external REST API from a cloud function. The API that I used returns a random (Chuck Norris 💪) joke. In this blog post I want to show you to how pass a parameter to the cloud function. We can pass a joke number to the API and get that particular joke back 🤣.

Using the code from the previous blog post:

var request = require("request");

function main(params) {
   var options = {
      url: "https://api.icndb.com/jokes/random",
      json: true
   };

   return new Promise(function (resolve, reject) {
      request(options, function (err, resp) {
         if (err) {
            console.log(err);
            return reject({err: err});
         }
      return resolve({joke:resp.body.value.joke});
      });
   });
}

to get a particular joke number, change the URL to look like this:

url: "https://api.icndb.com/jokes/" + params.joke

params – passed to main function is a JSON object that holds parameters (input) to this cloud function.

Continue reading “How to Pass Parameters to a Cloud Function”

How to Invoke an External REST API from a Cloud Function

In a previous blog post I showed how to create your first cloud function (plus a video). It’s very likely that your cloud function will need to invoke an external REST API. The following tutorial will show you how to create such function (it’s very easy).

  1. Sign into an IBM Cloud account
  2. Click Catalog
  3. Remove the label:lite filter and type functions
  4. Click on Functions box
  5. Click Start Creating button
  6. Click Create Action
  7. For Action Name enter ajoke and click the Create button.  A new cloud function will be created with Hello World message
  8. Replace the function code with the following code which invokes a 3rd party REST API which returns a random joke:
    var request = require("request");
    
    function main(params) {
       var options = {
          url: "https://api.icndb.com/jokes/random",
          json: true
       };
    
       return new Promise(function (resolve, reject) {
          request(options, function (err, resp) {
             if (err) {
                console.log(err);
                return reject({err: err});
             }
          return resolve({joke:resp.body.value.joke});
          });
       });
    }
    
    • The code is simple. It uses the request Node.js package to connect to an external REST API
    • The external REST API returns a random joke
    • A JavaScript Promise is used for invoking the REST API
    • At the end the cloud function returns a response in JSON format
  9. Now click the Save button to save the code. Once the code is saved the button will change to Invoke. Click the button to invoke the function. In the right-hand panel you should see output with a random joke:
    {
      "joke": "Project managers never ask Chuck Norris for estimations... ever."
    }
    

This is how it looks inside the IBM Cloud Functions editor:

cloudfunctions-invoke-restapi
Cloud function code

Of course you can also build and test a cloud function using the CLI. I’ll cover that in another blog post.

Continue reading “How to Invoke an External REST API from a Cloud Function”