All Products
Search
Document Center

Resource Orchestration Service:ALIYUN::SWAS::RunCommand

Last Updated:Apr 02, 2026

The ALIYUN::SWAS::RunCommand resource executes commands on Simple Application Server instances.

Syntax

{
  "Type": "ALIYUN::SWAS::RunCommand",
  "Properties": {
    "CommandContent": String,
    "InstanceId": String,
    "Name": String,
    "Type": String,
    "ContentEncoding": String,
    "EnableParameter": Boolean,
    "Parameters": Map,
    "Sync": Boolean,
    "Timeout": Integer,
    "WorkingDir": String,
    "WorkingUser": String,
    "WindowsPasswordName": String
  }
}

Properties

Property Name

Type

Required

Updatable

Description

Constraints

CommandContent

String

Yes

Yes

The command content.

Note the following:

  • Set EnableParameter=true to enable custom parameters in the command content.

  • Define custom parameters using `{{}}`. Spaces and line feeds before and after the parameter name within {{}} are ignored.

  • The number of custom parameters cannot exceed 20.

  • Custom parameter names can only contain a-zA-Z0-9-_ characters. Other characters are not supported. Parameter names are case-insensitive.

  • A single custom parameter name cannot exceed 64 bytes.

InstanceId

String

Yes

No

The ID of the Simple Application Server instance.

None

Name

String

Yes

Yes

The name of the command to execute.

None

Type

String

Yes

Yes

The language type of the command.

Valid values:

  • RunBatScript: Bat commands for Windows instances.

  • RunPowerShellScript: PowerShell commands for Windows instances.

  • RunShellScript: Shell commands for Linux instances.

ContentEncoding

String

No

Yes

The encoding mode for the command content.

Valid values:

PlainText: The command content is not encoded and is transmitted as plaintext. (Default value)

Base64: Base64 encoding is used.

EnableParameter

Boolean

No

Yes

Indicates whether the command contains custom parameters.

Default value: false.

Parameters

Map

No

Yes

If the command contains custom parameters, specify the key-value pairs for these custom parameters when executing the command.

For example, if the command content is echo {{name}}, you can pass the key-value pair {"name":"Jack"} using the Parameters parameter. The custom parameter automatically replaces the variable value name, resulting in a new command that actually executes echo Jack.

The number of custom parameters ranges from 0 to 20. Note the following:

  • Keys cannot be empty strings and can contain a maximum of 64 characters.

  • Values can be empty strings.

  • The combined length of custom parameters and the original command content, after Base64 encoding, cannot exceed 16 KB.

  • The set of custom parameter names must be a subset of the parameter set defined when creating the command. For parameters not passed, use an empty string as a placeholder.

The default value is empty, which means canceling the setting of this parameter to disable custom parameters.

Sync

Boolean

No

No

Indicates whether to run the command synchronously.

None

Timeout

Integer

No

Yes

Set the timeout for the command on the server instance.

Unit: seconds.

If the command execution times out, Command Assistant forcibly stops the task process. The timeout can be set from 10 to 86400 seconds (24 hours).

Default value: 60.

WorkingDir

String

No

Yes

Customize the execution path for the command.

Default paths are as follows:

  • Linux instances: The default execution path is in the /root directory of the root administrator.

  • Windows instances: The default execution path is in the C:\Windows\system32 directory.

WorkingUser

String

No

Yes

Specify an existing user on the Simple Application Server instance to execute the command.

Use a regular user to execute commands to reduce security risk. Default values:

  • root: For Linux instances, commands are executed by the root user by default.

  • system: For Windows instances, commands are executed by the system user by default.

WindowsPasswordName

String

No

No

The password name of the user who executes the command in a Windows instance.

If you want to execute commands as a non-default user (System) in a Windows instance, pass both `WorkingUser` and this parameter. To reduce the risk of password leakage, store the plaintext password in the parameter repository of the O&M orchestration service. Only pass the password name here.

Return Values

Fn::GetAtt

  • InvokeResult: The result of the command execution.

  • InvokeId: The command execution ID.

Examples

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  CommandContent:
    AssociationProperty: TextArea
    Type: String
    Description:
      en: The plaintext content of the command to run.
    Required: true
  Type:
    Type: String
    Description:
      en: |-
        The language type of the O&M script. Valid values:
        RunShellScript: shell scripts for Linux instances
        RunBatScript: batch scripts for Windows instances
        RunPowerShellScript: PowerShell scripts for Windows instances
    AllowedValues:
      - RunShellScript
      - RunBatScript
      - RunPowerShellScript
    Required: true
  InstanceId:
    Type: String
    Description:
      en: The ID of the SWAS instance on which to run the command. The instance must be in 'Running' status.
    Required: true
  Name:
    Type: String
    Description:
      en: The name of the command to run.
    Required: true
Resources:
  RunCommand:
    Type: ALIYUN::SWAS::RunCommand
    Properties:
      CommandContent:
        Ref: CommandContent
      Type:
        Ref: Type
      InstanceId:
        Ref: InstanceId
      Name:
        Ref: Name
Outputs:
  InvokeResult:
    Description: The result of the command execution.
    Value:
      Fn::GetAtt:
        - RunCommand
        - InvokeResult
  InvokeId:
    Description: The ID of the command execution.
    Value:
      Fn::GetAtt:
        - RunCommand
        - InvokeId
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "CommandContent": {
      "AssociationProperty": "TextArea",
      "Type": "String",
      "Description": {
        "en": "The plaintext content of the command to run."
      },
      "Required": true
    },
    "Type": {
      "Type": "String",
      "Description": {
        "en": "The language type of the O&M script. Valid values:\nRunShellScript: shell scripts for Linux instances\nRunBatScript: batch scripts for Windows instances\nRunPowerShellScript: PowerShell scripts for Windows instances"
      },
      "AllowedValues": [
        "RunShellScript",
        "RunBatScript",
        "RunPowerShellScript"
      ],
      "Required": true
    },
    "InstanceId": {
      "Type": "String",
      "Description": {
        "en": "The ID of the SWAS instance on which to run the command. The instance must be in 'Running' status."
      },
      "Required": true
    },
    "Name": {
      "Type": "String",
      "Description": {
        "en": "The name of the command to run."
      },
      "Required": true
    }
  },
  "Resources": {
    "RunCommand": {
      "Type": "ALIYUN::SWAS::RunCommand",
      "Properties": {
        "CommandContent": {
          "Ref": "CommandContent"
        },
        "Type": {
          "Ref": "Type"
        },
        "InstanceId": {
          "Ref": "InstanceId"
        },
        "Name": {
          "Ref": "Name"
        }
      }
    }
  },
  "Outputs": {
    "InvokeResult": {
      "Description": "The result of the command execution.",
      "Value": {
        "Fn::GetAtt": [
          "RunCommand",
          "InvokeResult"
        ]
      }
    },
    "InvokeId": {
      "Description": "The ID of the command execution.",
      "Value": {
        "Fn::GetAtt": [
          "RunCommand",
          "InvokeId"
        ]
      }
    }
  }
}