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.

For now, let’s expose this cloud function as a REST API so we can invoke it outside the console. In fact, you will be able to invoke it directly from the browser once we make it a Web Action.

  1. On the left-hand side, click Endpoints
  2. Check Enable as Web Action and click Save
  3. Copy the URL and enter into a browser’s address bar

Here is how it looks in Firefox:

cloudfunctions-test-browser
Invoking a cloud function

That was easy, right?

In this blog post you learned how to create a cloud function which invokes an external (3rd party) API. It’s very likely that even the simplest application will need to get data from an external API so this a good example/template to have.

6-Part Online Meetup Series On How Technology Can Help With Natural Disasters

We are launching a 6-part online meetup series where we will cover technologies and solutions that can greatly help before, during and after a natural disaster. In fact, this webinar series is a part of Call for Code initiative headed by IBM, The Linux Foundation, UN Human Rights, and American Red Cross.

The online meetups are only 30 minutes. If you are up to answering the call and would like to participate in the challenge, the online meetups will cover available resources to help you get started fast and build a solution. Join our online meetups regardless as they fun and educational.

  • Translate Written Communications to Improve Information Sharing
    • Wednesday, July 25, 9:30am PT
    • Register
  • Build Financial Networks with Blockchain to Execute Secure Transactions
    • Wednesday, August 1, 9:30am Pacific Time
    • Register
  • Build a cellular IoT Asset Tracker with Blockchain
    • Thursday, August 2, 9:30am Pacific Time
    • Register
  • Evaluate Person’s Pulse Data with Machine Learning 
    • Wednesday, August 8, 9:30am Pacific Time
    • Register
  • Learn How to Create and Analyze Charts, Graphs, and Maps
    • Thursday, August 9, 9:30am Pacific Time
    • Register
  • Learn How to Add Visual Recognition to an iOS App
    • Wednesday, August 15, 9:30am Pacific Time
    • Register

Video: Build Your First Cloud Function

Last week I showed you how to build your first cloud function using IBM Cloud Functions. I also recorded a 5-minute video that shows how to build your first function and a number of ways to invoke it via a REST API. Check it out below and let me know what you think.

Build a Serverless “Hello World” Function

Serverless, Function as a Service (FaaS) or just cloud functions allows you to write code that will run in the cloud. You can use a number of different languages such as JavaScript (Node.js), Swift, Python, Java, PHP and others to write the function code.  What’s nice is that you don’t need to worry about servers, containers, deployment, etc. You write the code and a cloud platform will make sure it executes!

In this blog post you will learn how to build a Hello World function. You will use IBM Cloud Functions to build and run the function (more information about this at the end). For now, let’s jump to creating your first function.

Continue reading “Build a Serverless “Hello World” Function”

4-part Webinar Series: Containers, Docker, Kubernetes and Istio

Marek Sadowski and Maya Reyes from the IBM San Francisco City Team hosted a 4-part webinar series on Containers. They covered Containers, Docker, Kubernetes and Istio.  The sessions are short, about 30-minutes. Check out the recordings below.

  1. Introduction to Containers
  2. Introduction to Docker
  3. Introduction to Kubernetes
  4. Introduction to Istio

Check out our upcoming events on Blockchain, Machine Learning, Watson AI, Serverless and more.

How to Create a Cluster on the IBM Cloud to Run Containerized Applications

If you are planning to run containerized applications on the IBM Cloud, here are the steps to upgrade your account and create a cluster:

  1. Please register for an IBM Cloud account (it’s free!). You can also login if you have an existing account
  2. Once you register, click on Catalog (top right menu)
  3. Remove the label:lite filter (the X top right on the ribbon above the menu)
  4. From the left-hand side menu, click on Containers
  5. Click on IBM Cloud Kubernetes Service
  6. In order to create a cluster click Upgrade and enter your billing information. Here is why you need to upgrade your account:
    1. Entering a credit card will activate a Lite (free) tier for Containers
    2. Your credit card will not be charged
    3. A credit card is needed to prevent fraud (such as using the cluster to do cryptocurrency mining)
    4. You will also get 512 Mb of memory
    5. $200 credit toward any paid services
    6. Continued access to the Lite plan
  7. Once your account is upgraded, select Free (Cluster type) and click Create Cluster
  8. The last step is to test your Docker installation
    1. Download or update Docker
    2. Run the following command to test the installation:
      $docker run ubuntu echo Hello World
    3. You should see Hello World text displayed in the terminal (after some initial downloads of Ubuntu images)
  9. Have fun 😎

If you want to learn how to build and deploy containerized applications in face-to-face hands-on sessions, you should come to one of our events.

Learn How to Convert Audio to Text

Converting speech or audio to text has a large number of applications and can bring advanced capabilities to applications.

