Cloud Functions concept
    • PDF

    Cloud Functions concept

    • PDF

    Article Summary

    Available in Classic and VPC

    A few important concepts about Cloud Functions are explained prior to learning overall scenarios of using Cloud Functions. The following are the main concepts to be explained.

    Note

    Refer to Glossary to help understanding of Cloud Functions concepts.

    Namespace

    A namespace is a unique area assigned to each user when they request subscription, which is actually a string created in the form of random numbers. Since all Cloud Functions resources such as packages, actions, and triggers are created under a namespace, all resources that belong to a namespace are deleted when the user cancels subscription. When the user requests subscription again, a new namespace is assigned.
    Namespace is a standard for measuring each user's usage and fees.

    Action

    An action means snippets of a stateless code defined by a user. Actions can be written in various languages including JavaScript, Swift, Java, Python, and PHP. The languages you can use to write actions in NAVER Cloud Platform's Cloud Functions can be seen in Prerequisites for using Cloud Functions.
    An action can be called by a user, or run in response to an event. It can also be run in sequence, receiving another action's result as an input. An action's input and output are JSON values that take the form of key-values. An activation is created every time an action is explicitly executed, or executed as a result of a specific event. For information on activation, refer to Activation.

    Action container

    Each action is run on a container that is independent to another. Every time an action is executed, the user-defined code is run on a container created for that action, and the result is delivered. The container, once created, is kept for a certain time rather than killed immediately. It is reused when the same action is executed. It is automatically deleted afterward, eliminating security problems such as being shared to another user or reused.
    It may take about 50 to 200 ms to create a container when an action is run for the first time. To reduce this time, a technique called "pre-warming" is applied. You can have an action container of a specific language running in advance, using this "pre-warming" technique.

    Sequence

    Sequence means the same thing as sequence action. A sequence action executes multiple actions written in various languages in sequential order. The JSON value returned from the code defined in a previous action is delivered to be used as the action parameter value of the follow-up action.

    compute-compute-15-2-9_workflow_en.png

    The user can implement a simple workflow by branching the action logic by the previous action's results.

    Activation

    An activation means the result of an action or trigger. An activation includes an execution result and metadata. An activation is created every time an action is run, and each activation has a unique ID to be identified with this activation ID. An activation ID is a random alphanumeric value of 32 digits.

    Execution result

    See below for example code and description for each item in the execution result.

    {
        "namespace": "U749rOIuHnuy",
        "name": "rp",
        "version": "0.0.1",
        "subject": "U749rOIuHnuy",
        "activationId": "626c0dfabf274aa7ac0dfabf270aa759",
        "start": 1517461496130,
        "end": 1517461496451,
        "duration": 321,
        "response": {
            "status": "success",
            "statusCode": 0,
            "success": true,
            "result": {
                "status": "ok"
            }
        },
        "logs": [],
        "annotations": [
            {
                "key": "path",
                "value": "U749rOIuHnuy/package/action"
            },
            {
                "key": "waitTime",
                "value": 33
            },
            {
                "key": "kind",
                "value": "nodejs:12"
            },
            {
                "key": "limits",
                "value": {
                    "logs": 10,
                    "memory": 256,
                    "timeout": 60000
                }
            },
            {
                "key": "initTime",
                "value": 262
            }
        ],
        "publish": false
    }
    
    • namespace: namespace where the action (trigger) belongs, a unique space assigned to the user by contract
    • name: action (trigger)'s name
    • activationId: unique ID for the action (trigger) result
    • start: time when the action (trigger) execution was started (ms)
    • end: time when the action (trigger) execution was ended (ms)
    • duration: time taken to carry out the action (trigger) (ms)
    • response: execution result (status) of the action (trigger) The final returned value for the action (trigger) execution is delivered as the result field.
    • logs: log output in the action (trigger) by the user
    • annotations: information related to the action (trigger)
    • publish: whether the action (trigger) is shared
    Note

    If the result option is used for an execution of an action, then only the result information is returned among the components above.

    Metadata

    Metadata related to execution is provided with every action by default. The following is a metadata example code and description of each environment variable in the metadata.

    function main(params) {
        return {
          payload: {
            namespace:  process.env.__OW_NAMESPACE,
            name:       process.env.__OW_ACTION_NAME,
            activation: process.env.__OW_ACTIVATION_ID,
            deadline:   process.env.__OW_DEADLINE
          }
        };
    }
    
    • __OW_NAMESPACE: information for the namespace where the currently running action's execution result will be saved
    • __OW_ACTION_NAME: full name of the action that is currently running
    • __OW_ACTIVATION_ID: activation ID of the action currently running
    • __OW_DEADLINE: deadline before which the action can be run

    Trigger

    A trigger is an object that delivers events that may execute an action through an event of a cloud service or external service linkable from Cloud Functions. In other words, it is used as the channel to receive an event. For instance, a trigger can be created in the following situations.

    • When an address is updated
    • When a document is uploaded to a website
    • When sending an email
    • When there are changes to code (saved) in GitHub
    • When a deployment is finished
    • When an event occurs in an IoT device

    In case a user-registered event occurs, one or more actions can be run in parallel depending on the event. The event's data delivered when the trigger is executed is then delivered as each action's execution parameter.
    Events occurred in or out of NAVER Cloud Platforms are linked to actions through triggers, and the actions can carry out tasks that respond to the events. When you link a trigger and action, the action is run every time the trigger event runs, using the trigger's event parameter.
    You can also link the same trigger with multiple different actions. Sequence actions can also be connected. A trigger can't be included in a package, but it's possible for a trigger to call an action contained in a package.
    A trigger can be activated using a dictionary, which consists of pairs of key and value. A dictionary may also refer to an event. An activation is created every time a trigger is run, in the same way as actions. Each activation has a unique ID to be identified with this activation ID.


    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.