Table Of Contents

Feedback

User Guide

First time using the AWS CLI? See the User Guide for help getting started.

[ aws . elbv2 ]

create-rule

Description

Creates a rule for the specified listener. The listener must be associated with an Application Load Balancer.

Rules are evaluated in priority order, from the lowest value to the highest value. When the conditions for a rule are met, its actions are performed. If the conditions for no rules are met, the actions for the default rule are performed. For more information, see Listener Rules in the Application Load Balancers Guide .

To view your current rules, use describe-rules . To update a rule, use modify-rule . To set the priorities of your rules, use set-rule-priorities . To delete a rule, use delete-rule .

See also: AWS API Documentation

See 'aws help' for descriptions of global parameters.

Synopsis

  create-rule
--listener-arn <value>
--conditions <value>
--priority <value>
--actions <value>
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

Options

--listener-arn (string)

The Amazon Resource Name (ARN) of the listener.

--conditions (list)

The conditions. Each condition specifies a field name and a single value.

If the field name is host-header , you can specify a single host name (for example, my.example.com). A host name is case insensitive, can be up to 128 characters in length, and can contain any of the following characters. Note that you can include up to three wildcard characters.

  • A-Z, a-z, 0-9
    • .
    • (matches 0 or more characters)
  • ? (matches exactly 1 character)

If the field name is path-pattern , you can specify a single path pattern. A path pattern is case sensitive, can be up to 128 characters in length, and can contain any of the following characters. Note that you can include up to three wildcard characters.

  • A-Z, a-z, 0-9
  • _ - . $ / ~ " ' @ : +
  • (using amp;)
    • (matches 0 or more characters)
  • ? (matches exactly 1 character)

Shorthand Syntax:

Field=string,Values=string,string ...

JSON Syntax:

[
  {
    "Field": "string",
    "Values": ["string", ...]
  }
  ...
]

--priority (integer)

The rule priority. A listener can't have multiple rules with the same priority.

--actions (list)

The actions. Each rule must include one forward action.

If the action type is forward , you can specify a single target group.

If the action type is authenticate-oidc , you can use an identity provider that is OpenID Connect (OIDC) compliant to authenticate users as they access your application.

If the action type is authenticate-cognito , you can use Amazon Cognito to authenticate users as they access your application.

Shorthand Syntax:

Type=string,TargetGroupArn=string,AuthenticateOidcConfig={Issuer=string,AuthorizationEndpoint=string,TokenEndpoint=string,UserInfoEndpoint=string,ClientId=string,ClientSecret=string,SessionCookieName=string,Scope=string,SessionTimeout=long,AuthenticationRequestExtraParams={KeyName1=string,KeyName2=string},OnUnauthenticatedRequest=string},AuthenticateCognitoConfig={UserPoolArn=string,UserPoolClientId=string,UserPoolDomain=string,SessionCookieName=string,Scope=string,SessionTimeout=long,AuthenticationRequestExtraParams={KeyName1=string,KeyName2=string},OnUnauthenticatedRequest=string},Order=integer ...

JSON Syntax:

[
  {
    "Type": "forward"|"authenticate-oidc"|"authenticate-cognito",
    "TargetGroupArn": "string",
    "AuthenticateOidcConfig": {
      "Issuer": "string",
      "AuthorizationEndpoint": "string",
      "TokenEndpoint": "string",
      "UserInfoEndpoint": "string",
      "ClientId": "string",
      "ClientSecret": "string",
      "SessionCookieName": "string",
      "Scope": "string",
      "SessionTimeout": long,
      "AuthenticationRequestExtraParams": {"string": "string"
        ...},
      "OnUnauthenticatedRequest": "deny"|"allow"|"authenticate"
    },
    "AuthenticateCognitoConfig": {
      "UserPoolArn": "string",
      "UserPoolClientId": "string",
      "UserPoolDomain": "string",
      "SessionCookieName": "string",
      "Scope": "string",
      "SessionTimeout": long,
      "AuthenticationRequestExtraParams": {"string": "string"
        ...},
      "OnUnauthenticatedRequest": "deny"|"allow"|"authenticate"
    },
    "Order": integer
  }
  ...
]

--cli-input-json (string) Performs service operation based on the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

See 'aws help' for descriptions of global parameters.

Examples

To create a rule using a path condition

