Switch from lambda to IBM Functions (OpenWhisk)

Hello,

I’ve deployed some functions using Serverless framework on AWS Lambda. I would like to switch provider to IBM Functions, because they’re using OpenWhisk and it’s a really cool open source project backed up by apache.

I assume just changing provider in the yml won’t work because openwhisk functions have different signature then lambda. Also, I’m using the context object in my functions, but openwhisk doesn’t pass it as a parameter.

  1. How can I do this switch? (or should I say migration?)
  2. Why does it say that Serverless is cloud agnostic if I cannot just switch to another provider in a transparent way?

Thanks in advance,
Harel

1 Like

It’s true that each cloud provider has slightly different handler function styles, and that means you can’t just change the provider in the serverless.yml file and have the app work perfectly with the new provider. I think that managing this is something that could be attempted in the future, by creating adapter libraries for each provider with a unified interface for Serverless.

In the mean time, you can make this a lot easier to deal with by practicing clean code. What that means is separating your code into different layers. For example, instead of an AWS Lambda handler performing all of the work for the use case (checking the user validity, accessing the database to perform some work, etc), you have separate functions that do this specific work. You can call the specific functions from different handlers identically. You would just pass in whatever data is needed as parameters.

For example, you might have a function called createUser with parameters of type { newUserName: string } and SQLConnection. You can pass these parameters in from the AWS Lambda handler. If you switch to Google Cloud Functions in the future, you’d just have to change the handler code. You’d still call the createUser function the same way.

This style of writing code is pretty useful in general. It makes code easier to test and makes it more modular, whether or not you’re using Serverless.