Calling FunctionGraph using API calls¶
Source for this sample can be found in: /samples-doc/invoke-fg.
For details on API calls, see:
Prerequisites¶
Environment Variables¶
See environment variables section in: Prerequisites
Deployed FunctionGraph Event Function¶
Method A: Deploy using console¶
Deploy the function manually as described in Prerequisites using the OpenTelekomCloud Console.
Method B: Deploy using API calls¶
Or deploy the function using the provided Go code using API calls.
cd samples-doc/invoke-fg/src
go test -run TestCreateFunction_UsernamePassword
this will create function with code and parameters from:
package invoke_fg
const functionApp = "default"
const functionName = "DefaultPython3_10_From_Go_SDK"
const functionVersion = "latest"
const appCode = `
# -*- coding:utf-8 -*-
import json
def handler (event, context):
return {
"statusCode": 200,
"isBase64Encoded": False,
"body": json.dumps(event),
"headers": {
"Content-Type": "application/json"
}
}
`
After testing, you can delete the function using:
cd samples-doc/invoke-fg/src
go test -run TestDeleteFunction_UsernamePassword
Call Functiongraph using Username and Password synchronously¶
Source for this sample can be found in: /samples-doc/invoke-fg/src/invokeSync_UsernamePassword.go.
As API calls require a token, this has to obtained by calling the IAM token endpoint with username and password first. (See Obtaining a User Token)
To run the sample, execute:
cd samples-doc/invoke-fg/src
go test -run TestInvokeSync_UsernamePassword
Call Functiongraph using AK/SK synchronously¶
Source for this sample can be found in: /samples-doc/invoke-fg/src/invokeSync_AKSK.go.
Using AK/SK authentication, no token retrieval is necessary, but the requests have to be signed with the AK/SK (or for temporal credentials with SecurityAccessKey/SecurityKey/SecurityToken).
For request signing the otc-api-sign-sdk-go can be used.
To run the sample, execute:
cd samples-doc/invoke-fg/src
go test -run TestInvokeSync_AKSK
Note
Don’t forget to clean up the deployed resources after testing.