Invoking FunctionGraph Functions¶
Following pages demonstrate how to call a FunctionGraph implemented in Node.js:
For details on function invocation, see
in FunctionGraph API reference.
Prerequisites¶
Environment Variables¶
Following environment variables need to be set:
Name |
Description |
|---|---|
OTC_SDK_PROJECTID |
Project ID |
OTC_SDK_REGION |
Region, e.g. “eu-de” |
OTC_SDK_AK |
Access Key (*) |
OTC_SDK_SK |
Secret Key |
OTC_USER_NAME |
User name (*) |
OTC_USER_PASSWORD |
User password |
OTC_DOMAIN_NAME |
Domain name |
OTC_IAM_ENDPOINT |
IAM Endpoint, e.g. https://iam.eu-de.otc.t-systems.com/v3 |
(* User needs to have permission to invoke FunctionGraph)
Deployed FunctionGraph Event Function¶
Use following settings to create the FunctionGraph event function using the FunctionGraph console:
Project : as specified in the environment variable
OTC_SDK_PROJECT_IDRegion: as specified in the environment variable
OTC_SDK_REGIONName:
nodejs-sample-invoke-functionRuntime:
Node.js 20.15Version:
latestApplication:
defaultFunction code: Use the following sample code for the function code.
// filename: index.js "use strict"; // Sample event structure class SampleEvent { constructor(event) { this._event = event || {}; } getKey() { return this._event.key || ""; } } // initializer name: index.initializer (optional) exports.initializer = function (context, callback) { const logger = context.getLogger(); logger.info("initializing :", context.getFunctionName()); callback(null, ""); }; // handler name: index.handler exports.handler = function (event, context, callback) { const logger = context.getLogger(); logger.info("Function name:", context.getFunctionName()); const sampleEvent = new SampleEvent(event); logger.info("Key value from event:", sampleEvent.getKey()); const output = { statusCode: 200, headers: { "Content-Type": "application/json", }, isBase64Encoded: false, body: JSON.stringify(event), }; callback(null, output); };
Handler name:
index.handler
Permissions¶
Make sure that your user has the necessary permissions to invoke the function.