Skip to content

RunCommand

This class encapsulates and extends the ROS resource type ALIYUN::ECS::RunCommand, which is used to run a shell, PowerShell, or batch command on Elastic Compute Service (ECS) instances.

Initializers

import ros_cdk_ecs
ros_cdk_ecs.RunCommand(
  scope: Construct,
  id: str,
  command_content: typing.Union[str, IResolvable],
  instance_ids: typing.Union[IResolvable, typing.List[typing.Union[str, IResolvable]]],
  type: typing.Union[str, IResolvable],
  container_id: typing.Union[str, IResolvable] = None,
  container_name: typing.Union[str, IResolvable] = None,
  content_encoding: typing.Union[str, IResolvable] = None,
  description: typing.Union[str, IResolvable] = None,
  enable_parameter: typing.Union[bool, IResolvable] = None,
  frequency: typing.Union[str, IResolvable] = None,
  keep_command: typing.Union[bool, IResolvable] = None,
  name: typing.Union[str, IResolvable] = None,
  parameters: typing.Union[IResolvable, typing.Mapping[typing.Any]] = None,
  repeat_mode: typing.Union[str, IResolvable] = None,
  resource_group_id: typing.Union[str, IResolvable] = None,
  run_again_on: typing.Union[IResolvable, typing.List[typing.Union[str, IResolvable]]] = None,
  sync: typing.Union[bool, IResolvable] = None,
  tags: typing.List[TagsProperty] = None,
  timeout: typing.Union[typing.Union[int, float], IResolvable] = None,
  username: typing.Union[str, IResolvable] = None,
  windows_password_name: typing.Union[str, IResolvable] = None,
  working_dir: typing.Union[str, IResolvable] = None,
  enable_resource_property_constraint: bool = None
)
Name Type Description
scope ros_cdk_core.Construct No description.
id str No description.
command_content typing.Union[str, ros_cdk_core.IResolvable] Property commandContent: The plaintext content or the Base64-encoded content of the script.
instance_ids typing.Union[ros_cdk_core.IResolvable, typing.List[typing.Union[str, ros_cdk_core.IResolvable]]] Property instanceIds: The instance id list.
type typing.Union[str, ros_cdk_core.IResolvable] Property type: The language type of the O&M script.
container_id typing.Union[str, ros_cdk_core.IResolvable] Property containerId: The ID of the container.
container_name typing.Union[str, ros_cdk_core.IResolvable] Property containerName: The name of the container.
content_encoding typing.Union[str, ros_cdk_core.IResolvable] Property contentEncoding: The encoding mode of script content (CommandContent).
description typing.Union[str, ros_cdk_core.IResolvable] Property description: The description of the script, which supports all character sets.
enable_parameter typing.Union[bool, ros_cdk_core.IResolvable] Property enableParameter: Specifies whether the script contains custom parameters.
frequency typing.Union[str, ros_cdk_core.IResolvable] Property frequency: The execution period of recurring tasks.
keep_command typing.Union[bool, ros_cdk_core.IResolvable] Property keepCommand: Specifies whether to retain the script after it is run.
name typing.Union[str, ros_cdk_core.IResolvable] Property name: The name of the script, which supports all character sets.
parameters typing.Union[ros_cdk_core.IResolvable, typing.Mapping[typing.Any]] Property parameters: The key-value pairs of custom parameters passed in when the script contains custom parameters.
repeat_mode typing.Union[str, ros_cdk_core.IResolvable] Property repeatMode: Specifies how to run the command.
resource_group_id typing.Union[str, ros_cdk_core.IResolvable] Property resourceGroupId: The ID of the resource group to which to assign the command executions.
run_again_on typing.Union[ros_cdk_core.IResolvable, typing.List[typing.Union[str, ros_cdk_core.IResolvable]]] Property runAgainOn: The stage of executing the command again.
sync typing.Union[bool, ros_cdk_core.IResolvable] Property sync: Whether to invoke synchronously.
tags typing.List[TagsProperty] Property tags: Tags to attach to run_command.
timeout typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable] Property timeout: The timeout period for script execution.
username typing.Union[str, ros_cdk_core.IResolvable] Property username: The username to use to run the command on instances.
windows_password_name typing.Union[str, ros_cdk_core.IResolvable] Property windowsPasswordName: The name of the password to use to run the command on Windows instances.
working_dir typing.Union[str, ros_cdk_core.IResolvable] Property workingDir: The running directory of the script in the ECS instance.
enable_resource_property_constraint bool No description.

scopeRequired

  • Type: ros_cdk_core.Construct

idRequired

  • Type: str

command_contentRequired

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property commandContent: The plaintext content or the Base64-encoded content of the script.

The Base64-encoded script content cannot exceed 16 KB. You can enable the custom parameter function by setting EnableParameter=true in the script content: Define custom parameters in the {{}} format. Within {{}}, the spaces and line breaks before and after the name of the parameter are ignored. The number of custom parameters cannot exceed 20. A custom parameter name can contain only letters, digits, underscores (_), and hyphens (-). It is case insensitive. Each custom parameter key cannot exceed 64 bytes.


