-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::ECS::UploadOssFile.yml
172 lines (171 loc) · 4.8 KB
/
ACS::ECS::UploadOssFile.yml
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
FormatVersion: OOS-2019-06-01
Description:
name-en: ACS::ECS::UploadOssFile
name-zh-cn: 上传OSS文件(ECS)
en: Upload OSS files
zh-cn: 上传OSS文件 (ECS)
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地域ID
AssociationProperty: ALIYUN::ECS::RegionId
Default: '{{ ACS::RegionId }}'
ossRegion:
Description:
en: The region id of OSS
zh-cn: OSS所在地域
Label:
en: OSS Region
zh-cn: OSS地域
Type: String
AssociationProperty: ALIYUN::ECS::RegionId
Default: '{{ ACS::RegionId }}'
bucketName:
Label:
en: BucketName
zh-cn: OSS bucket 名称
Type: String
AssociationProperty: ALIYUN::OSS::Bucket::BucketName
AssociationPropertyMetadata:
RegionId: ossRegion
objectName:
Label:
en: ObjectName
zh-cn: OSS object 名称
Description:
en: The full path of the file to be uploaded to OSS, including the file name, such as path_section_1/path_section_2/file_name.md
zh-cn: 文件上传到oss上的完整路径,末尾包含文件名,如 path_section_1/path_section_2/file_name.md
Type: String
validTime:
Label:
en: Valid time of OSS file (s)
zh-cn: OSS文件有效期(秒)
Type: Number
Default: 6000
instanceId:
Label:
en: ECSInstanceId
zh-cn: ECS实例ID
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
RegionId: regionId
fileToUpload:
Label:
en: File to upload
zh-cn: 待上传文件
Description:
en: Path of the file to be uploaded on the ecs
zh-cn: 待上传文件在ecs上的路径,如/root/your_file.zip (linux), C:\\Users\\Administrator\\your_file.zip (windows)
Type: String
uploadWaitingTime:
Label:
en: Waiting time for upload (s)
zh-cn: 上传等待时间(秒)
Type: Number
Default: 600
Tasks:
- Name: queryInstanceOSType
Action: 'ACS::ExecuteApi'
Description:
en: Queries ECS instance OS type
zh-cn: 获取ECS实例操作系统类型
Properties:
Service: ECS
API: DescribeInstances
Parameters:
RegionId: '{{ regionId }}'
InstanceIds:
- '{{ instanceId }}'
Outputs:
OSType:
Type: String
ValueSelector: 'Instances.Instance[].OSType'
- Name: generateUrl
Action: ACS::ExecuteAPI
Description:
en: Generate upload url
zh-cn: 生成上传链接
Properties:
Service: OSS
API: GenerateUrl
Method: PUT
URI: '{{ objectName }}'
Headers:
Content-MD5: ""
Content-Type: application/json
Parameters:
BucketName: '{{ bucketName }}'
RegionId: '{{ ossRegion }}'
Expires: '{{ validTime }}'
Internal:
Fn::If:
- Fn::Equals:
- '{{ ossRegion }}'
- '{{ regionId }}'
- 'true'
- 'false'
Body: ''
Outputs:
temporaryUrl:
Type: String
ValueSelector: .Url
- Name: uploadFile
Description:
en: Upload file to OSS
zh-cn: 上传文件到OSS
Action: ACS::ECS::RunCommand
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ instanceId }}'
timeout: '{{ uploadWaitingTime }}'
commandType:
Fn::If:
- Fn::Equals:
- '{{ queryInstanceOSType.OSType }}'
- 'linux'
- RunShellScript
- RunPowerShellScript
commandContent:
Fn::If:
- Fn::Equals:
- '{{ queryInstanceOSType.OSType }}'
- 'linux'
- |-
response=$(curl -X PUT -T "{{fileToUpload}}" -w "%{http_code}" -v "{{generateUrl.temporaryUrl}}")
# 检查响应
if [ "$response" -ne 200 ]; then
echo "Curl Failed."
exit 1
fi
- |-
$localFilePath = "{{fileToUpload}}"
$uploadUrl = "{{generateUrl.temporaryUrl}}"
$response = Invoke-WebRequest -Uri $uploadUrl -Method Put -InFile $localFilePath -UseBasicParsing -ErrorAction Stop
# 检查响应内容是否包含 "AccessDenied"
if ($response.StatusCode -ne 200) {
Write-Host "Invoke-WebRequest Failed."
exit 1
}
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- ossRegion
- bucketName
- objectName
- validTime
Label:
default:
zh-cn: Oss信息
en: Oss Info
- Parameters:
- regionId
- instanceId
- fileToUpload
Label:
default:
zh-cn: Ecs信息与上传路径
en: Ecs Info and Download Path