Skip to content

Intrinsic functions

Intrinsic functions transform payload values inside a state definition, without calling out to a task. They are available in JSONPath query-language mode, in fields whose name ends with .$:

"Parameters": {
  "greeting.$": "States.Format('Hello, {}!', $.name)",
  "id.$": "States.UUID()"
}

In JSONata mode you use JSONata expressions instead of intrinsic functions. See JSONata.

Referencing data

In JSONPath mode, a string value references runtime data by its prefix:

$ / $.path
The state input. $ is the whole input; $.order.id selects a path within it.
$$.path
The context object, for example $$.Execution.Id, $$.State.Name or $$.State.EnteredTime.
$name
A variable set earlier with Assign, for example $customer or $customer.email.

An intrinsic function's arguments may be literals, input paths ($, $.…) or context paths ($$.…). Assigned variables ($name) can be used in ordinary JSONPath fields, but are not resolved inside intrinsic-function arguments. This differs from AWS and is a known limitation.

Available functions

Stegflow implements the 18 standard Amazon States Language intrinsics.

States.Array(value, ...)
Builds an array from the given values.
States.ArrayContains(array, value)
Returns true if array contains value.
States.ArrayGetItem(array, index)
Returns the element at zero-based index.
States.ArrayLength(array)
Returns the number of elements in array.
States.ArrayPartition(array, chunkSize)
Splits array into chunks of chunkSize.
States.ArrayRange(start, end, step)
Builds an array of numbers from start to end by step.
States.ArrayUnique(array)
Removes duplicate elements from array.
States.Base64Encode(string)
Encodes string to Base64.
States.Base64Decode(base64)
Decodes a Base64 string.
States.Format(template, value, ...)
Replaces each {} placeholder in template with the given values.
States.Hash(data, algorithm)
Hashes data. algorithm is one of MD5, SHA-1, SHA-256, SHA-384, SHA-512.
States.JsonMerge(json1, json2, isDeep)
Merges two objects. isDeep is a boolean: false for a shallow merge, true for a deep merge.
States.JsonToString(path)
Serializes the value at path to a JSON string.
States.MathAdd(num1, num2)
Returns num1 + num2.
States.MathRandom(start, end)
Returns a random integer between start and end. An optional third argument seeds the generator for reproducible values.
States.StringSplit(string, delimiter)
Splits string on delimiter into an array.
States.StringToJson(string)
Parses a JSON string into a value.
States.UUID()
Returns a version 4 UUID.

Examples

{
  "chunks.$": "States.ArrayPartition($.items, 10)",
  "checksum.$": "States.Hash($.payload, 'SHA-256')",
  "merged.$": "States.JsonMerge($.defaults, $.overrides, false)",
  "roll.$": "States.MathRandom(1, 6)",
  "parts.$": "States.StringSplit('a,b,c', ',')"
}

Functions can be nested, and their arguments may be literals or JSONPath references into the state input.