forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obtain-signature-information-from-the-server-and-upload-data-to-oss.yml
295 lines (293 loc) · 9.23 KB
/
obtain-signature-information-from-the-server-and-upload-data-to-oss.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Obtain signature information from the server and upload data to OSS.
zh-cn: 从服务器获取签名信息并上传数据到OSS。
Parameters:
BucketName:
Type: String
Label:
en: NewBucketName
zh-cn: 新建存储空间名称
Description:
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 (-).
zh-cn: Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。
AllowedPattern: ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$
ZoneId:
Type: String
Label:
en: Zone ID
zh-cn: 可用区ID
Description:
en: The available zone ID, you should confirm the zone support ECS、VPC、VSwitch
or not.
zh-cn: 可用区ID,需确认所选可用区下是否支持ECS、VPC、VSwitch等资源。
AssociationProperty: ALIYUN::VPC::Zone::ZoneId
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${InstanceType}
Password:
Type: String
Label:
en: Login Password
zh-cn: 实例密码
Description:
en: |-
The password must be 8 to 32 characters in length. <br>
It must consist three of the the following character types: uppercase letters, lowercase letters, digits, and special characters. <br>
Special characters include <span style="background:#E7E9EB;"><b>()`~!@#$%^&*_-+=|{}[]:;'<>,.?/</b></span>.<br>
zh-cn: 长度为8-30位,需包含大写字母、小写字母、特殊符号和数字中的三个,允许的特殊字符包括<span style="background:#E7E9EB;"><b>()`~!@#$%^&*_-+=|{}[]:;'<>,.?/</b></span>。
Default: null
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
Bucket:
Type: ALIYUN::OSS::Bucket
Properties:
BucketName:
Ref: BucketName
DeletionForce: true
CORSConfiguration:
CORSRule:
- AllowedHeader:
- '*'
AllowedMethod:
- POST
AllowedOrigin:
- '*'
InstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId: centos_7
InstanceType:
Ref: InstanceType
SystemDiskCategory:
Ref: SystemDiskCategory
Password:
Ref: Password
IoOptimized: optimized
MaxAmount: 1
AllocatePublicIP: false
Eip:
Type: ALIYUN::VPC::EIP
Properties:
Name: create_by_document
InternetChargeType: PayByTraffic
Bandwidth: 5
EipAssociation:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Fn::Select:
- 0
- Fn::GetAtt:
- InstanceGroup
- InstanceIds
AllocationId:
Fn::GetAtt:
- Eip
- AllocationId
SecurityGroupIngress_22:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 22/22
SecurityGroupIngress_80:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 80/80
SecurityGroupIngress_443:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 443/443
SecurityGroupIngress_8080:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 8080/8080
ServerCommand:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Fn::GetAtt:
- InstanceGroup
- InstanceIds
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
yum -y install unzip python3 nginx
wget -O aliyun-oss-appserver-python-master.zip 'https://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/97721/cn_zh/1545016122500/aliyun-oss-appserver-python-master.zip?file=aliyun-oss-appserver-python-master.zip'
unzip -o aliyun-oss-appserver-python-master.zip && mv aliyun-oss-appserver-python-preview_1.0.1-2f62c60e04b4ff204320adf47ded9d83fd79e826/* .
rm -rf aliyun-oss-appserver-python-preview_1.0.1-2f62c60e04b4ff204320adf47ded9d83fd79e826
sed -i 's/<yourAccessKeyId>/${AccessKey.AccessKeyId}/g' appserver.py
sed -i 's/<yourAccessKeySecret>/${AccessKey.AccessKeySecret}/g' appserver.py
sed -i 's/bucket-name.oss-cn-hangzhou.aliyuncs.com/${BucketName}.oss-${ALIYUN::Region}.aliyuncs.com/g' appserver.py
sed -i 's/expire_syncpoint = 1612345678/# expire_syncpoint = 1612345678/g' appserver.py
touch runserver.sh && cat > runserver.sh << EOF
pip3 uninstall crypto
pip3 uninstall pycrypto
pip3 install pycryptodome
nohup python3 appserver.py &
EOF
bash runserver.sh
mkdir -p /var/www/html && cd /var/www/html
wget -O aliyun-oss-appserver-js-master.zip 'https://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/86983/APP_zh/1537971352825/aliyun-oss-appserver-js-master.zip?file=aliyun-oss-appserver-js-master.zip'
unzip aliyun-oss-appserver-js-master.zip
cd aliyun-oss-appserver-js-master/
sed -i 's|88.88.88.88:8888|${Eip.EipAddress}:8080|g' upload.js
sed -i "s|'callback' : callbackbody|//'callback' : callbackbody|g" upload.js
touch /etc/nginx/conf.d/oss-client.conf
cat > /etc/nginx/conf.d/oss-client.conf << EOF
server {
listen 80 default_server;
server_name _;
location / {
root /var/www/html/aliyun-oss-appserver-js-master;
index index.html;
}
}
EOF
systemctl start nginx
DependsOn:
- SecurityGroupIngress_22
- SecurityGroupIngress_443
- SecurityGroupIngress_80
- SecurityGroupIngress_8080
User:
Type: ALIYUN::RAM::User
Properties:
UserName:
Fn::Sub: create_by_document-${ALIYUN::StackId}
PolicyAttachments:
System:
- AliyunOSSFullAccess
AccessKey:
Type: ALIYUN::RAM::AccessKey
Properties:
UserName:
Ref: User
Outputs:
OssClientAddress:
Description:
en: Client address, use this address to directly experience file upload.
zh-cn: 客户端地址,使用此地址可直接体验文件上传。
Value:
Fn::Sub: http://${Eip.EipAddress}
ApplicationServerAddress:
Description:
en: Application server address, configure this address in the local client source
code to experience file upload locally.
zh-cn: 应用服务端地址,在本地客户端源码中配置此地址可在本地体验文件上传。
Value:
Fn::Sub: ${Eip.EipAddress}:8080
EcsInstanceId:
Description:
en: Ecs instance id.
zh-cn: ECS实例id。
Value:
Fn::Select:
- 0
- Fn::GetAtt:
- InstanceGroup
- InstanceIds
EipAllocationId:
Description:
en: Eip allocation id.
zh-cn: EIP实例id。
Value:
Fn::GetAtt:
- Eip
- AllocationId
OssBucketName:
Description:
en: Oss bucket name.
zh-cn: 存储空间名称。
Value:
Ref: Bucket
EcsLoginAddress:
Description:
en: Ecs login address.
zh-cn: ECS登陆地址。
Value:
Fn::Sub:
- https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs®ionId=${Region}&instanceId=${InstanceId}
- Region:
Ref: ALIYUN::Region
InstanceId:
Fn::Select:
- 0
- Fn::GetAtt:
- InstanceGroup
- InstanceIds
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- BucketName
- ZoneId
- InstanceType
- SystemDiskCategory
- Password
TemplateTags:
- acs:document-help:oss:服务端签名后直传