Function

Last Updated: Sep 15, 2017

The Resource Orchestration Service provides multiple built-in functions to help manage your stack. You can use internal functions in resources and outputs.

Fn::Base64

Internal function Fn::Base64 returns the Base64-encoded result of the entered string.

Statement

  1. "Fn::Base64" : stringToEncode

Parameters

stringToEncode

  1. String to be converted to Base64.

Return values

Original string using the Base64 method.

Example

  1. "Fn::Base64" : "string to encode"

Fn::FindInMap

Internal function Fn::FindInMap returns the value corresponding to the key in the double layer mapping stated in the Mappings part.

Statement

  1. "Fn::FindInMap" : [ "MapName", "TopLevelKey", "SecondLevelKey"]

Parameters

MapName

  1. The mapping ID stated in the Mappings part, including a key and value.

TopLevelKey

  1. The first level key, whose value is a key/value pair list.

SecondLevelKey

  1. The second level key, whose value is a string or number.

Return values

The value allocated to the SecondLevelKey.

Example

The following example shows how to use Fn::FindInMap:

  1. {
  2. "ROSTemplateFormatVersion": "2015-09-01",
  3. "Parameters": {
  4. "regionParam": {
  5. "Description": " Select the region for creating an ECS",
  6. "Type": "String",
  7. "AllowedValues": ["hangzhou", "beijing"]
  8. }
  9. },
  10. "Mappings" : {
  11. "RegionMap" : {
  12. "hangzhou" : { "32" : "m-25l0rcfjo", "64" : "m-25l0rcfj1" },
  13. "beijing" : { "32" : "m-25l0rcfj2", "64" : "m-25l0rcfj3" }
  14. }
  15. },
  16. "Resources": {
  17. "WebServer": {
  18. "Type": "ALIYUN::ECS::Instance",
  19. "Properties": {
  20. "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "regionParam" }, "32"]},
  21. "InstanceType": "ecs.t1.small",
  22. "SecurityGroupId": "sg-25zwc3se0",
  23. "ZoneId": "cn-beijing-b",
  24. "Tags": [{
  25. "Key": "key1",
  26. "Value": "value1"
  27. },{
  28. "Key": "key2",
  29. "Value": "value2"
  30. }
  31. ]
  32. }
  33. }
  34. }
  35. }

In the preceding example, the ImageId attribute needs to be specified when the resource named WebServer is created. The Mappings part describes the ImageId mappings differentiated according to regions. The Parameters part describes the regions that need to be specified by you. Fn::FindInMap will find the corresponding ImageId mapping in RegionMap according to the region specified by you. Then, find the ImageId corresponding to 32 in the mapping.

  • MapName can be set according to personal preference. It is “RegionMap” in this example.

  • TopLevelKey is set to the region for creating a stack, which is determined by you using {“Ref”: “regionParam”}.

  • SecondLevelKey is set to the desired architecture, which is “32” in this example.

Supported functions

You can use the following functions in the Fn::FindInMap function:

  • Fn::FindInMap

  • Ref

Fn::GetAtt

The internal function Fn::GetAtt returns the attribute value of resource in the template.

Statement

  1. "Fn::GetAtt": [ "resourceID", "attributeName" ]

Parameters

resourceID

  1. ID of the target resource.

attributeName

  1. Attribute name of the target resource.

Return values

Attribute value.

Example

In this example, the returned Resource ID is the ImageId attribute of MyEcsInstance.

  1. "Fn::GetAtt" : [ "MyEcsInstance" , "ImageID" ]

Fn::Join

The internal function Fn::Join joins a group of values, which are separated using specific separators.

