-
Notifications
You must be signed in to change notification settings - Fork 0
/
d2hw_fg.py
46 lines (39 loc) · 1.41 KB
/
d2hw_fg.py
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
# coding: utf-8
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkfunctiongraph.v2.region.functiongraph_region import FunctionGraphRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkfunctiongraph.v2 import *
import base64
filename="script.zip"
with open(filename, 'rb') as fileObj:
image_data = fileObj.read()
base64_data = base64.b64encode(image_data)
if __name__ == "__main__":
import os
import notification
ak = os.environ['HW_AK']
sk = os.environ['HW_SK']
credentials = BasicCredentials(ak, sk) \
client = FunctionGraphClient.new_builder() \
.with_credentials(credentials) \
.with_region(FunctionGraphRegion.value_of("cn-east-3")) \
.build()
try:
request = UpdateFunctionCodeRequest()
request.function_urn = os.environ['HW_URN']
funcCodeFuncCode = FuncCode(
file=base64_data
)
request.body = UpdateFunctionCodeRequestBody(
func_code=funcCodeFuncCode,
code_filename="script.zip",
code_type="zip"
)
response = client.update_function_code(request)
print('部署成功')
except exceptions.ClientRequestException as e:
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)
notification.notify_QW_AM('部署失败', e.error_msg)