When migrating off IBM Cloud Capabilities, IBM Cloud Code Engine is likely one of the potential deployment targets. Code Engine provides apps, jobs and (not too long ago operate) you could (or want) to choose from. On this publish, we offer some dialogue factors and share suggestions and methods on the right way to work with Code Engine features.
IBM Cloud Code Engine is a totally managed, serverless platform to (not solely) run your containerized workloads. It has developed lots since March 2021, after I printed the weblog publish “Migrating Cloud Capabilities Code to Code Engine.” In 2021, there have been solely Code Engine apps and jobs. Earlier this yr, Code Engine added assist for features (Capabilities-as-a-Service, or FaaS).
On this publish, I’m going to take a recent take a look at that subject and focus on the choices on the right way to transfer from IBM Cloud Capabilities to Code Engine.
Apps, jobs and features
IBM Cloud Code Engine options three alternative ways to run your enterprise logic:
An app is a repeatedly run course of that solutions to HTTP requests.
A job runs to deal with a job after which terminates.
A operate is a stateless code snippet that’s invoked by an HTTP request and, after producing a response, terminates. Furthermore, jobs normally run considerably longer than features (“batch processing”).
There are various extra traits that assist distinguish between apps, jobs and features. In brief, apps are a great match if you wish to craft a REST API or deploy an online utility with backend/frontend performance. You’ve gotten full management over the HTTP server and its assets.
Jobs, then again, are long-running processes that don’t require any consumer interplay. They could possibly be typical batch actions, analytics processing and even AI mannequin coaching.
Lastly, features can react to incoming HTTP requests in a short time. They serve low-latency use instances nicely, like chatbot integrations or webhooks. In distinction to apps, you don’t and can’t outline and configure the HTTP server.
When coming from Cloud Capabilities, you will have skilled that there are a lot of use instances supported by Cloud Capabilities. Equally, a operate could have totally different attributes which can be essential relying on the case:
The invocation or start-up time (chilly begin) may be essential, resulting in an total quick response time.
In different instances, the price (billing) may need been the aggressive issue.
The simplicity and agility, attributable to a operate as unit for improvement and deployment in a DevSecOps course of leads some initiatives to go for features.
Typically, it’s a mixture of the above that results in individuals preferring features (FaaS) over different runtime or compute choices.
From Cloud Capabilities to Code Engine
When transferring from Cloud Capabilities to Code Engine, the next operate traits must be taken under consideration when deciding to on an app, a job or a Code Engine operate:
Is an http endpoint wanted to invoke the code?
Is the processing triggered by an occasion?
What programming language is used for the prevailing operate and the way huge are the required libraries?
How lengthy does the processing take, what compute assets are wanted, is parallel processing desired?
The information Migrating IBM Cloud Capabilities to Code Engine has an in depth overview with Code Engine app, job and performance traits. They enable you to to pick the perfect entity in your current workload. Moreover, the present Code Engine operate limitations and the final limits and quotas for Code Engine must be taken under consideration. The part Migrating IBM Cloud Capabilities Actions to Code Engine Capabilities FAQ would possibly enable you to resolve the right way to migrate.
Suggestions and methods for Code Engine features
The next suggestions and methods are primarily based on my experiences with transferring current code from Cloud Capabilities to Code Engine features. They assist in slicing down deployment cycles by first using native exams to implement comparable performance in combining Code Engine features and jobs and designing built-in APIs by making use of Code Engine system variables.
Native testing of features
Apps are common internet purposes, jobs are like scripts, and each may be examined domestically in a number of methods. As a result of features are code snippets, some wrapper is required to show them into applications. The next strategy has served me nicely up to now.
With the operate code in a subdirectory “func,” I make the most of both the Python or Node.js wrapper code proven under and place it within the mother or father listing. There, I additionally keep recordsdata with take a look at configurations as JSON objects, comparable to what’s handed by Code Engine to the operate on invocation. For testing, I run the wrapper together with the configuration file as parameter. The wrappers for Python and Node.js are proven under:
# syntax: python wrapper.py params.json
# import the Code Engine operate: func/__main__.py
from func.__main__ import important
import sys, json
if __name__ == “__main__”:
# open file, learn JSON config
with open(str(sys.argv[1])) as confFile:
params=json.load(confFile)
# invoke the CE operate and print the consequence
print(important(params))
// syntax: node wrapper.js params.json
// require the Code Engine operate: func/important.js
var func=require(‘./func/important.js’)
// learn the file with operate parameters
const fs = require(“fs”);
const knowledge = fs.readFileSync(course of.argv[2]);
// invoke the CE operate and log the consequence
console.log(func.important(JSON.parse(knowledge)));
Job-like features
Typically, you would possibly want the HTTP endpoint of a operate and the presumably longer execution time of a job. In that case, create each a operate and a job. Then, make the most of the Code Engine API to create a job run from inside the operate. On this hybrid strategy, the operate can get referred to as through its HTTP endpoint and it terminates after kicking off the job run. A job might then run as much as 24 hours and profit from the parallel job processing capabilities in Code Engine. You will discover a pattern implementation of this sample within the Code Engine code examples.
Atmosphere variables and API design
For designing your API and features namespace, you may make the most of Code Engine-injected surroundings variables like __ce_path and __ce_method. The previous holds the trail element of the requested URL like “/object”, and the latter has the HTTP technique like GET or POST. By switching on the provided values for these variables, you may serve a number of API features from the identical Code Engine operate. The profit is a single base URL.
Relying in your venture and code administration, you would possibly even wish to mix this strategy with separating every API operate implementation into its personal file—much like the wrapper strategy proven above.
Conclusions
IBM Cloud Capabilities have many use instances and properties, so there isn’t any easy mapping to a particular Code Engine entity (i.e., app, job or operate). By evaluating an current (Cloud Capabilities) operate’s attribute to these of the Code Engine entities, you may decide the perfect match. In lots of instances, a Code Engine operate may be a good selection. For these instances, we shared suggestions and methods that you should use in your Capabilities-as-a-Service venture with Code Engine.
Use the next IBM Cloud Code Engine documentation to get began:
When you’ve got suggestions, strategies, or questions on this publish, please attain out to me on Twitter (@data_henrik), Mastodon (@data_henrik@mastodon.social) or LinkedIn.