CloudOps Orchestration Service (OOS) provides multiple built-in functions to help you process the parameters and outputs of templates.
Built-in functions
Fn::Base64Encode: returns the Base64-encoded result of the source string.
Fn::Base64Decode: returns the Base64-decoded result of the source string.
Fn::MergeMapToList: returns a list in which multiple maps are merged.
Fn::MergeMap: returns a map in which multiple maps are merged.
Fn::Join: returns a string in which the elements in a list are joined by the specified delimiter.
Fn::Select: returns a data element from a data element container based on the specified index.
Fn::Split: splits a string into an array of substrings based on the specified delimiter and returns a list of the substrings.
Fn::Replace: returns a string in which the specified substring is replaced by another substring.
Fn::Min: returns the element with the smallest value in the specified list.
Fn::Max: returns the element with the largest value in the specified list.
Fn::First: returns the first element in the specified list.
Fn::Last: returns the last element in the specified list.
Fn::ListJoin: returns a list in which multiple elements are joined.
Fn::Equals: compares whether two values are equal.
Fn::If: returns one value if the specified condition evaluates to true or another value if the specified condition evaluates to false.
Fn::Not: returns true for a condition that evaluates to false, or returns false for a condition that evaluates to true.
Fn::AddHour: changes the time zone by offsetting N hours from the UTC time.
Fn::FormatUTCTime: changes the time granularity of the UTC time as required.
Fn::Eval: executes a single-line expression in a string and returns the execution result.
Fn::CalculateTimeByOpsWindow: returns a point in time in the specified time period based on the execution time of this function.
Fn::And: returns true if all the specified conditions evaluate to true, or returns false if any one of the conditions evaluates to false.
Fn:Or: returns true if any one of the specified conditions evaluates to true, or returns false if all the conditions evaluate to false.
Fn::Intersection: returns the intersection of multiple arrays.
Fn::Union: returns the union of multiple arrays.
Fn::Difference: returns a new array that contains the difference of the union and intersection of multiple arrays.
Fn::Jq: filters a JSON object and returns the required property values in the JSON object.
Fn::MapJoin: combines two lists into a map in which all values in the first list are used as the keys of key-value pairs and values in the second list are used as the values of key-value pairs.
Fn::IsIpInCIDR: evaluates whether the specified IP address falls within the specified CIDR block.
Fn::Sub: substitutes variables in an input string with the values that you specify.
Fn::DurationBetween: returns the duration between two points in time.
Fn::Escape: escapes a string.
Fn::ConvertMapToList: converts a JSON object into a table that stores data as key-value pairs.
Syntax
A built-in function consists of the name of the function and the parameters to be processed. When you call the declaration expression of a function, the function processes the parameters and returns a result. You can reference the returned result like other parameters.
Fn::Base64Encode
Returns the Base64-encoded result of the source string.
Syntax
{"Fn::Base64Encode": "StringToBeBase64"}
Parameters
StringToBeBase64: the string to be encoded in Base64.
Return value
The Base64-encoded result of the source string.
Sample request
{"Fn::Base64Encode": "hello"}
Sample return value
"aGVsbG8="
Fn::Base64Decode
Returns the Base64-decoded result of the source string.
Syntax
{"Fn::Base64Decode": "Base64ToBeString"}
Parameters
Base64ToBeString: the Base64-encoded string to be decoded.
Return value
The Base64-decoded result of the source string.
Sample request
{"Fn::Base64Decode": "aGVsbG8="}
Sample return value
"hello"
Fn::MergeMapToList
Returns a list in which multiple maps are merged.
Syntax
{"Fn::MergeMapToList": "aListConatinsDicts"}
Parameters
aListConatinsDicts: a list that contains multiple maps.
Return value
A list in which multiple maps are merged.
Sample request 1
{
"Fn::MergeMapToList": [
{
"key_1": [
"kye_1_item_1",
"kye_1_item_2"
]
},
{
"key_2": [
"kye_2_item_1",
"kye_2_item_2"
]
},
{
"key_3": [
"kye_3_item_1",
"kye_3_item_2"
]
}
]
}
Sample return value 1
[
{
"key_1": "kye_1_item_1",
"key_2": "kye_2_item_1",
"key_3": "kye_3_item_1"
},
{
"key_1": "kye_1_item_2",
"key_2": "kye_2_item_2",
"key_3": "kye_3_item_2"
}
]
Sample request 2
{
"Fn::MergeMapToList": [
{
"key_1": [
"kye_1_item_1",
"kye_1_item_2"
]
},
{
"key_2": [
"kye_2_item_1",
"kye_2_item_2",
"key_2_item_3"
]
},
{
"key_3": [
"kye_3_item_1",
"kye_3_item_2"
]
}
]
}
Sample return value 2
[
{
"key_1": "kye_1_item_1",
"key_2": "kye_2_item_1",
"key_3": "kye_3_item_1"
},
{
"key_1": "kye_1_item_2",
"key_2": "kye_2_item_2",
"key_3": "kye_3_item_2"
},
{
"key_1": "kye_1_item_2",
"key_2": "kye_2_item_3",
"key_3": "kye_3_item_2"
}
]
Fn::MergeMap
Returns a map in which multiple maps are merged.
Syntax
{ "Fn::MergeMap": "aListConatinsDicts"}
Parameters
aListConatinsDicts: a list that contains multiple maps.
Return value
A map in which multiple maps are merged.
Sample request
{
"Fn::MergeMap": [
{
"key_1": "value_1"
},
{
"key_2": "value_2"
}
]
}
Sample return value
{"key_1": "value_1","key_2": "value_2"}
Fn::Join
Returns a string in which the elements in a list are joined by the specified delimiter.
Syntax
{"Fn::Join": ["Connector","aListContainsString"]}
Parameters
Connector: the string used to separate the elements in the returned string.
aListContainsString: a list that contains the elements to be joined.
Return value
A string in which the elements in the list are joined.
Sample request
{
"Fn::Join": [
",",
[
"a",
"b",
"c"
]
]
}
Sample return value
"a,b,c"
Fn::Select
Returns a data element from a data element container based on the specified index.
Syntax
{"Fn::Select": ["Index","Container"]}
Parameters
Index: the String or Number index that is used to query a data element from the container.
Container: the list or map to be queried.
Return value
A data element queried from the container based on the specified index.
Sample request 1
{
"Fn::Select": [
"IpAddress",
{
"IpAddress": [
"192.168.1.123",
"192.168.1.234"
]
}
]
}
Sample return value 1
["192.168.1.123","192.168.1.234"]
Sample request 2
{
"Fn::Select": [
"1",
[
"192.168.1.123",
"192.168.1.234"
]
]
}
Sample return value 2
"192.168.1.234"
Fn::Split
Splits a string into an array of substrings based on the specified delimiter and returns a list of the substrings.
Syntax
{"Fn::Split": ["Separator","StringToSeprate"]}
Parameters
Separator: the string to be used as the delimiter.
StringToSeprate: the string to be split by the delimiter.
Return value
A list of substrings split by the delimiter.
Sample request
{
"Fn:: Split": [",","a,b,c"]
}
Sample return value
[
"a",
"b",
"c"
]
Fn::Replace
Returns a string in which the specified substring is replaced by another substring.
Syntax
{ "Fn::Replace": [{"$varName": "StringToReplaceWith"}, "StringToReplace"]}
Parameters
$varName: a placeholder that starts with the dollar sign ($) followed by the name of a common parameter. The name requirements for the parameter that follows the dollar sign ($) are the same as those for the template parameters.
StringToReplaceWith: the substring that is used to replace the placeholder.
StringToReplace: the substring, including the placeholder, to be replaced, such as $varName is foo.
Return value
If the StringToReplaceWith parameter is set to baz, the returned string is baz is foo.
Sample request
{ "Fn::Replace": [{"$varName": "baz"}, "$varName is foo" ]}
Sample return value
"baz is foo"
Fn::Min
Returns the element with the smallest value in the specified list.
Syntax
{"Fn::Min": "aList"}
Parameters
aList: a list that contains elements. The type of the elements in the list can be String, Int, Datetime, or None. All elements in the same list must be of the same type.
Return value
The element with the smallest value in the list excluding the element whose value is None. If all the values of all elements in the list are None, None is returned.
Sample request
{
"Fn::Min": ["123","234"]
}
Sample return value
"123"
Fn::Max
Returns the element with the largest value in the specified list.
Syntax
{"Fn::Max": "aList"}
Parameters
aList: a list that contains elements. The type of the elements in the list can be String, Int, Datetime, or None. All elements in the same list must be of the same type.
Return value
The element with the largest value in the list excluding the element whose value is None. If all the values of all elements in the list are None, None is returned.
Sample request
{
"Fn::Max": ["123","234"]
}
Sample return value
"234"
Fn::First
Returns the first element in the specified list.
Syntax
{ "Fn::First": "aList"}
Parameters
aList: a list that contains elements. The types of elements in the list are not limited.
Return value
The first element returned for an iteration. For a loop task, the elements are sorted based on the task execution IDs generated for iterations.
Sample request
{
"Fn::First": ["123","234"]
}
Sample return value
"123"
Fn::Last
Returns the last element in the specified list.
Syntax
{"Fn::Last": "aList"}
Parameters
aList: a list that contains elements. The types of elements in the list are not limited.
Return value
The last element returned for an iteration. For a loop task, the elements are sorted based on the task execution IDs generated for iterations.
Sample request
{
"Fn::Last": ["123","234"]
}
Sample return value
"234"
Fn::ListJoin
Returns a list in which multiple elements are joined.
Syntax
{"Fn::ListJoin": "IterableContainer"}
Parameters
IterableContainer: a set of iterable elements. The types of the elements in the set are not limited.
Return value
A list in which the elements in the set are joined.
Sample request
{"Fn::ListJoin": ["a",2, 3]}
Sample return value
["a",2,3]
Fn::Equals
Compares whether two values are equal. If the two values are equal, true is returned. If the two values are not equal, false is returned.
Syntax
{ "Fn::Equals": ["parameter1", "parameter2"]}
Parameters
parameter1 and parameter2: the values to be compared. The types of the values are not limited.
Return value
If the two values are equal, true is returned. If the two values are not equal, false is returned.
Sample request
{ "Fn::Equals": ["Running","Stopped"]}
Sample return value
false
Fn::If
Returns one value if the specified condition evaluates to true or another value if the specified condition evaluates to false.
Syntax
{
"Fn::If": [
"condition",
"value_if_true",
"value_if_false"
]
}
Parameters
condition_name: the condition to be evaluated.
value_if_true: the value to be returned if the specified condition evaluates to true.
value_if_false: the value to be returned if the specified condition evaluates to false.
Return value
If the specified condition evaluates to true, the value specified by the value_if_true parameter is returned.
If the specified condition evaluates to false, the value specified by the value_if_false parameter is returned.
Sample request
{"Fn::If": [false,"Stopped","Running"]}
Sample return value
"Running"
Fn::Or
Returns true if any one of the specified conditions evaluates to true, or returns false if all the conditions evaluate to false.
Syntax
{"Fn::Or": ["condition1","condition2"]}
Parameters
condition1 and condition2: the conditions to be evaluated.
Return value
If both condition1 and condition2 evaluate to false, false is returned. Otherwise, true is returned.
Sample request
{"Fn::Or": [true,false]}
Sample return value
true
Fn::And
Returns true if any one of the specified conditions evaluates to true, or returns false if all the conditions evaluate to false.
Syntax
{"Fn::And": [ "condition1", "condition2"]}
Parameters
condition1 and condition2: the conditions to be evaluated.
Return value
If both condition1 and condition2 evaluate to true, true is returned. Otherwise, false is returned.
Sample request
{"Fn::And": [true,false]}
Sample return value
false
Fn::Not
Returns true for a condition that evaluates to false, or returns false for a condition that evaluates to true.
Syntax
{"Fn::Not": "condition"}
Parameters
condition: the condition to be evaluated.
Return value
If the condition evaluates to true, false is returned. If the condition evaluates to false, true is returned.
Sample request
{"Fn::Not": true}
Sample return value
false
Fn::AddHour
Changes the time zone by offsetting N hours from the UTC time.
Syntax
{"Fn::AddHour": ["utc_time", "hours_count" ]}
Parameters
utc_time: the UTC time from which N hours is to be offset.
hours_count: the number of hours that you want to offset from the UTC time. The value must be an integer.
Return value
The new UTC time that is obtained after N hours is offset from the previous UTC time.
Sample request
{ "Fn::AddHour": ["2019-06-01T02:12:45Z", 6]}
Sample return value
"2019-06-01T08:12:45Z"
Fn::FormatUTCTime
Changes the time granularity of the UTC time as required.
Syntax
Fn::FormatUTCTime: ["utc_time", "to_be_utc_time_format"]
Parameters
utc_time: the UTC time for which you want to change the time granularity.
to_be_utc_time_format: the specified time granularity.
Return value
The UTC time in the specified time granularity.
Sample request
{ "Fn::FormatUTCTime": ["2019-06-01T02:12:45Z","%Y-%m-%dT%H:%MZ"]}
Sample return value
"2019-06-01T02:12Z"
Fn::Eval
Executes a single-line expression in a string and returns the execution result. You cannot use this function to execute expressions that contains line breaks. Syntax
{
"Fn::Eval": [
"expression"
]
}
Parameters
expression: the expression to be executed, such as an operation expression.
Return value
The execution result of the expression.
Sample request
{ "Fn::Eval": ["1+3*2+3%2+1"]}
Sample return value
9
Fn::CalculateTimeByOpsWindow
Returns a point in time in the specified time period based on the execution time of this function. The time period must be less than 24 hours. The Fn::CalculateTimeByOpsWindow function returns a point in time by following these rules: If the function is executed during the specified time period on the current day, it returns the point in time which is one minute later than the execution time of the specified function. If the function is executed earlier than the start time of the time period on the current day, it returns a random point in time during the time period on the current day. If the function is executed later than the end time of the time period on the current day, it returns a random point in time during the time period on the next day after the function is executed.
Syntax
Fn::CalculateTimeByOpsWindow: [ "startTime", "endTime" ]
Parameters
startTime: the start time of the time period, such as 01:00:00Z.
endTime: the end time of the time period, such as 03:00:00Z. The interval between the start time and end time must be less than 24 hours.
Return value
A string that indicates a point in time in the specified time period, in UTC.
Sample request
{ "Fn::CalculateTimeByOpsWindow": ["01:00:00Z", "03:00:00Z"]}
Sample return value
"2019-09-24T01:01:00Z"
Fn::Jq
Filters a JSON object and returns the required property values in the JSON object.
Syntax
{ "Fn::Jq": [ "type", "jqSelector", "jsonObject" ]}
Parameters
type: specifies whether to return the first property value or all property values in the specified JSON object. Valid values: First and All. If you set the type parameter to First, only the first property value is returned. If you set the type parameter to All, all property values are returned.
jqSelector: the jq expression used for filtering. For more information, visit https://yq.aliyun.com/articles/714479.
jsonObject: the JSON object to be filtered.
Return value
The result returned after the JSON object is filtered by using the jq expression.
Sample request 1
{
"Fn::Jq": [
"First",".PrivateIpAddress.IpAddress",
{
"PrivateIpAddress": {
"IpAddress": [
"192.168.1.123", "192.168.1.234"
]
},
"VpcId": "vpc-xzxbamns",
"VSwitchId": "vsw-zxcdsa"
}
}
Sample return value 1
"192.168.1.123"
Sample request 2
{
"Fn::Jq": [
"All",".PrivateIpAddress.IpAddress",
{
"PrivateIpAddress": {
"IpAddress": [
"192.168.1.123", "192.168.1.234"
]
},
"VpcId": "vpc-xzxbamns",
"VSwitchId": "vsw-zxcdsa"
}
}
Sample return value 2
["192.168.1.123", "192.168.1.234"]
Fn::Intersection
Returns the intersection of multiple arrays.
Syntax
{ "Fn::Intersection": [ list1, list2]}
Parameters
list1 and list2: the arrays of which you want to take the intersection.
Return value
An array whose elements are values shared by multiple arrays.
Sample request
{ "Fn::Intersection": [["i-1","i-2"],["i-1","i-3"]]}
Sample return value
["i-1"]
Fn::Union
Returns the union of multiple arrays.
Syntax
{ "Fn::Union": [ list1, list2]}
Parameters
list1 and list2: the arrays to be merged.
Return value
An array whose elements are the values in the union of multiple arrays.
Sample request
{
"Fn::Union": [
[
"i-1",
"i-2"
],
[
"i-1",
"i-3"
]
]
}
Sample return value
["i-1","i-2","i-3"]
Fn::Difference
Returns a new array that contains the difference of the union and intersection of multiple arrays.
Syntax
{ "Fn::Difference": [ list1, list2]}
Parameters
list1 and list2: the arrays that contain different elements.
Return value
An array whose elements are the difference of the union and intersection of multiple arrays.
Sample request
{
"Fn::Difference": [
["i-1","i-2"],
["i-1"]]
}
Sample return value
["i-2"]
Fn::MapJoin
Combines two lists into a map in which all values in the first list are used as the keys of key-value pairs and values in the second list are used as the values of key-value pairs.
Syntax
{'Fn::MapJoin': [List1, List2] }
Parameters
aListConatinsDicts: a list that contains multiple maps.
Return value
A map in which the keys of key-value pairs are the elements of the List1 list and the values of key-value pairs are the elements of the List2 list.
Sample request
{'Fn::MapJoin': [['i-1', 'i-2', 'i-3'], [1, 2, 3]] }
Sample return value
{'i-1': 1, 'i-2': 2, 'i-3': 3}
Fn::IsIpInCIDR
Evaluates whether the specified IP address falls within the specified CIDR block.
Syntax
{'Fn::IsIpInCIDR': [Ip, CIDR] }
Parameters
Ip: the IP address. CIDR: the CIDR block.
Return value
true or false
Sample request 1
{'Fn::IsIpInCIDR': ["10.0.1.159", "192.168.0.0/16"] }
Sample return value 1
false
Sample request 2
{'Fn::IsIpInCIDR': ["192.168.255.0", "192.168.0.0/16"] }
Sample return value 2
true
Fn::Sub
Substitutes variables in an input string with the values that you specify.
Syntax
{'Fn::Sub': [TargetString, JSON]}
Parameters
TargetString and JSON
Return value
String
Sample request
{
"Fn::Sub": [
"Var1: ${Var1}, Var2: ${Var2}",
{
"Var1": "Var1Value",
"Var2": "Var2Value"
}
]
}
Sample return value
"Var1: Var1Value, Var2: Var2Value"
Fn::DurationBetween
Returns the duration between two points in time.
Syntax
{'Fn::DurationBetween': [DateTime_1, DateTime_2]}
Parameters
DateTime_1 and DateTime_2
Return value
String
Sample request
{
"Fn::DurationBetween": [
"12:00:00",
"13:00:00"
]
}
Sample return value
PT3600S
Fn::Escape
Escapes a string.
Syntax
{'Fn::Escape': [String, ShellType] }
Parameters
String and ShellType
The ShellType parameter is set to PowerShell.
Return value
String
Sample request
{
"Fn::Sub": [
'{"ACS:File":{"Collection":"Enabled","Filters":"[{\\"Path\\": \\"/home/admin/test\\",\\"Pattern\\":[\\"*\\"],\\"Recursive\\":false}]"},"ACS:Application":{"Collection":"Enabled"}, "ACS:Network":{"Collection":"Enabled"}}',
'PowerShell'
]
}
Sample return value
'{\\"ACS:File\\":{\\"Collection\\":\\"Enabled\\",\\"Filters\\":\\"[{\\\\\\"Path\\\\\\": \\\\\\"/home/admin/test\\\\\\",\\\\\\"Pattern\\\\\\":[\\\\\\"*\\\\\\"],\\\\\\"Recursive\\\\\\":false}]\\"},\\"ACS:Application\\":{\\"Collection\\":\\"Enabled\\"}, \\"ACS:Network\\":{\\"Collection\\":\\"Enabled\\"}}'
Fn::ConvertMapToList
Converts a JSON object into a table that stores data as key-value pairs.
Syntax
{'Fn::ConvertMapToList': [JSON/JSONString] }
Parameters
JSON
Return value
List
Sample request 1
{
"Fn::ConvertMapToList": [
{
"key1": "value1",
"key2": "value2"
}
]
}
Sample return value 1
[
{
"Key": "key1",
"Value": "value1"
},
{
"Key": "key2",
"Value": "value2"
}
]
Sample request 2
{
"Fn::ConvertMapToList": [
"{\"key1\": \"value1\", \"key2\": \"value2\"}"
]
}
Sample return value 2
[
{
"Key": "key1",
"Value": "value1"
},
{
"Key": "key2",
"Value": "value2"
}
]