This example creates a rule that forwards requests to the specified target group if the URL contains the specified pattern (for example, /img/*).

Command:

aws elbv2 create-rule --listener-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2 --priority 10 --conditions Field=path-pattern,Values='/img/*' --actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067

Output:

{
  "Rules": [
      {
          "Actions": [
              {
                  "Type": "forward",
                  "TargetGroupArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
              }
          ],
          "IsDefault": false,
          "Conditions": [
              {
                  "Field": "path-pattern",
                  "Values": [
                      "/img/*"
                  ]
              }
          ],
          "Priority": "10",
          "RuleArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/9683b2d02a6cabee"
      }
  ]
}

To create a rule using a host condition

This example creates a rule that forwards requests to the specified target group if the hostname in the host header matches the specified hostname (for example, *.example.com).

Command:

aws elbv2 create-rule --listener-arn arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2 --priority 5 --conditions Field=host-header,Values='*.example.com' --actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067

Output:

{
  "Rules": [
      {
          "Actions": [
              {
                  "Type": "forward",
                  "TargetGroupArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
              }
          ],
          "IsDefault": false,
          "Conditions": [
              {
                  "Field": "host-header",
                  "Values": [
                      "*.example.com"
                  ]
              }
          ],
          "Priority": "5",
          "RuleArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:listener-rule/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2/db8b4ff9007785e9"
      }
  ]
}

Output

Rules -> (list)

Information about the rule.

(structure)

Information about a rule.

RuleArn -> (string)

The Amazon Resource Name (ARN) of the rule.

Priority -> (string)

The priority.

Conditions -> (list)

The conditions.

(structure)

Information about a condition for a rule.

Field -> (string)

The name of the field. The possible values are host-header and path-pattern .

Values -> (list)

The condition value.

If the field name is host-header , you can specify a single host name (for example, my.example.com). A host name is case insensitive, can be up to 128 characters in length, and can contain any of the following characters. Note that you can include up to three wildcard characters.

  • A-Z, a-z, 0-9
    • .
    • (matches 0 or more characters)
  • ? (matches exactly 1 character)

If the field name is path-pattern , you can specify a single path pattern (for example, /img/*). A path pattern is case sensitive, can be up to 128 characters in length, and can contain any of the following characters. Note that you can include up to three wildcard characters.

  • A-Z, a-z, 0-9
  • _ - . $ / ~ " ' @ : +
  • (using amp;)
    • (matches 0 or more characters)
  • ? (matches exactly 1 character)

(string)

Actions -> (list)

The actions.

(structure)

Information about an action.

Type -> (string)

The type of action. Each rule must include one forward action.

TargetGroupArn -> (string)

The Amazon Resource Name (ARN) of the target group. Specify only when Type is forward .

For a default rule, the protocol of the target group must be HTTP or HTTPS for an Application Load Balancer or TCP for a Network Load Balancer.

AuthenticateOidcConfig -> (structure)

[HTTPS listener] Information about an identity provider that is compliant with OpenID Connect (OIDC). Specify only when Type is authenticate-oidc .

Issuer -> (string)

The OIDC issuer identifier of the IdP. This must be a full URL, including the HTTPS protocol, the domain, and the path.

AuthorizationEndpoint -> (string)

The authorization endpoint of the IdP. This must be a full URL, including the HTTPS protocol, the domain, and the path.

TokenEndpoint -> (string)

The token endpoint of the IdP. This must be a full URL, including the HTTPS protocol, the domain, and the path.

UserInfoEndpoint -> (string)

The user info endpoint of the IdP. This must be a full URL, including the HTTPS protocol, the domain, and the path.

ClientId -> (string)

The OAuth 2.0 client identifier.

ClientSecret -> (string)

The OAuth 2.0 client secret.

SessionCookieName -> (string)

The name of the cookie used to maintain session information. The default is AWSELBAuthSessionCookie.

Scope -> (string)

The set of user claims to be requested from the IdP. The default is openid .

To verify which scope values your IdP supports and how to separate multiple values, see the documentation for your IdP.

SessionTimeout -> (long)

The maximum duration of the authentication session, in seconds. The default is 604800 seconds (7 days).

AuthenticationRequestExtraParams -> (map)

The query parameters (up to 10) to include in the redirect request to the authorization endpoint.

key -> (string)

value -> (string)

OnUnauthenticatedRequest -> (string)

The behavior if the user is not authenticated. The following are possible values:

  • deny- Return an HTTP 401 Unauthorized error.
  • allow- Allow the request to be forwarded to the target.
  • authenticate- Redirect the request to the IdP authorization endpoint. This is the default value.

AuthenticateCognitoConfig -> (structure)

[HTTPS listener] Information for using Amazon Cognito to authenticate users. Specify only when Type is authenticate-cognito .

UserPoolArn -> (string)

The Amazon Resource Name (ARN) of the Amazon Cognito user pool.

UserPoolClientId -> (string)

The ID of the Amazon Cognito user pool client.

UserPoolDomain -> (string)

The domain prefix or fully-qualified domain name of the Amazon Cognito user pool.

SessionCookieName -> (string)

The name of the cookie used to maintain session information. The default is AWSELBAuthSessionCookie.

Scope -> (string)

The set of user claims to be requested from the IdP. The default is openid .

To verify which scope values your IdP supports and how to separate multiple values, see the documentation for your IdP.

SessionTimeout -> (long)

The maximum duration of the authentication session, in seconds. The default is 604800 seconds (7 days).

AuthenticationRequestExtraParams -> (map)

The query parameters (up to 10) to include in the redirect request to the authorization endpoint.

key -> (string)

value -> (string)

OnUnauthenticatedRequest -> (string)

The behavior if the user is not authenticated. The following are possible values:

  • deny- Return an HTTP 401 Unauthorized error.
  • allow- Allow the request to be forwarded to the target.
  • authenticate- Redirect the request to the IdP authorization endpoint. This is the default value.

Order -> (integer)

The order for the action. This value is required for rules with multiple actions. The action with the lowest value for order is performed first. The forward action must be performed last.

IsDefault -> (boolean)

Indicates whether this is the default rule.