Statement

  1. { "Fn::Join" : [ "delimiter", [ "string1", "string2", ... ] }

Parameters

delimiter

  1. Separator. The separator can be blank so that all the values are joined directly.

[ “string1”, “string2”, … ]

  1. List of joined values.

Return values

Joined strings.

Example

“Fn::Join” : [ “,”, [ “a”, “b”, “c” ] ]

Returned: “a,b,c”.

Supported functions

  • Fn::Base64

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

Fn::Select

The internal function Fn::Select returns the single data element in the data element list through the index.

Statement

The data element list can be an array:

  1. "Fn::Select" : [ "index", [ "value1", "value2", ... ] ]

The data element list can also be a mapping table:

  1. "Fn::Select" : [ "index", { "key1": "value1", ... } ]

Parameters

index

  1. Index of data elements to be retrieved. If the data element list is an array, the index is a value between 0 and N-1, where N indicates the number of elements in the array. If the data element list is a mapping table, the index is a key in the mapping table.
  2. If the corresponding value of index cannot be found, the system returns a blank string.

Return values

Selected data element.

Example

If the data element list is an array:

  1. { "Fn::Select" : [ "1", [ "apples", "grapes", "oranges", "mangoes" ] ] }

The returned value in this example: “grapes”.

If the data element list is a mapping table:

  1. { "Fn::Select" : [ "key1", [ "key1": "grapes", "key2": "mangoes" ] ] }

The returned value in this example: “grapes”.

If the data element list is a CommaDelimitedList:

  1. "Parameters" : {
  2. "userParam": {
  3. "Type": "CommaDelimitedList",
  4. "Default": "10.0.100.0/24, 10.0.101.0/24, 10.0.102.0/24"
  5. }
  6. }
  7. "Resources": {
  8. "resourceID": {
  9. "Properties": {
  10. "CidrBlock": { "Fn::Select" : [ "0", {"Ref": "userParam"} ] }
  11. }
  12. }
  13. },

Supported functions

For the Fn::Select index value, you can use the Ref function.

For the Fn::Select list of an object, you can use the following functions:

  • Fn::Base64

  • Fn::FindInMap

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

Ref

The internal function Ref returns the value of a specified parameter or resource.

  • If the specified parameter is a Resource ID, the system returns the value of the resource.

  • Otherwise, the system will deem the specified parameter to be a parameter and will attempt to return the parameter value.

Statement

  1. "Ref" : "logicalName"

Parameters

logicalName

  1. The logical name of a resource or parameter to which you want to make a reference.

Return values

The value of the resource or parameter.

Example

Use the Ref function to specify regionParam as the region parameter for RegionMap of WebServer:

  1. {
  2. "ROSTemplateFormatVersion": "2015-09-01",
  3. "Parameters": {
  4. "regionParam": {
  5. "Description": " Select the region for creating an ECS",
  6. "Type": "String",
  7. "AllowedValues": ["hangzhou", "beijing"]
  8. }
  9. },
  10. "Mappings" : {
  11. "RegionMap" : {
  12. "hangzhou" : { "32" : "m-25l0rcfjo", "64" : "m-25l0rcfj1" },
  13. "beijing" : { "32" : "m-25l0rcfj2", "64" : "m-25l0rcfj3" }
  14. }
  15. },
  16. "Resources": {
  17. "WebServer": {
  18. "Type": "ALIYUN::ECS::Instance",
  19. "Properties": {
  20. "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "regionParam" }, "32"]},
  21. "InstanceType": "ecs.t1.small",
  22. "SecurityGroupId": "sg-25zwc3se0",
  23. "ZoneId": "cn-beijing-b",
  24. "Tags": [{
  25. "Key": "tiantt",
  26. "Value": "ros"
  27. },{
  28. "Key": "tiantt1",
  29. "Value": "ros1"
  30. }
  31. ]
  32. }
  33. }
  34. }
  35. }

Supported functions

No function can be used in the Ref function. A string must be specified as the logical ID of resource.

Fn::GetAZs

The internal function Fn::GetAZs returns the available region list of the specified Region.

Statement

  1. "Fn::GetAZs": "region"

Parameters

region

  1. region ID.

Return values

List of available regions under the specified Region.

Example

In this example, an ECS instance is created in the first available region of the specified Region.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Resources" : {
  4. "WebServer": {
  5. "Type": "ALIYUN::ECS::Instance",
  6. "Properties": {
  7. "ImageId" : "centos7u2_64_40G_cloudinit_20160728.raw",
  8. "InstanceType": "ecs.n1.tiny",
  9. "SecurityGroupId": "sg-2zedcm7ep5quses05fs4",
  10. "Password": "Ros12345",
  11. "AllocatePublicIP": true,
  12. "InternetChargeType": "PayByTraffic",
  13. "InternetMaxBandwidthIn": 100,
  14. "InternetMaxBandwidthOut": 100,
  15. "SystemDiskCategory": "cloud_efficiency",
  16. "IoOptimized": "optimized",
  17. "ZoneId": {"Fn::Select": ["0", {"Fn::GetAZs": {"Ref": "ALIYUN::Region"}}]}
  18. }
  19. }
  20. },
  21. "Outputs": {
  22. "InstanceId": {
  23. "Value" : {"Fn::GetAtt": ["WebServer","InstanceId"]}
  24. },
  25. "PublicIp": {
  26. "Value" : {"Fn::GetAtt": ["WebServer","PublicIp"]}
  27. }
  28. }
  29. }

