

# IAM JSON policy elements: Condition
<a name="reference_policies_elements_condition"></a>

The `Condition` element (or `Condition` *block*) lets you specify conditions for when a policy is in effect. The `Condition` element is optional. In the `Condition` element, you build expressions in which you use [condition operators](reference_policies_elements_condition_operators.md) (equal, less than, and others) to match the context keys and values in the policy against keys and values in the request context. To learn more about the request context, see [Components of a request](intro-structure.md#intro-structure-request).

```
"Condition" : { "{condition-operator}" : { "{condition-key}" : "{condition-value}" }}
```

The context key that you specify in a policy condition can be a [global condition context key](reference_policies_condition-keys.md) or a service-specific context key. Global condition context keys have the `aws:` prefix. Service-specific context keys have the service's prefix. For example, Amazon EC2 lets you write a condition using the `ec2:InstanceType` context key, which is unique to that service. To view service-specific IAM context keys with the `iam:` prefix, see [IAM and AWS STS condition context keys](reference_policies_iam-condition-keys.md).

Context key *names* are not case-sensitive. For example, including the `aws:SourceIP` context key is equivalent to testing for `AWS:SourceIp`. Case-sensitivity of context key *values* depends on the [condition operator](reference_policies_elements_condition_operators.md) that you use. For example, the following condition includes the `StringEquals` operator to make sure that only requests made by `john` match. Users named `John` are denied access.

```
"Condition" : { "StringEquals" : { "aws:username" : "john" }}
```

The following condition uses the [`StringEqualsIgnoreCase`](reference_policies_elements_condition_operators.md#Conditions_String) operator to match users named `john` or `John`.

```
"Condition" : { "StringEqualsIgnoreCase" : { "aws:username" : "john" }}
```

Some context keys support key–value pairs that allow you to specify part of the key name. Examples include the [`aws:RequestTag/tag-key`](reference_policies_condition-keys.md#condition-keys-requesttag) context key, the AWS KMS [https://docs.aws.amazon.com/kms/latest/developerguide/policy-conditions.html#conditions-kms-encryption-context](https://docs.aws.amazon.com/kms/latest/developerguide/policy-conditions.html#conditions-kms-encryption-context), and the [`ResourceTag/tag-key`](reference_policies_condition-keys.md#condition-keys-resourcetag) context key supported by multiple services.
+ If you use the `ResourceTag/tag-key` context key for a service such as [Amazon EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-policy-structure.html#amazon-ec2-keys), then you must specify a key name for the `tag-key`. 
+ **Key names are not case-sensitive.** This means that if you specify `"aws:ResourceTag/TagKey1": "Value1"` in the condition element of your policy, then the condition matches a resource tag key named either `TagKey1` or `tagkey1`, but not both.
+ AWS services that support these attributes might allow you to create multiple key names that differ only by case. For example, you might tag an Amazon EC2 instance with `ec2=test1` and `EC2=test2`. When you use a condition such as `"aws:ResourceTag/EC2": "test1"` to allow access to that resource, the key name matches both tags, but only one value matches. This can result in unexpected condition failures.

**Important**  
As a best practice, make sure that members of your account follow a consistent naming convention when naming key–value pair attributes. Examples include tags or AWS KMS encryption contexts. You can enforce this using the [`aws:TagKeys`](reference_policies_condition-keys.md#condition-keys-tagkeys) context key for tagging, or the [https://docs.aws.amazon.com/kms/latest/developerguide/policy-conditions.html#conditions-kms-encryption-context-keys](https://docs.aws.amazon.com/kms/latest/developerguide/policy-conditions.html#conditions-kms-encryption-context-keys) for the AWS KMS encryption context.
+ For a list of all of the condition operators and a description of how they work, see [Condition operators](reference_policies_elements_condition_operators.md).
+ Unless otherwise specified, all context keys can have multiple values. For a description of how to handle context keys that have multiple values, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys).
+ For a list of all of the globally available context keys, see [AWS global condition context keys](reference_policies_condition-keys.md).
+ For condition context keys that are defined by each service, see [Actions, Resources, and Condition Keys for AWS Services](reference_policies_actions-resources-contextkeys.html).

## The request context
<a name="AccessPolicyLanguage_RequestContext"></a>

When a [principal](https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html?icmpid=docs_homepage_addtlrcs#principal) makes a [request](intro-structure.md#intro-structure-request) to AWS, AWS gathers the request information into a request context. The request context includes information about the principal, resources, actions, and other environmental properties. Policy evaluation matches the properties in the policy against the properties sent in the request to evaluate and authorize actions you can perform in AWS.

You can use the `Condition` element of a JSON policy to test specific context keys against the request context. For example, you can create a policy that uses the [aws:CurrentTime](reference_policies_condition-keys.md#condition-keys-currenttime) context key to [allow a user to perform actions within only a specific range of dates](reference_policies_examples_aws-dates.md).

The following example shows a representation of the request context when Martha Rivera sends a request to deactivate her MFA device.

```
Principal: AROA123456789EXAMPLE
Action: iam:DeactivateMFADevice
Resource: arn:aws:iam::user/martha
Context:
  – aws:UserId=AROA123456789EXAMPLE:martha
  – aws:PrincipalAccount=1123456789012
  – aws:PrincipalOrgId=o-example
  – aws:PrincipalARN=arn:aws:iam::1123456789012:assumed-role/TestAR
  – aws:MultiFactorAuthPresent=true
  – aws:MultiFactorAuthAge=2800
  – aws:CurrentTime=...
  – aws:EpochTime=...
  – aws:SourceIp=...
```

The request context is matched against a policy that allows users to remove their own multi-factor authentication (MFA) device, but only if they have signed in using MFA in the last hour (3,600 seconds).

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Sid": "AllowRemoveMfaOnlyIfRecentMfa",
        "Effect": "Allow",
        "Action": [
            "iam:DeactivateMFADevice"
        ],
        "Resource": "arn:aws:iam::*:user/${aws:username}",
        "Condition": {
            "NumericLessThanEquals": {"aws:MultiFactorAuthAge": "3600"}
        }
    }
}
```

------

In this example, the policy matches the request context: the action is the same, the resource matches the “\$1” wildcard, and the value for `aws:MultiFactorAuthAge` is 2800, which is less than 3600, so the policy allows this authorization request.

AWS evaluates each context key in the policy and returns a value of *true* or *false*. A context key that is not present in the request is considered a mismatch.

The request context can return the following values:
+ **True** – If the requester signed in using MFA in the last one hour or less, then the condition returns *true*.
+ **False** – If the requester signed in using MFA more than one hour ago, then the condition returns *false*.
  + **Not present** – If the requester made a request using their IAM user access keys in the AWS CLI or AWS API, the key is not present. In this case, the key is not present, and it won't match.

**Note**  
In some cases, when the condition key value is not present, the condition can still return true. For example, if you add the `ForAllValues` qualifier, the request returns true if the context key is not in the request. To prevent missing context keys or context keys with empty values from evaluating to true, you can include the [Null condition operator](reference_policies_elements_condition_operators.md#Conditions_Null) in your policy with a `false` value to check if the context key exists and its value is not null.

## The condition block
<a name="AccessPolicyLanguage_ConditionBlock"></a>

The following example shows the basic format of a `Condition` element:

```
"Condition": {"StringLike": {"s3:prefix": ["jane/*"]}}
```

A value from the request is represented by a context key, in this case `s3:prefix`. The context key value is compared to a value that you specify as a literal value, such as `jane/*`. The type of comparison to make is specified by the [condition operator](reference_policies_elements_condition_operators.md) (here, `StringLike`). You can create conditions that compare strings, dates, numbers, and more using typical Boolean comparisons such as equals, greater than, and less than. When you use [string operators](reference_policies_elements_condition_operators.md#Conditions_String) or [ARN operators](reference_policies_elements_condition_operators.md#Conditions_ARN), you can also use a [policy variable](reference_policies_variables.md) in the context key value. The following example includes the `aws:username` variable. 

```
"Condition": {"StringLike": {"s3:prefix": ["${aws:username}/*"]}}
```

Under some circumstances, context keys can contain multiple values. For example, a request to Amazon DynamoDB might ask to return or update multiple attributes from a table. A policy for access to DynamoDB tables can include the `dynamodb:Attributes` context key, which contains all the attributes listed in the request. You can test the multiple attributes in the request against a list of allowed attributes in a policy by using set operators in the `Condition` element. For more information, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys). 

When the policy is evaluated during a request, AWS replaces the key with the corresponding value from the request. (In this example, AWS would use the date and time of the request.) The condition is evaluated to return true or false, which is then factored into whether the policy as a whole allows or denies the request. 

### Multiple values in a condition
<a name="Condition-multiple-conditions"></a>

A `Condition` element can contain multiple condition operators, and each condition operator can contain multiple context key-value pairs. The following figure illustrates this. 

![\[two condition operator block diagrams. The first block includes two context key placeholders, each with multiple values. The second condition block includes one context key with multiple values.\]](http://docs.aws.amazon.com/IAM/latest/UserGuide/images/AccessPolicyLanguage_Condition_Block.diagram.png)


For more information, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys). 

# IAM JSON policy elements: Condition operators
<a name="reference_policies_elements_condition_operators"></a>

<a name="topiclist"></a>

Use condition operators in the `Condition` element to match the condition key and value in the policy against values in the request context. For more information about the `Condition` element, see [IAM JSON policy elements: Condition](reference_policies_elements_condition.md).

The condition operator that you can use in a policy depends on the condition key you choose. You can choose a global condition key or a service-specific condition key. To learn which condition operator you can use for a global condition key, see [AWS global condition context keys](reference_policies_condition-keys.md). To learn which condition operator you can use for a service-specific condition key, see [Actions, Resources, and Condition Keys for AWS Services](reference_policies_actions-resources-contextkeys.html) and choose the service that you want to view.

**Important**  
If the key that you specify in a policy condition is not present in the request context, the values do not match and the condition is *false*. If the policy condition requires that the key is *not* matched, such as `StringNotLike` or `ArnNotLike`, and the right key is not present, the condition is *true*. This logic applies to all condition operators except [...IfExists](#Conditions_IfExists) and [Null check](#Conditions_Null). These operators test whether the key is present (exists) in the request context.

The condition operators can be grouped into the following categories:
+ [String](#Conditions_String)
+ [Numeric](#Conditions_Numeric)
+ [Date and time](#Conditions_Date)
+ [Boolean](#Conditions_Boolean)
+ [Binary](#Conditions_BinaryEquals)
+ [IP address](#Conditions_IPAddress)
+ [Amazon Resource Name (ARN)](#Conditions_ARN) (available for only some services.)
+ [...IfExists](#Conditions_IfExists) (checks if the key value exists as part of another check)
+ [Null check](#Conditions_Null) (checks if the key value exists as a standalone check)

## String condition operators
<a name="Conditions_String"></a>

String condition operators let you construct `Condition` elements that restrict access based on comparing a key to a string value.
+  **Policy variables** – [Supported](reference_policies_variables.md)
+ **Wildcards** – [Supported](#Conditions_String-wildcard)


****  

| Condition operator | Description | 
| --- | --- | 
|   `StringEquals`   |  Exact matching, case sensitive  | 
|   `StringNotEquals`   |  Negated matching  | 
|   `StringEqualsIgnoreCase`   |  Exact matching, ignoring case  | 
|   `StringNotEqualsIgnoreCase`   |  Negated matching, ignoring case  | 
|   `StringLike`   | Case-sensitive matching. The values can include multi-character match wildcards (\$1) and single-character match wildcards (?) anywhere in the string. You must specify wildcards to achieve partial string matches.   If a key contains multiple values, `StringLike` can be qualified with set operators—`ForAllValues:StringLike` and `ForAnyValue:StringLike`. For more information, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys).   | 
|   `StringNotLike`   |  Negated case-sensitive matching. The values can include multi-character match wildcards (\$1) or single-character match wildcards (?) anywhere in the string.  | 

**Example string condition operator**  
For example, the following statement contains a `Condition` element that uses [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principaltag](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principaltag) key to specify that the principal making the request must be tagged with the `iamuser-admin` job category.    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Effect": "Allow",
        "Action": "iam:*AccessKey*",
        "Resource": "arn:aws:iam::111122223333:user/*",
        "Condition": {
            "StringEquals": {
                "aws:PrincipalTag/job-category": "iamuser-admin"
            }
        }
    }
}
```
If the key that you specify in a policy condition is not present in the request context, the values do not match. In this example, the `aws:PrincipalTag/job-category` key is present in the request context if the principal is using an IAM user with attached tags. It is also included for a principal using an IAM role with attached tags or session tags. If a user without the tag attempts to view or edit an access key, the condition returns `false` and the request is implicitly denied by this statement.  
The following table shows how AWS evaluates this policy based on the condition key values in your request.  


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/job-category": "iamuser-admin"<br />}</pre>  | <pre>aws:PrincipalTag/job-category:<br />  – iamuser-admin</pre>  |  Match | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/job-category": "iamuser-admin"<br />}</pre>  | <pre>aws:PrincipalTag/job-category:<br />  – dev-ops</pre>  | No match | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/job-category": "iamuser-admin"<br />}</pre>  |  No `aws:PrincipalTag/job-category` in the request context.  | No match | 

**Example using a policy variable with a string condition operator**  
The following example uses the `StringLike` condition operator to perform string matching with a [policy variable](reference_policies_variables.md) to create a policy that lets an IAM user use the Amazon S3 console to manage his or her own "home directory" in an Amazon S3 bucket. The policy allows the specified actions on an S3 bucket as long as the `s3:prefix` matches any one of the specified patterns.    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets",
        "s3:GetBucketLocation"
      ],
      "Resource": "arn:aws:s3:::*"
    },
    {
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
      "Condition": {
        "StringLike": {
          "s3:prefix": [
            "",
            "home/",
            "home/${aws:username}/"
          ]
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}",
        "arn:aws:s3:::amzn-s3-demo-bucket/home/${aws:username}/*"
      ]
    }
  ]
}
```
The following table shows how AWS evaluates this policy for different users based on the [aws:username](reference_policies_condition-keys.md#condition-keys-username) value in the request context.  


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"StringLike": {<br />  "s3:prefix": [<br />    "home/",<br />    "home/${aws:username}/"<br />  ]<br />}</pre>  | <pre>aws:username:<br />  – martha_rivera</pre>  | <pre>"StringLike": {<br />  "s3:prefix": [<br />    "home/",<br />    "home/martha_rivera/"<br />  ]<br />}</pre>  | 
|  <pre>"StringLike": {<br />  "s3:prefix": [<br />    "home/",<br />    "home/${aws:username}/"<br />  ]<br />}</pre>  |  <pre>aws:username:<br />  – nikki_wolf</pre>  |  <pre>"StringLike": {<br />  "s3:prefix": [<br />    "home/",<br />    "home/nikki_wolf/"<br />  ]<br />}</pre>  | 
|  <pre>"StringLike": {<br />  "s3:prefix": [<br />    "home/",<br />    "home/${aws:username}/"<br />  ]<br />}</pre>  |  No `aws:username` in the request context.  | No match | 
For an example of a policy that shows how to use the `Condition` element to restrict access to resources based on an application ID and a user ID for OIDC federation, see [Amazon S3: Allows Amazon Cognito users to access objects in their bucket](reference_policies_examples_s3_cognito-bucket.md). 

### Multivalued string condition operators
<a name="conditions_string_multivalued"></a>

If a key in the request contains multiple values, string operators can be qualified with set operators `ForAllValues` and `ForAnyValue`. For more information on the evaluation logic of multiple context keys or values, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys).


| Condition operator | Description | 
| --- | --- | 
|  `ForAllValues:StringEquals` `ForAllValues:StringEqualsIgnoreCase`  |  All of the values for the condition key in the request must match at least one of the values in your policy.  | 
|  `ForAnyValue:StringEquals` `ForAnyValue:StringEqualsIgnoreCase`  |  At least one condition key value in the request must match one of the values in your policy.  | 
|  `ForAllValues:StringNotEquals` `ForAllValues:StringNotEqualsIgnoreCase`  |  Negated matching. None of the values of the context key in the request can match any of the context key values in your policy.  | 
|  `ForAnyValue:StringNotEquals` `ForAnyValue:StringNotEqualsIgnoreCase`  |  Negated matching. At least one context key value in the request must NOT match any of values in the context key in your policy.  | 
|  `ForAllValues:StringLike`  |  All of the values for the condition key in the request must match at least one of the values in your policy.  | 
|  `ForAnyValue:StringLike`  |  At least one condition key value in the request must match one of the values in your policy.  | 
|  `ForAllValues:StringNotLike`  |  Negated matching. None of the values of the context key in the request can match any of the context key values in your policy.  | 
|  `ForAnyValue:StringNotLike`  |  Negated matching. At least one context key value in the request must NOT match any of values in the context key in your policy.  | 

**Example using `ForAnyValue` with a string condition operator**  
This example shows how you might create an identity-based policy that allows using the Amazon EC2 `CreateTags` action to attach tags to an instance. When you use `StringEqualsIgnoreCase`, you can attach tags only if the tag contains the `environment` key with the `preprod` or `storage` values. When you append `IgnoreCase` to the operator, you allow any existing tag value capitalization, such as `preprod`, `Preprod`, and `PreProd`, to resolve to true.  
When you add the `ForAnyValue` modifier with the [aws:TagKeys](reference_policies_condition-keys.md#condition-keys-tagkeys) condition key, at least one tag key value in the request must match the value `environment`. `ForAnyValue` comparison is case sensitive, which stops users from using the incorrect case for the tag key, such as using `Environment` instead of `environment`.    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": "ec2:CreateTags",
    "Resource": "arn:aws:ec2:*:*:instance/*",
    "Condition": {
      "StringEqualsIgnoreCase": {
        "aws:RequestTag/environment": [
          "preprod",
          "storage"
        ]
      },
      "ForAnyValue:StringEquals": {
        "aws:TagKeys": "environment"
      }
    }
  }
}
```
 The following table shows how AWS evaluates this policy based on the condition key values in your request.   


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />aws:RequestTag/environment:<br />  – preprod</pre>  | Match  | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – costcenter<br />aws:RequestTag/environment:<br />  – PreProd</pre>  | Match  | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  | <pre>aws:TagKeys:<br />  – Environment<br />aws:RequestTag/Environment:<br />  – preprod</pre>  | No match  | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  | <pre>aws:TagKeys:<br />  – costcenter<br />aws:RequestTag/environment:<br />  – preprod</pre>  | No match  | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  |  No `aws:TagKeys` in the request context. <pre>aws:RequestTag/environment:<br />  – storage</pre>  | No match  | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment</pre> No `aws:RequestTag/environment` in the request context.  | No match  | 
|  <pre>"StringEqualsIgnoreCase": {<br />  "aws:RequestTag/environment": [<br />    "preprod",<br />    "storage"<br />  ]<br />},<br />"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "environment"<br />}</pre>  |  No `aws:TagKeys` in the request context. No `aws:RequestTag/environment` in the request context.  | No match  | 

### Wildcard matching
<a name="Conditions_String-wildcard"></a>

String condition operators perform a patternless matching that does not enforce a predefined format. ARN and Date condition operators are a subset of string operators that enforce a structure on the condition key value.

We recommend you use condition operators that correspond to the values you're comparing keys to. For example, you should use [String condition operators](#Conditions_String) when comparing keys to string values. Similarly, you should use [Amazon Resource Name (ARN) condition operators](#Conditions_ARN) when comparing keys to ARN values.

**Example**  
This example shows how you might create a boundary around resources in your organization. The condition in this policy denies access to Amazon S3 actions unless the resource being accessed is in a specific set of organizational units (OUs) in AWS Organizations. An AWS Organizations path is a text representation of the structure of an organization's entity.  
The condition requires that `aws:ResourceOrgPaths` contains any of the listed OU paths. Because `aws:ResourceOrgPaths` is a multi-value condition, the policy uses the `ForAllValues:StringNotLike` operator to compare the values of `aws:ResourceOrgPaths` to the list of OUs in the policy.    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyS3AccessOutsideMyBoundary",
      "Effect": "Deny",
      "Action": [
        "s3:*"
      ],
      "Resource": "*",
      "Condition": {
        "ForAllValues:StringNotLike": {
          "aws:ResourceOrgPaths": [
            "o-acorg/r-acroot/ou-acroot-mediaou/",
            "o-acorg/r-acroot/ou-acroot-sportsou/*"
          ] 
        }
      }
    }
  ]
}
```
The following table shows how AWS evaluates this policy based on the condition key values in your request.  


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"ForAllValues:StringNotLike": {<br />  "aws:ResourceOrgPaths": [<br />    "o-acorg/r-acroot/ou-acroot-mediaou/",<br />    "o-acorg/r-acroot/ou-acroot-sportsou/*"<br />  ] <br />}</pre>  | <pre>aws:ResourceOrgPaths:<br />  – o-acorg/r-acroot/ou-acroot-sportsou/costcenter/</pre>  | Match | 
|  <pre>"ForAllValues:StringNotLike": {<br />  "aws:ResourceOrgPaths": [<br />    "o-acorg/r-acroot/ou-acroot-mediaou/",<br />    "o-acorg/r-acroot/ou-acroot-sportsou/*"<br />  ] <br />}</pre>  | <pre>aws:ResourceOrgPaths:<br />  – o-acorg/r-acroot/ou-acroot-mediaou/costcenter/</pre>  | No match | 
|  <pre>"ForAllValues:StringNotLike": {<br />  "aws:ResourceOrgPaths": [<br />    "o-acorg/r-acroot/ou-acroot-mediaou/",<br />    "o-acorg/r-acroot/ou-acroot-sportsou/*"<br />  ] <br />}</pre>  |  No `aws:ResourceOrgPaths:` in the request.  | No match | 

## Numeric condition operators
<a name="Conditions_Numeric"></a>

Numeric condition operators let you construct `Condition` elements that restrict access based on comparing a key to an integer or decimal value.
+  **Policy variables** – Not supported
+ **Wildcards** – Not supported


****  

| Condition operator | Description | 
| --- | --- | 
|   `NumericEquals`   |  Matching  | 
|   `NumericNotEquals`   |  Negated matching  | 
|   `NumericLessThan`   |  "Less than" matching  | 
|   `NumericLessThanEquals`   |  "Less than or equals" matching  | 
|   `NumericGreaterThan`   |  "Greater than" matching  | 
|   `NumericGreaterThanEquals`   |  "Greater than or equals" matching  | 

For example, the following statement contains a `Condition` element that uses the `NumericLessThanEquals` condition operator with the `s3:max-keys` key to specify that the requester can list *up to* 10 objects in `amzn-s3-demo-bucket` at a time.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": "s3:ListBucket",
    "Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
    "Condition": {"NumericLessThanEquals": {"s3:max-keys": "10"}}
  }
}
```

------

If the key that you specify in a policy condition is not present in the request context, the values do not match. In this example, the `s3:max-keys` key is always present in the request when you perform the `ListBucket` operation. If this policy allowed all Amazon S3 operations, then only the operations that include the `max-keys` context key with a value of less than or equal to 10 would be allowed. 

## Date condition operators
<a name="Conditions_Date"></a>

Date condition operators let you construct `Condition` elements that restrict access based on comparing a key to a date/time value. You use these condition operators with [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-currenttime](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-currenttime) key or [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-epochtime](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-epochtime) key. You must specify date/time values with one of the [W3C implementations of the ISO 8601 date formats](http://www.w3.org/TR/NOTE-datetime) or in epoch (UNIX) time. 
+  **Policy variables** – Not supported
+ **Wildcards** – Not supported


****  

| Condition operator | Description | 
| --- | --- | 
|   `DateEquals`   |  Matching a specific date  | 
|   `DateNotEquals`   |  Negated matching  | 
|   `DateLessThan`   |  Matching before a specific date and time  | 
|   `DateLessThanEquals`   |  Matching at or before a specific date and time  | 
|   `DateGreaterThan`   |  Matching after a specific a date and time  | 
|   `DateGreaterThanEquals`   |  Matching at or after a specific date and time  | 

For example, the following statement contains a `Condition` element that uses the `DateGreaterThan` condition operator with the [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-tokenissuetime](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-tokenissuetime) key. This condition specifies that the temporary security credentials used to make the request were issued in 2020. This policy can be updated programmatically every day to ensure that account members use fresh credentials.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Effect": "Allow",
        "Action": "iam:*AccessKey*",
        "Resource": "arn:aws:iam::111122223333:user/*",
        "Condition": {
            "DateGreaterThan": {
                "aws:TokenIssueTime": "2020-01-01T00:00:01Z"
            }
        }
    }
}
```

------

If the key that you specify in a policy condition is not present in the request context, the values do not match. The `aws:TokenIssueTime` key is present in the request context only when the principal uses temporary credentials to make the request. The key is not present in AWS CLI, AWS API, or AWS SDK requests that are made using access keys. In this example, if an IAM user attempts to view or edit an access key, the request is denied.

## Boolean condition operators
<a name="Conditions_Boolean"></a>

Boolean conditions let you construct `Condition` elements that restrict access based on comparing a key to `true` or `false`.

If a key contains multiple values, boolean operators can be qualified with set operators `ForAllValues` and `ForAnyValue`. For more information on the evaluation logic of multiple context keys or values, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys).
+  **Policy variables** – [Supported](reference_policies_variables.md)
+ **Wildcards** – Not supported


****  

| Condition operator | Description | 
| --- | --- | 
|   `Bool`   |  Boolean matching  | 
|   `ForAllValues:Bool`   |  Use with the Array of Bool data type. All of the booleans in the context key values must match the boolean values in your policy. To prevent `ForAllValues` operators from evaluating missing context keys or context keys with empty values as Allowed, you can include the [Null condition operator](#Conditions_Null) in your policy.  | 
|   `ForAnyValue:Bool`   |  Use with the Array of Bool data type. At least one of the booleans in the context key values must match the boolean values in your policy.  | 

**Example boolean condition operator**  
The following identity-based policy uses the `Bool` condition operator with the [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-securetransport](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-securetransport) key to deny replicating objects and object tags to the destination bucket and its contents if the request is not over SSL.  
This policy does not allow any actions. Use this policy in combination with other policies that allow specific actions.   
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "BooleanExample",
      "Action": "s3:ReplicateObject",
      "Effect": "Deny",
      "Resource": [
        "arn:aws:s3:::amzn-s3-demo-bucket",
        "arn:aws:s3:::amzn-s3-demo-bucket/*"
      ],
      "Condition": {
        "Bool": {
          "aws:SecureTransport": "false"
        }
      }
    }
  ]
}
```
The following table shows how AWS evaluates this policy based on the condition key values in your request.  


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"Bool": {<br />  "aws:SecureTransport": "false"<br />}</pre>  | <pre>aws:SecureTransport:<br />  – false</pre>  | Match | 
|  <pre>"Bool": {<br />  "aws:SecureTransport": "false"<br />}</pre>  | <pre>aws:SecureTransport:<br />  – true</pre>  | No match | 
|  <pre>"Bool": {<br />  "aws:SecureTransport": "false"<br />}</pre>  |  No `aws:SecureTransport` in the request context.  | No match | 

## Binary condition operators
<a name="Conditions_BinaryEquals"></a>

The `BinaryEquals` condition operator lets you construct `Condition` elements that test key values that are in binary format. It compares the value of the specified key byte for byte against a [base-64](https://en.wikipedia.org/wiki/Base64) encoded representation of the binary value in the policy. If the key that you specify in a policy condition is not present in the request context, the values do not match.
+  **Policy variables** – Not supported
+ **Wildcards** – Not supported

```
"Condition" : {
  "BinaryEquals": {
    "key" : "QmluYXJ5VmFsdWVJbkJhc2U2NA=="
  }
}
```


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"BinaryEquals": {<br />  "key" : "QmluYXJ5VmFsdWVJbkJhc2U2NA=="<br />}</pre>  | <pre>key:<br />  – QmluYXJ5VmFsdWVJbkJhc2U2NA==</pre>  | Match | 
|  <pre>"BinaryEquals": {<br />  "key" : "QmluYXJ5VmFsdWVJbkJhc2U2NA=="<br />}</pre>  | <pre>key:<br />  – ASIAIOSFODNN7EXAMPLE</pre>  | No match | 
|  <pre>"BinaryEquals": {<br />  "key" : "QmluYXJ5VmFsdWVJbkJhc2U2NA=="<br />}</pre>  |  No `key` in the request context.  | No match | 

## IP address condition operators
<a name="Conditions_IPAddress"></a>

IP address condition operators let you construct `Condition` elements that restrict access based on comparing a key to an IPv4 or IPv6 address or range of IP addresses. You use these with the [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceip](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceip) key. The value must be in the standard CIDR format (for example, 203.0.113.0/24 or 2001:DB8:1234:5678::/64). If you specify an IP address without the associated routing prefix, IAM uses the default prefix value of `/32`.

Some AWS services support IPv6, using :: to represent a range of 0s. To learn whether a service supports IPv6, see the documentation for that service.
+  **Policy variables** – Not supported
+ **Wildcards** – Not supported


****  

| Condition operator | Description | 
| --- | --- | 
|   `IpAddress`   |  The specified IP address or range  | 
|   `NotIpAddress`   |  All IP addresses except the specified IP address or range  | 

**Example IP address condition operator**  
The following statement uses the `IpAddress` condition operator with the `aws:SourceIp` key to specify that the request must come from the IP range 203.0.113.0 to 203.0.113.255.    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Effect": "Allow",
        "Action": "iam:*AccessKey*",
        "Resource": "arn:aws:iam::111122223333:user/*",
        "Condition": {
            "IpAddress": {
                "aws:SourceIp": "203.0.113.0/24"
            }
        }
    }
}
```
The `aws:SourceIp` condition key resolves to the IP address that the request originates from. If the requests originates from an Amazon EC2 instance, `aws:SourceIp` evaluates to the instance's public IP address.   
If the key that you specify in a policy condition is not present in the request context, the values do not match. The `aws:SourceIp` key is always present in the request context, except when the requester uses a VPC endpoint to make the request. In this case, the condition returns `false` and the request is implicitly denied by this statement.  
The following table shows how AWS evaluates this policy based on the condition key values in your request.  


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"IpAddress": {<br />  "aws:SourceIp": "203.0.113.0/24"<br />}</pre>  | <pre>aws:SourceIp:<br />  – 203.0.113.1</pre>  | Match | 
|  <pre>"IpAddress": {<br />  "aws:SourceIp": "203.0.113.0/24"<br />}</pre>  | <pre>aws:SourceIp:<br />  – 198.51.100.1</pre>  | No match | 
The following example shows how to mix IPv4 and IPv6 addresses to cover all of your organization's valid IP addresses. We recommend that you update your organization's policies with your IPv6 address ranges in addition to IPv4 ranges you already have to ensure the policies continue to work as you make the transition to IPv6.    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": "someservice:*",
    "Resource": "*",
    "Condition": {
      "IpAddress": {
        "aws:SourceIp": [
          "203.0.113.0/24",
          "2001:DB8:1234:5678::/64"
        ]
      }
    }
  }
}
```
The `aws:SourceIp` condition key works only in a JSON policy if you are calling the tested API directly as a user. If you instead use a service to call the target service on your behalf, the target service sees the IP address of the calling service rather than the IP address of the originating user. This can happen, for example, if you use AWS CloudFormation to call Amazon EC2 to construct instances for you. There is currently no way to pass the originating IP address through a calling service to the target service for evaluation in a JSON policy. For these types of service API calls, do not use the `aws:SourceIp` condition key.

## Amazon Resource Name (ARN) condition operators
<a name="Conditions_ARN"></a>

Amazon Resource Name (ARN) condition operators let you construct `Condition` elements that restrict access based on comparing a key to an ARN. The ARN is considered a string.
+  **Policy variables** – [Supported](reference_policies_variables.md)
+ **Wildcards** – [Supported](reference_policies_elements_resource.md#reference_policies_elements_resource_wildcards)


****  

| Condition operator | Description | 
| --- | --- | 
|   `ArnEquals`, `ArnLike`  |  Case-sensitive matching of the ARN. Each of the six colon-delimited components of the ARN is checked separately and each can include multi-character match wildcards (\$1) or single-character match wildcards (?). The `ArnEquals` and `ArnLike` condition operators behave identically.  | 
|   `ArnNotEquals`, `ArnNotLike`  |  Negated matching for ARN. The `ArnNotEquals` and `ArnNotLike` condition operators behave identically.  | 

**Example ARN condition operator**  
The following resource-based policy example shows a policy attached to an Amazon SQS queue to which you want to send SNS messages. It gives Amazon SNS permission to send messages to the queue (or queues) of your choice, but only if the service is sending the messages on behalf of a particular Amazon SNS topic (or topics). You specify the queue in the `Resource` field, and the Amazon SNS topic as the value for the `SourceArn` key.    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": {
        "Effect": "Allow",
        "Principal": {
            "Service": "sns.amazonaws.com"
        },
        "Action": "SQS:SendMessage",
        "Resource": "arn:aws:sqs:us-east-1:123456789012:QUEUE-ID",
        "Condition": {
            "ArnEquals": {
                "aws:SourceArn": "arn:aws:sns:us-east-1:123456789012:TOPIC-ID"
            }
        }
    }
}
```
The [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn) key is present in the request context only if a resource triggers a service to call another service on behalf of the resource owner. If an IAM user attempts to perform this operation directly, the condition returns `false` and the request is implicitly denied by this statement.  
The following table shows how AWS evaluates this policy based on the condition key values in your request.  


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"ArnEquals": {<br />  "aws:SourceArn": "arn:aws:sns:us-west-2:123456789012:TOPIC-ID"<br />}</pre>  | <pre>aws:SourceArn:<br />  – arn:aws:sns:us-west-2:123456789012:TOPIC-ID</pre>  | Match | 
|  <pre>"ArnEquals": {<br />  "aws:SourceArn": "arn:aws:sns:us-west-2:123456789012:TOPIC-ID"<br />}</pre>  | <pre>aws:SourceArn:<br />  – arn:aws:sns:us-west-2:777788889999:TOPIC-ID</pre>  | No match | 
|  <pre>"ArnEquals": {<br />  "aws:SourceArn": "arn:aws:sns:us-west-2:123456789012:TOPIC-ID"<br />}</pre>  |  No `aws:SourceArn` in the request context.  | No match | 

### Multivalued ARN condition operators
<a name="conditions_arn_multivalued"></a>

If a key in the request contains multiple values, ARN operators can be qualified with set operators `ForAllValues` and `ForAnyValue`. For more information on the evaluation logic of multiple context keys or values, see [Set operators for multivalued context keys](reference_policies_condition-single-vs-multi-valued-context-keys.md#reference_policies_condition-multi-valued-context-keys).


| Condition operator | Description | 
| --- | --- | 
|  `ForAllValues:ArnEquals` `ForAllValues:ArnLike`  |  All of the ARNs in the request context must match at least one of the ARN patterns in your policy.  | 
|  `ForAnyValue:ArnEquals` `ForAnyValue:ArnLike`  |  At least one ARN in the request context must match one of the ARN patterns in your policy.  | 
|  `ForAllValues:ArnNotEquals` `ForAllValues:ArnNotLike`  |  Negated matching. None of the ARNs in the request context can match any string ARN patterns in your policy.  | 
|  `ForAnyValue:ArnNotEquals` `ForAnyValue:ArnNotLike`  |  Negated matching. At least one ARN in the request context must NOT match any of ARN patterns in your policy.  | 

**Example using `ForAllValues` with an ARN condition operator**  
The following example uses `ForAllValues:ArnLike` to create or update a logical delivery source for Amazon CloudWatch Logs logs. The condition block includes the condition key [https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchlogs.html#amazoncloudwatchlogs-policy-keys](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchlogs.html#amazoncloudwatchlogs-policy-keys) to filter the log generating resource ARNs passed in the request. Using this condition operator, all of the ARNs in the request must match at least one ARN in the policy.    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "logs:PutDeliverySource",
            "Resource": "arn:aws:logs:us-east-1:123456789012:delivery-source:*",
            "Condition": {
                "ForAllValues:ArnLike": {
                    "logs:LogGeneratingResourceArns": [
                        "arn:aws:cloudfront::123456789012:distribution/*",
                        "arn:aws:cloudfront::123456789012:distribution/support*"
                    ]
                }
            }
        }
    ]
}
```
The following table shows how AWS evaluates this policy based on the condition key values in your request.  


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"ForAllValues:ArnLike": {<br />  "logs:LogGeneratingResourceArns": [<br />    "arn:aws::cloudfront:123456789012:distribution/*",<br />    "arn:aws::cloudfront:123456789012:distribution/support*"<br />  ]<br />}</pre>  | <pre>logs:LogGeneratingResourceArns:<br />  – arn:aws::cloudfront:123456789012:distribution/costcenter</pre>  | Match | 
|  <pre>"ForAllValues:ArnLike": {<br />  "logs:LogGeneratingResourceArns": [<br />    "arn:aws::cloudfront:123456789012:distribution/*",<br />    "arn:aws::cloudfront:123456789012:distribution/support*"<br />  ]<br />}</pre>  | <pre>logs:LogGeneratingResourceArns:<br />  – arn:aws::cloudfront:123456789012:distribution/costcenter<br />  – arn:aws::cloudfront:123456789012:distribution/support2025</pre>  | Match | 
|  <pre>"ForAllValues:ArnLike": {<br />  "logs:LogGeneratingResourceArns": [<br />    "arn:aws::cloudfront:123456789012:distribution/*",<br />    "arn:aws::cloudfront:123456789012:distribution/support*"<br />  ]<br />}</pre>  | <pre>logs:LogGeneratingResourceArns:<br />  – arn:aws::cloudfront:123456789012:distribution/costcenter<br />  – arn:aws::cloudfront:123456789012:distribution/admin</pre>  | No match | 
|  <pre>"ForAllValues:ArnLike": {<br />  "logs:LogGeneratingResourceArns": [<br />    "arn:aws::cloudfront:123456789012:distribution/*",<br />    "arn:aws::cloudfront:123456789012:distribution/support*"<br />  ]<br />}</pre>  | <pre>logs:LogGeneratingResourceArns:<br />  – arn:aws::cloudfront:777788889999:distribution/costcenter</pre>  | No match | 
|  <pre>"ForAllValues:ArnLike": {<br />  "logs:LogGeneratingResourceArns": [<br />    "arn:aws::cloudfront:123456789012:distribution/*",<br />    "arn:aws::cloudfront:123456789012:distribution/support*"<br />  ]<br />}</pre>  |  No `logs:LogGeneratingResourceArns` in the request context.  | Match  | 
The `ForAllValues` qualifier returns true if there are no context keys in the request or if the context key value resolves to a null dataset, such as an empty string. To prevent missing context keys or context keys with empty values from evaluating to true, you can include the [Null condition operator](#Conditions_Null) in your policy with a `false` value to check if the context key exists and its value is not null.

## ...IfExists condition operators
<a name="Conditions_IfExists"></a>

You can add `IfExists` to the end of any condition operator name except the `Null` condition—for example, `StringLikeIfExists`. You do this to say "If the condition key is present in the context of the request, process the key as specified in the policy. If the key is not present, evaluate the condition element as true." Other condition elements in the statement can still result in a nonmatch, but not a missing key when checked with `...IfExists`. If you are using an `"Effect": "Deny"` element with a negated condition operator like `StringNotEqualsIfExists`, the request is still denied even if the condition key is not present.

**Example using `IfExists`**

Many condition keys describe information about a certain type of resource and only exist when accessing that type of resource. These condition keys are not present on other types of resources. This doesn't cause an issue when the policy statement applies to only one type of resource. However, there are cases where a single statement can apply to multiple types of resources, such as when the policy statement references actions from multiple services or when a given action within a service accesses several different resource types within the same service. In such cases, including a condition key that applies to only one of the resources in the policy statement can cause the `Condition` element in the policy statement to fail such that the statement's `"Effect"` does not apply.

For example, consider the following policy example:

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "THISPOLICYDOESNOTWORK",
    "Effect": "Allow",
    "Action": "ec2:RunInstances",
    "Resource": "*",
    "Condition": {"StringLike": {"ec2:InstanceType": [
      "t1.*",
      "t2.*",
      "m3.*"
    ]}}
  }
}
```

------

The *intent* of the preceding policy is to enable the user to launch any instance that is type `t1`, `t2` or `m3`. However, launching an instance requires accessing many resources in addition to the instance itself; for example, images, key pairs, security groups, and more. The entire statement is evaluated against every resource that is required to launch the instance. These additional resources do not have the `ec2:InstanceType` condition key, so the `StringLike` check fails, and the user is not granted the ability to launch *any* instance type. 

To address this, use the `StringLikeIfExists` condition operator instead. This way, the test only happens if the condition key exists. You could read the following policy as: "If the resource being checked has an "`ec2:InstanceType`" condition key, then allow the action only if the key value begins with `t1.`, `t2.`, or `m3.`. If the resource being checked does not have that condition key, then don't worry about it." The asterisk (\$1) in the condition key values, when used with the `StringLikeIfExists` condition operator, is interpreted as a wildcard to achieve partial string matches. The `DescribeActions` statement includes the actions required to view the instance in the console.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "RunInstance",
      "Effect": "Allow",
      "Action": "ec2:RunInstances",
      "Resource": "*",
      "Condition": {
        "StringLikeIfExists": {
          "ec2:InstanceType": [
            "t1.*",
            "t2.*",
            "m3.*"
          ]
        }
      }
    },
    {
      "Sid": "DescribeActions",
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeImages",
        "ec2:DescribeInstances",
        "ec2:DescribeVpcs",
        "ec2:DescribeKeyPairs",
        "ec2:DescribeSubnets",
        "ec2:DescribeSecurityGroups"
      ],
      "Resource": "*"
    }
  ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request.


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"StringLikeIfExists": {<br />  "ec2:InstanceType": [<br />    "t1.*",<br />    "t2.*",<br />    "m3.*"<br />  ]<br />}</pre>  | <pre>ec2:InstanceType:<br />  – t1.micro</pre>  | Match | 
|  <pre>"StringLikeIfExists": {<br />  "ec2:InstanceType": [<br />    "t1.*",<br />    "t2.*",<br />    "m3.*"<br />  ]<br />}</pre>  | <pre>ec2:InstanceType:<br />  – m2.micro</pre>  | No match | 
|  <pre>"StringLikeIfExists": {<br />  "ec2:InstanceType": [<br />    "t1.*",<br />    "t2.*",<br />    "m3.*"<br />  ]<br />}</pre>  |  No `ec2:InstanceType` in the request context.  | Match | 

## Condition operator to check existence of condition keys
<a name="Conditions_Null"></a>

Use a `Null` condition operator to check if a condition key is absent at the time of authorization. In the policy statement, use either `true` (the key doesn't exist — it is null) or `false` (the key exists and its value is not null).

You can not use a [policy variable](reference_policies_variables.md) with the `Null` condition operator.

For example, you can use this condition operator to determine whether a user is using temporary credentials or their own credentials to make a request. If the user is using temporary credentials, then the key `aws:TokenIssueTime` exists and has a value. The following example shows a condition that states that the user must be using temporary credentials (the key cannot be absent) for the user to use the Amazon EC2 API.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement":{
      "Action":"ec2:*",
      "Effect":"Allow",
      "Resource":"*",
      "Condition":{"Null":{"aws:TokenIssueTime":"false"}}
  }
}
```

------

# Conditions with multiple context keys or values
<a name="reference_policies_condition-logic-multiple-context-keys-or-values"></a>

You can use the `Condition` element of a policy to test multiple context keys or multiple values for a single context key in a request. When you make a request to AWS, either programmatically or through the AWS Management Console, your request includes information about your principal, operation, tags, and more. You can use context keys to test the values of the matching context keys in the request, with the context keys specified in the policy condition. To learn about information and data included in a request, see [The request context](reference_policies_elements_condition.md#AccessPolicyLanguage_RequestContext).

**Topics**
+ [

## Evaluation logic for multiple context keys or values
](#reference_policies_multiple-conditions-eval)
+ [

## Evaluation logic for negated matching condition operators
](#reference_policies_multiple-conditions-negated-matching-eval)

## Evaluation logic for multiple context keys or values
<a name="reference_policies_multiple-conditions-eval"></a>

A `Condition` element can contain multiple condition operators, and each condition operator can contain multiple context key-value pairs. Most context keys support using multiple values, unless otherwise specified.
+ If your policy statement has multiple [condition operators](reference_policies_elements_condition_operators.md), the condition operators are evaluated using a logical `AND`.
+ If your policy statement has multiple context keys attached to a single condition operator, the context keys are evaluated using a logical `AND`.
+ If a single condition operator includes multiple values for a context key, those values are evaluated using a logical `OR`.
+ If a single negated matching condition operator includes multiple values for a context key, those values are evaluated using a logical `NOR`. 

All context keys in a condition element block must resolve to true to invoke the desired `Allow` or `Deny` effect. The following figure illustrates the evaluation logic for a condition with multiple condition operators and context key-value pairs.

![\[Condition block showing how AND and OR are applied to multiple context keys and values\]](http://docs.aws.amazon.com/IAM/latest/UserGuide/images/AccessPolicyLanguage_Condition_Block_AND_2.diagram.png)


For example, the following S3 bucket policy illustrates how the previous figure is represented in a policy. The condition block includes condition operators `StringEquals` and `ArnLike`, and context keys `aws:PrincipalTag` and `aws:PrincipalArn`. To invoke the desired `Allow` or `Deny` effect, all context keys in the condition block must resolve to true. The user making the request must have both principal tag keys, *department* and *role*, that include one of the tag key values specified in the policy. Also, the principal ARN of the user making the request must match one of the `aws:PrincipalArn` values specified in the policy to be evaluated as true.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "ExamplePolicy",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::222222222222:root"
      },
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
      "Condition": {
        "StringEquals": {
          "aws:PrincipalTag/department": [
            "finance",
            "hr",
            "legal"
          ],
          "aws:PrincipalTag/role": [
            "audit",
            "security"
          ]
        },
        "ArnLike": {
          "aws:PrincipalArn": [
            "arn:aws:iam::222222222222:user/Ana",
            "arn:aws:iam::222222222222:user/Mary"
          ]
        }
      }
    }
  ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request.


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | <pre>aws:PrincipalTag/department: legal<br />aws:PrincipalTag/role: audit<br />aws:PrincipalArn: <br />  arn:aws:iam::222222222222:user/Mary</pre>  |  **Match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | <pre>aws:PrincipalTag/department: hr<br />aws:PrincipalTag/role: audit<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Nikki</pre>  | **No match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | <pre>aws:PrincipalTag/department: hr<br />aws:PrincipalTag/role: payroll<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Mary</pre>  | **No match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  |  No `aws:PrincipalTag/role` in the request context. <pre>aws:PrincipalTag/department: hr<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Mary</pre>  | **No match**  | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | No `aws:PrincipalTag` in the request context. <pre>aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Mary</pre>  | **No match**  | 

## Evaluation logic for negated matching condition operators
<a name="reference_policies_multiple-conditions-negated-matching-eval"></a>

Some [condition operators,](reference_policies_elements_condition_operators.md) such as `StringNotEquals` or `ArnNotLike`, use negated matching to compare the context key-value pairs in your policy against the context key-value pairs in a request. When multiple values are specified for a single context key in a policy with negated matching condition operators, the effective permissions work like a logical `NOR`. In negated matching, a logical `NOR` or `NOT OR` returns true only if all values evaluate to false.

The following figure illustrates the evaluation logic for a condition with multiple condition operators and context key-value pairs. The figure includes a negated matching condition operator for context key 3.

![\[Condition block showing how AND and OR are applied to multiple context keys and values when a negated matching condition operator is used\]](http://docs.aws.amazon.com/IAM/latest/UserGuide/images/AccessPolicyLanguage_Condition_Block_AND_Negated_NOR_2.diagram.png)


For example, the following S3 bucket policy illustrates how the previous figure is represented in a policy. The condition block includes condition operators `StringEquals` and `ArnNotLike`, and context keys `aws:PrincipalTag` and `aws:PrincipalArn`. To invoke the desired `Allow` or `Deny` effect, all context keys in the condition block must resolve to true. The user making the request must have both principal tag keys, *department* and *role*, that include one of the tag key values specified in the policy. Since the `ArnNotLike` condition operator uses negated matching, the principal ARN of the user making the request must not match any of the `aws:PrincipalArn` values specified in the policy to be evaluated as true.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "ExamplePolicy",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::222222222222:root"
      },
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
      "Condition": {
        "StringEquals": {
          "aws:PrincipalTag/department": [
            "finance",
            "hr",
            "legal"
          ],
          "aws:PrincipalTag/role": [
            "audit",
            "security"
          ]
        },
        "ArnNotLike": {
          "aws:PrincipalArn": [
            "arn:aws:iam::222222222222:user/Ana",
            "arn:aws:iam::222222222222:user/Mary"
          ]
        }
      }
    }
  ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request.


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnNotLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | <pre>aws:PrincipalTag/department: legal<br />aws:PrincipalTag/role: audit<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Nikki<br /></pre>  |  **Match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnNotLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | <pre>aws:PrincipalTag/department: hr<br />aws:PrincipalTag/role: audit<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Mary</pre>  | **No match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnNotLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | <pre>aws:PrincipalTag/department: hr<br />aws:PrincipalTag/role: payroll<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Nikki</pre>  | **No match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnNotLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | >No `aws:PrincipalTag/role` in the request context. <pre>aws:PrincipalTag/department: hr<br />aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Nikki</pre>  | **No match** | 
|  <pre>"StringEquals": {<br />  "aws:PrincipalTag/department": [<br />    "finance",<br />    "hr",<br />    "legal"<br />  ],<br />  "aws:PrincipalTag/role": [<br />    "audit",<br />    "security"<br />  ]<br />},<br />"ArnNotLike": {<br />  "aws:PrincipalArn": [<br />      "arn:aws:iam::222222222222:user/Ana",<br />      "arn:aws:iam::222222222222:user/Mary"<br />  ]<br />}</pre>  | No `aws:PrincipalTag` in the request context. <pre>aws:PrincipalArn:<br />  arn:aws:iam::222222222222:user/Nikki</pre>  | **No match**  | 

# Single-valued vs. multivalued context keys
<a name="reference_policies_condition-single-vs-multi-valued-context-keys"></a>

The difference between single-valued and multivalued context keys lies in the number of values in the [request context](intro-structure.md#intro-structure-request), not the number of values in the policy condition.
+ *Single-valued* condition context keys have at most one value in the request context. For example, when you tag resources in AWS, each resource tag is stored as a key-value pair. Since a resource tag key can have only a single tag value, [aws:ResourceTag/*tag-key*](reference_policies_condition-keys.md#condition-keys-resourcetag) is a single-valued context key. Do not use a condition set operator with a single-valued context key.
+ *Multivalued* condition context keys can have multiple values in the request context. For example, when you tag resources in AWS, you can include multiple tag key-value pairs in a single request. Therefore, [aws:TagKeys](reference_policies_condition-keys.md#condition-keys-tagkeys) is a multivalued context key. Multivalued context keys require a condition set operator.

For example, a request can originate from at most one VPC endpoint, so [aws:SourceVpce](reference_policies_condition-keys.md#condition-keys-sourcevpce) is a single-valued context key. Since a service can have more than one service principal name that belongs to the service, [aws:PrincipalServiceNamesList](reference_policies_condition-keys.md#condition-keys-principalservicenameslist) is a multivalued context key.

**Important**  
The difference between single-valued and multivalued context keys depends on the number of values in the request context, not the number of values in the policy condition.

## Key points
<a name="reference_policies_condition-key-points"></a>
+ The *Single-valued* and *Multivalued* classifications are included in the description of each condition context key as *Value type* in the [AWS global condition context keys](reference_policies_condition-keys.md) topic.
+ Multivalued context keys in the [Service Authorization Reference](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html) use an `ArrayOf` prefix followed by the condition operator category type, such as `ArrayOfString` or `ArrayOfARN`, indicating that the request may include multiple values for a condition context key.
+ You can use any available single-valued context key as a policy variable, but you cannot use a multivalued context key as a policy variable. For more information about policy variables, see [IAM policy elements: Variables and tags](reference_policies_variables.md).
+ When using context keys that include key-value pairs, it's important to note that even though there can be multiple tag-key values, each `tag-key` can have only one value.
  + [aws:PrincipalTag/*tag-key*](reference_policies_condition-keys.md#condition-keys-principaltag), [aws:RequestTag/*tag-key*](reference_policies_condition-keys.md#condition-keys-requesttag) and [aws:ResourceTag/*tag-key*](reference_policies_condition-keys.md#condition-keys-resourcetag) are single-valued context keys.
  + [aws:TagKeys](reference_policies_condition-keys.md#condition-keys-tagkeys) defines what tag-keys are allowed in a request but does not include the tag-key values. Because you can include multiple tag key-value pairs in a request, `aws:TagKeys` is a multivalued context key.
+ Multivalued context keys require a condition set operator. Do not use condition set operators `ForAllValues` or `ForAnyValue` with single-valued context keys. Using condition set operators with single-valued context keys can lead to overly permissive policies.

## Set operators for multivalued context keys
<a name="reference_policies_condition-multi-valued-context-keys"></a>

To compare your condition context key against a [request context](intro-structure.md#intro-structure-request) key with multiple values, you must use the `ForAllValues` or `ForAnyValue` set operators. These set operators are used to compare two sets of values, such as the set of tags in a request and the set of tags in a policy condition.

The `ForAllValues` and `ForAnyValue` qualifiers add set-operation functionality to the condition operator, allowing you to test request context keys with multiple values against multiple context key values in a policy condition. Additionally, if you include a multivalued string context key in your policy with a wildcard or a variable, you must also use the `StringLike` [condition operator](reference_policies_elements_condition_operators.md#Conditions_String). Multiple condition key values must be enclosed in brackets like an [array](reference_policies_grammar.md#policies-grammar-json), for example, `"Key2":["Value2A", "Value2B"]`.

### ForAllValues
<a name="reference_policies_condition-forallvalues"></a>

The `ForAllValues` qualifier tests whether the value of every member of the request context matches the condition operator that follows the qualifier. The condition returns `true` if every context key value in the request matches a context key value in the policy. It also returns `true` if there are no context keys in the request.

**Important**  
Use caution if you use `ForAllValues` with an `Allow` effect, as it can be overly permissive if the presence of missing context keys in the request context is unexpected. You should always include the [`Null`](reference_policies_elements_condition_operators.md#Conditions_Null) condition operator in your policy with a `false` value to check if the context key exists and its value is not null. For an example, see [Controlling access based on tag keys](access_tags.md#access_tags_control-tag-keys).

#### Example ForAllValues set operator
<a name="reference_policies_condition-forallvalues-example"></a>

In the following example, ForAllValues is used with aws:TagKeys to allow users to delete specific tags assigned to an EC2 instance. This policy allows users to delete only the `environment` and `cost-center` tags. You can delete them separately or together. The tag-keys in the request must match exactly the specified keys in the policy.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "ec2:DeleteTags",
            "Resource": "arn:aws:ec2:us-east-1:111122223333:instance/*",
            "Condition": {
                "ForAllValues:StringEquals": {
                    "aws:TagKeys": [
                        "environment",
                        "cost-center"
                    ]
                },
                "Null": {
                    "aws:TagKeys": "false"
                }
            }
        }
    ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request.


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"ForAllValues:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />},<br />"Null": {<br />  "aws:TagKeys": "false"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment</pre>  |  **Match**  | 
|  <pre>"ForAllValues:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />},<br />"Null": {<br />  "aws:TagKeys": "false"<br />}</pre>  | <pre>aws:TagKeys:<br />  – cost-center</pre>  |  **Match**  | 
|  <pre>"ForAllValues:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />},<br />"Null": {<br />  "aws:TagKeys": "false"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – cost-center</pre>  |  **Match**  | 
|  <pre>"ForAllValues:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />},<br />"Null": {<br />  "aws:TagKeys": "false"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – dept</pre>  |  **No match**  | 
|  <pre>"ForAllValues:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />},<br />"Null": {<br />  "aws:TagKeys": "false"<br />}</pre>  |  No `aws:TagKeys` in the request context.  |  **No match**  | 

Note that in the last example, the result is "No Match" because the Null condition check prevents matching when the context key is missing. This is a best practice to avoid overly permissive policies.

### ForAnyValue
<a name="reference_policies_condition-foranyvalue"></a>

The `ForAnyValue` qualifier tests whether at least one member of the set of request context key values matches at least one member of the set of context key values in your policy condition. The condition returns `true` if any one of the context key values in the request matches any one of the context key values in the policy. For no matching context key or if the key does not exist, the condition returns `false`.

**Important**  
When using `ForAnyValue` with a `Deny` effect, if the context key is not present in the request, the policy evaluates as **No match**. For consistent behavior, add an explicit [`Null`](reference_policies_elements_condition_operators.md#Conditions_Null) condition check in your policy to verify whether the context key exists. For details, see [Condition operator to check existence of condition keys](reference_policies_elements_condition_operators.md#Conditions_Null).

#### Example ForAnyValue set operator
<a name="reference_policies_condition-foranyvalue-example"></a>

In the following example, ForAnyValue is used with aws:TagKeys to allow users to delete specific tags assigned to an EC2 instance. This policy allows users to delete tags for an instance if the tag keys specified in the request include `environment` or `cost-center`. The request can include additional tag keys beyond those specified in the policy, but must include at least one of the specified keys to match the condition.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "ec2:DeleteTags",
            "Resource": "arn:aws:ec2:us-east-1:111122223333:instance/*",
            "Condition": {
                "ForAnyValue:StringEquals": {
                    "aws:TagKeys": [
                        "environment",
                        "cost-center"
                    ]
                }
            }
        }
    ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request.


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment</pre>  |  **Match**  | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – cost-center</pre>  |  **Match**  | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – cost-center</pre>  |  **Match**  | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – dept</pre>  |  **Match**  | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – dept</pre>  |  **No match**  | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": [<br />    "environment",<br />    "cost-center"<br />  ]<br />}</pre>  |  No `aws:TagKeys` in the request context.  |  **No match**  | 

# Condition policy examples
<a name="reference_policies_condition_examples"></a>

In IAM policies, you can specify multiple values for both single-valued and multivalued context keys for comparison against the request context. The following set of policy examples demonstrates policy conditions with multiple context keys and values.

**Note**  
If you would like to submit a policy to be included in this reference guide, use the **Feedback** button at the bottom of this page. For IAM identity-based policy examples, see [Example IAM identity-based policies](access_policies_examples.md).

## Condition policy examples: Single-valued context keys
<a name="reference_policies_condition_example_library_single-valued"></a>
+ Multiple condition blocks with single-valued context keys. ([View this example](reference_policies_condition_examples-single-valued-context-keys.md#reference_policies_condition_examples-single-valued-context-keys-1).)
+ One condition block with multiple single-valued context keys and values. ([View this example](reference_policies_condition_examples-single-valued-context-keys.md#reference_policies_condition_examples-single-valued-context-keys-2).)

## Condition policy examples: Multivalued context keys
<a name="reference_policies_condition_example_library_multi-valued"></a>
+ Deny policy with condition set operator `ForAllValues`. ([View this example](reference_policies_condition_examples-multi-valued-context-keys.md#reference_policies_condition_examples-multi-valued-context-keys-1).)
+ Deny policy with condition set operator `ForAnyValue`. ([View this example](reference_policies_condition_examples-multi-valued-context-keys.md#reference_policies_condition_examples-multi-valued-context-keys-2).)

# Multivalued context key examples
<a name="reference_policies_condition_examples-multi-valued-context-keys"></a>

The following set of policy examples demonstrate how to create policy conditions with multivalued context keys.

## Example: Deny policy with condition set operator ForAllValues
<a name="reference_policies_condition_examples-multi-valued-context-keys-1"></a>

The following examples show how to use an identity-based policy to deny the use of IAM tagging actions when specific tag key prefixes are included in the request. The values for [`aws:TagKeys`](reference_policies_condition-keys.md#condition-keys-tagkeys) include a wildcard (\$1) for partial string matching. The policy includes the `ForAllValues` set operator with context key `aws:TagKeys` because the request context key can include multiple values. In order for context key `aws:TagKeys` to match, every value in the request context must match at least one value in the policy.

The `ForAllValues` set operator also returns true if there are no context keys in the request.

You can prevent missing context keys or context keys with empty values from evaluating to true by including a `Null` condition operator in your policy with a value of `false` to check if the context key in the request exists and its value is not null. For more information, see [Condition operator to check existence of condition keys](reference_policies_elements_condition_operators.md#Conditions_Null).

**Important**  
This policy does not allow any actions. Use this policy in combination with other policies that allow specific actions.

**Example Deny a single policy condition value for a multivalued context key**  
In the following example, the policy denies requests where the values for `aws:TagKeys` in the request do not include the prefix **key1**. The request context can have multiple values, but because of the `ForAllValues` condition set operator, all the tag key values in the request context must start with the prefix **key1**.    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyRestrictedTags",
      "Effect": "Deny",
      "Action": [
        "iam:Tag*",
        "iam:UnTag*"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {
        "ForAllValues:StringNotLike": {
          "aws:TagKeys": "key1*"
        }
      }
    }
  ]
}
```
The following table shows how AWS evaluates this policy based on the condition key values in your request. For a Deny statement, Match is Denied and No match is Not denied, so it may be allowed by another statement.  


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"ForAllValues:StringNotLike": {<br />  "aws:TagKeys": "key1*"<br />}</pre>  | <pre>aws:TagKeys:<br />  – key1:legal</pre>  |  **No match** May be allowed by another statement. | 
| <pre>"ForAllValues:StringNotLike": {<br />  "aws:TagKeys": "key1*"<br />}</pre>  | <pre>aws:TagKeys:<br />  – key1:hr<br />  – key1:personnel</pre>  | **No match** May be allowed by another statement. | 
| <pre>"ForAllValues:StringNotLike": {<br />  "aws:TagKeys": "key1*"<br />}</pre>  | <pre>aws:TagKeys:<br />  – key2:audit</pre>  | **Match** | 
| <pre>"ForAllValues:StringNotLike": {<br />  "aws:TagKeys": "key1*"<br />}</pre>  | No `aws:TagKeys` in the request context.  | **Match** | 

**Example Deny multiple policy condition values for a multivalued context key**  
In the following example, the policy denies requests where the values for `aws:TagKeys` in the request do not include the prefix **key1** or **key2**. The request context can have multiple values, but because of the `ForAllValues` condition set operator, all the tag key values in the request context must start with the prefix **key1** or **key2**.    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyRestrictedTags",
      "Effect": "Deny",
      "Action": [
        "iam:Tag*",
        "iam:UnTag*"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {
        "ForAllValues:StringNotLike": {
          "aws:TagKeys": [
            "key1*",
            "key2*"
          ]
        }
      }
    }
  ]
}
```
The following table shows how AWS evaluates this policy based on the condition key values in your request. For a Deny statement, Match is Denied and No match is Not denied, so it may be allowed by another statement.  


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"ForAllValues:StringNotLike": {<br />  "aws:TagKeys": [<br />    "key1*",<br />    "key2*"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – key1:legal</pre>  |  **No match** May be allowed by another statement. | 
| <pre>"ForAllValues:StringNotLike": {<br />   "aws:TagKeys": [<br />    "key1*",<br />    "key2*"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – key1:hr<br />  – key1:personnel</pre>  | **No match** May be allowed by another statement. | 
| <pre>"ForAllValues:StringNotLike": {<br />   "aws:TagKeys": [<br />    "key1*",<br />    "key2*"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – key1:hr<br />  – key2:audit</pre>  | **No match** May be allowed by another statement. | 
| <pre>"ForAllValues:StringNotLike": {<br />   "aws:TagKeys": [<br />    "key1*",<br />    "key2*"<br />  ]<br />}</pre>  | <pre>aws:TagKeys:<br />  – key3:legal</pre>  | **Match**  | 
| <pre>"ForAllValues:StringNotLike": {<br />   "aws:TagKeys": [<br />    "key1*",<br />    "key2*"<br />  ]<br />}</pre>  | No `aws:TagKeys` in the request context.  | **Match** | 

## Example: Deny policy with condition set operator ForAnyValue
<a name="reference_policies_condition_examples-multi-valued-context-keys-2"></a>

The following identity-based policy example denies creating snapshots of EC2 instance volumes if any snapshots are tagged with one of the tag keys specified in the policy, `environment` or `webserver`. The policy includes the `ForAnyValue` set operator with context key `aws:TagKeys` because the request context key can include multiple values. If your tagging request includes any one of the tag key values specified in the policy, the `aws:TagKeys` context key returns true invoking the deny policy effect.

**Important**  
This policy does not allow any actions. Use this policy in combination with other policies that allow specific actions.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Deny",
      "Action": [
        "ec2:CreateSnapshot",
        "ec2:CreateSnapshots"
      ],
      "Resource": "arn:aws:ec2:us-west-2::snapshot/*",
      "Condition": {
        "ForAnyValue:StringEquals": {
          "aws:TagKeys": "webserver"
        }
      }
    }
  ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request. For a Deny statement, Match is Denied and No match is Not denied, so it may be allowed by another statement.


| Policy Condition | Request Context | Result | 
| --- | --- | --- | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "webserver"<br />}</pre>  | <pre>aws:TagKeys:<br />  – webserver</pre>  | **Match** | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "webserver"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – webserver<br />  – test</pre>  |  **Match** | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "webserver"<br />}</pre>  | <pre>aws:TagKeys:<br />  – environment<br />  – test</pre>  | **No match** May be allowed by another statement. | 
|  <pre>"ForAnyValue:StringEquals": {<br />  "aws:TagKeys": "webserver"<br />}</pre>  | No `aws:TagKeys` in the request context.  | **No match** May be allowed by another statement.  | 

# Single-valued context key policy examples
<a name="reference_policies_condition_examples-single-valued-context-keys"></a>

The following set of policy examples demonstrate how to create policy conditions with single-valued context keys.

## Example: Multiple condition blocks with single-valued context keys
<a name="reference_policies_condition_examples-single-valued-context-keys-1"></a>

When a condition block has multiple conditions, each with a single context key, all context keys must resolve to true for the desired `Allow` or `Deny` effect to be invoked. When you use negated matching condition operators, the evaluation logic of the condition value is reversed.

The following example lets users create EC2 volumes and apply tags to the volumes during volume creation. The request context must include a value for context key `aws:RequestTag/project`, and the value for context key `aws:ResourceTag/environment` can be anything except production.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "ec2:CreateVolume",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "ec2:CreateTags",
      "Resource": "arn:aws:ec2:us-east-1:123456789012:volume/*",
      "Condition": {
        "StringLike": {
          "aws:RequestTag/project": "*"
        }
      }
    },
    {
      "Effect": "Allow",
      "Action": "ec2:CreateTags",
      "Resource": "arn:aws:ec2:us-east-1:123456789012:*/*",
      "Condition": {
        "StringNotEquals": {
          "aws:ResourceTag/environment": "production"
        }
      }
    }
  ]
}
```

------

The request context must include a project tag-value and cannot be created for a production resource to invoke the `Allow` effect. The following EC2 volume is successfully created because the project name is `Feature3` with a `QA` resource tag.

```
aws ec2 create-volume \
    --availability-zone us-east-1a \
    --volume-type gp2 \
    --size 80 \
    --tag-specifications 'ResourceType=volume,Tags=[{Key=project,Value=Feature3},{Key=environment,Value=QA}]'
```

## Example: One condition block with multiple single-valued context keys and values
<a name="reference_policies_condition_examples-single-valued-context-keys-2"></a>

When a condition block contains multiple context keys and each context key has multiple values, each context key must resolve to true for at least one key value for the desired `Allow` or `Deny` effect to be invoked. When you use negated matching condition operators, the evaluation logic of the context key value is reversed.

The following example allows users to start and run tasks on Amazon Elastic Container Service clusters.
+ The request context must include `production` **OR** `prod-backup` for the `aws:RequestTag/environment` context key **AND**.
+ The `ecs:cluster` context key makes sure that tasks are run on either the `default1` **OR** `default2` ARN ECS clusters.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ecs:RunTask",
        "ecs:StartTask"
      ],
      "Resource": [
        "*"
      ],
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/environment": [
            "production",
            "prod-backup"
          ]
        },
        "ArnEquals": {
          "ecs:cluster": [
            "arn:aws:ecs:us-east-1:111122223333:cluster/default1",
            "arn:aws:ecs:us-east-1:111122223333:cluster/default2"
          ]
        }
      }
    }
  ]
}
```

------

The following table shows how AWS evaluates this policy based on the condition key values in your request.


| Policy condition | Request context | Result | 
| --- | --- | --- | 
|  <pre>"StringEquals": {<br />  "aws:RequestTag/environment": [<br />    "production",<br />    "prod-backup"<br />  ]<br />},<br />"ArnEquals": {<br />  "ecs:cluster": [<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default1",<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default2"<br />  ]<br />}</pre>  | <pre>aws:RequestTag: environment:production<br />ecs:cluster:<br />  arn:aws:ecs:us-east-1:111122223333:cluster/default1</pre>  | Match | 
| <pre>"StringEquals": {<br />  "aws:RequestTag/environment": [<br />    "production",<br />    "prod-backup"<br />  ]<br />},<br />"ArnEquals": {<br />  "ecs:cluster": [<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default1",<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default2"<br />  ]<br />}</pre>  | <pre>aws:RequestTag: environment:prod-backup<br />ecs:cluster:<br />  arn:aws:ecs:us-east-1:111122223333:cluster/default2</pre>  | Match | 
| <pre>"StringEquals": {<br />  "aws:RequestTag/environment": [<br />    "production",<br />    "prod-backup"<br />  ]<br />},<br />"ArnEquals": {<br />  "ecs:cluster": [<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default1",<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default2"<br />  ]<br />}</pre>  | <pre>aws:RequestTag: webserver:production<br />ecs:cluster:<br />  arn:aws:ecs:us-east-1:111122223333:cluster/default2</pre>  | No match | 
| <pre>"StringEquals": {<br />  "aws:RequestTag/environment": [<br />    "production",<br />    "prod-backup"<br />  ]<br />},<br />"ArnEquals": {<br />  "ecs:cluster": [<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default1",<br />    "arn:aws:ecs:us-east-1:111122223333:cluster/default2"<br />  ]<br />}</pre>  |  No `aws:RequestTag` in the request context. <pre>ecs:cluster<br />  arn:aws:ecs:us-east-1:111122223333:cluster/default2</pre>  | No match | 