-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::ECS::CopyLinuxInstanceFileToOSS.json
137 lines (137 loc) · 3.93 KB
/
ACS::ECS::CopyLinuxInstanceFileToOSS.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::ECS::CopyLinuxInstanceFileToOSS",
"name-zh-cn": "复制ECS实例中的文件到OSS",
"en": "Copies the file from ECS instance to OSS by RunCommand",
"zh-cn": "通过执行命令复制Linux实例中的文件到OSS"
},
"Parameters": {
"regionId": {
"Description": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String",
"Default": "{{ ACS::RegionId }}"
},
"instanceId": {
"Description": {
"en": "The ID of ECS Instance",
"zh-cn": "ECS实例ID"
},
"Type": "String",
"MaxLength": 30,
"MinLength": 1
},
"instanceRole": {
"Description": {
"en": "The ramRole attached on the instance",
"zh-cn": "实例上挂载的RAM角色"
},
"Type": "String"
},
"srcUrl": {
"Description": {
"en": "Current directory of the file in linux instance",
"zh-cn": "文件在实例中的目录"
},
"Type": "String"
},
"destUrl": {
"Description": {
"en": "Target directory for file copy in OSS",
"zh-cn": "文件在OSS中存储的目录"
},
"Type": "String"
}
},
"Tasks": [
{
"Name": "checkInstanceReady",
"Action": "ACS::CheckFor",
"Description": {
"en": "Checks the ECS instance is in running status",
"zh-cn": "检查实例是否是running状态"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
},
"DesiredValues": [
"Running"
],
"PropertySelector": "Instances.Instance[].Status"
}
},
{
"Name": "checkInstanceRAMRoleReady",
"Action": "ACS::CheckFor",
"Description": {
"en": "Checks the instance RAMrole is available",
"zh-cn": "检查实例上挂载的RAM角色是否可用"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstanceRAMRole",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
],
"RamRoleName": "{{ instanceRole }}"
},
"DesiredValues": [
"{{ instanceRole }}"
],
"PropertySelector": "InstanceRamRoleSets.InstanceRamRoleSet[].RamRoleName"
}
},
{
"Name": "runCommand",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Runs command to copy file",
"zh-cn": "执行复制文件的命令"
},
"Properties": {
"regionId": "{{ regionId }}",
"commandContent": {
"Fn::Join": [
" ",
[
"if [ ! -d oos ];then mkdir /root/oos; fi;",
"cd /root/oos;",
"if [ ! -f \"/root/oos/ossutil64\" ];then wget https://oos-public-{{ACS::RegionId}}.oss-{{ ACS::RegionId }}-internal.aliyuncs.com/x64/ossutil64 && chmod 755 ossutil64; fi;",
"echo \"[Credentials]\" > oss.cfg;",
"echo \"languague=EN\" >> oss.cfg;",
"echo \"endpoint=https://oss-{{ ACS::RegionId }}-internal.aliyuncs.com\" >> oss.cfg;",
"echo \"[AkService]\" >> oss.cfg;",
"echo \"ecsAk=http://100.100.100.200/latest/meta-data/Ram/security-credentials/{{ instanceRole }}\" >> oss.cfg;",
"./ossutil64 --config-file oss.cfg cp {{ SrcUrl }} {{ DestUrl }}"
]
]
},
"instanceId": "{{ InstanceId }}",
"commandType": "RunShellScript"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
}
],
"Outputs": {
"result": {
"Type": "String",
"Value": "{{ runCommand.commandOutput }}"
}
}
}