Skip to content

/AWS1/IF_NWS=>CREATERULE()

About CreateRule

Creates a rule. A rule defines a network security configuration to enforce, such as an AWS WAF rule group or configuration data. Use isPublished to create the rule in published (ACTIVE) or draft (DRAFT) state.

Method Signature

METHODS /AWS1/IF_NWS~CREATERULE
  IMPORTING
    !IV_CLIENTTOKEN TYPE /AWS1/NWSIDEMPOTENCYTOKEN OPTIONAL
    !IV_RULENAME TYPE /AWS1/NWSRULENAME OPTIONAL
    !IV_FIREWALLTYPE TYPE /AWS1/NWSRULEFIREWALLTYPE OPTIONAL
    !IV_RULETYPE TYPE /AWS1/NWSRULETYPE OPTIONAL
    !IV_RULEDESCRIPTION TYPE /AWS1/NWSDESCRIPTION OPTIONAL
    !IO_CONFIGURATION TYPE REF TO /AWS1/CL_RT_DOCUMENT OPTIONAL
    !IV_ISPUBLISHED TYPE /AWS1/NWSISPUBLISHED OPTIONAL
    !IT_TAGS TYPE /AWS1/CL_NWSTAGMAP_W=>TT_TAGMAP OPTIONAL
  RETURNING
    VALUE(OO_OUTPUT) TYPE REF TO /aws1/cl_nwscreateruleoutput
  RAISING
    /AWS1/CX_NWSACCESSDENIEDEX
    /AWS1/CX_NWSCONFLICTEXCEPTION
    /AWS1/CX_NWSINTERNALSERVEREX
    /AWS1/CX_NWSSERVICEQUOTAEXCDEX
    /AWS1/CX_NWSSERVICEUNAVAILEX
    /AWS1/CX_NWSTAGPOLICYVIOEX
    /AWS1/CX_NWSTHROTTLINGEX
    /AWS1/CX_NWSVLDTNEXCEPTION
    /AWS1/CX_NWSCLIENTEXC
    /AWS1/CX_NWSSERVEREXC
    /AWS1/CX_RT_TECHNICAL_GENERIC
    /AWS1/CX_RT_SERVICE_GENERIC.

IMPORTING

Required arguments:

iv_rulename TYPE /AWS1/NWSRULENAME /AWS1/NWSRULENAME

The name of the rule.

iv_firewalltype TYPE /AWS1/NWSRULEFIREWALLTYPE /AWS1/NWSRULEFIREWALLTYPE

The firewall type associated with the resource.

iv_ruletype TYPE /AWS1/NWSRULETYPE /AWS1/NWSRULETYPE

The type of the rule. CONFIGURATION rules contain firewall settings, and INSPECTION rules contain rule groups.

io_configuration TYPE REF TO /AWS1/CL_RT_DOCUMENT /AWS1/CL_RT_DOCUMENT

The firewall configuration for the rule, as a JSON document. The structure depends on the rule's firewall type and rule type. For an AWS WAF INSPECTION rule, provide an AWS WAF rule group. For an AWS WAF CONFIGURATION rule, provide a single web ACL setting, such as DefaultAction or VisibilityConfig; use wafConfigDataType to declare which setting the document contains. For the schema of each setting and complete examples, see Writing rule configurations in the AWS Network Security Manager Developer Guide.

Optional arguments:

iv_clienttoken TYPE /AWS1/NWSIDEMPOTENCYTOKEN /AWS1/NWSIDEMPOTENCYTOKEN

A unique, case-sensitive token that you provide to ensure that the operation completes no more than one time. If you retry a request with the same client token and the same parameters, the service returns the result of the original successful request.

iv_ruledescription TYPE /AWS1/NWSDESCRIPTION /AWS1/NWSDESCRIPTION

A description of the rule.

iv_ispublished TYPE /AWS1/NWSISPUBLISHED /AWS1/NWSISPUBLISHED

Specifies whether to publish the resource. When true, the resource is saved in published (ACTIVE) state. When false, it is saved as a draft (DRAFT). Default: true.

it_tags TYPE /AWS1/CL_NWSTAGMAP_W=>TT_TAGMAP TT_TAGMAP

The tags to add to the resource when it is created.

RETURNING

oo_output TYPE REF TO /aws1/cl_nwscreateruleoutput /AWS1/CL_NWSCREATERULEOUTPUT

Examples

Syntax Example

This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.

DATA(lo_result) = lo_client->createrule(
  io_configuration = /AWS1/CL_RT_DOCUMENT=>FROM_JSON_STR( |\{"foo":"this is a JSON object..."\}| )
  it_tags = VALUE /aws1/cl_nwstagmap_w=>tt_tagmap(
    (
      VALUE /aws1/cl_nwstagmap_w=>ts_tagmap_maprow(
        key = |string|
        value = new /aws1/cl_nwstagmap_w( |string| )
      )
    )
  )
  iv_clienttoken = |string|
  iv_firewalltype = |string|
  iv_ispublished = ABAP_TRUE
  iv_ruledescription = |string|
  iv_rulename = |string|
  iv_ruletype = |string|
).

This is an example of reading all possible response values

lo_result = lo_result.
IF lo_result IS NOT INITIAL.
  lv_ruleid = lo_result->get_ruleid( ).
  lv_rulearn = lo_result->get_rulearn( ).
  lv_rulename = lo_result->get_rulename( ).
  lv_rulefirewalltype = lo_result->get_firewalltype( ).
  lv_ruletype = lo_result->get_ruletype( ).
  lv_description = lo_result->get_ruledescription( ).
  lo_/aws1/cl_rt_document = lo_result->get_configuration( ).
  IF lo_/aws1/cl_rt_document IS NOT INITIAL.
  ENDIF.
  lv_entitystatus = lo_result->get_status( ).
  lv_entityversion = lo_result->get_version( ).
  lv_updatetoken = lo_result->get_updatetoken( ).
  lv_issnapshot = lo_result->get_issnapshot( ).
  lv_haspublishedversion = lo_result->get_haspublishedversion( ).
  lv_datetimestamp = lo_result->get_updatedat( ).
ENDIF.

Create a WAF rule

Creates a new WAF inspection rule in draft state.

DATA(lo_result) = lo_client->createrule(
  io_configuration = /AWS1/CL_RT_DOCUMENT=>FROM_JSON_STR( |\{\}| )
  iv_clienttoken = |550e8400-e29b-41d4-a716-446655440000|
  iv_firewalltype = |WAF|
  iv_ispublished = ABAP_FALSE
  iv_ruledescription = |Blocks requests from known malicious IP addresses|
  iv_rulename = |block-known-bad-ips|
  iv_ruletype = |INSPECTION|
).