Supported functions

  • Fn::Base64

  • Fn::FindInMap

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

Fn::Replace

The internal function Fn::Replace replaces the specified sub-string in a string with a new sub-string.

Statement

  1. { "Fn::Replace" : [ {"object_key": "object_value"}, "object_string"]

Parameters

{“object_key”: “object_value”}

  1. object_key: String to be replaced.
  2. object_value: Replaced strings.

object_string

  1. Using object_string, replace all the object_key sub-strings in object_string with object_value.

Return values

String after replacement.

Example

Replace “print” in the specified script in UserData with “echo”.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Resources" : {
  4. "WebServer": {
  5. "Type": "ALIYUN::ECS::Instance",
  6. "Properties": {
  7. "ImageId" : "centos_7_2_64_40G_base_20170222.vhd",
  8. "InstanceType": "ecs.n1.medium",
  9. "SecurityGroupId": "sg-94q49gota",
  10. "Password": "MytestPassword1234",
  11. "IoOptimized": "optimized",
  12. "VSwitchId": "vsw-94vdvonyi",
  13. "VpcId": "vpc-949uzr8c9",
  14. "SystemDiskCategory": "cloud_ssd",
  15. "UserData": {"Fn::Replace": [{"print": "echo"},
  16. {"Fn::Join": ["\\n", [
  17. "#!/bin/sh",
  18. "mkdir ~/test_ros",
  19. "print hello > ~/1.txt"
  20. ]]}]}
  21. }
  22. }
  23. },
  24. "Outputs": {
  25. "InstanceId": {
  26. "Value" : {"Fn::GetAtt": ["WebServer","InstanceId"]}
  27. },
  28. "PublicIp": {
  29. "Value" : {"Fn::GetAtt": ["WebServer","PublicIp"]}
  30. }
  31. }
  32. }

Supported functions

  • Fn::Base64

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

Fn::Split

With the internal function Fn::Split, split strings by the specified separator, and return the list consisting of all splits.

Statement

  1. "Fn::Split" : [ "delim", "original_string" ]

Parameter

delim

  1. Separators, such as ',', ';', '\n', '\t'.

original_string

  1. The strings to be split.

Return value

The list consisting of all split strings.

Example

If a metadata list is an array,

  1. {"Fn::Split": [";", "foo; bar; achoo"]}

The returned value is [“foo”, “ bar”, “achoo “].

In the template below, split InstanceIds using Fn::Split:

  1. "Parameters" : {
  2. "InstanceIds": {
  3. "Type": "String",
  4. "Default": "instane1_id,instance2_id,instance2_id"
  5. }
  6. },
  7. "Resources": {
  8. "resourceID": {
  9. "Type": "ALIYUN::SLB::BackendServerAttachment":
  10. "Properties": {
  11. "BackendServerList": { "Fn::Split" : [ ",", {"Ref": "InstanceIds"} ] }
  12. }
  13. }
  14. }

Supported functions

  • Fn::Base64

  • Fn::FindInMap

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Fn::Replace

  • Fn::GetAZs

  • Fn::If

  • Ref

Fn::Equals

This parameter is used to compare two values. If the two values are equal, TRUE is returned. If the two values are unequal, FALSE is returned.

Statement

  1. {"Fn::Equals": ["value_1", "value_2"]}

Parameters

value

  1. Vales in any type to be compared.

Return values

TRUE or FALSE.

Example

