diff --git a/README.md b/README.md
index 744b845..550d72c 100644
--- a/README.md
+++ b/README.md
@@ -2,15 +2,6 @@
Node.js libraries for FunctionGraph on T Cloud Public.
-> [!Note]
->
-> ###############################################
-> Work in progress....
-> !! SUBJECT TO CHANGE WITHOUT NOTICE !!
-> ###############################################
->
->
-
## Documentation
For documentation see: [otc-functiongraph-nodejs-runtime](https://opentelekomcloud-community.github.io/otc-functiongraph-nodejs-runtime/)
diff --git a/doc/doc-utils/README.md b/doc/doc-utils/README.md
index f0a1161..04071a0 100644
--- a/doc/doc-utils/README.md
+++ b/doc/doc-utils/README.md
@@ -14,12 +14,12 @@ Requires src-fg/index.js installed as FunctionGraph with:
- Function type: event-function from scratch
- Name: ``getNodeJSRuntimeInfo``
- Runtime: nodejs20.15
-- Project: OTC_SDK_PROJECT_ID
+- Project: OTC_SDK_PROJECTID
- Region: OTC_SDK_REGION
To run, following environment variables must be set on client side:
-- Project: OTC_SDK_PROJECT_ID
+- Project: OTC_SDK_PROJECTID
- Region: OTC_SDK_REGION
- Access Key: OTC_SDK_AK
- Secret key: OTC_SDK_SK
diff --git a/doc/doc-utils/src/createLibraryDocs.js b/doc/doc-utils/src/createLibraryDocs.js
index 23a5b1c..c9dbaec 100644
--- a/doc/doc-utils/src/createLibraryDocs.js
+++ b/doc/doc-utils/src/createLibraryDocs.js
@@ -21,7 +21,7 @@
*
* Following environment variables are required for this script:
* - OTC_SDK_REGION: The region where your FunctionGraph service is hosted (default is "eu-de").
- * - OTC_SDK_PROJECT_ID: Your 'T Cloud Public' project ID.
+ * - OTC_SDK_PROJECTID: Your 'T Cloud Public' project ID.
* - OTC_SDK_AK: Your 'T Cloud Public' Access Key.
* - OTC_SDK_SK: Your 'T Cloud Public' Secret Key.
*******************************************************************/
@@ -36,7 +36,7 @@ const { type } = require("os");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
-const projectId = process.env.OTC_SDK_PROJECT_ID;
+const projectId = process.env.OTC_SDK_PROJECTID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
diff --git a/doc/doc-utils/src/fg/index.js b/doc/doc-utils/src/fg/index.js
index aedd467..8e08437 100644
--- a/doc/doc-utils/src/fg/index.js
+++ b/doc/doc-utils/src/fg/index.js
@@ -5,7 +5,7 @@
* - Function type: event-function from scratch
* - Name: getNodeJSRuntimeInfo
* - Runtime: nodejs20.15
- * - Project: OTC_SDK_PROJECT_ID
+ * - Project: OTC_SDK_PROJECTID
* - Region: OTC_SDK_REGION
*************************************************************************/
const fs = require("fs");
diff --git a/doc/doc-utils/src/getPublicFGDependencies.js b/doc/doc-utils/src/getPublicFGDependencies.js
index a0bd7dd..6170fa0 100644
--- a/doc/doc-utils/src/getPublicFGDependencies.js
+++ b/doc/doc-utils/src/getPublicFGDependencies.js
@@ -20,7 +20,7 @@
*
* Following environment variables are required for this script:
* - OTC_SDK_REGION: The region where your FunctionGraph service is hosted (default is "eu-de").
- * - OTC_SDK_PROJECT_ID: Your 'T Cloud Public' project ID.
+ * - OTC_SDK_PROJECTID: Your 'T Cloud Public' project ID.
* - OTC_SDK_AK: Your 'T Cloud Public' Access Key.
* - OTC_SDK_SK: Your 'T Cloud Public' Secret Key.
*
@@ -33,7 +33,7 @@ const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
-const projectId = process.env.OTC_SDK_PROJECT_ID;
+const projectId = process.env.OTC_SDK_PROJECTID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
diff --git a/doc/source/devguide/_index.rst b/doc/source/devguide/_index.rst
index 07cc92e..f9b3d32 100644
--- a/doc/source/devguide/_index.rst
+++ b/doc/source/devguide/_index.rst
@@ -80,14 +80,26 @@ for building functions from scratch:
- Node.js16.17
- /opt/function/runtime/nodejs16.17/rtsp/nodejs/bin/node
- * - NodeJS 18.20
- - Node.js18.20
- - /opt/function/runtime/nodejs18.20/rtsp/nodejs/bin/node
+ * - NodeJS 18.15
+ - Node.js18.15
+ - /opt/function/runtime/nodejs18.15/rtsp/nodejs/bin/node
* - NodeJS 20.15
- Node.js20.15
- /opt/function/runtime/nodejs20.15/rtsp/nodejs/bin/node
+For supported runtimes see also: :otc_fg_umn:`Runtimes ` in User Guide.
+
+.. note::
+
+ If you need newer Node.js runtimes, use custom container images
+ to build your functions.
+
+ For more information, see
+
+ - :ref:`devguide_event_function_container_index`
+ - :ref:`devguide_http_function_container_index`
+
Bundled third-party components integrated in the Node.js runtime
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/doc/source/devguide/bestpractices/coldstart.rst b/doc/source/devguide/bestpractices/coldstart.rst
index e7065c5..ae02d28 100644
--- a/doc/source/devguide/bestpractices/coldstart.rst
+++ b/doc/source/devguide/bestpractices/coldstart.rst
@@ -78,4 +78,4 @@ two methods:
* Use reserved instances to avoid cold starts. For detailed usage instructions, please refer to
the :docs_otc:`Reserved Instance Management `
- section .
\ No newline at end of file
+ section.
\ No newline at end of file
diff --git a/doc/source/devguide/bestpractices/packaging_node.rst b/doc/source/devguide/bestpractices/packaging_node.rst
index 1af2fe2..38cb3cb 100644
--- a/doc/source/devguide/bestpractices/packaging_node.rst
+++ b/doc/source/devguide/bestpractices/packaging_node.rst
@@ -40,17 +40,17 @@ Adapt your package.json file to include the necessary scripts and dependencies f
},
"dependencies": {
- // add here dependencies of your function
+ // add dependencies of your function here
},
"devDependencies": {
- // add here dev dependencies of your function
+ // add dev dependencies of your function here
},
"bundleDependencies": [
- // add here bundle dependencies if needed
+ // add bundle dependencies if needed here
// these are dependencies from "dependencies" that will be included in the zip package
],
"files": [
- // add here files to be included in the bundle, e.g.:
+ // add files to be included in the bundle here, e.g.:
"*.js",
"src/**/*",
"bootstrap" // for http functions
diff --git a/doc/source/devguide/bestpractices/performance.rst b/doc/source/devguide/bestpractices/performance.rst
index b8a76ae..4e7cf0e 100644
--- a/doc/source/devguide/bestpractices/performance.rst
+++ b/doc/source/devguide/bestpractices/performance.rst
@@ -41,7 +41,7 @@ Performance testing of functions is a crucial step in ensuring the selection of
During function load testing, platform-provided metrics, logs, call chains, and other tools can be
used to further analyze function performance data, thereby optimizing function configuration selection.
For details on specific observable metrics, please refer to the
-:docs_otc:`Function Monitoring Overview `.
+:docs_otc:`Function Monitoring Overview `.
Streamlined code and image slimming
---------------------------------------------------------------
@@ -65,9 +65,9 @@ Allocating more memory to functions can improve CPU performance, thereby speedin
startup and execution. You can evaluate the impact of different memory configurations on function
performance by monitoring function execution time, and then choose the optimal memory size.
-For detailed monitoring information, please refer to the monitoring metric description.
+For detailed monitoring information, please refer to the :docs_otc:`monitoring metrics description `.
For steps on configuring memory, please refer to the
-:docs_otc:`configuration function information `.
+:docs_otc:`function configuration information `.
Use common dependency packages to speed up
---------------------------------------------------------------
diff --git a/doc/source/devguide/bestpractices/security.rst b/doc/source/devguide/bestpractices/security.rst
index ce26261..3d0ea3a 100644
--- a/doc/source/devguide/bestpractices/security.rst
+++ b/doc/source/devguide/bestpractices/security.rst
@@ -72,7 +72,7 @@ Configure a VPC for the function to prevent external attacks
When a user function needs to access resources within a Virtual Private
Cloud (VPC), such as RDS, it is recommended to
-:docs_otc:`configure a VPC `
+:docs_otc:`configure a VPC `
for the function to ensure that communication between the function and other cloud services takes
place in an isolated network environment.
diff --git a/doc/source/devguide/deployment/terraform/_index.rst b/doc/source/devguide/deployment/terraform/_index.rst
index a0aed6f..2a9652b 100644
--- a/doc/source/devguide/deployment/terraform/_index.rst
+++ b/doc/source/devguide/deployment/terraform/_index.rst
@@ -28,7 +28,7 @@ see following:
- :ref:`Deploy FunctionGraph Event Function from ZIP`
- :ref:`Deploy FunctionGraph Event Function from OBS`
-For more complex deployment scenarios,see the "terraform" folder
+For more complex deployment scenarios, see the "terraform" folder
in the other sample files, e.g.:
- Deploy FunctionGraph as container in: :github_repo_master:`container-event-express `
diff --git a/doc/source/devguide/deployment/terraform/deploy_from_obs/_index.rst b/doc/source/devguide/deployment/terraform/deploy_from_obs/_index.rst
index 9d88e18..0150205 100644
--- a/doc/source/devguide/deployment/terraform/deploy_from_obs/_index.rst
+++ b/doc/source/devguide/deployment/terraform/deploy_from_obs/_index.rst
@@ -20,7 +20,7 @@ Prerequisites
- running on Linux / Windows Subsystem for Linux (WSL)
- make installed
- curl installed
-- Terraform installed and configured, see :ref:`terraform_setup`.
+- Terraform installed and configured, see :ref:`Terraform Setup`.
What will be deployed
----------------------------------
@@ -78,18 +78,7 @@ The file ``provider.tf`` defines the provider configuration for this sample:
You might need to adapt the provider configuration to your needs,
especially the provider version and backend configuration for terraform state.
-For variables used in provider.tf, see :ref:`terraform_setup`.
-
-.. note::
- Currently the opentelekomcloud provider does not update FunctionGraph
- function code after the code is uploaded to OBS,
- so in this sample we also use the
- `devops-rob/terracurl provider `_
- to update the function code using an API request to update FunctionGraph.
- To use curl and the terracurl provider, the variable OTC_USER_NAME and OTC_PASSWORD
- with your OTC credentials must be defined as environment variables.
-
- See : `Feature request #3360 for opentelekomcloud provider `_.
+For variables used in provider.tf, see :ref:`Terraform Setup`.
variables.tf
@@ -112,9 +101,6 @@ The file ``code_from_obs_bucket.tf`` defines the obs bucket and obs bucket obje
:caption: code_from_obs_bucket.tf
:tab-width: 2
-Additional to uploading the function code to OBS,
-this will also call FunctionGraph API to update the function code after code changes.
-
function.tf
^^^^^^^^^^^^
@@ -129,8 +115,6 @@ The relevant part for deploying function code from zip file is:
.. code-block:: hcl
- depends_on = [opentelekomcloud_obs_bucket_object.code_object]
-
###### relevant part for deploy function code from obs file ######
code_type = "obs"
code_url = format("https://%s/%s/%s",
@@ -138,6 +122,9 @@ The relevant part for deploying function code from zip file is:
"code",
basename(var.zip_file_name)
)
+
+ # on change of the code object etag (hash) new code version will be deployed.
+ source_code_hash = opentelekomcloud_obs_bucket_object.code_object.etag
###### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ######
@@ -217,7 +204,7 @@ Adapt the **BACKEND_CONFIG_*** variables in the Makefile
- endpoints={s3=\"https://obs.eu-de.otc.t-systems.com\"}
-Adaptions in variables.tfv
+Adaptions in variables.tf
""""""""""""""""""""""""""""""
Adapt the variables in the ``variables.tf``
@@ -269,9 +256,25 @@ FunctionGraph:
Testing the deployed function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+For testing the deployed function, you will need to set the following
+environment variables. These are used in "tokenFromUsername.sh" script to get Token
+for Token-based authentication when calling FunctionGraph API.
+
+.. list-table:: Environment Variables
+ :widths: 25 25
+ :header-rows: 1
+
+ * - Name
+ - Description
+ * - OTC_USER_NAME
+ - User name
+ * - OTC_USER_PASSWORD
+ - User password
+
Synchronous invocation
"""""""""""""""""""""""""""""
After the deployment is done, you can test the deployed function with the following command:
+
.. code-block:: bash
make test_deployed_sync
diff --git a/doc/source/devguide/deployment/terraform/deploy_from_zip/_index.rst b/doc/source/devguide/deployment/terraform/deploy_from_zip/_index.rst
index 493db9e..1cefc81 100644
--- a/doc/source/devguide/deployment/terraform/deploy_from_zip/_index.rst
+++ b/doc/source/devguide/deployment/terraform/deploy_from_zip/_index.rst
@@ -20,7 +20,7 @@ Prerequisites
- running on Linux / Windows Subsystem for Linux (WSL)
- make installed
- curl installed
-- Terraform/OpenTofu installed and Terraform/OpenTofu configured, see :ref:`terraform_setup`.
+- Terraform/OpenTofu installed and Terraform/OpenTofu configured, see :ref:`Terraform Setup`.
What will be deployed
----------------------------------
@@ -76,7 +76,7 @@ The file ``provider.tf`` defines the provider configuration for this sample:
You might need to adapt the provider configuration to your needs,
especially the provider version and backend configuration for terraform state.
-For variables used in provider.tf, see :ref:`terraform_setup`.
+For variables used in provider.tf, see :ref:`Terraform Setup`.
variables.tf
@@ -240,6 +240,7 @@ Testing the deployed function
Synchronous invocation
"""""""""""""""""""""""""""""
After the deployment is done, you can test the deployed function with the following command:
+
.. code-block:: bash
make test_deployed_sync
diff --git a/doc/source/devguide/deployment/terraform/setuptf.rst b/doc/source/devguide/deployment/terraform/setuptf.rst
index b477257..e172124 100644
--- a/doc/source/devguide/deployment/terraform/setuptf.rst
+++ b/doc/source/devguide/deployment/terraform/setuptf.rst
@@ -143,5 +143,7 @@ See: `Terraform State
s3cmd \
--access_key=${OTC_SDK_AK} \
--secret_key=${OTC_SDK_SK} \
+ --host=https://obs.eu-de.otc.t-systems.com \
+ --host-bucket="%(bucket)s.obs.eu-de.otc.t-systems.com" \
--no-ssl \
mb s3://
diff --git a/doc/source/devguide/event_function/_index.rst b/doc/source/devguide/event_function/_index.rst
index 3d8e426..9c3c589 100644
--- a/doc/source/devguide/event_function/_index.rst
+++ b/doc/source/devguide/event_function/_index.rst
@@ -11,7 +11,7 @@ FunctionGraph Event Functions
Event functions can be configured with event triggers and integrate
a variety of products (such as object storage service OBS,
-distributed messaging service RabbitMQ version, cloud log service LTS, etc.).
+distributed messaging service DMS, cloud log service LTS, etc.).
Types of Event Functions
------------------------------------
diff --git a/doc/source/devguide/event_function/container/creating.rst b/doc/source/devguide/event_function/container/creating.rst
index 31e46f2..5a3de42 100644
--- a/doc/source/devguide/event_function/container/creating.rst
+++ b/doc/source/devguide/event_function/container/creating.rst
@@ -1,8 +1,12 @@
.. _creating_an_event_function_using_a_container_image_built:
-Creating an Event Function Using a Container Image Built with Node.js
+Creating an Event Function using a container image built with Node.js
======================================================================
+.. toctree::
+ :maxdepth: 1
+ :hidden:
+
For general details about how to use a container image
to create and execute an event function,
see :otc_fg_umn:`Creating an Event Function Using a Container Image and executing the Function `.
@@ -31,6 +35,8 @@ Step 1: Create the Project
In this example we use the `express` framework to create an HTTP server.
+For full example, see: :github_repo_master:`container-event-express ` sample in the GitHub repository.
+
For details about express, see `Express - Node.js web application framework `_.
Initialize the project with npm:
@@ -40,6 +46,10 @@ First, create a project directory and initialize it with npm:
.. code-block:: bash
+ # this sample uses Node.js 25.7.0, you can use nvm to
+ # switch to this version using:
+ nvm use 25.7.0
+
mkdir -p my-event-function/src
cd my-event-function
npm init -y
@@ -62,21 +72,53 @@ For example:
.. literalinclude:: ../../../../../samples-doc/container-event-express/package.json
:language: json
+ :caption: :github_repo_master:`package.json `
-Implement the function
+Implementing the function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Next, create the entry file for the function, for example, ``src/index.js``:
+Next, create two files:
+
+- src/index.js for the function entry and
+- src/loggingmiddleware.js for the logging middleware.
+
+File: src/index.js
+""""""""""""""""""""""""""""""""""""""""
+This is the main entry file for the function:
.. literalinclude:: ../../../../../samples-doc/container-event-express/src/index.js
:language: javascript
+ :caption: :github_repo_master:`src/index.js `
In this code, we create an express application that listens on port 8000.
We define two POST endpoints:
-* **/invoke** for function execution and
-* **/init** for function initialization.
+
+- **/invoke** for function execution and
+- **/init** for function initialization.
+
+File: src/loggingmiddleware.js
+""""""""""""""""""""""""""""""""""""""""
+The default logger implementation does not include request id and timestamp in the logs,
+which makes it difficult to correlate logs with specific requests.
+
+To add request id and timestamp to the logs, we use a middleware that runs for every request.
+
+.. literalinclude:: ../../../../../samples-doc/container-event-express/src/loggingmiddleware.js
+ :language: javascript
+ :caption: :github_repo_master:`src/loggingmiddleware.js `
+
+This middleware is activated in the index.js file with following lines of code:
+
+.. code-block:: javascript
+
+ const { loggingMiddleware } = require("./loggingmiddleware");
+
+ ...
+ app.use(loggingMiddleware);
+ ...
+
Run and Test server from code
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -114,7 +156,7 @@ create a **Makefile** in the project root folder:
.. literalinclude:: ../../../../../samples-doc/container-event-express/Makefile
:language: make
- :caption: Makefile
+ :caption: :github_repo_master:`Makefile `
:tab-width: 2
Create a Dockerfile
@@ -146,11 +188,13 @@ Following example uses an Alpine base image with Node.js installed.
.. literalinclude:: ../../../../../samples-doc/container-event-express/Dockerfile
:language: docker
+ :caption: :github_repo_master:`Dockerfile `
Create following entrypoint script to start the server in the container:
.. literalinclude:: ../../../../../samples-doc/container-event-express/entrypoint.sh
:language: shell
+ :caption: :github_repo_master:`entrypoint.sh `
Build and verify the image locally
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -312,17 +356,17 @@ Upload the image to SWR either using **shell commands** or the Makefile target *
.. code-block:: shell
:caption: **1. Login to SWR**
- docker login -u $(OTC_SDK_PROJECTNAME)@$(OTC_SDK_AK) -p $(OTC_SWR_LOGIN_KEY) ${OTC_SWR_ENDPOINT}
+ docker login -u ${OTC_SDK_PROJECTNAME}@${OTC_SDK_AK} -p ${OTC_SWR_LOGIN_KEY} ${OTC_SWR_ENDPOINT}
.. code-block:: shell
:caption: **2. Tag the image**
- docker tag $(IMAGE_NAME):latest ${OTC_SWR_ENDPOINT}/$(OTC_SWR_ORGANIZATION)/$(IMAGE_NAME):latest
+ docker tag ${IMAGE_NAME}:latest ${OTC_SWR_ENDPOINT}/${OTC_SWR_ORGANIZATION}/${IMAGE_NAME}:latest
.. code-block:: shell
:caption: **3. Push the image to SWR**
- docker push ${OTC_SWR_ENDPOINT}/$(OTC_SWR_ORGANIZATION)/$(IMAGE_NAME):latest
+ docker push ${OTC_SWR_ENDPOINT}/${OTC_SWR_ORGANIZATION}/${IMAGE_NAME}:latest
.. tab:: using Makefile target "docker_push"
@@ -414,7 +458,7 @@ In the displayed dialog box, create a test event:
- and click **Create**.
-See also: :otc_fg_umn:`Step 5: Testing the Function `
+See also: :otc_fg_umn:`Step 5: Testing the Function `
in the user manual.
Step 6: View the Execution Result
diff --git a/doc/source/devguide/event_function/scratch/_index.rst b/doc/source/devguide/event_function/scratch/_index.rst
index ddb6347..27fa5e3 100644
--- a/doc/source/devguide/event_function/scratch/_index.rst
+++ b/doc/source/devguide/event_function/scratch/_index.rst
@@ -34,7 +34,7 @@ Function Development Overview
.. code-block:: javascript
exports.handler = async (event, context, callback [optional]) => {
- // Your code her
+ // Your code here
return data;
}
diff --git a/doc/source/devguide/event_function/scratch/context.rst b/doc/source/devguide/event_function/scratch/context.rst
index 9df3204..f3444d5 100644
--- a/doc/source/devguide/event_function/scratch/context.rst
+++ b/doc/source/devguide/event_function/scratch/context.rst
@@ -105,9 +105,7 @@ you can import the Context class from the npm package as dev dependency and crea
.. code-block:: bash
- npm install @opentelekomcloud-community/fg-runtime --save-dev
- # or
- npm install @opentelekomcloud-community/fg-context -D
+ npm install @opentelekomcloud-community/fg-runtime --save-dev
.. note::
All npm packages are hosted on GitHub Packages.
diff --git a/doc/source/devguide/event_function/scratch/initializer.rst b/doc/source/devguide/event_function/scratch/initializer.rst
index 6d4764e..3dfdcdf 100644
--- a/doc/source/devguide/event_function/scratch/initializer.rst
+++ b/doc/source/devguide/event_function/scratch/initializer.rst
@@ -62,17 +62,21 @@ Features of the Initializer
The initializer of each runtime has the following features:
* No custom parameters
+
The initializer does not support custom parameters and only uses the
variables in context for logic processing.
* No return values
+
No values will be returned for initializer invocation.
* Initialization timeout
+
You can set an initialization timeout (≤ 300s) different from the timeout
for invoking the handler.
* Execution duration
+
Function instances are processes that execute function logic in a
container and automatically scale if the number of requests changes.
When a new function instance is generated, the system invokes the
@@ -80,6 +84,7 @@ The initializer of each runtime has the following features:
successful.
* One-time execution
+
After each function instance starts, the initializer can only be executed
once. If an instance fails to execute the initializer, the instance is
abandoned and another instance starts to execute the initializer.
@@ -89,10 +94,12 @@ The initializer of each runtime has the following features:
again within its lifecycle.
* Naming rule
+
For all runtimes except Java, the initializer can be named in the format
of **[File name].[Initializer name]**, which is similar with the format of a
handler name.
* Billing
+
The initializer execution duration will be billed at the same rate as
the function execution duration.
diff --git a/doc/source/devguide/event_function/trigger_events/_index.rst b/doc/source/devguide/event_function/trigger_events/_index.rst
index 1617bf0..60889ed 100644
--- a/doc/source/devguide/event_function/trigger_events/_index.rst
+++ b/doc/source/devguide/event_function/trigger_events/_index.rst
@@ -12,7 +12,6 @@ Function-supported trigger events
DDS Event
DMS Kafka Event
DMS RocketMQ Event
- DMS RabbitMQ Event
Kafka (Open-Source) Event
LTS Event
OBS Event
@@ -79,16 +78,8 @@ invoked whenever the corresponding event is detected.
For instructions on triggering and using the distributed messaging Kafka, please refer to:
- Use :ref:`Kafka triggers `.
- - Using :ref:`open-source Kafka triggers `
-
- * - Distributed messaging service RabbitMQ (DMS for RabbitMQ)
- - FunctionGraph can periodically poll the queues bound to a specified Exchange in a RabbitMQ
- instance for new messages.
- FunctionGraph then passes the polled messages as parameters to call the function.
-
- For instructions on triggering and using RabbitMQ distributed messaging, please refer to
- :ref:`Using RabbitMQ Triggers `.
-
+ - Using :ref:`open-source Kafka triggers `
+
* - Log Tank Service (LTS)
- Write FunctionGraph functions to process logs subscribed to from the Cloud Log Service.
Once the Cloud Log Service collects the subscribed logs, it can call the FunctionGraph
diff --git a/doc/source/devguide/event_function/trigger_events/trigger_dms4rabbitmq_event.rst b/doc/source/devguide/event_function/trigger_events/trigger_dms4rabbitmq_event.rst
deleted file mode 100644
index 630df7a..0000000
--- a/doc/source/devguide/event_function/trigger_events/trigger_dms4rabbitmq_event.rst
+++ /dev/null
@@ -1,65 +0,0 @@
-.. _devguide_event_function_trigger_events_dms4rabbitmq:
-
-DMS for RabbitMQ Event Source
-=======================================
-
-.. note::
- coming soon...
-
-DMS for RabbitMQ is a message queuing service that provides RabbitMQ premium
-instances. If you create a RabbitMQ trigger for a function, when a message is sent
-to a RabbitMQ instance topic, FunctionGraph will retrieve the message and trigger
-the function to perform other operations.
-
-For the use of RabbitMQ triggers, please refer to
-:docs_otc:`Using a RabbitMQ Trigger `.
-
-RabbitMQ example event
-----------------------
-
-.. literalinclude:: /../../fg-events/fg-dms4rabbitmq-event/resources/rabbitmq_event.json
- :language: json
- :caption: :github_repo_master:`rabbitmq_event.json `
-
-
-Parameter description
----------------------
-
-
-.. list-table::
- :header-rows: 1
- :widths: 20 15 40
-
- * - Parameter
- - Type
- - Description
- * - event_version
- - String
- - Event version
- * - event_time
- - String
- - Time when an event occurs
- * - trigger_type
- - String
- - Event type: **RABBITMQ**
- * - region
- - String
- - Region where a RabbitMQ instance resides
- * - instance_id
- - String
- - RabbitMQ instance ID
- * - messages
- - String[]
- - Message content
- * - exchange
- - String
- - Exchange identifier
-
-Example
--------
-
-.. literalinclude:: /../../samples-doc/scratch-event-dms4rabbitmq/src/index.js
- :language: javascript
- :caption: :github_repo_master:`index.js `
-
-Full sample code is available in the :github_repo_master:`samples-doc/scratch-event-dms4rabbitmq`.
diff --git a/doc/source/devguide/http_function/container/creating.rst b/doc/source/devguide/http_function/container/creating.rst
index aa1fe82..87cf4e6 100644
--- a/doc/source/devguide/http_function/container/creating.rst
+++ b/doc/source/devguide/http_function/container/creating.rst
@@ -1,8 +1,12 @@
.. _creating_an_http_function_using_a_container_image_built:
-Creating an HTTP Function Using a Container Image Built with Node.js
+Creating an HTTP Function using a container image built with Node.js
====================================================================
+.. toctree::
+ :maxdepth: 1
+ :hidden:
+
For general details about how to use a container image
to create and execute an HTTP function,
see :otc_fg_umn:`Creating an HTTP Function Using a Container Image and executing the Function `.
@@ -14,3 +18,432 @@ and perform local verification for HTTP functions.
You need to implement an **HTTP server** in the image listening to port **8000** to receive requests.
+Step 1: Create the Project
+--------------------------------------------
+
+In this example we use the `koa` framework to create an HTTP server.
+
+For full example, see: :github_repo_master:`container-http-koa ` sample in the GitHub repository.
+
+For details about koa, see `Koa - Node.js web framework `_.
+
+Initialize the project with npm:
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+First, create a project directory and initialize it with npm:
+
+.. code-block:: bash
+
+ # this sample uses Node.js 25.7.0, you can use nvm to
+ # switch to this version using:
+ nvm use 25.7.0
+
+ mkdir -p my-http-function/src
+ cd my-http-function
+ npm init -y
+
+Then, install the koa framework:
+
+.. code-block:: bash
+
+ npm install koa
+
+You can then modify the generated ``package.json`` file to specify
+
+* the Node.js version,
+* CPU architecture,
+* and OS platform required by the function,
+* as well as the function execution entry file and
+* dependencies.
+
+For example:
+
+.. literalinclude:: ../../../../../samples-doc/container-http-koa/package.json
+ :language: json
+ :caption: :github_repo_master:`package.json `
+
+Implementing the function
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Next, create following file:
+
+- src/index.js for the function entry
+
+
+.. literalinclude:: ../../../../../samples-doc/container-http-koa/src/index.js
+ :language: javascript
+ :caption: :github_repo_master:`src/index.js `
+
+
+In this code, we create a koa application that listens on port 8000.
+
+We define following endpoints:
+
+- POST **/init** for function initialization,
+- GET **/index** for function execution and
+- POST **/index** for function initialization.
+
+The default logger implementation does not include request id and timestamp in the logs,
+which makes it difficult to correlate logs with specific requests.
+
+To solve this problem, this examples creates a contextual logger that includes
+request id and timestamp in the logs.
+
+Run and Test server from code
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+You can run the server directly from the code to verify that it works as expected:
+
+.. code-block:: bash
+
+ npm run dev
+
+Then, you can send test requests to the server using curl or any API testing tool.
+
+For example, to test the function execution entry, you can send a POST request to the **/invoke** endpoint:
+
+.. code-block:: bash
+
+ curl -X POST http://localhost:8000/index?user=John
+
+
+You should see the response from the server indicating that the event was processed successfully.
+
+.. code-block:: text
+
+ Hello World, user!
+
+Step 2: Build the Container Image
+--------------------------------------------
+
+Create a Makefile
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+To simplify the development and testing process,
+create a **Makefile** in the project root folder:
+
+.. literalinclude:: ../../../../../samples-doc/container-http-koa/Makefile
+ :language: make
+ :caption: :github_repo_master:`Makefile `
+ :tab-width: 2
+
+Create a Dockerfile
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Create a **Dockerfile** in the project root folder to define the image.
+
+.. note::
+
+ * | In the cloud environment, **UID 1003** and **GID 1003** are used to start the container by default.
+ | The two IDs can be modified by choosing **Configuration** > **Basic Settings** > **Container Image Override**
+ | on the function details page. They cannot be **root** or a **reserved** ID.
+
+ * | If the base image of the **Alpine** version is used,
+ run the **addgroup** and **adduser** instead of
+ **groupadd** and **useradd** commands.
+
+ * You can use any base image that meets your application requirements.
+
+.. note::
+
+ * Ubuntu images are larger in size but come with more pre-installed libraries.
+
+ * Alpine images are smaller in size but may require additional libraries
+ depending on the application requirements.
+
+
+Following example uses an Alpine base image with Node.js installed.
+
+.. literalinclude:: ../../../../../samples-doc/container-http-koa/Dockerfile.node
+ :language: docker
+ :caption: :github_repo_master:`Dockerfile `
+
+Create following entrypoint script to start the server in the container:
+
+.. literalinclude:: ../../../../../samples-doc/container-http-koa/entrypoint.sh
+ :language: shell
+ :caption: :github_repo_master:`entrypoint.sh `
+
+Build and verify the image locally
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+**1. Build the image**
+
+Build the image either using **docker build** or the Makefile target **docker_build**:
+
+.. tabs::
+
+ .. tab:: using docker build
+ Run the following command in the project root folder to build the image:
+
+ .. code-block:: shell
+
+ docker buildx build \
+ --platform linux/amd64 \
+ --file Dockerfile.node \
+ --tag custom_container_http_koa_nodejs:latest .
+
+
+ .. tab:: using Makefile target "docker_build"
+ Run the following command in the project root folder to build the image:
+
+ .. code-block:: shell
+
+ make docker_build
+
+
+**2. Run the image locally**
+
+Run the image either using **docker run** or the Makefile target **docker_run_local**:
+
+.. tabs::
+
+ .. tab:: using docker run
+ Run the following command in the project root folder to run the image:
+
+ .. code-block:: shell
+
+ docker container run --rm \
+ --platform linux/amd64 \
+ --publish 8000:8000 \
+ --name custom_container_http_koa_nodejs \
+ custom_container_http_koa_nodejs:latest
+
+ .. tab:: using Makefile target "docker_run_local"
+
+ Run the following command in the project root folder to run the image:
+
+ .. code-block:: shell
+
+ make docker_run_local
+
+**3. Test the image locally**
+
+Test the image either using **curl** or the Makefile target **test_local**:
+
+.. tabs::
+
+ .. tab:: using curl
+ Run the following command in a new terminal
+ to test the image using a curl command:
+
+ .. code-block:: shell
+
+ curl -X POST -H 'Content-Type: application/json' -d '{"key":"Hello World of FunctionGraph"}' localhost:8000/index
+
+ .. tab:: using Makefile target "test_local"
+ Run the following command in a new terminal to test the image:
+
+ .. code-block:: shell
+
+ make test_local
+
+You should see output similar to the following:
+
+.. code-block:: text
+
+ Hello World, user!
+
+
+Step 3: Upload the Container Image to SWR (SoftWare Repository for Container)
+-----------------------------------------------------------------------------
+
+For details on SWR (SoftWare Repository for Container), see:
+
+* :docs_otc:`Software Repository for Container User Manual `
+* :docs_otc:`Uploading an Image through a Container Engine Client `
+* :docs_otc:`Obtaining a Long-Term Docker Login Command `
+
+Prerequisites
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+* SWR instance created.
+ For more information, see :otc_fg_umn:`Creating a Software Repository for Container `.
+
+* Credentials for SWR created.
+ For more information, see :otc_fg_umn:`Creating Access Credentials `.
+
+Upload the image to SWR
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+To upload the container image to SWR, following values are needed:
+
+.. list-table::
+ :header-rows: 1
+ :widths: 20 80
+
+ * - Parameter
+ - Description
+ * - OTC_SDK_PROJECTNAME
+ - | Your project name.
+ | To obtain this, see: :api_usage:`Obtaining a Project ID`
+ in API usage guide but use the **project name** instead of the project ID.
+ * - OTC_SDK_AK
+ - Your Access Key
+ * - OTC_SWR_LOGIN_KEY
+ - | The login key for SWR.
+ | For details see: :docs_otc:`Obtaining a Long-Term Docker Login Command `
+ in the Software Repository for Container user manual.
+ |
+ | It can be generated using the access key **${OTC_SDK_AK}** and secret key **${OTC_SDK_SK}** as follows:
+
+ .. code-block:: shell
+
+ export OTC_SWR_LOGIN_KEY=$(printf "${OTC_SDK_AK}" | \
+ openssl dgst -binary -sha256 -hmac "${OTC_SDK_SK}" | \
+ od -An -vtx1 | sed 's/[ \n]//g' | sed 'N;s/\n//')
+
+ * - OTC_SWR_ENDPOINT
+ - SWR endpoint, e.g. **swr.eu-de.otc.t-systems.com**
+ * - OTC_SWR_ORGANIZATION
+ - Your SWR organization name
+ * - IMAGE_NAME
+ - The name of your container image
+
+Set the environment variables:
+ .. code-block:: shell
+
+ export OTC_SDK_PROJECTNAME=
+ export OTC_SDK_AK=
+ export OTC_SDK_SK=
+ export OTC_SWR_LOGIN_KEY=$(printf "${OTC_SDK_AK}" | \
+ openssl dgst -binary -sha256 -hmac "${OTC_SDK_SK}" | \
+ od -An -vtx1 | sed 's/[ \n]//g' | sed 'N;s/\n//')
+ export OTC_SWR_ENDPOINT=swr.eu-de.otc.t-systems.com
+ export OTC_SWR_ORGANIZATION=
+ export IMAGE_NAME=custom_container_event_example
+
+
+
+Upload the image to SWR either using **shell commands** or the Makefile target **docker_push**:
+
+.. tabs::
+
+ .. tab:: Pushing using shell commands
+ Run the following commands in the **container-event** folder to upload the image to SWR:
+
+ .. code-block:: shell
+ :caption: **1. Login to SWR**
+
+ docker login -u ${OTC_SDK_PROJECTNAME}@${OTC_SDK_AK} -p ${OTC_SWR_LOGIN_KEY} ${OTC_SWR_ENDPOINT}
+
+ .. code-block:: shell
+ :caption: **2. Tag the image**
+
+ docker tag ${IMAGE_NAME}:latest ${OTC_SWR_ENDPOINT}/${OTC_SWR_ORGANIZATION}/${IMAGE_NAME}:latest
+
+ .. code-block:: shell
+ :caption: **3. Push the image to SWR**
+
+ docker push ${OTC_SWR_ENDPOINT}/${OTC_SWR_ORGANIZATION}/${IMAGE_NAME}:latest
+
+
+ .. tab:: using Makefile target "docker_push"
+ Run the following command in the **container-event** folder to upload the image to SWR:
+
+ .. code-block:: shell
+
+ make docker_push
+
+
+Step 4: Create an HTTP Function Using the Container Image
+---------------------------------------------------------------
+
+1. In the left navigation pane of the management console, choose **Compute** > **FunctionGraph**.
+ On the :fg_console:`FunctionGraph console <>`, choose **Functions** > **Function List** from the navigation pane.
+2. Click **Create Function** in the upper right corner. On the displayed page, select **Container Image**
+ for creation mode.
+3. Set the basic function information.
+
+ - **Function Type**: Select **HTTP Function**.
+
+ - **Region**: The default value is used. You can select other regions.
+
+ **Regions are geographic areas isolated from each other.
+ Resources are region-specific and cannot be used across regions through internal network connections.
+ For low network latency and quick resource access, select the nearest region.**
+
+ - **Function Name**: Enter e.g. **custom_container_http**.
+
+ - **Enterprise Project**: The default value is **default**. You can select the created enterprise project.
+
+ Enterprise projects let you manage cloud resources and users by project.
+
+ - **Agency**: Select an agency with the **SWR Admin** permission.
+ If no agency is available, create one by referring to
+ :otc_fg_umn:`Creating an Agency `.
+
+ - **Container Image**: Enter the image uploaded to SWR.
+ The format is: **{SWR_endpoint}/{organization_name}/{image_name}:{tag}**.
+
+ Example: *swr.eu-de.otc.t-systems.com/my_organization/custom_container_http_example:latest*.
+
+
+4. **Advanced Settings**: **Collect Logs** is disabled by default. If it is enabled,
+ function execution logs will be reported to Log Tank Service (LTS).
+ You will be billed for log management on a pay-per-use basis.
+
+ .. list-table::
+ :header-rows: 1
+ :widths: 20 80
+
+ * - Parameter
+ - Description
+
+ * - Log Configuration
+ - You can select **Auto** or **Custom**.
+
+ - **Auto**: Use the default log group and log stream.
+ Log groups prefixed with "functiongraph.log.group" are filtered out.
+ - **Custom**: Select a custom log group and log stream.
+ Log streams that are in the same enterprise project as your function.
+
+ * - Log Tag
+ - | You can use these tags to filter function logs in LTS.
+ | You can add 10 more tags.
+ | Tag key/value: Enter a maximum of 64 characters.
+ | Only digits, letters, underscores (_), and hyphens (-) are allowed.
+
+5. After the configuration is complete, click **Create Function**.
+
+See also: :otc_fg_umn:`Step 4: Creating Function `
+in the user manual.
+
+Step 5: Test the HTTP Function
+---------------------------------------------------------------
+
+On the function details page, click **Test**.
+In the displayed dialog box, create following test events.
+
+See also: :otc_fg_umn:`Step 5: Testing the Function `
+in the user manual.
+
+Test event for GET /index
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Select **blank-template**,
+- set **Event Name** to **get_index**,
+- modify the test event as follows,
+
+ .. literalinclude:: ../../../../../samples-doc/container-http-koa/resources/apig_get_index.json
+ :language: json
+ :caption: **Test event for GET /index**
+
+- and click **Create**.
+
+Test event for POST /index
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Select **blank-template**,
+- set **Event Name** to **post_index**,
+- modify the test event as follows,
+
+ .. literalinclude:: ../../../../../samples-doc/container-http-koa/resources/apig_post_index.json
+ :language: json
+ :caption: **Test event for POST /index**
+
+- and click **Create**.
+
+Step 6: View the Execution Result
+---------------------------------
+
+Click **Test** and view the execution result on the right.
diff --git a/doc/source/devguide/invoke/_index.rst b/doc/source/devguide/invoke/_index.rst
index 8bb2f2d..745cb4e 100644
--- a/doc/source/devguide/invoke/_index.rst
+++ b/doc/source/devguide/invoke/_index.rst
@@ -10,7 +10,8 @@ Node.js:
API calls
curl
- From FunctionGraph
+ From FunctionGraph with temp. Credentials
+ From FunctionGraph with Token
For details on function invocation, see
@@ -59,7 +60,7 @@ 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_ID``
+* **Project** : as specified in the environment variable ``OTC_SDK_PROJECTID``
* **Region**: as specified in the environment variable ``OTC_SDK_REGION``
* **Name**: ``nodejs-sample-invoke-function``
* **Runtime**: ``Node.js 20.15``
diff --git a/doc/source/devguide/invoke/invoke_api.rst b/doc/source/devguide/invoke/invoke_api.rst
index d60917a..4290f35 100644
--- a/doc/source/devguide/invoke/invoke_api.rst
+++ b/doc/source/devguide/invoke/invoke_api.rst
@@ -29,7 +29,7 @@ The SDK provides a method to sign the request with AK/SK or SecurityAccessKey/Se
Additional to the environment variables mentioned in the prerequisites,
you also need to set the following environment variables
-for AK/SK authentication :
+for AK/SK authentication:
- OTC_SDK_AK (Access Key with permission to invoke FunctionGraph)
- OTC_SDK_SK (Secret Key corresponding to the Access Key)
@@ -59,7 +59,7 @@ in FunctionGraph API reference for more details about synchronous invocation.
node src/invokeSync_AKSK.js
# or use npm script:
- npm run invokeSync_AKSK
+ npm run invokeSyncAKSK
.. tab:: Code using Node.js "fetch"
@@ -77,7 +77,7 @@ in FunctionGraph API reference for more details about synchronous invocation.
node src/invokeSyncFetch_AKSK.js
# or use npm script:
- npm run invokeSyncFetch_AKSK
+ npm run invokeSyncFetchAKSK
In both cases, you should see an output similar to the following in the terminal:
@@ -118,7 +118,7 @@ in FunctionGraph API reference for more details about asynchronous invocation.
node src/invokeASync_AKSK.js
# or use npm script:
- npm run invokeASync_AKSK
+ npm run invokeASyncAKSK
.. tab:: Code using Node.js "fetch"
@@ -135,7 +135,7 @@ in FunctionGraph API reference for more details about asynchronous invocation.
node src/invokeASyncFetch_AKSK.js
# or use npm script:
- npm run invokeASyncFetch_AKSK
+ npm run invokeASyncFetchAKSK
In both cases, you should see an output similar to the following in the terminal:
diff --git a/doc/source/devguide/invoke/invoke_curl.rst b/doc/source/devguide/invoke/invoke_curl.rst
index 28963de..15cb1bd 100644
--- a/doc/source/devguide/invoke/invoke_curl.rst
+++ b/doc/source/devguide/invoke/invoke_curl.rst
@@ -66,7 +66,7 @@ Sourcing the script to get token into environment variable
# Output example:
MIIGBQYJKoZIhvcNAQcCoIIF9jCCBfICAQExDTALBglghkgBZQMEAgEwggOKBgkqhkiG.....
-Calling Functiongraph
+Calling FunctionGraph
----------------------------------------------------------------
Synchronously
diff --git a/doc/source/devguide/invoke/invoke_fg.rst b/doc/source/devguide/invoke/invoke_fg.rst
index 2af0843..42bced7 100644
--- a/doc/source/devguide/invoke/invoke_fg.rst
+++ b/doc/source/devguide/invoke/invoke_fg.rst
@@ -1,5 +1,5 @@
-Invoke FunctionGraph Function from FunctionGraph
-=================================================
+Invoke FunctionGraph Function from FunctionGraph using temp. Credentials
+==========================================================================
.. toctree::
:maxdepth: 1
@@ -8,11 +8,14 @@ Invoke FunctionGraph Function from FunctionGraph
This page demonstrates how to call a FunctionGraph implemented
in Node.js from another FunctionGraph function using API calls and
-temporary security credentials (SecurityAccessKey/SecurityKey/SecurityToken)
+**temporary security credentials** (SecurityAccessKey/SecurityKey/SecurityToken)
provided by an agency of `Agency Type` **Cloud Service**
for `Cloud Service` **FunctionGraph Service** with permission to invoke FunctionGraph.
for authentication.
+Using temporary credentials the request has to be signed using the
+`otc-api-sign-sdk-nodejs `_.
+
See: :ref:`invoke_functiongraph_function_api` for more details on
how to use the REST API.
@@ -38,7 +41,9 @@ Prerequisites
}
return output;
}
-
+
+ .. note::
+ Ensure that the function and the subfunction are created in the same region.
2. An agency of `Agency Type` **Cloud Service** for `Cloud Service` **FunctionGraph Service**
with permission to invoke FunctionGraph.
@@ -102,6 +107,8 @@ Prerequisites
For example, **FunctionGraph:*:*:function:default/*** indicates
any function in the **default** group.
+ For more details, see :docs_otc:`Policy Syntax` in Identity and Access Management User Guide.
+
(Remark: changing the permission policy may take some time to take effect.)
@@ -116,6 +123,7 @@ FunctionGraph function that will call another FunctionGraph function.
.. literalinclude:: ../../../../samples-doc/invoke-fg2fg/package.json
:language: json
+ :caption: :github_repo_master:`samples-doc/invoke-fg2fg/package.json `
index.js
@@ -125,6 +133,7 @@ Create a function with following content to call another FunctionGraph function:
.. literalinclude:: ../../../../samples-doc/invoke-fg2fg/index.js
:language: javascript
+ :caption: :github_repo_master:`samples-doc/invoke-fg2fg/index.js `
Deployment
---------------------
diff --git a/doc/source/devguide/invoke/invoke_fg_token.rst b/doc/source/devguide/invoke/invoke_fg_token.rst
new file mode 100644
index 0000000..d274288
--- /dev/null
+++ b/doc/source/devguide/invoke/invoke_fg_token.rst
@@ -0,0 +1,146 @@
+Invoke FunctionGraph Function from FunctionGraph using token
+===================================================================
+
+.. toctree::
+ :maxdepth: 1
+ :hidden:
+
+
+This page demonstrates how to call a FunctionGraph implemented
+in Node.js from another FunctionGraph function using API calls and
+**token** provided by an agency of `Agency Type` **Cloud Service**
+for `Cloud Service` **FunctionGraph Service** with permission to invoke FunctionGraph.
+for authentication.
+
+See: :ref:`invoke_functiongraph_function_api` for more details on
+how to use the REST API.
+
+
+Prerequisites
+-----------------
+
+1. URN of Function to be called.
+ In this example the code of the function to be called is:
+
+ .. code-block:: javascript
+
+ exports.handler = async (event, context) => {
+ const output =
+ {
+ 'statusCode': 200,
+ 'headers':
+ {
+ 'Content-Type': 'application/json'
+ },
+ 'isBase64Encoded': false,
+ 'body': JSON.stringify(event),
+ }
+ return output;
+ }
+
+ .. note::
+ Ensure that the function and the subfunction are created in the same region.
+
+2. An agency of `Agency Type` **Cloud Service** for `Cloud Service` **FunctionGraph Service**
+ with permission to invoke FunctionGraph.
+
+ The permission policy should contain following policy statement:
+
+ .. code-block:: json
+
+ {
+ "Version": "1.1",
+ "Statement": [
+ {
+ "Action": [
+ "functiongraph:function:invokeAsync*",
+ "functiongraph:function:invoke"
+ ],
+ "Effect": "Allow"
+ }
+ ]
+ }
+
+ or use an agency with default permission **FunctionGraph CommonOperations**.
+
+ .. note::
+ The permissions shown above are for demonstration purpose.
+ Please follow the principle of least privilege when creating
+ the permission policy for the agency.
+
+ e.g. to grant permission to invoke only specific functions,
+ the policy statement should be like:
+
+ .. code-block:: json
+
+ {
+ "Version": "1.1",
+ "Statement": [
+ {
+ "Action": [
+ "functiongraph:function:invokeAsync*",
+ "functiongraph:function:invoke"
+ ],
+ "Effect": "Allow",
+ "Resource": [
+ "RESOURCE_PATH"
+ ]
+ }
+ ]
+ }
+
+ where **"RESOURCE_PATH"** is in format
+
+ .. code-block:: text
+
+ FunctionGraph:::function:group/function name
+
+ By adding Function name to the end of the generated prefix,
+ you can define a specific path.
+
+ An asterisk * is allowed to indicate any function.
+
+ For example, **FunctionGraph:*:*:function:default/*** indicates
+ any function in the **default** group.
+
+ For more details, see :docs_otc:`Policy Syntax` in Identity and Access Management User Guide.
+
+ (Remark: changing the permission policy may take some time to take effect.)
+
+
+Coding
+---------------------
+
+package.json
+^^^^^^^^^^^^^^^^^^^^^^
+
+Create a package with following content for the
+FunctionGraph function that will call another FunctionGraph function.
+
+.. literalinclude:: ../../../../samples-doc/invoke-fg2fg-token/package.json
+ :language: json
+ :caption: :github_repo_master:`samples-doc/invoke-fg2fg-token/package.json `
+
+
+index.js
+^^^^^^^^^^^^^^^^^^^^^^
+
+Create a function with following content to call another FunctionGraph function:
+
+.. literalinclude:: ../../../../samples-doc/invoke-fg2fg-token/index.js
+ :language: javascript
+ :caption: :github_repo_master:`samples-doc/invoke-fg2fg-token/index.js `
+
+Deployment
+---------------------
+
+Create a deployment package using **npm install** and **npm pack**
+and deploy the package to FunctionGraph using the console as
+event function from scratch using Node.JS 20.15.
+
+Configure the function:
+
+- set the handler name as **index.handler**.
+- specify an agency with permission to **invoke** FunctionGraph
+- and set the URN of the function to be called as Environment variable
+ with key **CALL_FG_URN**.
diff --git a/doc/source/samples/_index.rst b/doc/source/samples/_index.rst
index 94a98d5..057c084 100644
--- a/doc/source/samples/_index.rst
+++ b/doc/source/samples/_index.rst
@@ -5,8 +5,7 @@ Following samples are provided to demonstrate how to use
FunctionGraph with Node.js:
.. toctree::
- :maxdepth: 2
- :hidden:
+ :maxdepth: 1
container-event-express
container-event-koa
@@ -18,6 +17,8 @@ FunctionGraph with Node.js:
scratch-event-sync
scratch-http
+Some samples are not documented yet.
+You will find them in folder :github_repo_master:`samples-doc` in the GitHub repository.
General notes
------------------------------
@@ -48,7 +49,7 @@ General notes
:caption: package.json
"devDependencies": {
- "@opentelekomcloud-community/fg-context": "^1.0.0"
+ "@opentelekomcloud-community/fg-apig-event": "^1.0.0"
},
diff --git a/fg-events/fg-dms4rabbitmq-event/README.md b/fg-events/fg-dms4rabbitmq-event/README.md
deleted file mode 100644
index 854946c..0000000
--- a/fg-events/fg-dms4rabbitmq-event/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# DMS for RabbitMQ Event
-
-Package contains DMS for RabbitMQ trigger event structure used in T Cloud Public FunctionGraph.
-
-For details and usage see: [DMS for RabbitMQ Event Source](https://opentelekomcloud-community.github.io/otc-functiongraph-nodejs-runtime/devguide/event_function/trigger_events/trigger_dms4rabbitmq_event.html)
-
-## Code Assist (JSDoc)
-
-```javascript
-const { DMS4RabbitMQEvent } = require("@opentelekomcloud-community/fg-dms4rabbitmq-event");
-/** @typedef {import("@opentelekomcloud-community/fg-dms4rabitmq-event").DMS4RabbitMQEventJSON} DMS4RabbitMQEventJSON */
-
-/**
- * @param {DMS4RabbitMQEventJSON} event
- */
-exports.handler = async (event, context) => {
- const eventData = new DMS4RabbitMQEvent(event);
- return "OK";
-};
-```
\ No newline at end of file
diff --git a/fg-events/fg-dms4rabbitmq-event/jest.config.js b/fg-events/fg-dms4rabbitmq-event/jest.config.js
deleted file mode 100644
index e14e72b..0000000
--- a/fg-events/fg-dms4rabbitmq-event/jest.config.js
+++ /dev/null
@@ -1,18 +0,0 @@
-module.exports = {
- // setupFiles: ["./test/setEnvVars.js"],
- collectCoverageFrom: [
- "**/*.{js,jsx}",
- "!**/*.config.js",
- "!**/node_modules/**",
- "!**/test/**",
- "!**/coverage/**",
- ],
- globals: {
- NODE_ENV: "test",
- },
- moduleDirectories: ["node_modules"],
- rootDir: process.cwd(),
- testPathIgnorePatterns: ["/node_modules/", "/dist"],
- testRegex: "test/.*\\.test\\.js$",
- testEnvironment: "jsdom",
-};
diff --git a/fg-events/fg-dms4rabbitmq-event/package.json b/fg-events/fg-dms4rabbitmq-event/package.json
deleted file mode 100644
index fe3dccd..0000000
--- a/fg-events/fg-dms4rabbitmq-event/package.json
+++ /dev/null
@@ -1,46 +0,0 @@
-{
- "name": "@opentelekomcloud-community/fg-dms4rabbitmq-event",
- "description": "DMS for RabbitMQ event class for FunctionGraph DMS trigger",
- "homepage": "https://opentelekomcloud-community.github.io/otc-functiongraph-nodejs-runtime",
- "bugs": {
- "url": "https://github.com/opentelekomcloud-community/otc-functiongraph-nodejs-runtime/issues"
- },
- "publishConfig": {
- "registry": "https://npm.pkg.github.com"
- },
- "repository": {
- "type": "git",
- "url": "git+https://github.com/opentelekomcloud-community/otc-functiongraph-nodejs-runtime.git",
- "directory": "fg-events/fg-dms4rabbitmq-event"
- },
- "version": "1.0.2",
- "license": "Apache-2.0",
- "author": "T Cloud Public",
- "type": "commonjs",
- "main": "./src/dms4rabbitmqevent.js",
- "scripts": {
- "prepack": "npm i --workspaces false",
- "test": "jest --config ./jest.config.js --coverage --silent",
- "postpack": "name=$(bash -c 'echo \"${npm_package_name////-}-${npm_package_version}\" | sed \"s/@/ /g\"') && rm -f ${name}.zip && tarball=\"${name}.tgz\"; tar -tf $tarball | sed 's/^package\\///' | zip -@r ${name}.zip",
- "publish:github": "npm pack && npm publish --registry https://npm.pkg.github.com"
- },
- "dependencies": {},
- "devDependencies": {
- "jest": "^30.2.0",
- "jest-environment-jsdom": "^30.2.0"
- },
- "exports": {
- ".": {
- "import": "./src/dms4rabbitmqevent.js",
- "require": "./src/dms4rabbitmqevent.js",
- "default": "./src/dms4rabbitmqevent.js"
- },
- "./package.json": {
- "default": "./package.json"
- }
- },
- "files": [
- "src/**/*",
- "lib/**/*"
- ]
-}
diff --git a/fg-events/fg-dms4rabbitmq-event/resources/rabbitmq_event.json b/fg-events/fg-dms4rabbitmq-event/resources/rabbitmq_event.json
deleted file mode 100644
index df64b0f..0000000
--- a/fg-events/fg-dms4rabbitmq-event/resources/rabbitmq_event.json
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- "event_version": "v1.0",
- "event_time": 1576737962,
- "trigger_type": "RABBITMQ",
- "region": "region",
- "records": [
- {
- "messages": [
- "rabbitmq message1",
- "rabbitmq message2",
- "rabbitmq message3",
- "rabbitmq message4",
- "rabbitmq message5"
- ],
- "instance_id": "81335d56-b9fe-4679-ba95-7030949cc76b",
- "exchange": "topic"
- }
- ]
-}
diff --git a/fg-events/fg-dms4rabbitmq-event/src/dms4rabbitmqevent.d.ts b/fg-events/fg-dms4rabbitmq-event/src/dms4rabbitmqevent.d.ts
deleted file mode 100644
index a2af225..0000000
--- a/fg-events/fg-dms4rabbitmq-event/src/dms4rabbitmqevent.d.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * TypeScript definitions for DMS4RabbitMQ Event
- * DMS for RabbitMQ trigger event for FunctionGraph
- */
-
-export interface DMS4RabbitMQRecordMessageObject {
- message?: string;
-}
-
-export type DMS4RabbitMQRecordMessageJSON =
- | string
- | DMS4RabbitMQRecordMessageObject;
-
-export interface DMS4RabbitMQRecordJSON {
- exchange?: string;
- messages?: DMS4RabbitMQRecordMessageJSON[];
-}
-
-export interface DMS4RabbitMQEventJSON {
- event_version?: string;
- event_time?: string;
- region?: string;
- trigger_type?: string;
- instance_id?: string;
- records?: DMS4RabbitMQRecordJSON[];
-}
-
-export declare class DMS4RabbitMQEvent {
- constructor(event?: DMS4RabbitMQEventJSON);
-
- getEventVersion(): string;
- getEventTime(): string;
- getRegion(): string;
- getTriggerType(): string;
- getInstanceId(): string;
- getRecords(): DMS4RabbitMQRecord[];
- toJSON(): DMS4RabbitMQEventJSON;
-}
-
-export declare class DMS4RabbitMQRecord {
- constructor(record?: DMS4RabbitMQRecordJSON);
-
- getExchange(): string;
- getMessages(): DMS4RabbitMQRecordMessage[];
- toJSON(): DMS4RabbitMQRecordJSON;
-}
-
-export declare class DMS4RabbitMQRecordMessage {
- constructor(record?: DMS4RabbitMQRecordMessageJSON);
-
- getMessage(): string;
- toJSON(): DMS4RabbitMQRecordMessageJSON;
-}
diff --git a/fg-events/fg-dms4rabbitmq-event/src/dms4rabbitmqevent.js b/fg-events/fg-dms4rabbitmq-event/src/dms4rabbitmqevent.js
deleted file mode 100644
index 1024259..0000000
--- a/fg-events/fg-dms4rabbitmq-event/src/dms4rabbitmqevent.js
+++ /dev/null
@@ -1,162 +0,0 @@
-"use strict";
-
-/**
- * @typedef {Object} DMS4RabbitMQEventJSON
- * @property {string} [event_version] Event schema version
- * @property {string} [event_time] Event creation time
- * @property {string} [region] Region where the event was emitted
- * @property {string} [trigger_type] Trigger type for this invocation
- * @property {string} [instance_id] DMS instance ID
- * @property {DMS4RabbitMQRecordJSON[]} [records] Event records
- */
-
-/**
- * @typedef {Object} DMS4RabbitMQRecordJSON
- * @property {string} [exchange] Exchange identifier
- * @property {DMS4RabbitMQRecordMessageJSON[]} [messages] Messages received for the exchange
- */
-
-/**
- * @typedef {Object} DMS4RabbitMQRecordMessageObject
- * @property {string} [message] Raw message payload
- */
-
-/**
- * @typedef {string | DMS4RabbitMQRecordMessageObject} DMS4RabbitMQRecordMessageJSON
- */
-
-/**
- * DMS4RabbitMQEvent Class
- * Represents a DMS4RabbitMQ event for FunctionGraph
- */
-class DMS4RabbitMQEvent {
- /**
- * @param {DMS4RabbitMQEventJSON} event
- */
- constructor(event) {
- this._event = event || {};
- }
-
- /**
- * @returns {string}
- */
- getEventVersion() {
- return this._event.event_version || "";
- }
-
- /**
- * @returns {string}
- */
- getEventTime() {
- return this._event.event_time || "";
- }
-
- /**
- * @returns {string}
- */
- getRegion() {
- return this._event.region || "";
- }
-
- /**
- * @returns {string}
- */
- getTriggerType() {
- return this._event.trigger_type || "";
- }
-
- /**
- * @returns {string}
- */
- getInstanceId() {
- return this._event.instance_id || "";
- }
-
- /**
- * @returns {DMS4RabbitMQRecord[]}
- */
- getRecords() {
- const records = [];
- for (const record of this._event.records || []) {
- records.push(new DMS4RabbitMQRecord(record));
- }
- return records;
- }
-
- /**
- * Converts the wrapped payload back to a plain JSON object.
- * @returns {DMS4RabbitMQEventJSON} Payload as JSON object
- */
- toJSON() {
- return this._event;
- }
-}
-
-class DMS4RabbitMQRecord {
- /**
- * @param {DMS4RabbitMQRecordJSON} record
- */
- constructor(record) {
- this._record = record || {};
-
- this._messages = [];
- for (const message of this._record.messages || []) {
- this._messages.push(new DMS4RabbitMQRecordMessage(message));
- }
- }
-
- /**
- * @returns {string}
- */
- getExchange() {
- return this._record.exchange || "";
- }
-
- /**
- * @returns {DMS4RabbitMQRecordMessage[]}
- */
- getMessages() {
- return this._messages;
- }
-
- /**
- * Converts the wrapped payload back to a plain JSON object.
- * @returns {DMS4RabbitMQRecordJSON} Payload as JSON object
- */
- toJSON() {
- return this._record;
- }
-}
-
-class DMS4RabbitMQRecordMessage {
- /**
- * @param {DMS4RabbitMQRecordMessageJSON} record
- */
- constructor(record) {
- this._record = record || {};
- }
-
- /**
- * @returns {string}
- */
- getMessage() {
- if (typeof this._record === "string") {
- return this._record;
- }
- return this._record.message || "";
- }
-
- /**
- * Converts the wrapped payload back to a plain JSON object.
- * @returns {DMS4RabbitMQRecordMessageJSON} Payload as JSON object
- */
- toJSON() {
- return this._record;
- }
-}
-
-module.exports = {
- DMS4RabbitMQEvent,
- DMS4RabbitMQRecord,
- DMS4RabbitMQRecordMessage,
-};
diff --git a/fg-events/fg-dms4rabbitmq-event/test/dms4rocketmq.test.js b/fg-events/fg-dms4rabbitmq-event/test/dms4rocketmq.test.js
deleted file mode 100644
index 0c5e32d..0000000
--- a/fg-events/fg-dms4rabbitmq-event/test/dms4rocketmq.test.js
+++ /dev/null
@@ -1,18 +0,0 @@
-const assert = require("assert");
-const { DMS4RabbitMQEvent } = require("../src/dms4rabbitmqevent");
-
-const eventData = require("../resources/rabbitmq_event.json");
-const event = new DMS4RabbitMQEvent(eventData);
-
-test("DMS4RabbitMQEvent should correctly parse event data", () => {
- assert.strictEqual(event.getTriggerType(), "RABBITMQ");
- assert.strictEqual(event.getEventVersion(), "v1.0");
-
- const records = event.getRecords();
- assert.strictEqual(records.length, 1);
- assert.strictEqual(records[0].getExchange(), "topic");
-
- const messages = records[0].getMessages();
- assert.strictEqual(messages.length, 5);
- assert.strictEqual(messages[0].getMessage(), "rabbitmq message1");
-});
diff --git a/fg-events/fg-events.js b/fg-events/fg-events.js
index 8973216..0061e29 100644
--- a/fg-events/fg-events.js
+++ b/fg-events/fg-events.js
@@ -5,7 +5,6 @@ module.exports = {
...require("@opentelekomcloud-community/fg-cts-event"),
...require("@opentelekomcloud-community/fg-dds-event"),
...require("@opentelekomcloud-community/fg-dms4kafka-event"),
- ...require("@opentelekomcloud-community/fg-dms4rabbitmq-event"),
...require("@opentelekomcloud-community/fg-dms4rocketmq-event"),
...require("@opentelekomcloud-community/fg-kafkaopensource-event"),
...require("@opentelekomcloud-community/fg-lts-event"),
diff --git a/fg-events/package.json b/fg-events/package.json
index dbc8265..a632429 100644
--- a/fg-events/package.json
+++ b/fg-events/package.json
@@ -32,8 +32,7 @@
"@opentelekomcloud-community/fg-apig-event": "file:./fg-apig-event",
"@opentelekomcloud-community/fg-cts-event": "file:./fg-cts-event",
"@opentelekomcloud-community/fg-dds-event": "file:./fg-dds-event",
- "@opentelekomcloud-community/fg-dms4kafka-event": "file:./fg-dms4kafka-event",
- "@opentelekomcloud-community/fg-dms4rabbitmq-event": "file:./fg-dms4rabbitmq-event",
+ "@opentelekomcloud-community/fg-dms4kafka-event": "file:./fg-dms4kafka-event",
"@opentelekomcloud-community/fg-dms4rocketmq-event": "file:./fg-dms4rocketmq-event",
"@opentelekomcloud-community/fg-kafkaopensource-event": "file:./fg-kafkaopensource-event",
"@opentelekomcloud-community/fg-lts-event": "file:./fg-lts-event",
@@ -46,7 +45,6 @@
"@opentelekomcloud-community/fg-cts-event",
"@opentelekomcloud-community/fg-dds-event",
"@opentelekomcloud-community/fg-dms4kafka-event",
- "@opentelekomcloud-community/fg-dms4rabbitmq-event",
"@opentelekomcloud-community/fg-dms4rocketmq-event",
"@opentelekomcloud-community/fg-kafkaopensource-event",
"@opentelekomcloud-community/fg-lts-event",
diff --git a/fg-runtime/package.json b/fg-runtime/package.json
index be07b95..87693f6 100644
--- a/fg-runtime/package.json
+++ b/fg-runtime/package.json
@@ -24,7 +24,6 @@
"author": "T Cloud Public",
"license": "Apache-2.0",
"dependencies": {
- "moment": "^2.30.1"
},
"devDependencies": {
"jest": "^30.2.0",
@@ -38,6 +37,5 @@
"src/**/*"
],
"bundledDependencies": [
- "moment"
]
}
diff --git a/fg-runtime/src/logger.js b/fg-runtime/src/logger.js
index d7643cc..665eaa3 100644
--- a/fg-runtime/src/logger.js
+++ b/fg-runtime/src/logger.js
@@ -1,9 +1,9 @@
"use strict";
const util = require("util");
-const moment = require("moment");
function getTime() {
- return moment().utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
+ // "YYYY-MM-DDTHH:mm:ss.SSS[Z]"
+ return new Date().toISOString();
}
const MAX_SINGLE_LOG_SIZE = 90 * 1024;
diff --git a/package.json b/package.json
index 48bfc59..68f90cb 100644
--- a/package.json
+++ b/package.json
@@ -31,8 +31,7 @@
"pack:fg-events:cts": "cd fg-events/fg-cts-event && npm pack",
"pack:fg-events:dds": "cd fg-events/fg-dds-event && npm pack",
"pack:fg-events:dms4kafka": "cd fg-events/fg-dms4kafka-event && npm pack",
- "pack:fg-events:dms4rocketmq": "cd fg-events/fg-dms4rocketmq-event && npm pack",
- "pack:fg-events:dms4rabbitmq": "cd fg-events/fg-dms4rabbitmq-event && npm pack",
+ "pack:fg-events:dms4rocketmq": "cd fg-events/fg-dms4rocketmq-event && npm pack",
"pack:fg-events:kafkaopensource": "cd fg-events/fg-kafkaopensource-event && npm pack",
"pack:fg-events:lts": "cd fg-events/fg-lts-event && npm pack",
"pack:fg-events:obss3": "cd fg-events/fg-obss3-event && npm pack",
diff --git a/releasenotes/v1.0.3.md b/releasenotes/v1.0.3.md
new file mode 100644
index 0000000..1755b58
--- /dev/null
+++ b/releasenotes/v1.0.3.md
@@ -0,0 +1,15 @@
+# v1.0.3
+
+## What's changed
+
+### Changes
+
+- event definition for RabbitMQ removed as it's discontinued
+- documentation updated
+- samples added
+- bugfixes
+- references to moment.js removed
+- TF provider updated to 1.36.68 in all samples
+- deploy from obs bucket sample adapted to use new terraform provider with "source_code_hash"
+
+### BREAKING CHANGES:
diff --git a/samples-doc/container-event-express/README.md b/samples-doc/container-event-express/README.md
index 3af5157..2fb5b4d 100644
--- a/samples-doc/container-event-express/README.md
+++ b/samples-doc/container-event-express/README.md
@@ -1,5 +1,5 @@
# Container-event-express
-Example on how to deploy a FunctionGraph **Event** Function as a container image using the [Node-js Express framework](https://expressjs.com/)
+Example on how to deploy a FunctionGraph **Event** Function as a container image using the [Node-js Express framework](https://expressjs.com/).
diff --git a/samples-doc/container-event-express/package.json b/samples-doc/container-event-express/package.json
index f05ba8c..01dce25 100644
--- a/samples-doc/container-event-express/package.json
+++ b/samples-doc/container-event-express/package.json
@@ -21,8 +21,7 @@
"x64"
],
"dependencies": {
- "express": "^4.17.1",
- "moment": "^2.30.1"
+ "express": "^4.17.1"
},
"scripts": {
diff --git a/samples-doc/container-event-express/src/loggingmiddleware.js b/samples-doc/container-event-express/src/loggingmiddleware.js
index 033a62e..692c09b 100644
--- a/samples-doc/container-event-express/src/loggingmiddleware.js
+++ b/samples-doc/container-event-express/src/loggingmiddleware.js
@@ -1,13 +1,13 @@
"use strict";
-const moment = require("moment");
function loggingMiddleware(req, res, next) {
// Header names are case-insensitive; Express normalizes them.
const requestId = req.get("X-Cff-Request-Id") || "no-request-id";
- // Function to format timestamp as yyyymmddThh:mm:ss.SSSZ
+ // Function to format timestamp as yyyy-mm-ddThh:mm:ss.SSSZ
const getTimestamp = () => {
- return moment().utc().format("YYYYMMDDTHH:mm:ss.SSS[Z]");
+ // "YYYY-MM-DDTHH:mm:ss.SSS[Z]
+ return new Date().toISOString();
};
// Save on request for later use
diff --git a/samples-doc/container-event-express/terraform/provider.tf b/samples-doc/container-event-express/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/container-event-express/terraform/provider.tf
+++ b/samples-doc/container-event-express/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/container-event-koa/README.md b/samples-doc/container-event-koa/README.md
index 814703c..4864c15 100644
--- a/samples-doc/container-event-koa/README.md
+++ b/samples-doc/container-event-koa/README.md
@@ -1,4 +1,4 @@
# Container-event-koa
-Example on how to deploy a FunctionGraph **Event** Function as a container image using the [Node-js Koa framework](https://koajs.com/)
+Example on how to deploy a FunctionGraph **Event** Function as a container image using the [Node-js Koa framework](https://koajs.com/).
diff --git a/samples-doc/container-event-koa/package.json b/samples-doc/container-event-koa/package.json
index 039ea82..a874aa0 100644
--- a/samples-doc/container-event-koa/package.json
+++ b/samples-doc/container-event-koa/package.json
@@ -19,8 +19,7 @@
"dependencies": {
"@koa/router": "^15.3.0",
"koa": "^3.1.1",
- "koa-bodyparser": "^4.4.1",
- "moment": "^2.30.1"
+ "koa-bodyparser": "^4.4.1"
},
"scripts": {
"dev": "NODE_DEBUG=koa* node -harmony src/index.js",
diff --git a/samples-doc/container-event-koa/src/index.js b/samples-doc/container-event-koa/src/index.js
index 3d19cd3..7430dd5 100644
--- a/samples-doc/container-event-koa/src/index.js
+++ b/samples-doc/container-event-koa/src/index.js
@@ -4,7 +4,6 @@ const Koa = require("koa");
const KoaRouter = require("@koa/router");
const bodyParser = require("koa-bodyparser");
-const moment = require("moment");
const app = new Koa();
const router = new KoaRouter();
@@ -13,9 +12,9 @@ const router = new KoaRouter();
app.use(async (ctx, next) => {
const requestId = ctx.get("X-Cff-Request-Id") || "no-request-id";
- // Function to format timestamp as yyyymmddThh:mm:ss.SSSZ
+ // Function to format timestamp as yyyy-mm-ddThh:mm:ss.SSSZ
const getTimestamp = () => {
- return moment().utc().format("YYYYMMDDTHH:mm:ss.SSS[Z]");
+ return new Date().toISOString();
};
// Create a contextual logger that includes timestamp and request ID
diff --git a/samples-doc/container-event-koa/terraform/provider.tf b/samples-doc/container-event-koa/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/container-event-koa/terraform/provider.tf
+++ b/samples-doc/container-event-koa/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/container-http-koa/Makefile b/samples-doc/container-http-koa/Makefile
index d0431a2..3aa4f87 100644
--- a/samples-doc/container-http-koa/Makefile
+++ b/samples-doc/container-http-koa/Makefile
@@ -38,7 +38,7 @@ test_local:
-H "X-Cff-Func-Timeout: 30" \
-H 'Content-Type: application/json' \
-d '{"key":"Hello World of FunctionGraph"}' \
- localhost:8000/invoke
+ localhost:8000/index
@echo ""
clean:
diff --git a/samples-doc/container-http-koa/README.md b/samples-doc/container-http-koa/README.md
index d7dcf57..b9a98c7 100644
--- a/samples-doc/container-http-koa/README.md
+++ b/samples-doc/container-http-koa/README.md
@@ -1,3 +1,3 @@
# Container-http-koa
-Example on how to deploy a FunctionGraph **HTTP** Function as a container image using the [Node-js Koa framework](https://koajs.com/)
\ No newline at end of file
+Example on how to deploy a FunctionGraph **HTTP** Function as a container image using the [Node-js Koa framework](https://koajs.com/).
\ No newline at end of file
diff --git a/samples-doc/container-http-koa/entrypoint.sh b/samples-doc/container-http-koa/entrypoint.sh
new file mode 100644
index 0000000..9fa9c61
--- /dev/null
+++ b/samples-doc/container-http-koa/entrypoint.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cd /home/paas_user
+npm start
diff --git a/samples-doc/container-http-koa/package.json b/samples-doc/container-http-koa/package.json
index d6d4198..434d7b3 100644
--- a/samples-doc/container-http-koa/package.json
+++ b/samples-doc/container-http-koa/package.json
@@ -19,8 +19,7 @@
"dependencies": {
"@koa/router": "^15.3.0",
"koa": "^3.1.1",
- "koa-bodyparser": "^4.4.1",
- "moment": "^2.30.1"
+ "koa-bodyparser": "^4.4.1"
},
"scripts": {
"dev": "NODE_DEBUG=koa* node -harmony src/index.js",
diff --git a/samples-doc/container-http-koa/src/index.js b/samples-doc/container-http-koa/src/index.js
index 581e4e5..06efb6e 100644
--- a/samples-doc/container-http-koa/src/index.js
+++ b/samples-doc/container-http-koa/src/index.js
@@ -4,7 +4,6 @@ const Koa = require("koa");
const KoaRouter = require("@koa/router");
const bodyParser = require("koa-bodyparser");
-const moment = require("moment");
const app = new Koa();
const router = new KoaRouter();
@@ -13,9 +12,9 @@ const router = new KoaRouter();
app.use(async (ctx, next) => {
const requestId = ctx.get("X-Cff-Request-Id") || "no-request-id";
- // Function to format timestamp as yyyymmddThh:mm:ss.SSSZ
- const getTimestamp = () => {
- return moment().utc().format("YYYYMMDDTHH:mm:ss.SSS[Z]");
+ // Function to format timestamp as yyyy-mm-ddThh:mm:ss.SSSZ
+ const getTimestamp = () => {
+ return new Date().toISOString();
};
// Create a contextual logger that includes timestamp and request ID
diff --git a/samples-doc/container-http-koa/terraform/provider.tf b/samples-doc/container-http-koa/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/container-http-koa/terraform/provider.tf
+++ b/samples-doc/container-http-koa/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/deploy-from-obs/terraform/code_from_obs_bucket.tf b/samples-doc/deploy-from-obs/terraform/code_from_obs_bucket.tf
index 19fad98..d4d441a 100644
--- a/samples-doc/deploy-from-obs/terraform/code_from_obs_bucket.tf
+++ b/samples-doc/deploy-from-obs/terraform/code_from_obs_bucket.tf
@@ -1,9 +1,8 @@
-
###################################################################################
# Code bucket to store function code zip file
###################################################################################
resource "opentelekomcloud_obs_bucket" "codebucket" {
- bucket = format("%s-%s", var.prefix, "codebucket")
+ bucket = format("%s-%s-%s", var.prefix, "codebucket", var.tag_app_group)
acl = "private"
tags = {
@@ -21,112 +20,3 @@ resource "opentelekomcloud_obs_bucket_object" "code_object" {
etag = filemd5(var.zip_file_name)
content_type = "application/zip"
}
-
-###################################################################################
-# Store md5 of zip file in state to trigger update if file changes
-###################################################################################
-resource "terraform_data" "replacement" {
- input = [
- filemd5(var.zip_file_name)
- ]
-}
-
-###################################################################################
-# Get X_SUBJECT_TOKEN for User via HTTP POST to IAM Endpoint
-# Using a user token does not require to sign requests
-# Terraform http provider is used as it supports reading response headers
-###################################################################################
-data "http" "GET_X_SUBJECT_TOKEN" {
- depends_on = [ opentelekomcloud_fgs_function_v2.MyFunction ]
-
- url = format("%s/auth/tokens?nocatalog=true", var.OTC_IAM_ENDPOINT)
- method = "POST"
-
- request_headers = {
- "Content-Type" = "application/json;charset=UTF-8"
- }
-
- request_body = jsonencode({
- auth = {
- identity = {
- methods = ["password"],
- password = {
- user = {
- name = var.OTC_USER_NAME,
- password = var.OTC_USER_PASSWORD,
- domain = {
- name = var.OTC_SDK_DOMAIN_NAME
- }
- }
- }
- },
- scope = {
- domain = {
- name = var.OTC_SDK_DOMAIN_NAME
- },
- project = {
- id = var.OTC_SDK_PROJECTID
- }
- }
- }
- })
-}
-
-provider "terracurl" {
- # no configuration required
-}
-
-############################################################################
-# Update Function Code via HTTP PUT to FunctionGraph Endpoint
-# Terraform terracurl provider is used as it supports PUT method and
-# can ignore "409 Conflict" response code.
-# (reading response headers is not supported)
-#
-# see: https://docs.otc.t-systems.com/function-graph/api-ref/api/function_lifecycle_management/modifying_the_code_of_a_function.html#functiongraph-06-0110
-############################################################################
-
-resource "terracurl_request" "update_function_code" {
- name = "UpdateFunctionCode"
-
- depends_on = [
- opentelekomcloud_fgs_function_v2.MyFunction,
- opentelekomcloud_obs_bucket_object.code_object,
- terraform_data.replacement
- ]
-
- url = format("%s/v2/%s/fgs/functions/%s:%s/code",
- var.OTC_FGS_ENDPOINT,
- var.OTC_SDK_PROJECTID,
- opentelekomcloud_fgs_function_v2.MyFunction.urn,
- "latest")
- method = "PUT"
-
- headers = {
- "Content-Type" = "application/json;charset=UTF-8"
- "X-Auth-Token" = data.http.GET_X_SUBJECT_TOKEN.response_headers["X-Subject-Token"]
- "X-Project-Id" = var.OTC_SDK_PROJECTID
- }
-
- request_body = jsonencode({
- code_filename = basename(var.zip_file_name),
- code_type = "obs",
- code_url = format("https://%s/code/%s",
- opentelekomcloud_obs_bucket.codebucket.bucket_domain_name,
- basename(var.zip_file_name))
- })
-
- # Accept response codes 200 (OK) and 409 (Conflict).
- # 409 is returned if trying to replace code with same code.
- # (FSS.0409 The specified resource already exists.)
- response_codes = ["200", "409"]
-
- lifecycle {
- replace_triggered_by = [
- terraform_data.replacement
- ]
- # ignore changes to headers as X-Auth-Token will change on each run
- ignore_changes = [headers]
- }
-
-}
-
diff --git a/samples-doc/deploy-from-obs/terraform/function.tf b/samples-doc/deploy-from-obs/terraform/function.tf
index c48a351..ec61af1 100644
--- a/samples-doc/deploy-from-obs/terraform/function.tf
+++ b/samples-doc/deploy-from-obs/terraform/function.tf
@@ -2,7 +2,6 @@
# Create nodejs event function
##########################################################
resource "opentelekomcloud_fgs_function_v2" "MyFunction" {
- depends_on = [opentelekomcloud_obs_bucket_object.code_object]
name = format("%s_%s", var.prefix, var.function_name)
app = "default"
@@ -21,6 +20,8 @@ resource "opentelekomcloud_fgs_function_v2" "MyFunction" {
"code",
basename(var.zip_file_name)
)
+ # on change of the code object etag (hash) new code version will be deployed.
+ source_code_hash = opentelekomcloud_obs_bucket_object.code_object.etag
###### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ######
description = var.description
diff --git a/samples-doc/deploy-from-obs/terraform/provider.tf b/samples-doc/deploy-from-obs/terraform/provider.tf
index 78d939a..e9678a6 100644
--- a/samples-doc/deploy-from-obs/terraform/provider.tf
+++ b/samples-doc/deploy-from-obs/terraform/provider.tf
@@ -4,17 +4,6 @@
# - Declared as sensitive --> Not printed in console or log if used in resources
# ----------------------------------------------------------------------------
-variable "OTC_USER_NAME" {
- description = "Username for OTC"
- type = string
-}
-
-variable "OTC_USER_PASSWORD" {
- description = "Password for OTC"
- type = string
- sensitive = true
-}
-
# set by environment variable TF_VAR_OTC_SDK_AK
variable "OTC_SDK_AK" {
description = "Personal access key"
@@ -67,15 +56,9 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.65"
+ version = ">= 1.36.68"
}
- # terracurl provider to perform HTTP requests
- # see https://registry.terraform.io/providers/devops-rob/terracurl/latest
- terracurl = {
- source = "devops-rob/terracurl"
- version = "2.3.0"
- }
}
backend "s3" {
# See: https://registry.terraform.io/providers/opentelekomcloud/opentelekomcloud/latest/docs/guides/backends
diff --git a/samples-doc/deploy-from-obs/terraform/variables.tf b/samples-doc/deploy-from-obs/terraform/variables.tf
index 52d7f17..713dfa1 100644
--- a/samples-doc/deploy-from-obs/terraform/variables.tf
+++ b/samples-doc/deploy-from-obs/terraform/variables.tf
@@ -26,7 +26,7 @@ variable "initializer_name" {
default = "src/index.initializer"
}
-# name of zip file to deploy, generated by 'mvn package' command
+# name of zip file to deploy, generated by 'npm pack' command
variable "zip_file_name" {
type = string
default = "../deploy-from-obs.zip"
diff --git a/samples-doc/deploy-from-zip/terraform/provider.tf b/samples-doc/deploy-from-zip/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/deploy-from-zip/terraform/provider.tf
+++ b/samples-doc/deploy-from-zip/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/deploy-from-zip/terraform/variables.tf b/samples-doc/deploy-from-zip/terraform/variables.tf
index 56975c4..563ca83 100644
--- a/samples-doc/deploy-from-zip/terraform/variables.tf
+++ b/samples-doc/deploy-from-zip/terraform/variables.tf
@@ -26,7 +26,7 @@ variable "initializer_name" {
default = "src/index.initializer"
}
-# name of zip file to deploy, generated by 'mvn package' command
+# name of zip file to deploy, generated by 'npm pack' command
variable "zip_file_name" {
type = string
default = "../deploy-from-zip.zip"
diff --git a/samples-doc/event-sdk-obs/terraform/provider.tf b/samples-doc/event-sdk-obs/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/event-sdk-obs/terraform/provider.tf
+++ b/samples-doc/event-sdk-obs/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/invoke-fg/README.md b/samples-doc/invoke-fg/README.md
index 011aa58..c6ffc2e 100644
--- a/samples-doc/invoke-fg/README.md
+++ b/samples-doc/invoke-fg/README.md
@@ -6,7 +6,7 @@
| Environment variable | Value |
| -------------------- | ------------------------ |
-| ``OTC_SDK_PROJECT_ID`` | Project ID
+| ``OTC_SDK_PROJECTID`` | Project ID
| ``OTC_SDK_REGION`` | Region, defualt: "eu-de"
| ``OTC_SDK_AK`` | Access Key (*)
| ``OTC_SDK_SK`` | Secret Key
@@ -17,7 +17,7 @@
Deploy following FunctionGraph function using console:
-* **Project** : ``OTC_SDK_PROJECT_ID`` (see above)
+* **Project** : ``OTC_SDK_PROJECTID`` (see above)
* **Region**: ``OTC_SDK_REGION`` (see above)
* **Name**: ``nodejs-sample-invoke-function``
* **Runtime**: ``Node.js 20.15``
diff --git a/samples-doc/invoke-fg/src/invokeASyncFetch_AKSK.js b/samples-doc/invoke-fg/src/invokeASyncFetch_AKSK.js
index eb84dc0..c286f02 100644
--- a/samples-doc/invoke-fg/src/invokeASyncFetch_AKSK.js
+++ b/samples-doc/invoke-fg/src/invokeASyncFetch_AKSK.js
@@ -3,7 +3,7 @@ const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
-const projectId = process.env.OTC_SDK_PROJECT_ID;
+const projectId = process.env.OTC_SDK_PROJECTID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
diff --git a/samples-doc/invoke-fg/src/invokeASync_AKSK.js b/samples-doc/invoke-fg/src/invokeASync_AKSK.js
index f28ff4f..5b64956 100644
--- a/samples-doc/invoke-fg/src/invokeASync_AKSK.js
+++ b/samples-doc/invoke-fg/src/invokeASync_AKSK.js
@@ -5,7 +5,7 @@ const path = require("path");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
-const projectId = process.env.OTC_SDK_PROJECT_ID;
+const projectId = process.env.OTC_SDK_PROJECTID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
diff --git a/samples-doc/invoke-fg/src/invokeSyncFetch_AKSK.js b/samples-doc/invoke-fg/src/invokeSyncFetch_AKSK.js
index ec4269f..35094c4 100644
--- a/samples-doc/invoke-fg/src/invokeSyncFetch_AKSK.js
+++ b/samples-doc/invoke-fg/src/invokeSyncFetch_AKSK.js
@@ -3,7 +3,7 @@ const { Signer, HttpRequest } = require("otc-api-sign-sdk-nodejs");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
-const projectId = process.env.OTC_SDK_PROJECT_ID;
+const projectId = process.env.OTC_SDK_PROJECTID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
diff --git a/samples-doc/invoke-fg/src/invokeSync_AKSK.js b/samples-doc/invoke-fg/src/invokeSync_AKSK.js
index 5824b6a..6b5bd2c 100644
--- a/samples-doc/invoke-fg/src/invokeSync_AKSK.js
+++ b/samples-doc/invoke-fg/src/invokeSync_AKSK.js
@@ -5,7 +5,7 @@ const path = require("path");
const region = process.env.OTC_SDK_REGION || "eu-de";
const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
-const projectId = process.env.OTC_SDK_PROJECT_ID;
+const projectId = process.env.OTC_SDK_PROJECTID;
const ak = process.env.OTC_SDK_AK;
const sk = process.env.OTC_SDK_SK;
diff --git a/samples-doc/invoke-fg2fg-token/README.md b/samples-doc/invoke-fg2fg-token/README.md
new file mode 100644
index 0000000..857cd51
--- /dev/null
+++ b/samples-doc/invoke-fg2fg-token/README.md
@@ -0,0 +1,6 @@
+# invoke-fg2fg-token
+
+Example on how to invoke a FunctionGraph function from another one using token authorization.
+
+For details, see
+[Invoke FunctionGraph Function from FunctionGraph](https://opentelekomcloud-community.github.io/otc-functiongraph-nodejs-runtime/devguide/invoke/invoke_fg_token.html) in Developer Guide.
diff --git a/samples-doc/invoke-fg2fg-token/index.js b/samples-doc/invoke-fg2fg-token/index.js
new file mode 100644
index 0000000..992f12e
--- /dev/null
+++ b/samples-doc/invoke-fg2fg-token/index.js
@@ -0,0 +1,68 @@
+"use strict";
+const https = require("https");
+
+exports.handler = async function (event, context) {
+
+ const logger = context.getLogger();
+ const token = context.getToken();
+
+
+ // get the URN of the function to be called from user data
+ const CALL_FG_URN = context.getUserData("CALL_FG_URN");
+
+ // get region from function URN
+ const region = CALL_FG_URN.split(":")[2] || "eu-de";
+
+ // FunctionGraph endpoint
+ const fgEndpoint = `https://functiongraph.${region}.otc.t-systems.com`;
+
+ // get projectId from Runtime environment variable (set in FG backend)
+ const projectId = context.getProjectID();
+
+ // Endpoint for asynchronous invocation
+ // const invokeURI = `${fgEndpoint}/v2/${projectId}/fgs/functions/${CALL_FG_URN}/invocations-async`;
+ // or synchronous invocation
+ const invokeURI = `${fgEndpoint}/v2/${projectId}/fgs/functions/${CALL_FG_URN}/invocations`;
+
+ // set body according to your function input
+ const body = {
+ key: "Hello FunctionGraph",
+ };
+ const payload = JSON.stringify(body);
+
+ // set headers
+ const headers = {
+ "Content-Type": "application/json;charset=utf8",
+ "x-auth-token": token,
+ };
+
+
+ return new Promise((resolve, reject) => {
+ const req = https.request(invokeURI, { method: "POST", headers }, (res) => {
+ res.setEncoding("utf8");
+
+ let responseBody = "";
+ res.on("data", (chunk) => {
+ responseBody += chunk;
+ });
+
+ res.on("end", () => {
+ logger.info("Response: ", responseBody);
+ if (res.statusCode && res.statusCode >= 400) {
+ reject(
+ new Error(
+ `Backend request failed with status ${res.statusCode}: ${responseBody}`,
+ ),
+ );
+ return;
+ }
+
+ resolve(responseBody);
+ });
+ });
+
+ req.on("error", reject);
+ req.write(payload);
+ req.end();
+ });
+};
diff --git a/samples-doc/invoke-fg2fg-token/package.json b/samples-doc/invoke-fg2fg-token/package.json
new file mode 100644
index 0000000..2a05cd3
--- /dev/null
+++ b/samples-doc/invoke-fg2fg-token/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "invoke-fg2fg-token",
+ "version": "1.0.0",
+ "private": true,
+ "description": "Invoke FunctionGraph function from FunctionGraph function using token",
+ "main": "index.js",
+ "type": "commonjs",
+ "engines": {
+ "node": "20.15.1"
+ },
+ "scripts": {
+ "postpack": "name=$(bash -c 'echo \"${npm_package_name////-}-${npm_package_version}\" | sed \"s/@/ /g\"') && rm -f ${name}.zip && tarball=\"${name}.tgz\"; tar -tf $tarball | sed 's/^package\\///' | zip -@r ${name}.zip; rm $tarball"
+ },
+ "license": "Apache-2.0",
+ "dependencies": {
+ },
+ "bundleDependencies": [
+ ],
+ "files": [
+ "*.js",
+ "src/**/*",
+ "lib/**/*"
+ ]
+}
diff --git a/samples-doc/package.json b/samples-doc/package.json
index 75cccd0..85ded95 100644
--- a/samples-doc/package.json
+++ b/samples-doc/package.json
@@ -12,12 +12,11 @@
"version": "1.0.0",
"author": "T Cloud Public",
"license": "Apache-2.0",
- "workspaces": [
- "scratch-event-apig",
- "scratch-event-timer"
- ],
+
"scripts": {
"test": "",
- "testall": "npm run test --workspaces"
+ "test:scratch-event-apig": "cd scratch-event-apig && npm install && npm test",
+ "test:scratch-event-timer": "cd scratch-event-timer && npm install && npm test",
+ "test:all": "npm run test:scratch-event-apig && npm run test:scratch-event-timer"
}
}
diff --git a/samples-doc/scratch-event-async/terraform/provider.tf b/samples-doc/scratch-event-async/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/scratch-event-async/terraform/provider.tf
+++ b/samples-doc/scratch-event-async/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/scratch-event-dms4rabbitmq/README.md b/samples-doc/scratch-event-dms4rabbitmq/README.md
deleted file mode 100644
index 97636a2..0000000
--- a/samples-doc/scratch-event-dms4rabbitmq/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Scratch-event-dms4rabbitmq
-
-Example on how to use an event function with an DMS (for RabbitMQ) trigger.
\ No newline at end of file
diff --git a/samples-doc/scratch-event-dms4rabbitmq/package.json b/samples-doc/scratch-event-dms4rabbitmq/package.json
deleted file mode 100644
index 31f9969..0000000
--- a/samples-doc/scratch-event-dms4rabbitmq/package.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
- "name": "scratch-event-dms4rabbitmq",
- "version": "1.0.0",
- "description": "A sample for DMS for RabbitMQ event processing with scratch event",
- "homepage": "https://opentelekomcloud-community.github.io/otc-functiongraph-nodejs-runtime",
- "bugs": {
- "url": "https://github.com/opentelekomcloud-community/otc-functiongraph-nodejs-runtime/issues"
- },
- "repository": {
- "type": "git",
- "url": "git+https://github.com/opentelekomcloud-community/otc-functiongraph-nodejs-runtime.git"
- },
- "main": "src/index.js",
- "type": "commonjs",
- "engines": {
- "node": "20.15.1"
- },
- "cpu": [
- "x64"
- ],
- "scripts": {
- "test": "node ./test/index.test.js",
- "postpack": "rm -f ${npm_package_name}.zip && tarball=\"${npm_package_name}-${npm_package_version}.tgz\"; tar -tf $tarball | sed 's/^package\\///' | zip -@r ${npm_package_name}.zip; rm $tarball"
- },
- "devDependencies": {
- "@opentelekomcloud-community/fg-runtime": "file:../../fg-runtime"
- },
- "dependencies": {
- "@opentelekomcloud-community/fg-dms4rabbitmq-event": "file:../../fg-events/fg-dms4rabbitmq-event"
- },
- "files": [
- "src/**/*",
- "lib/**/*"
- ],
- "bundleDependencies": [
- "@opentelekomcloud-community/fg-dms4rabbitmq-event"
- ]
-}
diff --git a/samples-doc/scratch-event-dms4rabbitmq/resources/rabbitmq_event.json b/samples-doc/scratch-event-dms4rabbitmq/resources/rabbitmq_event.json
deleted file mode 100644
index 3c435bf..0000000
--- a/samples-doc/scratch-event-dms4rabbitmq/resources/rabbitmq_event.json
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- "event_version": "v1.0",
- "event_time": 1714040037,
- "trigger_type": "RABBITMQ",
- "region": "region",
- "instance_id": "4140112c-85fc-40b8-bf7f-1ced2691a0a6",
- "records": [
- {
- "messages": [
- "rabbitmq message1",
- "rabbitmq message2",
- "rabbitmq message3",
- "rabbitmq message4",
- "rabbitmq message5"
- ],
- "topic_id": "topic"
- }
- ]
-}
\ No newline at end of file
diff --git a/samples-doc/scratch-event-dms4rabbitmq/src/index.js b/samples-doc/scratch-event-dms4rabbitmq/src/index.js
deleted file mode 100644
index 61e1a03..0000000
--- a/samples-doc/scratch-event-dms4rabbitmq/src/index.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const { DMS4RabbitMQEvent } = require("@opentelekomcloud-community/fg-dms4rabbitmq-event");
-
-exports.initializer = function (context, callback) {
- const logger = context.getLogger();
- logger.info("Function initialized");
- callback(null, "");
-};
-
-exports.handler = async function (event, context) {
- const logger = context.getLogger();
-
- logger.info("Function Name:", context.getFunctionName());
-
- const dms = new DMS4RabbitMQEvent(event);
-
- logger.info("Trigger type:", dms.getTriggerType());
-
- const output = {
- trigger_type: dms.getTriggerType(),
- };
-
- return output;
-};
diff --git a/samples-doc/scratch-event-dms4rabbitmq/test/index.test.js b/samples-doc/scratch-event-dms4rabbitmq/test/index.test.js
deleted file mode 100644
index 482f762..0000000
--- a/samples-doc/scratch-event-dms4rabbitmq/test/index.test.js
+++ /dev/null
@@ -1,32 +0,0 @@
-const { randomUUID } = require('crypto');
-
-const { Context } = require("@opentelekomcloud-community/fg-runtime");
-const { handler } = require("../src/index");
-
-const event = require("../resources/rabbitmq_event.json");
-
-async function runTest() {
-
- const context = new Context({
- requestID: randomUUID(),
- funcEnv: {
- RUNTIME_FUNC_NAME: "rabbitmq-test",
- RUNTIME_PACKAGE: "default",
- RUNTIME_PROJECT_ID: process.env.OTC_SDK_PROJECTID,
- RUNTIME_FUNC_VERSION: "latest",
- RUNTIME_MEMORY: "128",
- RUNTIME_CPU: "1",
- RUNTIME_TIMEOUT: "5",
- },
-
- });
-
- const result = await handler(event, context);
-
- console.log("Result:", result);
-}
-
-// Run the examples
-if (require.main === module) {
- runTest().catch(console.error);
-}
\ No newline at end of file
diff --git a/samples-doc/scratch-event-sync/terraform/provider.tf b/samples-doc/scratch-event-sync/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/scratch-event-sync/terraform/provider.tf
+++ b/samples-doc/scratch-event-sync/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/scratch-event-timer/terraform/provider.tf b/samples-doc/scratch-event-timer/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/scratch-event-timer/terraform/provider.tf
+++ b/samples-doc/scratch-event-timer/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/samples-doc/scratch-http/package.json b/samples-doc/scratch-http/package.json
index 394fef3..019e9e2 100644
--- a/samples-doc/scratch-http/package.json
+++ b/samples-doc/scratch-http/package.json
@@ -28,14 +28,12 @@
"dependencies": {
"@koa/router": "^15.3.0",
"koa": "^3.1.1",
- "koa-bodyparser": "^4.4.1",
- "moment": "^2.30.1"
+ "koa-bodyparser": "^4.4.1"
},
"bundleDependencies": [
"@koa/router",
"koa",
- "koa-bodyparser",
- "moment"
+ "koa-bodyparser"
],
"files": [
"src/**/*",
diff --git a/samples-doc/scratch-http/src/index.js b/samples-doc/scratch-http/src/index.js
index ac13a05..1672cd3 100644
--- a/samples-doc/scratch-http/src/index.js
+++ b/samples-doc/scratch-http/src/index.js
@@ -4,7 +4,6 @@ const Koa = require("koa");
const KoaRouter = require("@koa/router");
const bodyParser = require("koa-bodyparser");
-const moment = require("moment");
const app = new Koa();
const router = new KoaRouter();
@@ -13,9 +12,9 @@ const router = new KoaRouter();
app.use(async (ctx, next) => {
const requestId = ctx.get("X-Cff-Request-Id") || "no-request-id";
- // Function to format timestamp as yyyymmddThh:mm:ss.SSSZ
- const getTimestamp = () => {
- return moment().utc().format("YYYYMMDDTHH:mm:ss.SSS[Z]");
+ // Function to format timestamp as yyyy-mm-ddThh:mm:ss.SSSZ
+ const getTimestamp = () => {
+ return new Date().toISOString();
};
// Create a contextual logger that includes timestamp and request ID
diff --git a/samples-doc/scratch-http/terraform/provider.tf b/samples-doc/scratch-http/terraform/provider.tf
index d004296..65b59e3 100644
--- a/samples-doc/scratch-http/terraform/provider.tf
+++ b/samples-doc/scratch-http/terraform/provider.tf
@@ -52,7 +52,7 @@ terraform {
opentelekomcloud = {
source = "opentelekomcloud/opentelekomcloud"
- version = ">= 1.36.57"
+ version = ">= 1.36.68"
}
}
backend "s3" {
diff --git a/utils/tokenFromUsername.sh b/utils/tokenFromUsername.sh
index acf755b..ea09fed 100755
--- a/utils/tokenFromUsername.sh
+++ b/utils/tokenFromUsername.sh
@@ -60,7 +60,7 @@ token=$(curl -i -s \
-d "${payload}" \
-o /dev/null \
--dump-header /dev/stdout \
-${OTC_IAM_ENDPOINT}/auth/tokens?nocatalog=true \
+"${OTC_IAM_ENDPOINT}/auth/tokens?nocatalog=true" \
| grep -i ^X-Subject-Token: | cut -d' ' -f2)
if [ "$DEBUG" -eq 1 ]; then