GuideReference
TrainingSupportCommunity
Guide

Behaviors & criteria

Property configuration rules and includes use behaviors to determine the action taken when specific conditions are met. The options you choose define your behavior and the criteria that trigger the behavior's action.

  • Behaviors belong to a specific rule format version and require you use a rule format no earlier than v2023-01-05.
  • Use the same rule format version across your rules and includes.
  • As newer behaviors are not backward compatible, check your rule format against the date located at the top of a behavior's reference page and update your rule format as needed.

Behaviors

Within rules, your behaviors are represented as an array of objects, each object a single behavior with its options.

Default rule behaviors

The default rule is our required base rule. Behaviors you set at the default rule level apply to all requests for your property hostnames unless another rule overrides the settings.

For example, a default rule has two behaviors, origin and cpCode. For all the property's hostnames, the behavior of the origin and CP code is governed by their defined options.

"rules": {
  "name": "default",
  "behaviors": [
    {
      "name": "origin",
      "options": {
        "originType": "CUSTOMER",
        "hostname": "my-behavior-example.com",
        "forwardHostHeader": "REQUEST_HOST_HEADER",
        "cacheKeyHostname": "ORIGIN_HOSTNAME",
        "compress": true,
        "tcipEnabled": false,
        "httpPort": 80
      }
    },
    {
      "name": "cpCode",
      "options": {
        "value": {
          "id": 12345,
          "name": "main site"
        }
      }
    }
  ]
}

Child rules

Nested within your rules are child rules and their behaviors.

Here, a child rule of Compress Text Content has a behavior of gzipResponse with an option.

"children": [
    {
      "name": "Compress Text Content",
      "behaviors": [
        {
          "name": "gzipResponse",
          "options": { "behavior": "ALWAYS" }
        }
      ]
    }
  ]

Criteria

Criteria are the situational conditions that trigger a behavior's action. Except for the default rule, you can have criteria for rules at any level of your rule tree.

In the child rule example above, the compress text content rule has a behavior that's set to always zip content, but if not all content types fit the rule, choose which types do in the criteria.

"criteria": [
  {
    "name": "contentType",
    "options": {
      "matchOperator": "IS_ONE_OF",
      "matchWildcard": true,
      "matchCaseSensitive": false,
      "values": [
        "text/html*",
        "text/css*",
        "application/x-javascript*"
      ]
    }
  }
]

Complete tree

Your property configuration, rules, child rules, and their behaviors and criteria, work together as a rule tree to shape a solution.

The sample code presented so far works together to deliver a solution that uses a customer's origin as the source of truth, its hostname to build out the keys for cached content, and directs requests for information through port 80.

The solution also collects all forwarded request metadata and compresses specific content types to reduce the amount of data sent in responses and increase display speed.

"rules": {
  "name": "default",
  "options": {
      "is_secure": false
  },
  "behaviors": [
    {
      "name": "origin",
      "options": {
        "originType": "CUSTOMER", 
        "hostname": "my-behavior-example.com", 
        "forwardHostHeader": "REQUEST_HOST_HEADER", 
        "cacheKeyHostname": "ORIGIN_HOSTNAME", 
        "compress": true, 
        "enable_true_client_ip": false,
        "httpPort": 80 
      }
    },
    {
      "name": "cpCode", 
      "options": {
        "value": {
            "id": 12345, 
            "name": "main site"
        }
      }
    }
  ],
  "children": [
    {
      "name": "Compress Text Content",
      "behaviors": [
        {
          "name": "gzipResponse",
          "options": { "behavior": "ALWAYS" }
        }
      ],
      "criteria": [
        {
          "name": "contentType",
          "options": {
            "matchOperator": "IS_ONE_OF",
            "matchWildcard": true,
            "matchCaseSensitive": false,
            "values": [
              "text/html*",
              "text/css*",
              "application/x-javascript*"
            ]
          }
        }
      ]
    }
  ]
}

Add behaviors to your rules

  1. Get your rule tree by importing an existing property or create a new property and import its default set of rules.
akamai terraform --edgerc "~/.edgerc" --section default export-property "my-property"

Once it's downloaded, run the included import script to add the property to your state.

  1. Choose behaviors to add, paying attention to any parent/child relationships mentioned on a reference page as some behaviors are dependent on others or on specific rules being present in your tree.
  2. Format the behavior for the default rule or as a child rule and save the behavior by its rule name within the property-snippets directory of your property configuration.

For rule names that contain spaces, replace the space with an underscore.

{
  "behaviors": [
    {
      "name": "logCustom",
      "options": {
        "customLogField": "done",
        "logCustomLogField": true
      }
    }
  ],
  "criteria": [
    {
      "name": "metadataStage",
      "options": {
        "matchOperator": "IS",
        "value": "client-done"
      }
    }
  ],
  "name": "Logging",
  "options": {},
  "criteriaMustSatisfy": "all"
}
{
  "children": [
    {
      "name": "Compress Text Content",
      "behaviors": [
        {
          "name": "gzipResponse",
          "options": { "behavior": "ALWAYS" }
        }
      ]
    }
  ]
}
  1. Use a variable to your behavior in your rules main.json file.
"children": [
    "#include:Logging.json",
    "#include:Compress_Text_Content.json",
  ],
  1. Add your changes to your property configuration.

Pushing changes to your rule tree automatically revises the version of your property configuration to the next major version.

resource "akamai_property" "my-property-behaviors" {
  name        = "My new property rule behaviors"
  product_id  = "prd_SPM"
  contract_id = C-0N7RAC7
  group_id    = 12345
  rule_format = "v2024-10-21"
  rules       = file("${path.root}/main.json") 
}

From here, you have a couple of options.

  • Push your rule changes out without a property activation. This lets you save your updates upstream and continue editing your property.

  • Push your rule changes with a property activation. This will apply your changes to the network you've chosen. Any additional changes you make trigger a new configuration version.

    To activate your property and apply your changes, add a property activation resource to your Terraform configuration.

    resource "akamai_property_activation" "my_activation" {
       property_id                    = "2345"
       network                        = "staging"
       contact                        = ["jsmith@email.com"]
       note                           = "My updated property activation"
       version                        = "3"
       auto_acknowledge_rule_warnings = true
       timeouts {
         default = "1h"
        }
    }
    

Whichever method you chose to manage your behavior changes, run terraform plan to check your syntax and then terraform apply to push your changes upstream.