Use Fn::Equals to define a condition in Conditions.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Parameters":{
  4. "EnvType":{
  5. "Default":"pre",
  6. "Type":"String"
  7. }
  8. },
  9. "Conditions": {
  10. "TestEqualsCond": {"Fn::Equals": ["prod", {"Ref": "EnvType"}]}
  11. }
  12. }

Supported functions

  • Fn::Or

  • Fn::Not

  • Fn::Equals

  • Fn::FindInMap

  • Fn::And

  • Ref

Fn::And

If all the specified conditions are calculated as TRUE, TRUE is returned. If any condition is calculated as FALSE, FALSE is returned. This function indicates the AND operator. It contains at least two conditions.

Statement

  1. {"Fn::And": ["condition", {...}]}

Parameters

condition

  1. Condition to be calculated as TRUE or FALSE.

Return values

TRUE or FALSE.

Example

Use Fn::And to define a condition in Conditions.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Parameters":{
  4. "EnvType":{
  5. "Default":"pre",
  6. "Type":"String"
  7. }
  8. },
  9. "Conditions": {
  10. "TestEqualsCond": {"Fn::Equals": ["prod", {"Ref": "EnvType"}]},
  11. "TestAndCond": {"Fn::And": ["TestEqualsCond", {"Fn::Equals": ["pre", {"Ref": "EnvType"}]}]}
  12. }
  13. }

Supported functions

  • Fn::Or

  • Fn::Not

  • Fn::Equals

  • Fn::FindInMap

  • Fn::And

  • Ref

Fn::Or

If any specified condition is calculated as TRUE, TRUE is returned. If all the conditions are calculated as FALSE, FALSE is returned. This function indicates the OR operator. It contains at least two conditions.

Statement

  1. {"Fn::Or": ["condition", {...}]}

Parameters

condition

  1. Condition to be calculated as TRUE or FALSE.

Return values

TRUE or FALSE.

Example

Use Fn::Or to define a condition in Conditions.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Parameters":{
  4. "EnvType":{
  5. "Default":"pre",
  6. "Type":"String"
  7. }
  8. },
  9. "Conditions": {
  10. "TestEqualsCond": {"Fn::Equals": ["prod", {"Ref": "EnvType"}]},
  11. "TestOrCond": {"Fn::And": ["TestEqualsCond", {"Fn::Equals": ["pre", {"Ref": "EnvType"}]}]}
  12. }
  13. }

Supported functions

  • Fn::Or

  • Fn::Not

  • Fn::Equals

  • Fn::FindInMap

  • Fn::And

  • Ref

Fn::Not

If a condition is calculated as FALSE, TRUE is returned. If a condition is calculated as TRUE, FALSE is returned. This function indicates the NOT operator.

Statement

  1. {"Fn::Not": "condition"}

Parameters

condition

  1. Condition to be calculated as TRUE or FALSE.

Return values

TRUE or FALSE.

Example

Use Fn::Not to define a condition in Conditions.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Parameters":{
  4. "EnvType":{
  5. "Default":"pre",
  6. "Type":"String"
  7. }
  8. },
  9. "Conditions": {
  10. "TestNotCond": {"Fn::Not": {"Fn::Equals": ["pre", {"Ref": "EnvType"}]}}
  11. }
  12. }

Supported functions

  • Fn::Or

  • Fn::Not

  • Fn::Equals

  • Fn::FindInMap

  • Fn::And

  • Ref

Fn::If

If the specified condition is calculated as TRUE, a value is returned. If the specified condition is calculated as FALSE, another value is returned. The Resources and Outputs attribute values in the template support the internal function Fn::If. You can use the pseudo parameter ALIYUN::NoValue as the return value to delete the corresponding attribute.

Statement

  1. {"Fn::If": ["condition_name", "value_if_true", "value_if_false"]}

Parameters

condition_name

  1. Name of the condition in Conditions. A condition is referenced using the condition name.

value_if_true

  1. If the specified condition is calculated as TRUE, this value is returned.

value_if_false

  1. If the specified condition is calculated as FALSE, this value is returned.

Example

