模板名称
ACS-TAG-MonitorTagEcsInstanceAndRunCommand 监听标签事件当给ECS实例打上指定标签时执行云助手命令
模板描述
监听标签事件当给ECS实例打上指定标签时执行云助手命令
模板类型
自动化
所有者
Alibaba Cloud
输入参数
参数名称 | 描述 | 类型 | 是否必填 | 默认值 | 约束 |
tagKey | 监听的标签键 | String | 是 | ||
tagValue | 监听的标签值 | String | 是 | ||
commandContent | 命令内容 | String | 是 | 最大长度 : 16384 | |
regionId | 地域ID | String | 否 | {{ ACS::RegionId }} | |
commandType | 命令类型 | String | 否 | RunShellScript | |
workingDir | 运行目录 | String | 否 | "" | |
timeout | 超时时间(秒) | Number | 否 | 600 | |
enableParameter | 命令中是否包含加密参数或自定义参数 | Boolean | 否 | False | |
username | 执行命令的用户名称 | String | 否 | "" | |
windowsPasswordName | 在Windows实例中执行命令的用户的密码名称 | String | 否 | "" | |
rateControl | 任务执行的并发比率 | Json | 否 | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | "" |
输出参数
参数名称 | 描述 | 类型 |
tagEventContent | String | |
instanceId | String | |
isTriggerExecute | String |
执行此模板需要的权限策略
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
}
]
}详情
ACS-TAG-MonitorTagEcsInstanceAndRunCommand详情
模板内容
FormatVersion: OOS-2019-06-01
Description:
en: Listen to tag events and execute cloud assistant commands when the specified tag is added to the ECS instance
zh-cn: 监听标签事件当给ECS实例打上指定标签时执行云助手命令
name-en: ACS-TAG-MonitorTagEcsInstanceAndRunCommand
name-zh-cn: 监听标签事件当给ECS实例打上指定标签时执行云助手命令
categories:
- event-trigger
- tag_event_trigger
Parameters:
regionId:
Label:
en: RegionId
zh-cn: 地域ID
Type: String
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
tagKey:
Label:
en: Tag key being monitored
zh-cn: 监听的标签键
Type: String
tagValue:
Label:
en: Tag value being monitored
zh-cn: 监听的标签值
Description:
en: When you tag an ECS instance, <font color='red'>the command will fail if the instance is in the stopped state.</font>
zh-cn: 当给ECS实例打上指定标签时,<font color='red'>如果实例处于停止状态,该命令会执行失败。</font>
Type: String
commandType:
Label:
en: CommandType
zh-cn: 命令类型
AssociationPropertyMetadata:
LocaleKey: ECSCommandType
Type: String
AllowedValues:
- RunShellScript
- RunPythonScript
- RunPerlScript
- RunBatScript
- RunPowerShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
zh-cn: 命令内容
Type: String
MaxLength: 16384
AssociationProperty: ALIYUN::OOS::Command::CommandContent
AssociationPropertyMetadata:
CommandType: ${commandType}
workingDir:
Description:
en: '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 asC:\Windows\System32. Please ensure you input the correct directory.'
zh-cn: Linux系统实例默认在管理员(root用户)的home目录下,即/root。Windows系统实例默认在云助手客户端进程所在目录,例如C:\Windows\System32。请确保您输入的目录是正确的。'
Label:
en: WorkingDir
zh-cn: 运行目录
Type: String
Default: ''
AssociationPropertyMetadata:
Value:
- Condition:
Fn::Or:
- Fn::Equals:
- ${commandType}
- RunShellScript
- Fn::Equals:
- ${commandType}
- RunPythonScript
- Fn::Equals:
- ${commandType}
- RunPerlScript
Value: /root
- Condition:
Fn::Or:
- Fn::Equals:
- ${commandType}
- RunBatScript
- Fn::Equals:
- ${commandType}
- RunPowerShellScript
Value: C:\\Windows\\System32
timeout:
Label:
en: Timeout (s)
zh-cn: 超时时间(秒)
Type: Number
Default: 600
enableParameter:
Label:
en: EnableParameter
zh-cn: 命令中是否包含加密参数或自定义参数
Type: Boolean
Default: false
username:
Description:
en: The username that is used to run the command on the ECS instance, length must not exceed 255 characters. Linux system ECS instance, the default is root. Windows system ECS instance, the default is System. Please ensure you input the correct username. <a href="https://www.alibabacloud.com/help/doc-detail/203771.html" target="_blank">See more</a>
zh-cn: 在ECS实例中执行命令的用户名称,长度不得超过255个字符。Linux系统的实例,默认以root用户执行命令。Windows系统的实例,默认以System用户执行命令。请确保您输入的用户名是正确的。<a href="https://www.alibabacloud.com/help/doc-detail/203771.html" target="_blank">了解更多</a>
Label:
en: Username
zh-cn: 执行命令的用户名称
Type: String
Default: ''
windowsPasswordName:
Label:
en: WindowsPasswordName
zh-cn: 在Windows实例中执行命令的用户的密码名称
Type: String
Default: ''
AssociationProperty: ALIYUN::OOS::SecretParameter::Value
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Or:
- Fn::Equals:
- ${commandType}
- RunBatScript
- Fn::Equals:
- ${commandType}
- RunPowerShellScript
rateControl:
Label:
en: RateControl
zh-cn: 任务执行的并发比率
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Description:
en: The RAM role to be assumed by OOS.
zh-cn: OOS扮演的RAM角色。
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: eventTrigger
Description:
en: Monitor the ECS instance TAG event.
zh-cn: 监控实例标签变化。
Action: ACS::EventTrigger
Properties:
Product: tag
Name:
- Tag:ChangeOnResource
Level:
- INFO
RegionId:
- '{{ regionId }}'
Content:
product:
- ecs
resourceType:
- instance
changedTagKeys:
- '{{ tagKey }}'
Outputs:
instanceId:
ValueSelector: .content.resourceId
Type: String
content:
ValueSelector: .content
Type: String
isAddTag:
ValueSelector: .content.tags|.{{tagKey}}=="{{tagValue}}"|tostring
Type: String
- Name: whetherTagSmc
Action: ACS::Choice
Properties:
DefaultTask: 'ACS::END'
Choices:
- When:
Fn::Equals:
- 'true'
- '{{ eventTrigger.isAddTag }}'
NextTask: runCommand
- Name: runCommand
Action: ACS::ECS::RunCommand
Description:
en: Execute cloud assistant command
zh-cn: 执行云助手命令
Properties:
regionId: '{{ regionId }}'
commandContent: '{{ commandContent }}'
instanceId: '{{ eventTrigger.instanceId }}'
commandType: '{{ commandType }}'
workingDir: '{{ workingDir }}'
timeout: '{{ timeout }}'
enableParameter: '{{ enableParameter }}'
username: '{{ username }}'
windowsPasswordName: '{{ windowsPasswordName }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Outputs:
tagEventContent:
Value: '{{ eventTrigger.content }}'
Type: String
instanceId:
Value: '{{ eventTrigger.instanceId }}'
Type: String
isTriggerExecute:
Value: '{{ eventTrigger.isAddTag }}'
Type: String
该文章对您有帮助吗?