Create actions

Prev Next

Available in Classic

You can create an action in Cloud Functions > Action on the NAVER Cloud Platform console. To create an action:

  1. In the Classic environment of the NAVER Cloud Platform console, navigate to i_menu > Services > Compute > Cloud Functions.
  2. Click the Action menu.
  3. Click [Create action].
  4. Set up the content of the action to create.
    • Basic information: Set the package, action type, name, and description.
    • Source code: Write code manually in the console using the selected language or upload a code file.
    • Default parameter: Write default parameter code for the action.
    • Option settings: Set the action main function name, memory, timeout, and web action.
  5. Click [Save].

Basic information

Set up basic information required for creating an action. The following describes each basic information item:

  • Package: Select the package the action belongs to. If you need to create a new package to include your action, click [+Create].
  • Type: Select the action type.
    • Basic action: Runs a single action as the basic action type.
    • Web action: Runs a single action and processes HTTP requests and responses when integrated with an API Gateway trigger using the HTTP type.
    • Sequence action: Connect multiple actions and run them in sequence.
    • Sequence web action: Connect multiple web actions and run them in sequence.
  • Name: Enter the action's name by combining upper and lowercase letters, numbers, hyphens, and/or underscores. However, you cannot use hyphen as the first character, and the name cannot duplicate other resource (package, action, trigger) names.
    • For example, if the package name is package_name and the action name is action_name, the action name format within the package is as follows:
      • package_name/action_name
  • Description: Enter a description for the action you want to create.
Note
  • It is possible to create an action without selecting a package so that it does not belong to any package, but it is better to create a package and put the action in the package.
  • For detailed configuration and usage of web actions, see API Gateway trigger.
  • To set sequence type or sequence web actions, see Sequence action.
  • Make your decisions carefully as an action's type and name cannot be edited.

Source code

You can write the action code directly in the console in your desired language or upload a code file. If you do not set runtime parameters at execution time, the default parameters of the package, linked trigger, or action are used. If you do not write separate code for additional settings beyond runtime parameters, default values apply for the related settings, and some values cannot be changed after creation, so proceed with caution. The following describes each source code item:

  • Runtime: Select the language and runtime version for the source code
Note

You can select recommended versions for each language. To select other versions, click others.

  • Type: Select how you want to write the source code.
    • Code: Write manually in the console.
    • File: Click Drag and drop file here or click to select to upload your source code files.
Caution
  • Java codes cannot be written directly on the console. They must be compiled and uploaded as a JAR file.
  • .Net codes can only be uploaded as a ZIP file format.

Code writing examples

There are language-specific code examples of an action that receives the parameter Params and returns the corresponding strings if Name and Place exist in Params, or returns World and Ncloud if they do not. Use this as a reference when writing the source code.

Note

For code uploaded as a ZIP or JAR file, the writing method is predefined. Make sure to follow the writing guide.

  • Node.js

    function main(params) {
        var name = params.name || 'World';
        var place = params.place || 'Ncloud';
        return {payload:  'Hello, ' + name + ' in ' + place + '!'};
    }
    
  • Python 3

    def main(args):
        name = args.get("name", "World")
        place  = args.get("place", "Ncloud")
        return {"payload": "Hello, " + name + " in " + place + "!"}
    
  • Swift 3.1.1

    func main(args: [String:Any]) -> [String:Any] {
        let name = args["name"] ?? "World"
        let place = args["place"] ?? "Ncloud"
        return  [ "payload" : "Hello, \(name) in \(place)"]
    }
    
  • PHP 7

    <?php
    function main(array $args) : array
    {
        $name = $args["name"] ?? "World";
        $place = $args["place"] ?? "Ncloud";
        return ["greeting" => "Hello, $name in $place!"];
    }
    ?>
    
  • Java 8

    import com.google.gson.JsonObject;
    
    public class Hello {
        public static JsonObject main(JsonObject args) {
            String name = "World";
            String place = "Ncloud";
            if (args.has("name"))
                name = args.getAsJsonPrimitive("name").getAsString();
            if (args.has("place"))
                place = args.getAsJsonPrimitive("place").getAsString();
    
            JsonObject response = new JsonObject();
            response.addProperty("payload", "Hello, " + name + " in " + place + "!");
            return response;
        }
    }
    

Default parameter

You can enter a default parameter which can be applied to actions by default rather than forwarding a parameter every time an action is run. An action's default parameter has a higher priority of application than a package parameter, and lower priority of application compared to trigger parameters or runtime parameters which are forwarded at the time of running the action. The following describes each default parameter item:

cloudfunctions-basicaction-vpc_03_ko

  • Input box: Enter values in JSON format.

The following shows an example of default parameters in JSON format:

{
  "name": "NCloud",
  "place": "Cloud Function"
}

Example codes

function main(params) {
  let name = params.name || "World";
  let place = params.place || "Naver";
  return {payload:  "Hello, " + name + " in " + place + "!"};
}

Execution result

{"payload":"Hello, NCloud in Cloud Function!"}

Option settings

You can set up an action's main function name, memory, or timeout, or set up web actions that provide URLs which can be called without a separate user authentication. Web Actions support all types of REST API requests including GET, POST, PUT, and DELETE.
The following describes each option setting item:

  • Main function: Enter the string to be used as the name of the action's main function or class.
  • Action memory: Select the memory size you want to use.
  • Action timeout: Enter the maximum time the action can run in milliseconds. Execution terminates with failure status when this time is exceeded.
  • Web action-related settings
    • Use HTTP raw text: Select whether the web action should receive and process the raw HTTP request. (True: Use HTTP raw text, False: Use JSON object)
    • Header option setting: Select whether headers can be modified in the code. (True: Allowed, False: CORS headers are added automatically to the response.)

Configure sequence action scenario

Configure the sequence action scenario for sequential execution of selected actions. Before configuring the scenario, review the following precautions:

  • Sequence actions can include basic actions, web actions, and other sequence actions.
  • It is recommended to add only web actions or sequence web actions to a sequence web action.
  • User action parameters are forwarded only to the first action. If subsequent actions need to use user action parameter values, explicitly add those values to the results in the preceding action.
  • Each action registered in a sequence action can use its default parameter values. If a default parameter has the same key resulting from a preceding action, the preceding action's result takes precedence.
  • If an error occurs in a preceding action, subsequent actions do not execute.
  • Sequence actions cannot specify a separate execution timeout. The maximum execution time equals the sum of registered action timeouts. Example: If action 1 and action 2 have timeouts of 1 and 3 minutes, respectively, the sequence action can run for up to 4 minutes.

To configure the sequence action scenario in consideration of the above precautions:

  1. In Packages/Actions, click the actions to add to the sequence action.
  2. Set the execution order of the added actions.
    cloudfunctions-sequence-vpc_01_ko
    • Execution order change: Drag the action you want to reorder.
    • Delete added action: Click cloudfunctions-ico_01.