JavaScript runtime 2.0 features for CloudFront Functions
The CloudFront Functions JavaScript runtime environment is compliant with ECMAScript (ES) version
5.1
Topics
Core features
The following core features of ES are supported.
- Types
-
All ES 5.1 types are supported. This includes boolean values, numbers, strings, objects, arrays, functions, and regular expressions.
- Operators
-
All ES 5.1 operators are supported.
The ES 7 exponentiation operator (
**) is supported. - Statements
-
The following ES 5.1 statements are supported:
-
break -
catch -
continue -
do-while -
else -
finally -
for -
for-in -
if -
label -
return -
switch -
throw -
try -
var -
while
The following ES 6 statements are supported:
-
const -
let
The following ES 8 statements are supported:
async-
await
Note
async,await,const, andletare supported in JavaScript runtime 2.0.awaitcan be used insideasyncfunctions only.asyncarguments and closures are not supported. -
- Literals
-
ES 6 template literals are supported: multiline strings, expression interpolation, and nesting templates.
- Functions
-
All ES 5.1 function features are supported.
ES 6 arrow functions are supported, and ES 6 rest parameter syntax is supported.
- Unicode
-
Source text and string literals can contain Unicode-encoded characters. Unicode code point escape sequences of six characters (for example,
\uXXXX) are also supported. - Strict mode
-
Functions operate in strict mode by default, so you don’t need to add a
use strictstatement in your function code. This cannot be changed.
Primitive objects
The following primitive objects of ES are supported.
- Object
-
The following ES 5.1 methods on objects are supported:
-
Object.create()(without properties list) -
Object.defineProperties() -
Object.defineProperty() -
Object.freeze() -
Object.getOwnPropertyDescriptor() -
Object.getOwnPropertyDescriptors() -
Object.getOwnPropertyNames() -
Object.getPrototypeOf() -
Object.isExtensible() -
Object.isFrozen() -
Object.isSealed() -
Object.keys() -
Object.preventExtensions() -
Object.seal()
The following ES 6 methods on objects are supported:
-
Object.assign()
The following ES 8 methods on objects are supported:
-
Object.entries() -
Object.values()
The following ES 5.1 prototype methods on objects are supported:
-
Object.prototype.hasOwnProperty() -
Object.prototype.isPrototypeOf() -
Object.prototype.propertyIsEnumerable() -
Object.prototype.toString() -
Object.prototype.valueOf()
The following ES 6 prototype methods on objects are supported:
-
Object.prototype.is() -
Object.prototype.setPrototypeOf()
-
- String
-
The following ES 5.1 methods on strings are supported:
String.fromCharCode()
The following ES 6 methods on strings are supported:
String.fromCodePoint()
The following ES 5.1 prototype methods on strings are supported:
-
String.prototype.charAt() -
String.prototype.concat() -
String.prototype.indexOf() -
String.prototype.lastIndexOf() -
String.prototype.match() -
String.prototype.replace() -
String.prototype.search() -
String.prototype.slice() -
String.prototype.split() -
String.prototype.substr() -
String.prototype.substring() -
String.prototype.toLowerCase() -
String.prototype.trim() -
String.prototype.toUpperCase()
The following ES 6 prototype methods on strings are supported:
-
String.prototype.codePointAt() -
String.prototype.endsWith() -
String.prototype.includes() -
String.prototype.repeat() -
String.prototype.startsWith()
The following ES 8 prototype methods on strings are supported:
-
String.prototype.padStart() -
String.prototype.padEnd()
The following ES 9 prototype methods on strings are supported:
-
String.prototype.trimStart() -
String.prototype.trimEnd()
The following ES 12 prototype methods on strings are supported:
String.prototype.replaceAll()Note
String.prototype.replaceAll()is new in JavaScript runtime 2.0.
- Number
-
ALL ES 5 numbers are supported.
The following ES 6 properties on numbers are supported:
Number.EPSILON-
Number.MAX_SAFE_INTEGER -
Number.MIN_SAFE_INTEGER -
Number.MAX_VALUE -
Number.MIN_VALUE -
Number.NaN -
Number.NEGATIVE_INFINITY -
Number.POSITIVE_INFINITY
The following ES 6 methods on numbers are supported:
-
Number.isFinite() -
Number.isInteger() -
Number.isNaN() -
Number.isSafeInteger() -
Number.parseInt() -
Number.parseFloat()
The following ES 5.1 prototype methods on numbers are supported:
-
Number.prototype.toExponential() -
Number.prototype.toFixed() -
Number.prototype.toPrecision()
ES 12 numeric separators are supported.
Note
ES 12 numeric separators are new in JavaScript runtime 2.0.
Built-in objects
The following built-in objects of ES are supported.
- Math
-
All ES 5.1 math methods are supported.
Note
In the CloudFront Functions runtime environment, the
Math.random()implementation uses OpenBSDarc4randomseeded with the timestamp of when the function runs.The following ES 6 math properties are supported:
-
Math.E -
Math.LN10 -
Math.LN2 -
Math.LOG10E -
Math.LOG2E -
Math.PI -
Math.SQRT1_2 -
Math.SQRT2
The following ES 6 math methods are supported:
-
Math.abs() -
Math.acos() -
Math.acosh() -
Math.asin() -
Math.asinh() -
Math.atan() -
Math.atan2() -
Math.atanh() -
Math.cbrt() -
Math.ceil() -
Math.clz32() -
Math.cos() -
Math.cosh() -
Math.exp() -
Math.expm1() -
Math.floor() -
Math.fround() -
Math.hypot() -
Math.imul() -
Math.log() -
Math.log1p() -
Math.log2() -
Math.log10() -
Math.max() -
Math.min() -
Math.pow() -
Math.random() -
Math.round() -
Math.sign() -
Math.sinh() -
Math.sin() -
Math.sqrt() -
Math.tan() -
Math.tanh() -
Math.trunc()
-
- Date
-
All ES 5.1
Datefeatures are supported.Note
For security reasons,
Datealways returns the same value—the function’s start time—during the lifetime of a single function run. For more information, see Restricted features. - Function
-
The following ES 5.1 prototype methods are supported:
Function.prototype.apply()-
Function.prototype.bind() -
Function.prototype.call()
Function constructors are not supported.
- Regular expressions
-
All ES 5.1 regular expression features are supported. The regular expression language is Perl compatible.
The following ES 5.1 prototype accessor properties are supported:
-
RegExp.prototype.global -
RegExp.prototype.ignoreCase -
RegExp.protoype.multiline -
RegExp.protoype.source -
RegExp.prototype.sticky -
RegExp.prototype.flagsNote
RegExp.prototype.stickyandRegExp.prototype.flagsare new in JavaScript runtime 2.0.
The following ES 5.1 prototype methods are supported:
-
RegExp.prototype.exec() -
RegExp.prototype.test() -
RegExp.prototype.toString() -
RegExp.prototype[@@replace]() -
RegExp.prototype[@@split]()Note
RegExp.prototype[@@split]()is new in JavaScript runtime 2.0.
The following ES 5.1 instance properties are supported:
-
lastIndex
ES 9 named capture groups are supported.
-
- JSON
-
The following ES 5.1 methods are supported:
-
JSON.parse() -
JSON.stringify()
-
- Array
-
The following ES 5.1 methods on arrays are supported:
-
Array.isArray()
The following ES 6 methods on arrays are supported:
-
Array.of()
The following ES 5.1 prototype methods are supported:
-
Array.prototype.concat() -
Array.prototype.every() -
Array.prototype.filter() -
Array.prototype.forEach() -
Array.prototype.indexOf() -
Array.prototype.join() -
Array.prototype.lastIndexOf() -
Array.prototype.map() -
Array.prototype.pop() -
Array.prototype.push() -
Array.prototype.reduce() -
Array.prototype.reduceRight() -
Array.prototype.reverse() -
Array.prototype.shift() -
Array.prototype.slice() -
Array.prototype.some() -
Array.prototype.sort() -
Array.prototype.splice() -
Array.prototype.unshift()
The following ES 6 prototype methods are supported
-
Array.prototype.copyWithin() -
Array.prototype.fill() -
Array.prototype.find() -
Array.prototype.findIndex()
The following ES 7 prototype methods are supported:
Array.prototype.includes()
-
- Typed arrays
-
The following ES 6 typed array constructors are supported:
-
Float32Array -
Float64Array -
Int8Array -
Int16Array -
Int32Array -
Uint8Array -
Uint8ClampedArray -
Uint16Array -
Uint32Array
The following ES 6 methods are supported:
-
TypedArray.from() -
TypedArray.of()Note
TypedArray.from()andTypedArray.of()are new in JavaScript runtime 2.0.
The following ES 6 prototype methods are supported:
-
TypedArray.prototype.copyWithin() -
TypedArray.prototype.every() -
TypedArray.prototype.fill() -
TypedArray.prototype.filter() -
TypedArray.prototype.find() -
TypedArray.prototype.findIndex() -
TypedArray.prototype.forEach() -
TypedArray.prototype.includes() -
TypedArray.prototype.indexOf() -
TypedArray.prototype.join() -
TypedArray.prototype.lastIndexOf() -
TypedArray.prototype.map() -
TypedArray.prototype.reduce() -
TypedArray.prototype.reduceRight() -
TypedArray.prototype.reverse() -
TypedArray.prototype.some() -
TypedArray.prototype.set() -
TypedArray.prototype.slice() -
TypedArray.prototype.sort() -
TypedArray.prototype.subarray() -
TypedArray.prototype.toString()Note
TypedArray.prototype.every(),TypedArray.prototype.fill(),TypedArray.prototype.filter(),TypedArray.prototype.find(),TypedArray.prototype.findIndex(),TypedArray.prototype.forEach(),TypedArray.prototype.includes(),TypedArray.prototype.indexOf(),TypedArray.prototype.join(),TypedArray.prototype.lastIndexOf(),TypedArray.prototype.map(),TypedArray.prototype.reduce(),TypedArray.prototype.reduceRight(),TypedArray.prototype.reverse(), andTypedArray.prototype.some()are new in JavaScript runtime 2.0.
-
- ArrayBuffer
-
The following ES 6 methods on ArrayBuffer are supported:
-
isView()
The following ES 6 prototype methods on ArrayBuffer are supported:
-
ArrayBuffer.prototype.slice()
-
- Promise
-
The following ES 6 methods on promises are supported:
-
Promise.all() -
Promise.allSettled() -
Promise.any() -
Promise.reject() -
Promise.resolve() -
Promise.race()Note
Promise.all(),Promise.allSettled(),Promise.any(), andPromise.race()are new in JavaScript runtime 2.0.
The following ES 6 prototype methods on promises are supported:
-
Promise.prototype.catch() -
Promise.prototype.finally() -
Promise.prototype.then()
-
- DataView
-
The following ES 6 prototype methods are supported:
-
DataView.prototype.getFloat32() -
DataView.prototype.getFloat64() -
DataView.prototype.getInt16() -
DataView.prototype.getInt32() -
DataView.prototype.getInt8() -
DataView.prototype.getUint16() -
DataView.prototype.getUint32() -
DataView.prototype.getUint8() -
DataView.prototype.setFloat32() -
DataView.prototype.setFloat64() -
DataView.prototype.setInt16() -
DataView.prototype.setInt32() -
DataView.prototype.setInt8() -
DataView.prototype.setUint16() -
DataView.prototype.setUint32() -
DataView.prototype.setUint8()Note
All Dataview ES 6 prototype methods are new in JavaScript runtime 2.0.
-
- Symbol
-
The following ES 6 methods are supported:
-
Symbol.for() -
Symbol.keyfor()Note
All Symbol ES 6 methods are new in JavaScript runtime 2.0.
-
- Text Decoder
-
The following prototype methods are supported:
-
TextDecoder.prototype.decode()
The following prototype accessor properties are supported:
-
TextDecoder.prototype.encoding -
TextDecoder.prototype.fatal -
TextDecoder.prototype.ignoreBOM
-
- Text Encoder
-
The following prototype methods are supported:
-
TextEncoder.prototype.encode() -
TextEncoder.prototype.encodeInto()
-
Error types
The following error objects are supported:
-
Error -
EvalError -
InternalError -
RangeError -
ReferenceError -
SyntaxError -
TypeError -
URIError
Globals
The globalThis object is supported.
The following ES 5.1 global functions are supported:
-
decodeURI() -
decodeURIComponent() -
encodeURI() -
encodeURIComponent() -
isFinite() -
isNaN() -
parseFloat() -
parseInt()
The following ES 6 global functions are supported:
atob()-
btoa()Note
atob()andbtoa()are new in JavaScript runtime 2.0.
The following global constants are supported:
-
NaN -
Infinity -
undefined -
arguments
Built-in modules
The following built-in modules are supported.
Modules
Buffer
The module provides the following methods:
-
Buffer.alloc(size[, fill[, encoding]])Allocate a
Buffer.-
size: Buffer size. Enter an integer. -
fill: Optional. Enter a string,Buffer, Uint8Array, or integer. Default is0. -
encoding: Optional. Whenfillis a string, enter one of the following:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.allocUnsafe(size)Allocate a non-initialized
Buffer.-
size: Enter an integer.
-
-
Buffer.byteLength(value[, encoding])Return the length of a value, in bytes.
-
value: A string,Buffer, TypedArray, Dataview, or Arraybuffer. -
encoding: Optional. Whenvalueis a string, enter one of the following:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.compare(buffer1, buffer2)Compare two
Buffers to help sort arrays. Returns0if they're the same,-1ifbuffer1comes first, or1ifbuffer2comes first.-
buffer1: Enter aBuffer. -
buffer2: Enter a differentBuffer.
-
-
Buffer.concat(list[, totalLength])Concatenate multiple
Buffers. Returns0if none. Returns up tototalLength.-
list: Enter a list ofBuffers. Note this will be truncated tototalLength. -
totalLength: Optional. Enter an unsigned integer. Use sum ofBufferinstances in list if blank.
-
-
Buffer.from(array)Create a
Bufferfrom an array.-
array: Enter a byte array from0to255.
-
-
Buffer.from(arrayBuffer, byteOffset[, length]))Create a view from
arrayBuffer, starting at offsetbyteOffsetwith lengthlength.-
arrayBuffer: Enter aBufferarray. -
byteOffset: Enter an integer. -
length: Optional. Enter an integer.
-
-
Buffer.from(buffer)Create a copy of the
Buffer.-
buffer: Enter aBuffer.
-
-
Buffer.from(object[, offsetOrEncoding[, length]])Create a
Bufferfrom an object. ReturnsBuffer.from(object.valueOf(), offsetOrEncoding, length)ifvalueOf()is not equal to the object.-
object: Enter an object. -
offsetOrEncoding: Optional. Enter an integer or encoding string. -
length: Optional. Enter an integer.
-
-
Buffer.from(string[, encoding])Create a
Bufferfrom a string.-
string: Enter a string. -
encoding: Optional. Enter one of the following:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.isBuffer(object)Check if
objectis a Buffer. Returnstrueorfalse.-
object: Enter an object.
-
-
Buffer.isEncoding(encoding)Check if
encodingis supported. Returnstrueorfalse.-
encoding: Optional. Enter one of the following:utf8,hex,base64,base64url. Default isutf8.
-
The module provides the following buffer prototype methods:
-
Buffer.prototype.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])Compare
Bufferwith target. Returns0if they're the same,1ifbuffercomes first, or-1iftargetcomes first.-
target: Enter aBuffer. -
targetStart: Optional. Enter an integer. Default is 0. -
targetEnd: Optional. Enter an integer. Default istargetlength. -
sourceStart: Optional. Enter an integer. Default is 0. -
sourceEnd: Optional. Enter an integer. Default isBufferlength.
-
-
Buffer.prototype.copy(target[, targetStart[, sourceStart[, sourceEnd]]])Copy buffer to
target.-
target: Enter aBufferorUint8Array. -
targetStart: Optional. Enter an integer. Default is 0. -
sourceStart: Optional. Enter an integer. Default is 0. -
sourceEnd: Optional. Enter an integer. Default isBufferlength.
-
-
Buffer.prototype.equals(otherBuffer)Compare
BuffertootherBuffer. Returnstrueorfalse.-
otherBuffer: Enter a string.
-
-
Buffer.prototype.fill(value[, offset[, end][, encoding])Fill
Bufferwithvalue.-
value: Enter a string,Buffer, or integer. -
offset: Optional. Enter an integer. -
end: Optional. Enter an integer. -
encoding: Optional. Enter one of the following:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.prototype.includes(value[, byteOffset][, encoding])Search for
valueinBuffer. Returnstrueorfalse.-
value: Enter a string,Buffer,Uint8Array, or integer. -
byteOffset: Optional. Enter an integer. -
encoding: Optional. Enter one of the following:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.prototype.indexOf(value[, byteOffset][, encoding])Search for first
valueinBuffer. Returnsindexif found; returns-1if not found.-
value: Enter a string,Buffer, Unit8Array, or integer from 0 to 255. -
byteOffset: Optional. Enter an integer. -
encoding: Optional. Enter one of the following ifvalueis a string:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.prototype.lastIndexOf(value[, byteOffset][, encoding])Search for last
valueinBuffer. Returnsindexif found; returns-1if not found.-
value: Enter a string,Buffer, Unit8Array, or integer from 0 to 255. -
byteOffset: Optional. Enter an integer. -
encoding: Optional. Enter one of the following ifvalueis a string:utf8,hex,base64,base64url. Default isutf8.
-
-
Buffer.prototype.readInt8(offset)Read
Int8atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readIntBE(offset, byteLength)Read
Intas big-endian atoffsetfromBuffer.-
offset: Enter an integer. -
byteLength: Optional. Enter an integer from1to6.
-
-
Buffer.prototype.readInt16BE(offset)Read
Int16as big-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readInt32BE(offset)Read
Int32as big-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readIntLE(offset, byteLength)Read
Intas little-endian atoffsetfromBuffer.-
offset: Enter an integer. -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.readInt16LE(offset)Read
Int16as little-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readInt32LE(offset)Read
Int32as little-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readUInt8(offset)Read
UInt8atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readUIntBE(offset, byteLength)Read
UIntas big-endian atoffsetfromBuffer.-
offset: Enter an integer. -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.readUInt16BE(offset)Read
UInt16as big-endian atoffsetfromBuffer. -
-
offset: Enter an integer.
-
-
Buffer.prototype.readUInt32BE(offset)Read
UInt32as big-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readUIntLE(offset, byteLength)Read
UIntas little-endian atoffsetfromBuffer.-
offset: Enter an integer. -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.readUInt16LE(offset)Read
UInt16as little-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readUInt32LE(offset)Read
UInt32as little-endian atoffsetfromBuffer.-
offset: Enter an integer.
-
-
Buffer.prototype.readDoubleBE([offset])Read a 64-bit double as big-endian at
offsetfromBuffer.-
offset: Optional. Enter an integer.
-
-
Buffer.prototype.readDoubleLE([offset])Read a 64-bit double as little-endian at
offsetfromBuffer.-
offset: Optional. Enter an integer.
-
-
Buffer.prototype.readFloatBE([offset])Read a 32-bit float as big-endian at
offsetfromBuffer.-
offset: Optional. Enter an integer.
-
-
Buffer.prototype.readFloatLE([offset])Read a 32-bit float as little-endian at
offsetfromBuffer.-
offset: Optional. Enter an integer.
-
-
Buffer.prototype.subarray([start[, end]])Returns a copy of
Bufferthat is offset and cropped with a newstartandend.-
start: Optional. Enter an integer. Default is 0. -
end: Optional. Enter an integer. Default is buffer length.
-
-
Buffer.prototype.swap16()Swap the
Bufferarray byte order, treating it as an array of 16-bit numbers.Bufferlength must be divisible by 2, or you will receive an error. -
Buffer.prototype.swap32()Swap the
Bufferarray byte order, treating it as an array of 32-bit numbers .Bufferlength must be divisible by 4, or you will receive an error. -
Buffer.prototype.swap64()Swap the
Bufferarray byte order, treating it as an array of 64-bit numbers.Bufferlength must be divisible by 8, or you will receive an error. -
Buffer.prototype.toJSON()Returns
Bufferas a JSON. -
Buffer.prototype.toString([encoding[, start[, end]]])Convert
Buffer, fromstarttoend, to encoded string.-
encoding: Optional. Enter one of the following:utf8,hex,base64, orbase64url. Default isutf8. -
start: Optional. Enter an integer. Default is 0. -
end: Optional. Enter an integer. Default is buffer length.
-
-
Buffer.prototype.write(string[, offset[, length]][, encoding])Write encoded
stringtoBufferif there is space, or a truncatedstringif there is not enough space.-
string: Enter a string. -
offset: Optional. Enter an integer. Default is 0. -
length: Optional. Enter an integer. Default is the length of the string. -
encoding: Optional. Optionally enter one of the following:utf8,hex,base64, orbase64url. Default isutf8.
-
-
Buffer.prototype.writeInt8(value, offset, byteLength)Write
Int8valueofbyteLengthatoffsettoBuffer.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeIntBE(value, offset, byteLength)Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeInt16BE(value, offset, byteLength)Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeInt32BE(value, offset, byteLength)Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeIntLE(offset, byteLength)Write
valueatoffsettoBuffer, using little-endian.-
offset: Enter an integer. -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeInt16LE(offset, byteLength)Write
valueatoffsettoBuffer, using little-endian.-
offset: Enter an integer. -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeInt32LE(offset, byteLength)Write
valueatoffsettoBuffer, using little-endian.-
offset: Enter an integer. -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUInt8(value, offset, byteLength)Write
UInt8valueofbyteLengthatoffsettoBuffer.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUIntBE(value, offset, byteLength)Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUInt16BE(value, offset, byteLength)Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUInt32BE(value, offset, byteLength)Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUIntLE(value, offset, byteLength)Write
valueatoffsettoBuffer, using little-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUInt16LE(value, offset, byteLength)Write
valueatoffsettoBuffer, using little-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeUInt32LE(value, offset, byteLength)Write
valueatoffsettoBuffer, using little-endian.-
value: Enter an integer. -
offset: Enter an integer -
byteLength: Enter an integer from1to6.
-
-
Buffer.prototype.writeDoubleBE(value, [offset])Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Optional. Enter an integer. Default is 0.
-
-
Buffer.prototype.writeDoubleLE(value, [offset])Write
valueatoffsettoBuffer, using little-endian.-
value: Enter an integer. -
offset: Optional. Enter an integer. Default is 0.
-
-
Buffer.prototype.writeFloatBE(value, [offset])Write
valueatoffsettoBuffer, using big-endian.-
value: Enter an integer. -
offset: Optional. Enter an integer. Default is 0.
-
-
Buffer.prototype.writeFloatLE(value, [offset])Write
valueatoffsettoBuffer, using little-endian.-
value: Enter an integer. -
offset: Optional. Enter an integer. Default is 0.
-
The following instance methods are supported:
-
buffer[index]Get and set octet (byte) at
indexinBuffer.-
Get a number from
0to255. Or set a number from from0to255.
-
The following instance properties are supported:
-
bufferGet the
ArrayBufferobject for the buffer. -
byteOffsetGet the
byteOffsetof the buffer'sArraybufferobject. -
lengthGet the buffer byte count.
Note
All Buffer module methods are new in JavaScript runtime 2.0.
Query string
Note
The CloudFront Functions event object automatically parses URL query strings for you. That means that in most cases you don’t need to use this module.
The query string module (querystring) provides methods for parsing
and formatting URL query strings. You can load the module using
require('querystring'). The module provides the following
methods.
querystring.escape(string)-
URL-encodes the given
string, returning an escaped query string. The method is used byquerystring.stringify()and should not be used directly. querystring.parse(string[, separator[, equal[, options]]])-
Parses a query string (
string) and returns an object.The
separatorparameter is a substring for delimiting key and value pairs in the query string. By default it is&.The
equalparameter is a substring for delimiting keys and values in the query string. By default it is=.The
optionsparameter is an object with the following keys:decodeURIComponent function-
A function to decode percent-encoded characters in the query string. By default it is
querystring.unescape(). maxKeys number-
The maximum number of keys to parse. By default it is
1000. Use a value of0to remove the limitations for counting keys.
By default, percent-encoded characters within the query string are assumed to use the UTF-8 encoding. Invalid UTF-8 sequences are replaced with the
U+FFFDreplacement character.For example, for the following query string:
'name=value&abc=xyz&abc=123'The return value of
querystring.parse()is:{ name: 'value', abc: ['xyz', '123'] }querystring.decode()is an alias forquerystring.parse(). querystring.stringify(object[, separator[, equal[, options]]])-
Serializes an
objectand returns a query string.The
separatorparameter is a substring for delimiting key and value pairs in the query string. By default it is&.The
equalparameter is a substring for delimiting keys and values in the query string. By default it is=.The
optionsparameter is an object with the following keys:encodeURIComponent function-
The function to use for converting URL-unsafe characters to percent-encoding in the query string. By default it is
querystring.escape().
By default, characters that require percent-encoding within the query string are encoded as UTF-8. To use a different encoding, specify the
encodeURIComponentoption.For example, for the following code:
querystring.stringify({ name: 'value', abc: ['xyz', '123'], anotherName: '' });The return value is:
'name=value&abc=xyz&abc=123&anotherName='querystring.encode()is an alias forquerystring.stringify(). querystring.unescape(string)-
Decodes URL percent-encoded characters in the given
string, returning an unescaped query string. This method is used byquerystring.parse()and should not be used directly.
Crypto
The cryptographic module (crypto) provides standard hashing and
hash-based message authentication code (HMAC) helpers. You can load the module using
require('crypto').
Hashing methods
crypto.createHash(algorithm)-
Creates and returns a hash object that you can use to generate hash digests using the given algorithm:
md5,sha1, orsha256. hash.update(data)-
Updates the hash content with the given
data. hash.digest([encoding])-
Calculates the digest of all of the data passed using
hash.update(). The encoding can behex,base64, orbase64url.
HMAC methods
crypto.createHmac(algorithm, secret key)-
Creates and returns an HMAC object that uses the given
algorithmandsecret key. The algorithm can bemd5,sha1, orsha256. hmac.update(data)-
Updates the HMAC content with the given
data. hmac.digest([encoding])-
Calculates the digest of all of the data passed using
hmac.update(). The encoding can behex,base64, orbase64url.
Restricted features
The following JavaScript language features are either unsupported or restricted due to security concerns.
- Dynamic code evaluation
-
Dynamic code evaluation is not supported. Both
eval()andFunctionconstructors throw an error if attempted. For example,const sum = new Function('a', 'b', 'return a + b')throws an error. - Timers
-
The
setTimeout(),setImmediate(), andclearTimeout()functions are not supported. There is no provision to defer or yield within a function run. Your function must synchronously run to completion. - Date and timestamps
-
For security reasons, there is no access to high-resolution timers. All
Datemethods to query the current time always return the same value during the lifetime of a single function run. The returned timestamp is the time when the function started running. Consequently, you cannot measure elapsed time in your function. - File system access
-
There is no file system access. For example, there is no
fsmodule for file system access like there is in Node.js. - Process access
-
There is no process access. For example, there is no
processglobal object for processing information access like there is in Node.js. - Environment variables
-
There is no access to environment variables. Instead, you can use CloudFront KeyValueStore to create a centralized datastore of key-value pairs for your CloudFront Functions. CloudFront KeyValueStore enables dynamic updates to your configuration data without needing to deploy code changes. For more information, see Amazon CloudFront KeyValueStore.
- Network access
-
There is no support for network calls. For example, XHR, HTTP(S), and socket are not supported.