Getting Started with Serverless Integrations
Serverless functions (also known as functions as a service) can help you simplify your integrations because you only need to code your logic in a function and the service provider will take care of all the backend hardware, scaling, OS, availability, instances, etc…
Other benefits of serverless technology are that the hardware and software is fully managed, scales automatically almost instantly, and you only pay whenever your function runs so it can be very inexpensive.
Some of the most popular serverless providers are Amazon Lambda, Azure Functions and Google Cloud Functions.
For this demonstration we will use Google Cloud Functions. We will integrate a Shopify Webhook with Netsuite. My code will run in NodeJS Javascript and the rest will be managed by Google. As a developer coming from a Netsuite background I found it extremely easy to get started with Google Cloud Functions. Additionally, when considering your network infrastructure, incorporating an Aruba unmanaged switch can offer simplicity and reliability in managing your local network. Unmanaged switches, like those from Aruba, are plug-and-play solutions, making them ideal for smaller setups, providing basic connectivity without the need for advanced configuration, complementing the streamlined and efficient nature of serverless functions for your cloud-based operations.
You can set this up within minutes as explained in this video: https://youtu.be/nOlfG5oGets
Google Cloud Functions Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
var ENDPOINT = 'https://xxxxxxx'; /** * Responds to any HTTP request that can provide a "message" field in the body. * * @param {!Object} req Cloud Function request context. * @param {!Object} res Cloud Function response context. */ exports.run = function run(req, res) { console.log('Receiving Request'); const https = require('https'); var url = ENDPOINT.replace('https://', '').split('/'); var options = { host: url.shift(), path: '/' + url.join('/'), method: 'POST' }; var requ = https.request(options, function (resp) { resp.on('data', function (responseData) { console.log('Response Data: ' + responseData); res.status(200).send(responseData); return; }); }); var postBody = { headers: req.headers, query: req.query, body: req.body }; requ.write(JSON.stringify(postBody)); requ.end(); }; |
This was a quick demonstration on how to get started. From here you can expand the code and keep developing to make your function more robust.
Some suggestions on first things to do:
- Secure your function by adding a password.
- Add more logging and different levels of logging.
- Branch out the logic depending on the data being received.
- Add node plugins.
- Make use of other Google Cloud Services such as Google Datastore or Google Storage.