Skip to content

Latest commit

 

History

History
129 lines (100 loc) · 9.17 KB

File metadata and controls

129 lines (100 loc) · 9.17 KB

On March 26, 2024, Segment is upgrading the Functions runtime environment to Node.js v18, which is the current long-term support (LTS) release.

This upgrade keeps your runtime current with industry standards. Based on the AWS Lambda{:target="_blank"} and Node.js{:target="_blank"} support schedule, Node.js v16 is no longer in Maintenance LTS. Production applications should only use releases of Node.js that are in Active LTS or Maintenance LTS.

All new functions will use Node.js v18 starting March 26, 2024.

For existing functions, this change automatically occurs as you update and deploy an existing function. Segment recommends that you check your function post-deployment to ensure everything's working. Your function may face issues due to the change in sytax between different Node.js versions and dependency compatibility.

Limited time opt-out option

If you need more time to prepare, you can opt out of the update before March 19, 2024.

Note that if you opt out:
- The existing functions will continue working on Node.js v16.
- You won't be able to create new functions after July 15, 2024.
- You won't be able to update existing functions after August 15, 2024.
- You won't receive future bug fixes, enhancements, and dependency updates to the functions runtime.

[Contact Segment](https://segment.com/help/contact/){:target="_blank"} to opt-out or with any questions.

Node.js 18

Segment strongly recommends updating to Node.js v18 to benefit from future runtime updates, the latest security, and performance improvements.

Functions do not currently support importing dependencies, but you can contact Segment Support{:target="_blank"} to request that one be added.

The following dependencies are installed in the function environment by default.

  • atob v2.1.2{:target="_blank"} exposed as atob

  • aws-sdk v2.488.0{:target="_blank"} exposed as AWS

  • btoa v1.2.1{:target="_blank"} exposed as btoa

  • fetch-retry{:target="_blank"} exposed as fetchretrylib.fetchretry

  • form-data v2.4.0{:target="_blank"} exposed as FormData

  • @google-cloud/automl v2.2.0{:target="_blank"} exposed as google.cloud.automl

  • @google-cloud/bigquery v5.3.0{:target="_blank"} exposed as google.cloud.bigquery

  • @google-cloud/datastore v6.2.0{:target="_blank"} exposed as google.cloud.datastore

  • @google-cloud/firestore v4.4.0{:target="_blank"} exposed as google.cloud.firestore

  • @google-cloud/functions v1.1.0{:target="_blank"} exposed as google.cloud.functions

  • @google-cloud/pubsub v2.6.0{:target="_blank"} exposed as google.cloud.pubsub

  • @google-cloud/storage v5.3.0{:target="_blank"} exposed as google.cloud.storage

  • @google-cloud/tasks v2.6.0{:target="_blank"} exposed as google.cloud.tasks

  • hubspot-api-nodejs{:target="_blank"} exposed as hubspotlib.hubspot

  • jsforce v1.11.0{:target="_blank"} exposed as jsforce

  • jsonwebtoken v8.5.1{:target="_blank"} exposed as jsonwebtoken

  • libphonenumber-js{:target="_blank"} exposed as libphonenumberjslib.libphonenumberjs

  • lodash v4.17.19{:target="_blank"} exposed as _

  • mailchimp marketing{:target="_blank"} exposed as mailchimplib.mailchimp

  • mailjet{:target="_blank"} exposed as const mailJet = nodemailjet.nodemailjet;

  • moment-timezone v0.5.31{:target="_blank"} exposed as moment

  • node-fetch v2.6.0{:target="_blank"} exposed as fetch

  • oauth v0.9.15{:target="_blank"} exposed as OAuth

  • @sendgrid/client v7.4.7{:target="_blank"} exposed as sendgrid.client

  • @sendgrid/mail v7.4.7{:target="_blank"} exposed as sendgrid.mail

  • skyflow{:target="_blank"} exposed as skyflowlib.skyflow

  • stripe v8.115.0{:target="_blank"} exposed as stripe

  • twilio v3.68.0{:target="_blank"} exposed as twilio

  • uuidv5 v1.0.0{:target="_blank"} exposed as uuidv5.uuidv5

  • winston v2.4.6{:target="_blank"} exposed as const winston = winstonlib.winston

  • xml v1.0.1{:target="_blank"} exposed as xml

  • xml2js v0.4.23{:target="_blank"} exposed as xml2js

  • zlib v1.0.5{:target="_blank"} exposed as zlib.zlib


    uuidv5 is exposed as an object. Use uuidv5.uuidv5 to access its functions. For example:

    async function onRequest(request, settings) {
         uuidv5 = uuidv5.uuidv5;
         console.log(typeof uuidv5);
    
          //Generate a UUID in the default URL namespace
          var urlUUID = uuidv5('url', 'http://google/com/page');
          console.log(urlUUID);
    
          //Default DNS namespace
          var dnsUUID = uuidv5('dns', 'google.com');
          console.log(dnsUUID);
      }

    zlib's asynchronous methods inflate and deflate must be used with async or await. For example:

    zlib = zlib.zlib;  // Required to access zlib objects and associated functions
    async function onRequest(request, settings) {
    const body = request.json();
    
    const input = 'something';
    
    // Calling inflateSync method
    var deflated = zlib.deflateSync(input);
    
    console.log(deflated.toString('base64'));
    
    // Calling inflateSync method
    var inflated = zlib.inflateSync(new Buffer.from(deflated)).toString();
    
    console.log(inflated);
    
    console.log('Done');
    }

The following Node.js modules are available:

Other built-in Node.js modules{:target="_blank"} aren't available.

For more information on using the aws-sdk module, see how to set up functions for calling AWS APIs.

Caching

Basic cache storage is available through the cache object, which has the following methods defined:

  • cache.load(key: string, ttl: number, fn: async () => any): Promise<any>
    • Obtains a cached value for the provided key, invoking the callback if the value is missing or has expired. The ttl is the maximum duration in milliseconds the value can be cached. If omitted or set to -1, the value will have no expiry.
  • cache.delete(key: string): void
    • Immediately remove the value associated with the key.

Some important notes about the cache:

  • When testing functions in the code editor, the cache will be empty because each test temporarily deploys a new instance of the function.
  • Values in the cache are not shared between concurrently-running function instances; they are process-local which means that high-volume functions will have many separate caches.
  • Values may be expunged at any time, even before the configured TTL is reached. This can happen due to memory pressure or normal scaling activity. Minimizing the size of cached values can improve your hit/miss ratio.
  • Functions that receive a low volume of traffic may be temporarily suspended, during which their caches will be emptied. In general, caches are best used for high-volume functions and with long TTLs. The following example gets a JSON value through the cache, only invoking the callback as needed:
const ttl = 5 * 60 * 1000 // 5 minutes
const val = await cache.load("mycachekey", ttl, async () => {
    const res = await fetch("http://echo.jsontest.com/key/value/one/two")
    const data = await res.json()
    return data
})