Create actions
    • PDF

    Create actions

    • PDF

    Article summary

    Available in Classic

    You can create an action on NAVER Cloud Platform console's Cloud Functions > Action. To create an action, take the following steps:

    1. From NAVER Cloud Platform console's Region menu, click and select the Region you're using.
    2. From the Platform menu, click and select Classic.
    3. Click Services > Compute > Cloud Functions in order.
    4. Click the Action menu.
    5. Click [Create action].
    6. Set up the content of the action to create.
      • Basic information: set up the package it belongs to, action type, name, and description
      • Source code: write the code yourself from the console in the language of your choice or upload a code file
      • Default parameter: write the default parameter code to use for the action
      • Option settings: set up the action's main function name, memory, timeout, and web action
    7. Click [Save].

    Basic information

    Set up basic information required for creating an action. Descriptions of each item in Basic information are as follows:

    • Package: select the package where the action will belong. Click [+Create] to create a new package and add it
    • Type: click to select the action types
      • Basic action: default action type that executes a single action
      • Web action: executes a single action and processes HTTP requests/responses by integrating with API Gateway trigger HTTP method
      • 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, and special characters "_" and "-". However, a hyphen (-) can't be used as the first letter. The name must be unique and not a duplicate of another resource (package, action, trigger) name
      • For example, if the package name is package_name and action name is action_name, the format for the name of the action is as follows:
        • package_name/action_name
    • Description: enter the description of the action to create
    Note
    • It's possible to create an action without selecting a package so that it doesn't belong to any package, but it's 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 learn how to create sequence type actions or sequence web actions, see Sequence action.
    • Make your decisions carefully as an action's type and name can't be edited.

    Source code

    You can write an action code in the language of your choice in the console, or upload a code file. If you don't set up a runtime parameter for the execution point when you write the code, a default parameter from the package or from triggers or actions connected to it will be used. It doesn't apply only to runtime parameters. If you don't write up a code about additional settings, default values will apply for the related settings. Note that some of them may not be edited after creation, so proceed with caution. The description of each item in source code is as follows:

    • Runtime: click to select the language and version environment where the source code will run
    Note

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

    • Type: select the method in which the source code is written
      • Code: write directly on the console
      • File: upload your source code file by clicking Drag and drop the file or click here.
    Caution
    • Java codes can't 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.

    Composition examples

    These are composition examples of source code by language for an action that receives parameter Params, and returns the Name and Place strings if they exist in Params or returns World and Ncloud if they don't exist. See them when you write your source code.

    Note

    The composition method is fixed for the codes to be uploaded in a ZIP or JAR file. Make sure to see the composition guide when you write them.

    • 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 delivering 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 delivered at the time of running the action. However, if you use the encryption settings, the decrypted parameters are applied with the highest priority. Descriptions of each item in Default parameter are as follows:

    cloudfunctions-basicaction-vpc_03_ko

    • Input box: enter in JSON format

    The following is an example code of a JSON default parameter:

    {
      "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 + "!"};
    }
    

    Run 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. For web actions, all requests (GET, POST, PUT, DELETE, and so on) of various types of REST APIs are supported.
    Descriptions of each item in Option settings are as follows:

    • Main function: enter strings to be used as the action's main function or class name
    • Action memory: select the desired memory size
    • Action timeout: enter the maximum time during which the action may run in ms unit. When the entered time is exceeded, it will finish and the execution result will be logged as failed
    • Web action-related settings
      • Use HTTP source: select whether to have the HTTP source sent and processed as is as a web action (True: use HTTP source, False: use JSON object)
      • Header option settings: select whether the header may be edited within the code (True: it can be edited, False: add the CORS header automatically to the response header)

    Configure sequence action scenario

    Configure the sequence action scenario for sequential execution of selected actions. Consider the following before configuration:

    • Sequence actions can include basic actions, web actions, and other sequence actions.
    • For sequence web actions, we recommend adding only web actions or sequence web actions.
    • User action parameters are passed 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

    You can configure the sequence action scenario as follows:

    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
      • Change execution order: drag the action to reorder
      • Delete added action: click cloudfunctions-ico_01

    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.