Image you are running a call center with thousands of simultaneous calls. You would like to identify some trends/analytics such as if the callers are having problems with a particular product or feature. Or if the callers sound frustrated or unhappy about something.

You might also be looking for particular words in the conversation that are being repeated and also need to know the frequency. Being able to analyze such information is vital to businesses. For example, if you identified that callers sound frustrated and the word “broken” is repeated all the time – you can take actions to improve the user experience. First, you can quickly teach the support team how to help with this particular problem, offer a solution or a workaround. Second, you can fix or improve the product.

In general, almost any audio can be converted to text, where the text is then analyzed for trends, analytics that are important to you. One tool that you can use to analyze text is the Watson Tone Analyzer service.

Continue reading “Learn How to Convert Audio to Text”

My Notes from Developer Relations Conference

March 26-27 I attended a Developer Relations conference hosted by Evans Data in Palo Alto, CA. I was a good conference, with great content and speakers. The conference probably had about 100-150 people which I really liked.

These are my notes from sessions and keynotes I attended. Again, these are my notes and what I was able to write down and not necessary what the presenter said/showed.

Anatomy of an Amazon Alexa Evangelist
Paul Cutsinger, Amazon – Head of Alexa Voice Design Education

  • You have to love to teach
  • You have to love to travel
  • Workshops == training
  • Send internal newsletter to show what you have been doing
  • User feedback loop
    • Important to be in meeting with product and tell them what works and what doesn’t work

Virtual Event ROI: Experiments and Learnings
Cliff Simpkins, Microsoft – Director, Azure Developer Marketing

  • Developer events
    • What has worked well
      • Focus more on in-person value, less on deep content
      • Do lecture for an hour
        • Do 15 minutes lab
    • Setup your labs so that developers get the “ah-ha” moment
    • Community events
  • Bringing engineers/experts to places that don’t usually see them
  •  Anti-hackathon
    • Tell about the hack upfront and help with the last “mile” of the project

Continue reading “My Notes from Developer Relations Conference”

Kubernetes Hands-on Training

We are running hands-on Containers and Kubernetes training in San Francisco on Tuesday, March 27, 2018. If you are new to Containers, this is a really good workshop you wouldn’t want to miss. Your instructor is Erin McKean who is awesome, she is the founder of Wordnik and loves APIs!

After attending the workshop developers will learn:

  • Understand the value that containers can bring to your applications
  • Differentiate between containers and VMs
  • Container orchestration (Kubernetes/K8s)
  • The value that containers can bring to your applications
  • How to differentiate between containers and VMs
  • The basics of containers
  • The current landscape of container orchestration and get hands-on practice with orchestrating your own containers with a simple Kubernetes exercise

Register for this workshop.

Great Index Conference Sessions I Attended with Videos

At the end of February IBM hosted its first open developer community conference called Index in San Francisco.  At the conference I was helping as a “room captain”. My duties included greeting the speaker, and ensuring the video/audio equipment was running smoothly as all the talks were recorded. Pretty simple 😉.

The conference had a number of very interesting sessions that I wanted to attend and most of them were in the same track – The Rise of the Human Side of Technology.  This worked very nice as I volunteered to be the room captain for sessions that I actually wanted to attend.

Below you will find the session I attended and links to videos. I highly recommend you watch the videos as all the talks were great.

Bear Douglas Lead Developer Advocate at Slack, in her talk Getting out of the bubble with global developer communities, covered strategies for planning and executing your first global developer tour – particularly in regions where you are less connected or unfamiliar with your developers. Watch the session video.

Alaina Kafkes Software Engineer at Medium, in her talk Tackling Technical Writing, covered empathetic, accessible, and thorough technical tutorials & blog posts break down tech’s barrier to entry and foster inclusion. Alaina shared actionable pointers to get people started with technical writing. Watch the session video.

Stephanie Morillo Content Manager at DigitalOcean, in her talk Creating a Sustainable Documentation Framework for Open Source Projects, discussed how content strategy inspired me to think beyond writing & editing Bundler’s docs, to thinking of docs as a product in itself. Watch the session video.

Sandra Person Global PM at Mozzila, in her talk Reflections on the Mozilla Developer Roadshow Journey talked about spending 10 months on the road collaborating with global partners and local meetups, influential speakers and freshly minted contributors, to bring over 57 Developer Roadshow programs all around the world. Watch the session video.

The following session is from Programming languages and platforms track.

Amahdy Abdelaziz, Developer Advocate at Vaadin, in his talk on Dismantling a Progressive Web App, demonstrated how you can actually build modern web applications that qualify as “Progressive Web Apps”. Watch the session video.

Of course there were many other great session and you can watch them all on the IBM Code YouTube channel.