Wednesday, October 16, 2024

Migration from IBM Cloud Functions to Code Engine

- Advertisement -

When moving from IBM Cloud Functions, IBM Cloud Code Engine is a deployment target. Choose from apps, jobs, and (recently) function on Code Engine. IBM cover Code Engine functions and offer advice in this post.

Fully managed, serverless IBM Cloud Code Engine runs containerized applications and more. Since IBM March 2021 blog post “Migrating Cloud Functions Code to Code Engine,” it has changed a lot. Only Code Engine apps and employment in 2021. FaaS functionality was added to Code Engine earlier this year.

- Advertisement -

IBM will revisit that topic and explore how to switch from IBM Cloud Functions to Code Engine in this post.

Jobs, apps, functionalities

IBM Cloud Code Engine offers three business logic execution methods:

  • Apps are continuous HTTP response processes.
  • A task-completing job terminates.
  • Functions are stateless code snippets that respond to HTTP requests and exit. Many jobs take longer than functions (“batch processing”).

There are many more differences between apps, jobs, and functions. In conclusion, applications are ideal for REST APIs and backend/frontend web apps. You control all HTTP server resources.

Long-running jobs don’t require user interaction. These could be batch tasks, analytics processing, or AI model training.

- Advertisement -

Finally, functions respond rapidly to HTTP queries. Chatbot integrations and webhooks benefit from their low latency. Unlike apps, you cannot configure the HTTP server.

You may have noticed that Cloud Functions supports various use cases. Depending on the case, a function may have crucial attributes:

  • Cold start may be important, resulting in a short response time.
  • Billing may have been the competitive issue in other circumstances.
  • Some projects employ functions for DevSecOps development and deployment due to their simplicity and agility.

Often, a combination of the foregoing makes people favor functions (FaaS) over alternative runtime or compute solutions.

Cloud Functions to Code Engine

When choosing an app, task, or Code Engine function from Cloud Functions, consider the following function characteristics:

  • Does the code require a http endpoint?
  • Has an event prompted processing?
  • Which programming language and library size are needed for the existing function?
  • How long does processing take, what computational resources are needed, and is parallel processing desired?

The guide Migrating IBM Cloud Functions to Code Engine details Code Engine app, job, and function features. They advise you on the best entity for your task. Current Code Engine function constraints and general limits and quotas must also be considered. Migrating IBM Cloud Functions Actions to Code Engine Functions FAQ may help you decide.

Tips for Code Engine functionality

Transferring code from Cloud Functions to Code Engine functions inspired these ideas. They reduce deployment cycles by using local tests to create similar functionality in Code Engine functions and processes and building integrated APIs with Code Engine system variables.

Local function testing

Jobs are scripts and apps are web apps that may be tested locally in numerous ways. Functions are code snippets that need a wrapper to become programs. The following strategy has worked for us.

You wrap the function code in a subfolder “func” with Python or Node.js and place it in the parent directory. You keep JSON files with test configurations, similar to what Code Engine passes to the function on invocation. Running the wrapper with the configuration file as argument tests it.

Job-like duties

The HTTP endpoint of a function and the lengthier job execution duration may be needed. Create a function and job. Create a task run from the function using the Code Engine API. With this hybrid technique, the function can be invoked over HTTP and ends after starting the job. Code Engine parallel job processing allowed a job to run for 24 hours. Programming Engine programming examples demonstrate this concept.

Environment variables, API design

Use Code Engine-injected environment variables like __ce_path and __ce_method to define your API and functions namespace. The former contains the URL path like “/object” and the latter the HTTP method like GET or POST. Switching on these variables lets you serve several API functions from one Code Engine function. The benefit is one base URL.

You may want to combine this strategy with splitting each API function implementation into its own file, like the wrapper approach, depending on your project and code management.

Conclusions

IBM Cloud Functions have multiple use cases and attributes, therefore mapping to a Code Engine app, process, or function is difficult. Comparing Cloud Functions attributes to Code Engine entities lets you choose the best fit. Code Engine functions can often be useful. IBM provided Code Engine Functions-as-a-Service project advice for these scenarios.

Start with IBM Cloud Code Engine documentation:

  • Starting IBM Cloud Code Engine
  • Using functions
  • IBM Cloud Functions to Code Engine Migration
- Advertisement -
RELATED ARTICLES

2 COMMENTS

Recent Posts

Popular Post

Govindhtech.com Would you like to receive notifications on latest updates? No Yes