Determine whether to create a data disk based on the input parameters.

  1. {
  2. "ROSTemplateFormatVersion":"2015-09-01",
  3. "Parameters":{
  4. "EnvType":{
  5. "Default":"pre",
  6. "Type":"String"
  7. }
  8. },
  9. "Conditions":{
  10. "CreateDisk":{
  11. "Fn::Equals":[
  12. "prod",
  13. {
  14. "Ref":"EnvType"
  15. }
  16. ]
  17. }
  18. },
  19. "Resources":{
  20. "WebServer":{
  21. "Type":"ALIYUN::ECS::Instance",
  22. "Properties":{
  23. "DiskMappings":{
  24. "Fn::If":[
  25. "CreateDisk",
  26. [
  27. {
  28. "Category":"cloud_efficiency",
  29. "DiskName":"FirstDataDiskName",
  30. "Size":40
  31. },
  32. {
  33. "Category":"cloud_ssd",
  34. "DiskName":"SecondDataDiskName",
  35. "Size":40
  36. }
  37. ],
  38. {
  39. "Ref":"ALIYUN::NoValue"
  40. }
  41. ]
  42. },
  43. "VpcId":"vpc-2zew9pxh2yirtzqxdboi1",
  44. "SystemDiskCategory":"cloud_efficiency",
  45. "SecurityGroupId":"sg-2zece6wcqriejf1v91sr",
  46. "SystemDiskSize":40,
  47. "ImageId":"centos_6_8_64_40G_base_20170222.vhd",
  48. "IoOptimized":"optimized",
  49. "VSwitchId":"vsw-2zed9txvy7h2srqo6jmgq",
  50. "InstanceType":"ecs.n1.medium"
  51. }
  52. }
  53. },
  54. "Outputs":{
  55. "InstanceId":{
  56. "Value":{
  57. "Fn::GetAtt":[
  58. "WebServer",
  59. "InstanceId"
  60. ]
  61. }
  62. },
  63. "ZoneId":{
  64. "Value":{
  65. "Fn::GetAtt":[
  66. "WebServer",
  67. "ZoneId"
  68. ]
  69. }
  70. }
  71. }
  72. }

Supported functions

  • Fn::Or

  • Fn::Not

  • Fn::Equals

  • Fn::FindInMap

  • Fn::And

  • Ref

Fn::ListMerge

This function merges multiple lists to one.

Statement

  1. {"Fn::ListMerge": [[list_1_item_1, list_1_imte_2, ...], [list_2_item_1, list_2_imte_2, ...]]}

Parameters

[list_1_item_1, list_1_imte_2, …]

  1. First list to be merged.

[list_2_item_1, list_2_imte_2, …]

  1. List to be merged to the first list.

Example

Attach two ECS instance groups to the same Server Load Balancer instance.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Resources" : {
  4. "LoadBalancer": {
  5. "Type": "ALIYUN::SLB::LoadBalancer",
  6. "Properties": {
  7. "LoadBalancerName": "ros",
  8. "AddressType": "internet",
  9. "InternetChargeType": "paybybandwidth",
  10. }
  11. },
  12. "BackendServer1": {
  13. "Type": "ALIYUN::ECS::InstanceGroup",
  14. "Properties": {
  15. "ImageId" : "m-2ze9uqi7wo61hwep5q52",
  16. "InstanceType": "ecs.t1.small",
  17. "SecurityGroupId": "sg-2ze8yxgempcdsq3iucsi",
  18. "MaxAmount": 1,
  19. "MinAmount": 1
  20. }
  21. },
  22. "BackendServer2": {
  23. "Type": "ALIYUN::ECS::InstanceGroup",
  24. "Properties": {
  25. "ImageId" : "m-2ze9uqi7wo61hwep5q52",
  26. "InstanceType": "ecs.t1.small",
  27. "SecurityGroupId": "sg-2ze8yxgempcdsq3iucsi",
  28. "MaxAmount": 1,
  29. "MinAmount": 1
  30. }
  31. },
  32. "Attachment": {
  33. "Type": "ALIYUN::SLB::BackendServerAttachment",
  34. "Properties": {
  35. "LoadBalancerId": {"Ref": "LoadBalancer"},
  36. "BackendServerList": { "Fn::ListMerge": [
  37. {"Fn::GetAtt": ["BackendServer1", "InstanceIds"]},
  38. {"Fn::GetAtt": ["BackendServer2", "InstanceIds"]}
  39. ]
  40. }
  41. }
  42. }
  43. }
  44. }