instance_idsRequired

  • Type: typing.Union[ros_cdk_core.IResolvable, typing.List[typing.Union[str, ros_cdk_core.IResolvable]]]

Property instanceIds: The instance id list.

Instances status must be running.


typeRequired

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property type: The language type of the O&M script.

Valid values: RunBatScript: batch scripts for Windows instances RunPowerShellScript: PowerShell scripts for Windows instances RunShellScript: shell scripts for Linux instances


container_idOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property containerId: The ID of the container.

Only 64-bit hexadecimal strings are supported. You can use container IDs that are prefixed with docker://, containerd://, or cri-o:// to specify container runtimes. Take note of the following items:

  • If you specify this parameter, Cloud Assistant runs scripts in the specified container of the instance.
  • If you specify this parameter, make sure that the version of Cloud Assistant Agent installed on Linux instances is 2.2.3.344 or later.- If you specify this parameter, Username that is specified in a request to call this operation and WorkingDir that is specified in a request to call the CreateCommand operation do not take effect. You can run the command only in the default working directory of the container by using the default user of the container.
  • If you specify this parameter, only shell scripts can be run in Linux containers. You cannot add a command in the format similar to #!/usr/bin/python at the beginning of a script to specify a script interpreter.

container_nameOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property containerName: The name of the container.

Take note of the following items:

  • If you specify this parameter, Cloud Assistant runs scripts in the specified container of the instance.
  • If you specify this parameter, make sure that the version of Cloud Assistant Agent installed on Linux instances is 2.2.3.344 or later.
  • If you specify this parameter, Username that is specified in a request to call this operation and WorkingDir that is specified in a request to call the CreateCommand operation do not take effect. You can run the command only in the default working directory of the container by using the default user of the container.
  • If you specify this parameter, only shell scripts can be run in Linux containers. You cannot add a command in the format similar to #!/usr/bin/python at the beginning of a script to specify a script interpreter.

content_encodingOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property contentEncoding: The encoding mode of script content (CommandContent).

Valid values (case insensitive): PlainText: The script content is not encoded, and transmitted in plaintext. Base64: base64-encoded. Default value: PlainText. If the specified value of this parameter is invalid, PlainText is used by default.


descriptionOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property description: The description of the script, which supports all character sets.

It can be up to 512 characters in length.


enable_parameterOptional

  • Type: typing.Union[bool, ros_cdk_core.IResolvable]

Property enableParameter: Specifies whether the script contains custom parameters.

Default value: false


frequencyOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property frequency: The execution period of recurring tasks.

If the Timed parameter is set to True, you must specify the Frequency parameter. The interval between two recurring tasks cannot be less than 10 seconds. The parameter value follows the cron expression. For more information, see Configure scheduled commands.


keep_commandOptional

  • Type: typing.Union[bool, ros_cdk_core.IResolvable]

Property keepCommand: Specifies whether to retain the script after it is run.

Valid values: true: The script is retained. You can call the InvokeCommand operation to run the script again, call the DescribeCommands operation to query the script, and call the DeleteCommands operation to delete the script. The retained script takes up the quota of Cloud Assistant scripts. false: The script is not retained. It is automatically deleted after running, without taking up the quota of Cloud Assistant scripts. Default value: false


nameOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property name: The name of the script, which supports all character sets.

It can be up to 128 characters in length.


parametersOptional

  • Type: typing.Union[ros_cdk_core.IResolvable, typing.Mapping[typing.Any]]

Property parameters: The key-value pairs of custom parameters passed in when the script contains custom parameters.

Number of custom parameters: 0 to 10. The key cannot be an empty string. It can be up to 64 characters in length. The value can be an empty string. After the custom parameters and the original script content are Base64 encoded, the total size cannot exceed 16 KB. The set of custom parameter names must be a subset of the parameter set that is defined when you created the script. You can use an empty string to represent the parameters that are not passed in. Default value: null, indicating that this parameter is canceled and customer parameters are disabled.


repeat_modeOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property repeatMode: Specifies how to run the command.

Valid values:

  • Once: immediately runs the command.
  • Period: runs the command on a schedule. If you set this parameter to Period, you must specify Frequency.
  • NextRebootOnly: runs the command the next time the instance is started.
  • *EveryReboot: runs the command every time the instance is started. Default value:
  • If you do not specify Frequency, the default value is Once.
  • If you specify Frequency, Period is used as the value of RepeatMode regardless of whether RepeatMode is set to Period.

resource_group_idOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property resourceGroupId: The ID of the resource group to which to assign the command executions.

The instances specified by InstanceIds must belong to the specified resource group.


run_again_onOptional

  • Type: typing.Union[ros_cdk_core.IResolvable, typing.List[typing.Union[str, ros_cdk_core.IResolvable]]]

Property runAgainOn: The stage of executing the command again.


syncOptional

  • Type: typing.Union[bool, ros_cdk_core.IResolvable]

Property sync: Whether to invoke synchronously.


tagsOptional

Property tags: Tags to attach to run_command.

