Invoke IBM Cloud Functions from API Connect

Cloud functions offer an easy way to build functionality and only pay for the time they are actually running without having to worry about how it will be hosted - you just right the code, save it and it is ready to be invoked. The function can be invoked through an event trigger or as a REST API - in this case I’m going to show how you can trigger a function as part of your API Connect assembly flow - providing an easy way to manage and socialise the functionality you have built.

To call an IBM Cloud function you first need to exchange your IBM Cloud API Key for an IAM access key using the IAM Authentication API.

This is a case of setting up and sending a post request to IBM Cloud IAM, to do this I used a set-variable policy to configure the headers and body followed by an invoke to https://iam.cloud.ibm.com/identity/token. The set-variable looks like this:

      - set-variable:
          version: 2.0.0
          title: setup iam request
          actions:
            - set: message.headers.content-type
              value: application/x-www-form-urlencoded
              type: string
            - set: message.headers.accept
              value: application/json
              type: string
            - set: message.body
              type: string
              value: >-
                grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=$(iam-apikey)​                

Once you have this access key you can use this to call your function using the endpoint provided in the UI:

{

For the authentication to the function URL we need to set the Authorization header to Bearer {access_key} where access_key is from the body of the previous request, so to obtain this we can use a Parse policy to parse the returned json, and then another set-variable policy to configure the headers for the Function invoke. This time the set-variable looks like this:

      - set-variable:
          version: 2.0.0
          title: setup function call
          actions:
            - set: message.headers.authorization
              value: Bearer $(iam.body.access_token)
              type: string
            - set: message.body
              value: $(request.body)
              type: any
            - set: message.headers.accept
              value: application/json
              type: string

As you can see we’re setting the authorization and accept headers, and passing the original request body from the inbound request. We follow this with an invoke of the function URL and a map, because the JSON returned from the function API includes details on invocation as well as the defined response:

{

The end to end flow looks like this:

{

Here is the complete sample swagger file which can be used in any API Connect deployment, including our new API Connect service on AWS

2002 - Wedding
2002 - Wedding
2003 - Malta
2003 - Malta
2004 - Iguazu
2004 - Iguazu
2005 - Greece
2005 - Greece
2006 - Abi
2006 - Abi
2007 - Cornwall
2007 - Cornwall
2008 - Malta
2008 - Malta
2009 - Jessica
2009 - Jessica
2010 - Portsmouth
2010 - Portsmouth
2011 - Torquay
2011 - Torquay
2012 - Olympics
2012 - Olympics
2013 - New Year's Eve
2013 - New Year's Eve
2014 - London
2014 - London
2015 - Majorca
2015 - Majorca
2016 - Valencia
2016 - Valencia
2017 - Nice
2017 - Nice
2018 - Lake Garda
2018 - Lake Garda
2019 - Switzerland
2019 - Switzerland
2020 - Gosport
2020 - Gosport
2021 - New Forest
2021 - New Forest
2022 - Costa Rica
2022 - Costa Rica

New York

The next morning I was up early and decided to head first to the High Line - a park/walkway created from an historic raised rail line which goes along the West Side of Manhatten. It’s fantastic to see the way the plants have been selected and seeing trees growing in between the old tracks with different sections having distinct settings from wild prairy to wooded sections providing a relaxed park atmosphere with a unique historic character to it. At the end of the line I headed to the Starbucks Reserve coffee roastery to have a coffee before heading back. I then went back to my hotel and got changed for the warmer day ahead and headed down to the dock for my boat tour. The boat tour took me right out past the Statue of Liberty with great views across the skyline along the way. I then checked out the Drama bookshop and then took the subway up to Central Park where I sat in the park to have my lunch. World Trade Center Then in the evening I went to Hudson Yards which is a really interesting development built over the top of railway yards, making use of land that couldn’t previously be used. There’s some really innovative sustainability steps been taken in how water and energy are managed and growing trees in shallow soil encouraging their routes to grow horizontally for stability and nutrients.

Hudson Yards - Sustainability Animation from Neoscape on Vimeo.

I then went up to The Edge where you get stunning views across the city. The next day was the AWS Summit which was the reason I was in town. This was a massive event and hugely popular, resulting in long queues for attendees to get in snaking across the entrance foyer and around the block. Fortunately being there as an exhibitor I'd been able to arrive early and prepare before the main entrance opened. IBM had a large booth with 4 demo screens and most of the day I spent here meeting people and talking about our new API Connect on AWS SaaS offering. I also got time to explore the other exhibitors and talk to some of the AWS team which was really interesting and useful. In the evening we had an IBM Client appreciation reception at the classic car club where I met more people and chatted with them surrounded by the impressive car whilst watching the sun go down over the Hudson until it was time for me to head to the airport for my flight home.

In the afternoon Laura and I did a ‘garden to glass’ experience at the Hotel, just the two of us, where Diego took us first around the gardens of the hotel to see their sustainability at work and the different plants they grow and how they can be used. We took a basket around with us and gathered lots of sprigs of herbs, flowers and even wild blackberries.

In the gardens we also met Floriana who oversees the gardens at the Belmar who we talked to about natural pest control and composting.

When we got back to the bar, we laid out all the ingredients on a table and Diego showed us how to make a coffee rum cocktail from rum which he’d left coffee beans soaking in earlier - very simple but delicious!

We then got to make our own cocktail from some of the items we’d gathered from the garden - first selecting the spirit and then crushing the leaves together with a caramelised orange segment. We then added these to a shaker with Guaro, syrup and ice and shook it. Diego smoked the glasses on a pine smoker, added ice and then we poured the cocktails in and garnished with more findings from the garden - in this case some flower petals and a carrot leaf.

For the last cocktail we learnt how to garnish the rim of the glass and then could sit back and watch the expert at work in making the cocktails for us with cucumber and basil from the garden.

After a delicious breakfast at Belmar, this time I had the breakfast sandwich of pesto, avocado, egg and roast peppers, we were picked up by the Selvatura transport to take us to the hanging bridges tour. We got there early and were assigned to a guide to take us around the park. He took us backwards around in order to avoid the other groups which seemed to work really well! We started the tour with a Coati coming across a mini bridge to us before admiring more of the beautiful cloud forest flora. Then we reached the first bridge of ?, each of which gave us a different view of the forest - some in the trees and some above the trees, all at different heights.

We saw lots more interesting plants and small birds that flew into sight briefly and then off again busy with whatever they were doing in the forest, but also, we saw some that stayed around for us to photograph - such as the Quetzal and Toucanet.

Seeing the forest canopy from above was amazing, so much variety in colours and shapes across the trees it was such a magical place.

After the tour finished, we had a quick look in the shop and lunch in the restaurant - I wouldn’t recommend these, just get the transport back.

on to Garden to glass