|Serverless Slackbot with Db2|
Setup using a Cloud Functions actionDeploying an app to the cloud often involves setting up, initializing or cleaning up services. With an app server, there could be an extra routine executed or API to be called. However, in a serverless environment, e.g., using IBM Cloud Functions, this is not possible. Thus, why not stick to the theme and do it in a serverless fashion? It avoids extra steps to be performed by the tutorial user or handling extra software. Utilizing Cloud Functions has the extra benefit that it is quite simple to implement. Many runtime environments have several database drivers readily available.
To see which database-related packages or modules are already included in the Node.js, Python, PHP, or Swift environments, check out the IBM Cloud Functions system details. They include drivers for IBM Db2 and IBM Informix, MySQL, Cloudant and CouchDB, MongoDB. To initialize a Db2 Warehouse on Cloud service, the following steps were necessary:
- Implement a function, e.g., in Node.js or Python. The code for my Db2 setup action in Node.js is available on Github. The function (or "action") has parameters that determine whether to create a table, to insert data or to drop that table. The Node.js driver for Db2 is part of the Node.js environment, importing the module "ibm_db" is all that needs to be done to use the driver.
- Create an action, bind the credentials to the Db2 service, then invoke the actions with the right parameters. See the setup script on Github.
If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.