Max support 20 tags to add during create run_command. Each tag with two properties Key and Value, and Key is required.


timeoutOptional

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

Property timeout: The timeout period for script execution.

Unit: seconds. A timeout error occurs when a script cannot be run because the process slows down, a specific module or the Cloud Assistant client does not exist. When the script times out, the script process is forcibly terminated. Default value: 60.


usernameOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property username: The username to use to run the command on instances.

The username can be up to 255 characters in length.

  • For Linux instances, the root username is used by default.
  • For Windows instances, the System username is used by default. You can also specify other usernames that already exist in the instances to run the command. For security purposes, we recommend that you run Cloud Assistant commands as a regular user.

windows_password_nameOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property windowsPasswordName: The name of the password to use to run the command on Windows instances.

The name can be up to 255 characters in length. If you do not want to use the default System user to run the command on Windows instances, specify both WindowsPasswordName and Username. To mitigate the risk of password leaks, the password is stored in plaintext in Operation Orchestration Service (OOS) Parameter Store, and only the name of the password is passed in by using WindowsPasswordName.


working_dirOptional

  • Type: typing.Union[str, ros_cdk_core.IResolvable]

Property workingDir: The running directory of the script in the ECS instance.

Default value: Linux instances: under the home directory of the administrator (root user): /root. Windows instances: under the directory where the process of the Cloud Assistant client is located, such as C:\ProgramData\aliyun\assist$(version).


enable_resource_property_constraintOptional

  • Type: bool

Methods

Name Description
to_string Returns a string representation of this construct.
synthesize Allows this construct to emit artifacts into the cloud assembly during synthesis.
add_condition No description.
add_count No description.
add_dependency No description.
add_resource_desc No description.
apply_removal_policy No description.
get_att No description.
set_metadata No description.

to_string

def to_string() -> str

Returns a string representation of this construct.

synthesize

def synthesize(
  session: ISynthesisSession
) -> None

Allows this construct to emit artifacts into the cloud assembly during synthesis.

This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

sessionRequired

  • Type: ros_cdk_core.ISynthesisSession

The synthesis session.


add_condition

def add_condition(
  condition: RosCondition
) -> None

conditionRequired

  • Type: ros_cdk_core.RosCondition

add_count

def add_count(
  count: typing.Union[typing.Union[int, float], IResolvable]
) -> None

countRequired

  • Type: typing.Union[typing.Union[int, float], ros_cdk_core.IResolvable]

add_dependency

def add_dependency(
  resource: Resource
) -> None

resourceRequired

  • Type: ros_cdk_core.Resource

add_resource_desc

def add_resource_desc(
  desc: str
) -> None

descRequired

  • Type: str

apply_removal_policy

def apply_removal_policy(
  policy: RemovalPolicy
) -> None

policyRequired

  • Type: ros_cdk_core.RemovalPolicy

get_att

def get_att(
  name: str
) -> IResolvable

nameRequired

  • Type: str

set_metadata

def set_metadata(
  key: str,
  value: typing.Any
) -> None

keyRequired

  • Type: str

valueRequired

  • Type: typing.Any

Static Functions

Name Description
is_construct Return whether the given object is a Construct.

is_construct

import ros_cdk_ecs
ros_cdk_ecs.RunCommand.is_construct(
  x: typing.Any
)

Return whether the given object is a Construct.

xRequired

  • Type: typing.Any

Properties

Name Type Description
node ros_cdk_core.ConstructNode The construct tree node associated with this construct.
ref str No description.
stack ros_cdk_core.Stack The stack in which this resource is defined.
resource ros_cdk_core.RosResource No description.
attr_command_id ros_cdk_core.IResolvable Attribute CommandId: The id of command created.
attr_invoke_id ros_cdk_core.IResolvable Attribute InvokeId: The invoke id of command.
attr_invoke_instances ros_cdk_core.IResolvable Attribute InvokeInstances: The InvokeInstances of command.
attr_invoke_results ros_cdk_core.IResolvable Attribute InvokeResults: The results of invoke command.

nodeRequired

node: ConstructNode
  • Type: ros_cdk_core.ConstructNode

The construct tree node associated with this construct.


refRequired

ref: str
  • Type: str

stackRequired

stack: Stack
  • Type: ros_cdk_core.Stack

The stack in which this resource is defined.


resourceOptional

resource: RosResource
  • Type: ros_cdk_core.RosResource

attr_command_idRequired

attr_command_id: IResolvable
  • Type: ros_cdk_core.IResolvable

Attribute CommandId: The id of command created.


attr_invoke_idRequired

attr_invoke_id: IResolvable
  • Type: ros_cdk_core.IResolvable

Attribute InvokeId: The invoke id of command.


attr_invoke_instancesRequired

attr_invoke_instances: IResolvable
  • Type: ros_cdk_core.IResolvable

Attribute InvokeInstances: The InvokeInstances of command.


attr_invoke_resultsRequired

attr_invoke_results: IResolvable
  • Type: ros_cdk_core.IResolvable

Attribute InvokeResults: The results of invoke command.