Basic action
    • PDF

    Basic action

    • PDF

    Article Summary

    Available in VPC

    You can create, edit, and delete basic type actions in the NAVER Cloud Platform console's Cloud Functions > Action. For how to run and monitor actions created, see Running action/trigger and Action.

    Create actions

    Create an action. You can connect a trigger to an action when creating it, or add a trigger for connection if there isn't a trigger to connect. You can also create an action that can work without a trigger connection. Follow these steps to create an action.

    1. From the Region menu on the NAVER Cloud Platform console, click and select the region you're using.
    2. From the Platform menu, click and select VPC.
    3. Click Services > Compute > Cloud Functions in order.
    4. Click the Action menu.
    5. Click the [Create action] button.
    6. Click and select a trigger to connect to the action from Select trigger's Trigger type.
      • Create action without setting up trigger: when you want to create an action without a trigger connection
    7. Click and select the trigger to connect from Name, and then click the [Add] button.
      • Create a new trigger: when there is no trigger to connect, or you want to create a new trigger for connection. For more information on how to use, see Trigger
    8. When the list of triggers to connect appears, check the information, and then click the [Next] button.
    9. Set up the content of the action to create.
    10. Click the [Create] button.

    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 the [Create] button to create a new package and add it
    • Type: select Basic among the action types
      • Basic: run a single action
      • Sequence: connect multiple 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
      • If the package name is package_name and action name is action_name, the format for the name of the action that belongs to the package: {package_name}/{action_name}
    • Description: enter the description of the action to create
    Caution
    • 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.
    • To learn how to create a sequence type action, see Sequence.
    • Make your decisions carefully as an action's name and type 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:

    • Language: select the language in which the source code is written
    • Type: select the method in which the source code is written
      • Code: write directly on the console
      • File: upload the written source code files by clicking Drop files here or click to upload.
    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. Refer to 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. Descriptions of each item in Default parameter are as follows:

    cloudfunctions-basicaction-vpc_03_ko

    • Input box: enter in JSON format

    The following is example code of a JSON default parameter.

    {
      "name": "NCloud",
      "place": "Cloud Function"
    }
    
    • Example code
    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!"}
    

    Encryption of default parameter

    If you want to use data needed for actions safely, you can integrate with Key Management Service by setting encryption of the default parameter of actions. Key Management Service is a service of NAVER Cloud Platform for protecting the key used for encrypting important information of users under strict and safe policies.

    In the action default parameter encryption settings, you can encrypt and safely save the data to be used for actions by using the safe key management service of the Key Management Service and when the actions are executed, you can conveniently use the decrypted data.

    Note
    • Default parameter encryption settings are supported only for VPC platforms.
    • For more information on how to use Key Management Service, see the Key Management Service user guide.
    • If you subscribe to the Key Management Service, an additional fee will be charged.
      For more information on Key Management Service and its pricing plan, see Introduction to Key Management Service.
    • Cloud Functions default parameter uses the key type "AES-256" in the Key Management Service as the master key for encryption. If you determine that encryption/decryption through the AES-256 symmetric key is not appropriate in accordance with the properties of the data, apply a separate data protection method.
    • Keys with the convergent encryption method set are not supported.
    • When using the default parameter encryption settings, the decrypted parameters are given the highest priority.
    Caution
    • To avoid exposing sensitive information, do not record decrypted parameters as logs or include decrypted parameters in the action result.
    • Example
    1. Write it to meet the JSON format of the data to use in the default parameter area. Only string type data with a depth of 1 among the written JSON data is supported for encryption.

    cloudfunctions-basicaction-vpc_04_ko

    1. Change the encryption settings to ON and select the AES-256 type key of the NCloud Key Management Service. You can select 1 key per action.

    cloudfunctions-basicaction-vpc_05_ko

    1. Select the JSON key of the default parameter to encrypt.

    cloudfunctions-basicaction-vpc_06_ko

    1. The default parameter falling under the selected JSON key is encrypted, and the encrypted parameter JSON key is displayed on the lower end of the parameter key area.

    cloudfunctions-basicaction-vpc_07_ko

    1. Action creation is completed and the action is run.

    VPC connection information

    Use an action to be able to access your own VPC resources. If you use Cloud Functions in a VPC environment, then VPC resource connection must be set up. Descriptions of each item in VPC connection information are as follows:

    • VPC: click and select the VPC name to be accessed by the action. To create a new VPC, click the [Create VPC] button
    • Subnet: select the subnet to be used when accessing the selected VPC
      • Types of subnets that can be connected: only private subnets can be connected
      • How to access public subnet resources: available by ACG setting, in the same way as private subnet resources
      • How to use internet communication in the action connected with a private subnet: this can be done by setting up NAT Gateway in the subnet. See the NAT Gateway user guide
    Note

    Cloud Functions supports multi-zone in each Region when you set up VPC resource access to guarantee high availability. Information on the zones supported in each Region are as follows:

    • Korea: KR-2
    • Singapore: SGN-4, SGN-5
    • Japan: JPN-4, JPN-5

    Note that only 1 VPC can be selected for each action. You can add 1 subnet per zone.

    Set ACG

    Once you've completed VPC and subnet settings, you need to set ACG for the resource to be accessed to enable access to the VPC resource within the action code.

    Note

    For more details on how to use ACG, see the ACG user guide.

    When a Cloud Functions action is created in a VPC environment, the alias in the format of cloudfunctions-vpc-{vpc ID} is automatically created as an access source that can be used for ACG setting in the connected VPC environment. The alias that is automatically created must be added to the access source in the ACG’s inbound rule.

    Note

    You can check the VPC ID in the NAVER Cloud Platform console's Services> Networking > VPC > VPC Management.
    cloudfunctions-basicaction-vpc_01_ko

    For instance, in order for an action code to access a server created in the VPC, you should click the Inbound tab menu from Settings of the ACG rule to be applied to the server, and then add cloudfunctions-vpc-{vpc ID} to the Access source.

    cloudfunctions-basicaction-vpc_02_ko

    You can access the Cloud DB created in the VPC by adding the alias automatically created when you create a DB server to an inbound rule of ACG in the same way as the regular servers.

    Note

    After setting up the VPC resource access, you can link Cloud Functions with Cloud DBs and build various services. Visit NAVER Cloud Platform official blog to see examples of providing APIs without application servers by connecting Cloud Functions and Cloud DBs.

    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 API 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. When the entered time is exceeded, it will finish and the execution result will be logged as a failure
    • Set web action: select whether to create a web action (True: create, False: do not create)
      • 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)
      • Set header option: 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)

    Edit actions

    You can edit everything except the name and type of the action. Follow these steps to edit them:

    1. From the Region menu on the NAVER Cloud Platform console, click and select the region you're using.
    2. From the Platform menu, click and select VPC.
    3. Click Services > Compute > Cloud Functions in order.
    4. Click the Action menu.
    5. Click the action to edit in Packages/Actions.
    6. Click the Basic information tab menu and then click the [Edit] button.
    7. Edit the necessary information.
    8. Click the [Save] button.

    Delete action

    You can delete an action. When an action is deleted, the resource and stage information of the external link address connected with the action will also be deleted. In addition, the sequence actions that contain the action to be deleted may also be edited or deleted. Proceed carefully as an action can't be restored once deleted. Follow these steps to delete an action.

    1. From the Region menu on the NAVER Cloud Platform console, click and select the region you're using.
    2. From the Platform menu, click and select VPC.
    3. Click Services > Compute > Cloud Functions in order.
    4. Click the Action menu.
    5. Click the action to delete in Packages/Actions.
    6. Click the Basic information tab menu and then click the [Delete] button.
    7. Click the [Delete] button.

    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.