-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
49 lines (43 loc) · 1.16 KB
/
handler.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
47
48
49
import json
import sample_pb2
import base64
import sample_pb2
def sample(event, context):
body = sample_pb2.Test()
body.test_id = 'test'
body.hoge = 'hogehoge'
response = {
'statusCode': 200,
'headers': {
"Access-Control-Allow-Origin": "*",
'Content-Type': 'application/x-protobuf'
},
'body': body.SerializeToString().decode('utf-8'),
'isBase64Encoded': True
}
return response
def get(event, context):
obj = sample_pb2.Test()
obj.ParseFromString(base64.b64decode(event['body']))
obj.test_id = 'bbb'
response = {
'statusCode': 200,
'headers': {
"Access-Control-Allow-Origin": "*",
'Content-Type': 'application/x-protobuf'
},
'body': obj.SerializeToString().decode('utf-8'),
'isBase64Encoded': True
}
return response
def multi(event, context):
response = {
'statusCode': 200,
'headers': {
"Access-Control-Allow-Origin": "*",
'Content-Type': 'application/x-protobuf'
},
'body': "",
'isBase64Encoded': True
}
return response