HTTP functions are designed to optimize web services. You can send HTTP requests to URLs to trigger function execution. HTTP functions support APIG triggers only.
const http = require('http'); // Import Node.js core module var server = http.createServer(function (req, res) { //create web server res.writeHead(200, { 'Content-Type': 'text/html' }); res.write('<html><body><h2>This is http function.</h2></body></html>'); res.end(); }); server.listen(8000, '127.0.0.1'); //6 - listen for any incoming requests console.log('Node.js web server at port 8000 is running..')
Example
The content of the bootstrap file is as follows:
/opt/function/runtime/nodejs12.13/rtsp/nodejs/bin/node $RUNTIME_CODE_ROOT/index.js
For HTTP functions in Python, add the -u parameter in the bootstrap file to ensure that logs can be flushed to the disk. Example:
/opt/function/runtime/python3.6/rtsp/python/bin/python3 -u $RUNTIME_CODE_ROOT/index.py
To use another runtime, change the runtime path by referring to Table 1. The code package path does not need to be changed.
Runtime |
Path |
---|---|
Java 8 |
/opt/function/runtime/java8/rtsp/jre/bin/java |
Java 11 |
/opt/function/runtime/java11/rtsp/jre/bin/java |
Node.js 6 |
/opt/function/runtime/nodejs6.10/rtsp/nodejs/bin/node |
Node.js 8 |
/opt/function/runtime/nodejs8.10/rtsp/nodejs/bin/node |
Node.js 10 |
/opt/function/runtime/nodejs10.16/rtsp/nodejs/bin/node |
Node.js 12 |
/opt/function/runtime/nodejs12.13/rtsp/nodejs/bin/node |
Node.js 14 |
/opt/function/runtime/nodejs14.18/rtsp/nodejs/bin/node |
Node.js 16 |
/opt/function/runtime/nodejs16.17/rtsp/nodejs/bin/node |
Node.js 18 |
/opt/function/runtime/nodejs18.15/rtsp/nodejs/bin/node |
Python 2.7 |
/opt/function/runtime/python2.7/rtsp/python/bin/python |
Python 3.6 |
/opt/function/runtime/python3.6/rtsp/python/bin/python3 |
Python 3.9 |
/opt/function/runtime/python3.9/rtsp/python/bin/python3 |
HTTP functions support APIG triggers only.
In this example, Security Authentication is set to None. You need to select an authentication mode based on site requirements.
The following table lists the default request header fields of an HTTP function.
Field |
Description |
---|---|
X-CFF-Request-Id |
ID of the current request |
X-CFF-Memory |
Allocated memory |
X-CFF-Timeout |
Function timeout duration |
X-CFF-Func-Version |
Function version |
X-CFF-Func-Name |
Function name |
X-CFF-Project-Id |
Project ID |
X-CFF-Package |
App to which the function belongs |
X-CFF-Region |
Current region |