Supported functions

  • Fn::Base64

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

  • Fn::Join

  • Fn::If

Fn::GetJsonValue

This function resolves a JSON string and obtains the value of the specified Key at the first layer.

Statement

  1. {"Fn::GetJsonValue": ["key", "json_string"]}

Parameters

key

  1. Key value.

json_string

  1. JSON string to be resolved.

Example

After the WebServer instance executes UserData and returns a JSON string, the WebServer2 instance obtains the corresponding value from the string.

  1. {
  2. "ROSTemplateFormatVersion" : "2015-09-01",
  3. "Resources" : {
  4. "WebServer": {
  5. "Type": "ALIYUN::ECS::Instance",
  6. "Properties": {
  7. "ImageId" : "m-2ze45uwova5fedlufpz7",
  8. "InstanceType": "ecs.n1.medium",
  9. "SecurityGroupId": "sg-2ze7pxymaix640qrg3vu",
  10. "Password": "Wenqiao1234",
  11. "IoOptimized": "optimized",
  12. "VSwitchId": "vsw-2zei67xd9nhcqxzec7qt7",
  13. "VpcId": "vpc-2zevx9ios1rszqv0azijb",
  14. "SystemDiskCategory": "cloud_ssd",
  15. "UserData": {"Fn::Join": ["", [
  16. "#!/bin/sh\n",
  17. "mkdir ~/test_ros\n",
  18. "print hello > ~/1.txt\n",
  19. "Fn::GetAtt": ["WaitConHandle", "CurlCli"],
  20. "\n",
  21. "Fn::GetAtt": ["WaitConHandle", "CurlCli"],
  22. " -d '{\\"id\\" : \\"1\\", \\"data\\": [\\"1111\\", \\"2222\\"]}'\n"
  23. ]]},
  24. "PrivateIpAddress": "192.168.2.110",
  25. "HostName": "userdata-1"
  26. }
  27. },
  28. "WaitConHandle": {
  29. "Type": "ALIYUN::ROS::WaitConditionHandle"
  30. },
  31. "WaitCondition": {
  32. "Type": "ALIYUN::ROS::WaitCondition",
  33. "Properties": {
  34. "Handle": {"Ref": "WaitConHandle"},
  35. "Timeout": 900
  36. }
  37. },
  38. "WebServer2": {
  39. "Type": "ALIYUN::ECS::Instance",
  40. "Properties": {
  41. "ImageId" : "m-2ze45uwova5fedlufpz7",
  42. "InstanceType": "ecs.n1.medium",
  43. "SecurityGroupId": "sg-2ze7pxymaix640qrg3vu",
  44. "Password": "Wenqiao1234",
  45. "IoOptimized": "optimized",
  46. "VSwitchId": "vsw-2zei67xd9nhcqxzec7qt7",
  47. "VpcId": "vpc-2zevx9ios1rszqv0azijb",
  48. "SystemDiskCategory": "cloud_ssd",
  49. "UserData":
  50. {"Fn::Join": ["", [
  51. "#!/bin/sh\n",
  52. "mkdir ~/test_ros\n",
  53. "echo hello > ~/1.txt\n",
  54. "server_1_token=",
  55. {"Fn::GetJsonValue": ["1", { "Fn::GetAtt": ["WaitCondition", "Data"]}]},
  56. "\n"
  57. ]]},
  58. "PrivateIpAddress": "192.168.2.111",
  59. "HostName": "userdata-2"
  60. }
  61. },
  62. },
  63. "Outputs": {
  64. "InstanceId": {
  65. "Value" : {"Fn::GetAtt": ["WebServer","InstanceId"]}
  66. },
  67. "PublicIp": {
  68. "Value" : {"Fn::GetAtt": ["WebServer","PublicIp"]}
  69. }
  70. }
  71. }

Supported functions

  • Fn::Base64

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

  • Fn::Join

  • Fn::If

Fn::MergeMapToList

Merge multiple Mappings to a list using Fn::MergeMapToList.

