伪参数是资源编排服务(ROS)的编排引擎提供的固定参数。它们可以和用户定义的参数一样被引用,其值在ROS运行时确定。

ROS提供了以下伪参数:
  • ALIYUN::StackName:获取当前资源栈的名称。
  • ALIYUN::StackId:获取当前资源栈的ID。
  • ALIYUN::Region:获取当前资源栈所在的地域。
  • ALIYUN::AccountId:获取当前资源栈的账户ID。
  • ALIYUN::TenantId:获取当前账户的阿里云主账号ID。
  • ALIYUN::NoValue:创建或更新资源栈时,如果ALIYUN::NoValue用于可选属性,则将删除该属性;如果ALIYUN::NoValue用于必选属性,则将按类型获取默认值(例如:用于String类型的属性则该属性的值为空字符串;用于Integer类型的属性则该属性的值为0;用于数组类型属性则该属性的值为空数组等)。

示例

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "EnvType": {
      "Default": "pre",
      "Type": "String"
    }
  },
  "Conditions": {
    "CreateDisk": {
      "Fn::Equals": [
        "prod",
        {
          "Ref": "EnvType"
        }
      ]
    }
  },
  "Resources": {
    "WebServer": {
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "DiskMappings": {
          "Fn::If": [
            "CreateDisk",
            [
              {
                "Category": "cloud_efficiency",
                "DiskName": "FirstDataDiskName",
                "Size": 40
              },
              {
                "Category": "cloud_ssd",
                "DiskName": "SecondDataDiskName",
                "Size": 40
              }
            ],
            {
              "Ref": "ALIYUN::NoValue"
            }
          ]
        },
        "VpcId": "vpc-m5eebunc50zfbmts7****",
        "SystemDiskCategory": "cloud_efficiency",
        "SecurityGroupId": "sg-m5eagh7rzys2z8sa****",
        "SystemDiskSize": 40,
        "ImageId": "centos_7",
        "IoOptimized": "optimized",
        "VSwitchId": "vsw-m5eem62p9729y6gps****",
        "InstanceType": "ecs.c5.large"
      }
    }
  },
  "Outputs": {
    "StackName": {
      "Value": {
        "Ref": "ALIYUN::StackName"
      }
    },
    "StackId": {
      "Value": {
        "Ref": "ALIYUN::StackId"
      }
    },
    "Region": {
      "Value": {
        "Ref": "ALIYUN::Region"
      }
    },
    "UserID": {
      "Value": {
        "Ref": "ALIYUN::AccountId"
      }
    }
  }
}

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  EnvType:
    Default: pre
    Type: String
Conditions:
  CreateDisk:
    Fn::Equals:
    - prod
    - Ref: EnvType
Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      DiskMappings:
        Fn::If:
        - CreateDisk
        - - Category: cloud_efficiency
            DiskName: FirstDataDiskName
            Size: 40
          - Category: cloud_ssd
            DiskName: SecondDataDiskName
            Size: 40
        - Ref: ALIYUN::NoValue
      VpcId: vpc-m5eebunc50zfbmts7****
      SystemDiskCategory: cloud_efficiency
      SecurityGroupId: sg-m5eagh7rzys2z8sa****
      SystemDiskSize: 40
      ImageId: centos_7
      IoOptimized: optimized
      VSwitchId: vsw-m5eem62p9729y6gps****
      InstanceType: ecs.c5.large
Outputs:
  StackName:
    Value:
      Ref: ALIYUN::StackName
  StackId:
    Value:
      Ref: ALIYUN::StackId
  Region:
    Value:
      Ref: ALIYUN::Region
  UserID:
    Value:
      Ref: ALIYUN::AccountId