-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathfunc.py
32 lines (28 loc) · 1.04 KB
/
func.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
#
# oci-invoke-function-python version 1.0.
#
# Copyright (c) 2020 Oracle, Inc.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
#
import io
import json
import oci
from fdk import response
def handler(ctx, data: io.BytesIO=None):
try:
body = json.loads(data.getvalue())
function_endpoint = body.get("function_endpoint")
function_ocid = body.get("function_ocid")
function_body = body.get("function_body")
except (Exception) as ex:
print('ERROR: Missing key in payload', ex, flush=True)
raise
signer = oci.auth.signers.get_resource_principals_signer()
client = oci.functions.FunctionsInvokeClient(config={}, signer=signer, service_endpoint=function_endpoint)
resp = client.invoke_function(function_id=function_ocid, invoke_function_body=function_body)
print(resp.data.text, flush=True)
return response.Response(
ctx,
response_data=resp.data.text,
headers={"Content-Type": "application/json"}
)