Statement

  1. {"Fn::MergeMapToList": [{"key_1": ["key_1_item_1", "key_1_item_2", ...]}, {"key_2":["key_2_item_1", "key_2_item_2", ...]}, ... ]}

Parameters

{“key_1”: [“key_1_item_1”, “key_1_item_2”, …]}

  1. In the first Mapping to be merged, "key_1" value must be a list. "key_1" is a key of each Mapping in the list of merged Mappings. "key_1" value is "key_1_item_1" in the first Mapping, "key_1_item_2" in the second Mapping, and so on. The final list of merged Mappings is the longest among "key_x" lists in all Mappings to be merged. If "key_y" list is short, the last element of the list is repeated, to make the list the longest.

{“key_2”: [“key_2_item_1”, “key_2_item_2”, …]}

  1. In the second Mapping to be merged, "key_2" value must be a list. "key_2" is a key of each Mapping in the merged list. "key_2" value is "key_2_item_1" in the first Mapping, "key_2_item_2" in the second Mapping, and so on.

Examples

Merge three Mappings. The length of the list corresponding to the key value in each Mapping is the same.

  1. {
  2. "Fn::MeregMapToList": [
  3. {"key_1": ["kye_1_item_1", "kye_1_item_2"]},
  4. {"key_2": ["kye_2_item_1", "kye_2_item_2"]},
  5. {"key_3": ["kye_3_item_1", "kye_3_item_2"]}
  6. ]
  7. }

The results are:

  1. [
  2. {
  3. "key_1": "kye_1_item_1",
  4. "key_2": "kye_2_item_1",
  5. "key_3": "kye_3_item_1"
  6. },
  7. {
  8. "key_1": "kye_1_item_2",
  9. "key_2": "kye_2_item_2",
  10. "key_3": "kye_3_item_2"
  11. }
  12. ]

Merge three Mappings. The length of the list corresponding to the key value in each Mapping varies.

  1. {
  2. "Fn::MeregMapToList": [
  3. {"key_1": ["kye_1_item_1", "kye_1_item_2"]},
  4. {"key_2": ["kye_2_item_1", "kye_2_item_2", "key_2_item_3"]},
  5. {"key_3": ["kye_3_item_1", "kye_3_item_2"]}
  6. ]
  7. }

The results are:

  1. [
  2. {
  3. "key_1": "kye_1_item_1",
  4. "key_2": "kye_2_item_1",
  5. "key_3": "kye_3_item_1"
  6. },
  7. {
  8. "key_1": "kye_1_item_2",
  9. "key_2": "kye_2_item_2",
  10. "key_3": "kye_3_item_2"
  11. },
  12. {
  13. "key_1": "kye_1_item_2",
  14. "key_2": "kye_2_item_3",
  15. "key_3": "kye_3_item_2"
  16. }
  17. ]

In the template below, add all instances created in the WebServer into the Virtual Server Group of one Server Load Balancer.

  1. {
  2. "ROSTemplateFormatVersion": "2015-09-01",
  3. "Resources": {
  4. "WebServer": {
  5. "Type": "ALIYUN::ECS::InstanceGroupClone",
  6. "Properties": {
  7. "SourceInstanceId": "i-xxxxx",
  8. "Password": "Hello1234",
  9. "MinAmount": 1,
  10. "MaxAmount": 1
  11. }
  12. },
  13. "CreateVServerGroup": {
  14. "Type": "ALIYUN::SLB::VServerGroup",
  15. "Properties": {
  16. "LoadBalancerId": "lb-yyyy",
  17. "VServerGroupName": "VServerGroup-test",
  18. "BackendServers": {
  19. "Fn::MergeMapToList": [
  20. {"Port": [6666, 9090, 8080]},
  21. {"ServerId": {"Fn::GetAtt": ["WebServer", "InstanceIds"]}},
  22. {"Weight": [20, 100]}
  23. ]
  24. }
  25. }
  26. }
  27. }
  28. }

Supported functions

  • Fn::Base64

  • Fn::GetAtt

  • Fn::Join

  • Fn::Select

  • Ref

  • Fn::Join

  • Fn::If

  • Fn::ListMerge

  • Fn::GetJsonValue

Thank you! We've received your feedback.