forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload-to-oss-with-server-signature.yml
380 lines (378 loc) · 9.44 KB
/
upload-to-oss-with-server-signature.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 从服务器获取签名信息并上传数据到OSS。
en: Obtain signature information from the server and upload data to OSS.
Parameters:
CommonName:
Type: String
Default: oss-server-sign
BucketName:
AssociationPropertyMetadata:
Length: 6
Prefix: test-bucketname-
CharacterClasses:
- Class: lowercase
min: 1
Description:
zh-cn: Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。
en: Bucket names must be globally unique within the scope of OSS. The length is 3~63 characters. Must start and end with a lowercase English letter or number, and can contain lowercase English letters, numbers, and dashes (-).
Label:
zh-cn: 新建存储空间名称
en: NewBucketName
AllowedPattern: ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$
AssociationProperty: AutoCompleteInput
Type: String
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
AutoSelectFirst: true
Label:
en: Availability Zone
zh-cn: 可用区
InstanceType:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 实例规格
Password:
NoEcho: true
Type: String
Description:
en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
Label:
en: ECS Instance Password
zh-cn: ECS实例密码
ConstraintDescription:
en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
AssociationProperty: ALIYUN::ECS::Instance::Password
Outputs:
Console.Bucket:
Label:
zh-cn: Bucket
en: Bucket
Description:
zh-cn: 文件上传到的bucket控制台页面。可访问该链接查看上传情况。
en: Bucket console page, view upload status.
Value:
Fn::Sub:
- https://oss.console.aliyun.com/bucket/oss-${Region}/${BucketName}
- Region:
Ref: ALIYUN::Region
BucketName:
Ref: BucketName
Console.OssClientAddress:
Label:
en: OSS Client Address
zh-cn: 客户端地址
Description:
zh-cn: 客户端地址,使用此地址可直接体验文件上传。
en: Client address, use this address to directly experience file upload.
Value:
Fn::Sub:
- http://${ServerAddress}:3001/index.html
- ServerAddress:
Fn::Select:
- 0
- Fn::GetAtt:
- InstanceGroup
- PublicIps
Resources:
AccessKey:
Type: ALIYUN::RAM::AccessKey
Properties:
UserName:
Ref: User
InstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_x64_20g_alibase_20240528.vhd
InstanceName:
Fn::Sub: ${CommonName}-ecs
InstanceType:
Ref: InstanceType
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
MaxAmount: 1
InternetMaxBandwidthOut: 5
Password:
Ref: Password
Bucket:
Type: ALIYUN::OSS::Bucket
Properties:
BucketName:
Ref: BucketName
CORSConfiguration:
CORSRule:
- AllowedHeader:
- '*'
AllowedOrigin:
- '*'
AllowedMethod:
- POST
DeletionForce: true
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 3001/3001
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
Role:
Type: ALIYUN::RAM::Role
Properties:
RoleName:
Fn::Sub: ram-oss-test-create-by-${ALIYUN::StackId}
Policies:
- PolicyName:
Fn::Sub: policy-create-by-${ALIYUN::StackId}
PolicyDocument:
Version: '1'
Statement:
- Action:
- oss:PutObject
Resource:
- Fn::Sub: acs:oss:*:*:${Bucket.Name}/*
Effect: Allow
AssumeRolePolicyDocument:
Version: '1'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
RAM:
- Fn::Sub: acs:ram::${ALIYUN::TenantId}:root
User:
Type: ALIYUN::RAM::User
Properties:
UserName:
Fn::Sub: user-create-by-${ALIYUN::StackId}
PolicyAttachments:
System:
- AliyunSTSAssumeRoleAccess
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
ZoneId:
Ref: ZoneId
ServerCommand:
Type: ALIYUN::ECS::RunCommand
Properties:
CommandContent:
Fn::Sub:
- |
#!/bin/bash
yum -y install unzip
yum install -y npm
wget -O server-signed-direct-upload.zip 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20240626/xfnqmy/server-signed-direct-upload.zip'
unzip -o server-signed-direct-upload.zip
rm -rf server-signed-direct-upload.zip
cat > /root/server-signed-direct-upload/node-html-post-object/server/config.js << EOF
module.exports = {
accessKeyId: "${AccessKey.AccessKeyId}",
accessKeySecret: "${AccessKey.AccessKeySecret}",
region: "oss-${ALIYUN::Region}",
bucket: "${Bucket.Name}",
roleArn: "${Role.Arn}",
};
EOF
sed -i 's/127.0.0.1/${ServerAddress}/g' /root/server-signed-direct-upload/node-html-post-object/index.html
cd /root/server-signed-direct-upload/node-html-post-object/
source /root/.bashrc
npm config set registry https://registry.npmmirror.com
npm install
nohup node server/index.js > output.log 2>&1 &
- ServerAddress:
Fn::Select:
- 0
- Fn::GetAtt:
- InstanceGroup
- PublicIps
Type: RunShellScript
Sync: true
InstanceIds:
Fn::GetAtt:
- InstanceGroup
- InstanceIds
Timeout: 3600
DependsOn:
- SecurityGroup
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- BucketName
- ZoneId
- InstanceType
- Password
TemplateTags:
- acs:document-help:oss:服务端签名后直传
ALIYUN::ROS::Composer:
'14533323':
Rect:
- 680
- 540
- 40
- 100
- 1
- 0
ResT: Composer::ROSParameter::AlibabaCloud
8c27d9f6:
Parent: '14533323'
Rect:
- 640
- 470
- 60
- 150
- 2
- 0
ResT: Composer::ROSParameter::Region
89ef2077:
Res:
- AccessKey
Parent: 8c27d9f6
Rect:
- 40
- 40
- 282
- 560
- 3
- 0
762d04a9:
Res:
- Bucket
Parent: 8c27d9f6
Rect:
- 40
- 40
- 510
- 560
- 3
- 0
267adc41:
Res:
- Role
Parent: 8c27d9f6
Rect:
- 40
- 40
- 180
- 560
- 3
- 0
6a2c1602:
Res:
- User
Parent: 8c27d9f6
Rect:
- 40
- 40
- 384
- 560
- 3
- 0
efd8b40a:
Res:
- Vpc
Parent: 8c27d9f6
Rect:
- 536
- 340
- 84
- 200
- 3
- 0
e81206b5:
Res:
- ServerCommand
Parent: efd8b40a
Rect:
- 40
- 40
- 100
- 380
- 4
- 0
882ad181:
Res:
- ZoneId
Parent: efd8b40a
Rect:
- 440
- 270
- 160
- 250
- 4
- 0
ResT: Composer::ROSParameter::Zone
e12827c5:
Res:
- VSwitch
Parent: 882ad181
Rect:
- 400
- 200
- 180
- 300
- 5
- 0
e04839d8:
Parent: 8c27d9f6
Edge:
- 89ef2077
- 6a2c1602
Line: 0:0:0:gray:0
3dd2b471:
Parent: efd8b40a
Edge:
- e81206b5
- f5cd84a9
Line: 0:0:0:gray:0
276ccee9:
Res:
- SecurityGroup
Parent: efd8b40a
Rect:
- 213
- 102
- 246
- 348
- 12
- 0
f5cd84a9:
Res:
- InstanceGroup
Parent: e12827c5
Rect:
- 40
- 40
- 332
- 380
- 13
- 0
Layer:
- 276ccee9