All Products
Search
Document Center

Resource Orchestration Service:Fn::Add

Last Updated:Mar 15, 2024

The built-in function Fn::Add calculates the sum of parameters of the Number type, combines parameters of the List type, or merges parameters of the Dictionary type.

Declaration

  • JSON

    {
      "Fn::Add": [
        {k1: v1},
        {k2: v2}
      ]
    }
  • YAML

    • Syntax for the full function name:

      Fn::Add:
        - k1: v1
        - k2: v2
    • Syntax for the short form:

      !Add [{k1: v1}, {k2: v2}, ...]

Parameters

  • Parameters must be arranged as a parameter set.

  • The parameters can be of the Number, List, or Dictionary type. A set of parameters must be of the same type. A parameter set must contain at least two parameters.

Return value

  • If the parameters are of the Number type, the sum of the parameter values are calculated.

  • If the parameters are of the List type, the parameters are combined.

  • If the parameters are of the Dictionary type, the parameters are merged. If parameters of the Dictionary type have the same key, the latter overwrites the former.

Examples

  • Parameters of the Dictionary type

    !Add
      - key1: value1
      - key2: value2

    In this example, {"key1": "value1", "key2": "value2"} is returned.

  • Parameters of the List type

    !Add
    	- - list_1_value_1
      	- list_1_value_2
      - - list_2_value_1
      	- list_2_value_2

    In this example, ["list_1_value_1","list_1_value_2","list_2_value_1","list_2_value_2"] is returned.

  • Parameters of the Number type

    !Add
     - 1
     - 2
     - 3

    In this example, 6 is returned.