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 asatob
-
aws-sdk v2.488.0
{:target="_blank"} exposed asAWS
-
btoa v1.2.1
{:target="_blank"} exposed asbtoa
-
fetch-retry
{:target="_blank"} exposed asfetchretrylib.fetchretry
-
form-data v2.4.0
{:target="_blank"} exposed asFormData
-
@google-cloud/automl v2.2.0
{:target="_blank"} exposed asgoogle.cloud.automl
-
@google-cloud/bigquery v5.3.0
{:target="_blank"} exposed asgoogle.cloud.bigquery
-
@google-cloud/datastore v6.2.0
{:target="_blank"} exposed asgoogle.cloud.datastore
-
@google-cloud/firestore v4.4.0
{:target="_blank"} exposed asgoogle.cloud.firestore
-
@google-cloud/functions v1.1.0
{:target="_blank"} exposed asgoogle.cloud.functions
-
@google-cloud/pubsub v2.6.0
{:target="_blank"} exposed asgoogle.cloud.pubsub
-
@google-cloud/storage v5.3.0
{:target="_blank"} exposed asgoogle.cloud.storage
-
@google-cloud/tasks v2.6.0
{:target="_blank"} exposed asgoogle.cloud.tasks
-
hubspot-api-nodejs
{:target="_blank"} exposed ashubspotlib.hubspot
-
jsforce v1.11.0
{:target="_blank"} exposed asjsforce
-
jsonwebtoken v8.5.1
{:target="_blank"} exposed asjsonwebtoken
-
libphonenumber-js
{:target="_blank"} exposed aslibphonenumberjslib.libphonenumberjs
-
lodash v4.17.19
{:target="_blank"} exposed as_
-
mailchimp marketing
{:target="_blank"} exposed asmailchimplib.mailchimp
-
mailjet
{:target="_blank"} exposed asconst mailJet = nodemailjet.nodemailjet;
-
moment-timezone v0.5.31
{:target="_blank"} exposed asmoment
-
node-fetch v2.6.0
{:target="_blank"} exposed asfetch
-
oauth v0.9.15
{:target="_blank"} exposed asOAuth
-
@sendgrid/client v7.4.7
{:target="_blank"} exposed assendgrid.client
-
@sendgrid/mail v7.4.7
{:target="_blank"} exposed assendgrid.mail
-
skyflow
{:target="_blank"} exposed asskyflowlib.skyflow
-
stripe v8.115.0
{:target="_blank"} exposed asstripe
-
twilio v3.68.0
{:target="_blank"} exposed astwilio
-
uuidv5 v1.0.0
{:target="_blank"} exposed asuuidv5.uuidv5
-
winston v2.4.6
{:target="_blank"} exposed asconst winston = winstonlib.winston
-
xml v1.0.1
{:target="_blank"} exposed asxml
-
xml2js v0.4.23
{:target="_blank"} exposed asxml2js
-
zlib v1.0.5
{:target="_blank"} exposed aszlib.zlib
uuidv5
is exposed as an object. Useuuidv5.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 methodsinflate
anddeflate
must be used withasync
orawait
. 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:
crypto
Node.js module{:target="_blank"} exposed ascrypto
.https
Node.js module{:target="_blank"} exposed ashttps
.
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.
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. Thettl
is the maximum duration in milliseconds the value can be cached. If omitted or set to-1
, the value will have no expiry.
- Obtains a cached value for the provided
cache.delete(key: string): void
- Immediately remove the value associated with the
key
.
- Immediately remove the value associated with the
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
})