ALIYUN::ECS::Command

更新时间:
复制 MD 格式

ALIYUN::ECS::Command creates a Cloud Assistant command.

Syntax

{
  "Type": "ALIYUN::ECS::Command",
  "Properties": {
    "Name": String,
    "WorkingDir": String,
    "CommandContent": String,
    "Timeout": Integer,
    "Type": String,
    "Description": String,
    "EnableParameter": Boolean,
    "Tags": List,
    "Launcher": String
    "ResourceGroupId": String,
    "ContentEncoding": String
  }
}

Properties

Property

Type

Required

Editable

Description

Constraint

Name

String

No

Yes

The command name.

1 to 128 characters. All character sets are supported.

WorkingDir

String

No

Yes

The working directory of the command on the ECS instance.

Defaults:

  • Linux: /root (home directory of the root user).

  • Windows: the Cloud Assistant Agent process directory, such as C:\Windows\System32.

Note

If you set a non-default value, ensure the directory exists on the instance.

CommandContent

String

No

No

The Base64-encoded content of the command.

  • Must be Base64-encoded. Maximum size: 18 KB.

  • To use custom parameters, set EnableParameter to true.

    • Custom parameters use the {{}} format. Spaces and line feeds around parameter names in {{}} are ignored.

    • Maximum: 20 custom parameters.

    • Parameter names can contain only letters, digits, hyphens (-), and underscores (_), are case-insensitive, and cannot use the ACS:: prefix to specify non-built-in environment parameters.

    • Maximum name length: 64 bytes.

  • You can specify built-in environment parameters as custom parameters in a command. When you run the command, Cloud Assistant automatically uses the environment parameter values for the custom parameters. You can specify the following built-in environment parameters:

    • {{ACS::RegionId}}: the region ID.

    • {{ACS::AccountId}}: the Alibaba Cloud account UID.

    • {{ACS::InstanceId}}: the instance ID. When running on multiple instances, requires Cloud Assistant Agent:

      • Linux: 2.2.3.309

      • Windows: 2.1.3.309

    • {{ACS::InstanceName}}: the instance name. When running on multiple instances, requires Cloud Assistant Agent:

      • Linux: 2.2.3.344

      • Windows: 2.1.3.344

    • {{ACS::InvokeId}}: the command task ID. If you want to specify {{ACS::InvokeId}} as a built-in environment variable, make sure that the version of Cloud Assistant Agent is not earlier than:

      • Linux: 2.2.3.309

      • Windows: 2.1.3.309

    • {{ACS::CommandId}}: the command ID. When calling the RunCommand operation, requires Cloud Assistant Agent:

      • Linux: 2.2.3.309

      • Windows: 2.1.3.309

Launcher

String

No

No

The launcher for the script execution.

The value can be up to 1 KB in size.

Timeout

Integer

No

Yes

The command execution timeout on the ECS instance.

When a command exceeds this period, Cloud Assistant Agent terminates the process by canceling its PID.

Default value: 60.

Unit: seconds.

Type

String

Yes

No

The command type.

Valid values:

  • RunBatScript: batch command, applicable to Windows instances.

  • RunPowerShellScript: PowerShell command, applicable to Windows instances.

  • RunShellScript: shell command, applicable to Linux instances.

Description

String

No

Yes

The command description.

1 to 512 characters. All character sets are supported.

EnableParameter

Boolean

No

No

Whether to use custom parameters in the command.

Valid values:

  • true

  • false (default)

Tags

List

No

No

The tags. Maximum: 20.

For more information, see Tags properties.

ContentEncoding

String

No

No

The command content encoding mode.

Valid values:

  • PlainText: no encoding.

  • Base64 (default): Base64 encoding.

Note

Invalid values default to Base64.

ResourceGroupId

String

No

Yes

The ID of the resource group to which the command belongs.

None.

Tags syntax

"Tags": [
  {
    "Key": String,
    "Value": String
  }
]

Tags properties

Property

Type

Required

Editable

Description

Constraint

Key

String

Yes

No

The tag key.

The tag key must be 1 to 128 characters in length and cannot contain http:// or https://. It cannot start with aliyun or acs:.

Value

String

No

No

The tag value.

The tag value can be up to 128 characters in length and cannot contain http:// or https://. It cannot start with aliyun or acs:.

Return values

Fn::GetAtt

CommandId: the command ID.

Note

You can run the command only once. For more information, see ALIYUN::ECS::RunCommand.

Examples

YAML format

ROSTemplateFormatVersion: '2015-09-01'
Parameters: {}
Resources:
  Command:
    Type: ALIYUN::ECS::Command
    Properties:
      CommandContent:
        Fn::Base64Encode: |
          #!/bin/bash
          echo "hello" >> /root/test.sh
      Type: RunShellScript
      Name:
        Ref: ALIYUN::StackName
Outputs:
  CommandId:
    Description: The id of command created.
    Value:
      Fn::GetAtt:
        - Command
        - CommandId

JSON format

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
  },
  "Resources": {
    "Command": {
      "Type": "ALIYUN::ECS::Command",
      "Properties": {
        "CommandContent": {
          "Fn::Base64Encode": "#!/bin/bash\necho \"hello\" >> /root/test.sh\n"
        },
        "Type": "RunShellScript",
        "Name": {
          "Ref": "ALIYUN::StackName"
        }
      }
    }
  },
  "Outputs": {
    "CommandId": {
      "Description": "The id of command created.",
      "Value": {
        "Fn::GetAtt": [
          "Command",
          "CommandId"
        ]
      }
    }
  }
}