

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Utilizzo delle chiavi di condizione
<a name="IAM.ConditionKeys"></a>

Puoi specificare le condizioni che determinano il modo in cui una policy IAM viene applicata. In ElastiCache, puoi utilizzare l'`Condition`elemento di una policy JSON per confrontare le chiavi nel contesto della richiesta con i valori chiave che specifichi nella tua policy. Per ulteriori informazioni, consulta [elementi della policy IAM JSON: condizione](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html).

Per visualizzare un elenco di chiavi di ElastiCache condizione, consulta [Condition Keys for Amazon ElastiCache](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticache.html#amazonelasticache-policy-keys) nel *Service Authorization Reference*.

Per un elenco delle chiavi di condizione globali, consulta [Chiavi di contesto delle condizioni globali AWS](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html).

**Utilizzo ElastiCache con AWS Global Condition Keys**

Quando si utilizzano [chiavi di condizione AWS globali](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html) che richiedono ElastiCache [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services), utilizzare una `OR` condizione con *entrambi* i Principal: `elasticache.amazonaws.com` e`ec.amazonaws.com`.

**Nota**  
Se non aggiungi entrambi i Principal per ElastiCache, l'azione «Consenti» o «Nega» prevista non verrà applicata correttamente per nessuna delle risorse elencate nella tua politica.

 Esempio di politica con chiave di condizione `aws:CalledVia` globale:

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "ec2:*", 
      "Resource": "*",
      "Condition": {
        "ForAnyValue:StringLike": {
          "aws:CalledVia": [
            "ec.amazonaws.com",
            "elasticache.amazonaws.com"
          ]
        }
      }
    }
  ]
}
```

------

## Specifica delle condizioni: Uso delle chiavi di condizione
<a name="IAM.SpecifyingConditions"></a>

Per implementare un controllo particolareggiato, scrivi una policy relativa alle autorizzazioni IAM che specifichi le condizioni per controllare un set di singoli parametri su determinate richieste. Quindi la policy viene applicata agli utenti, ai gruppi o ai ruoli IAM creati utilizzando la console IAM. 

Per applicare una condizione, aggiungere le informazioni sulla condizione all'istruzione della policy IAM. Nell'esempio seguente, si specifica la condizione che qualsiasi cluster basato su nodi creato sia del tipo di nodo. `cache.r5.large` 

**Nota**  
Per costruire `Condition` elementi utilizzando chiavi di condizione di `String` tipo, utilizzate gli operatori di condizione senza distinzione tra maiuscole e minuscole `StringEqualsIgnoreCase` o `StringNotEqualsIgnoreCase` per confrontare una chiave con un valore di stringa.
ElastiCache elabora gli argomenti di input per `CacheNodeType` e senza distinzione `CacheParameterGroupName` tra maiuscole e minuscole. Per questo motivo, la stringa condiziona gli operatori `StringEqualsIgnoreCase` e `StringNotEqualsIgnoreCase` deve essere utilizzata nelle politiche di autorizzazione che vi fanno riferimento.

Di seguito viene illustrato un esempio di questa politica di autorizzazioni quando si utilizza Valkey o Redis OSS.

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticache:CreateCacheCluster",
                "elasticache:CreateReplicationGroup"
            ],
            "Resource": [
                "arn:aws:elasticache:*:*:parametergroup:*",
                "arn:aws:elasticache:*:*:subnetgroup:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "elasticache:CreateCacheCluster",
                "elasticache:CreateReplicationGroup"
            ],
            "Resource": [
                "arn:aws:elasticache:*:*:cluster:*",
                "arn:aws:elasticache:*:*:replicationgroup:*"
            ],
            "Condition": {
                "StringEquals": {
                    "elasticache:CacheNodeType": [
                        "cache.r5.large"
                    ]
                }
            }
        }
    ]
}
```

------

Di seguito viene mostrato un esempio di questa politica di autorizzazioni quando si utilizza Memcached.

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "elasticache:CreateCacheCluster"
            ],
            "Resource": [
                "arn:aws:elasticache:*:*:parametergroup:*",
                "arn:aws:elasticache:*:*:subnetgroup:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "elasticache:CreateCacheCluster"
            ],
            "Resource": [
                "arn:aws:elasticache:*:*:cluster:*"
            ],
            "Condition": {
                "StringEquals": {
                    "elasticache:CacheNodeType": [
                        "cache.r5.large"
                    ]
                }
            }
        }
    ]
}
```

------

Per ulteriori informazioni, consulta [Taggare le tue risorse ElastiCache](Tagging-Resources.md). 

Per ulteriori informazioni sull'utilizzo degli operatori delle condizioni di policy, consulta [ElastiCache Autorizzazioni API: riferimento ad azioni, risorse e condizioni](IAM.APIReference.md). 

## Policy di esempio: Utilizzo di condizioni per il controllo granulare dei parametri
<a name="IAM.ExamplePolicies"></a>

Questa sezione mostra alcuni esempi di policy per l'implementazione di un controllo granulare degli accessi sui parametri elencati in precedenza. ElastiCache 

1. **elasticache:MaximumDataStorage:** Specificare la memorizzazione massima dei dati di una cache serverless. Utilizzando le condizioni fornite, il cliente non può creare cache in grado di archiviare più di una quantità specifica di dati.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "AllowDependentResources",
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateServerlessCache"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:serverlesscachesnapshot:*",
                   "arn:aws:elasticache:*:*:snapshot:*",
                   "arn:aws:elasticache:*:*:usergroup:*"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateServerlessCache"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:serverlesscache:*"
               ],
               "Condition": {
                   "NumericLessThanEquals": {
                       "elasticache:MaximumDataStorage": "30"
                   },
                   "StringEquals": {
                       "elasticache:DataStorageUnit": "GB"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:Maximum ECPUPer Second: specifica il valore massimo** di ECPU al secondo di una cache serverless. Utilizzando le condizioni fornite, il cliente non può creare cache in grado di eseguire più di un numero specifico di cache al secondo. ECPUs 

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "AllowDependentResources",
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateServerlessCache"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:serverlesscachesnapshot:*",
                   "arn:aws:elasticache:*:*:snapshot:*",
                   "arn:aws:elasticache:*:*:usergroup:*"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateServerlessCache"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:serverlesscache:*"
               ],
               "Condition": {
                   "NumericLessThanEquals": {
                       "elasticache:MaximumECPUPerSecond": "100000"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:CacheNodeType:** Specificate quali NodeType possono essere create da un utente. Utilizzando le condizioni fornite, il cliente può specificare un valore singolo o un valore di intervallo per un tipo di nodo.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:CacheNodeType": [
                           "cache.t2.micro",
                           "cache.t2.medium"
                       ]
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:CacheNodeType:** Con Memcached, specifica quali sono le creazioni che un utente può NodeType creare. Utilizzando le condizioni fornite, il cliente può specificare un valore singolo o un valore di intervallo per un tipo di nodo.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:CacheNodeType": [
                           "cache.t2.micro",
                           "cache.t2.medium"
                       ]
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:NumNodeGroups:** Crea un gruppo di replica con meno di 20 gruppi di nodi.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
               	"elasticache:CreateReplicationGroup"
               ],
               "Resource": [
               	"arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "NumericLessThanEquals": {
                       "elasticache:NumNodeGroups": "20"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:ReplicasPerNodeGroup:** Specificare le repliche per nodo tra 5 e 10.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "NumericGreaterThanEquals": {
                       "elasticache:ReplicasPerNodeGroup": "5"
                   },
                   "NumericLessThanEquals": {
                       "elasticache:ReplicasPerNodeGroup": "10"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:EngineVersion:** Specificare l'utilizzo della versione 5.0.6 del motore.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
        {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
              "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:EngineVersion": "5.0.6"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:EngineVersion:** Specificare l'utilizzo della versione 1.6.6 del motore Memcached

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
        {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:EngineVersion": "1.6.6"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:EngineType:** Specificare l'utilizzo solo di un motore Valkey o Redis OSS.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:EngineType": "redis"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:AtRestEncryptionEnabled:** Specificate che i gruppi di replica verranno creati solo con la crittografia abilitata.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
   
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "Bool": {
                       "elasticache:AtRestEncryptionEnabled": "true"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache: TransitEncryptionEnabled**

   1. Imposta la chiave di `elasticache:TransitEncryptionEnabled` condizione su `false` per l'[CreateReplicationGroup](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_CreateReplicationGroup.html)azione per specificare che i gruppi di replica possono essere creati solo quando TLS non viene utilizzato:

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

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "elasticache:CreateReplicationGroup"
                  ],
                  "Resource": [
                      "arn:aws:elasticache:*:*:parametergroup:*",
                      "arn:aws:elasticache:*:*:subnetgroup:*"
                  ]
              },
      
              {
                  "Effect": "Allow",
                  "Action": [
                      "elasticache:CreateReplicationGroup"
                  ],
                  "Resource": [
                      "arn:aws:elasticache:*:*:replicationgroup:*"
                  ],
                  "Condition": {
                      "Bool": {
                          "elasticache:TransitEncryptionEnabled": "false"
                      }
                  }
              }
          ]
      }
      ```

------

      Quando la chiave di `elasticache:TransitEncryptionEnabled` condizione è impostata su `false` in una politica per l'[CreateReplicationGroup](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_CreateReplicationGroup.html)azione, una `CreateReplicationGroup` richiesta sarà consentita solo se non viene utilizzato TLS (ovvero, se la richiesta non include un `TransitEncryptionEnabled` parametro impostato su `true` o un `TransitEncryptionMode` parametro impostato su. `required`

   1. Imposta la chiave `elasticache:TransitEncryptionEnabled` conditon su `true` per l'[CreateReplicationGroup](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_CreateReplicationGroup.html)azione per specificare che i gruppi di replica possono essere creati solo quando viene utilizzato TLS:

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

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "elasticache:CreateReplicationGroup"
                  ],
                  "Resource": [
                      "arn:aws:elasticache:*:*:parametergroup:*",
                      "arn:aws:elasticache:*:*:subnetgroup:*"
                  ]
              },
      
              {
                  "Effect": "Allow",
                  "Action": [
                      "elasticache:CreateReplicationGroup"
                  ],
                  "Resource": [
                      "arn:aws:elasticache:*:*:replicationgroup:*"
                  ],
                  "Condition": {
                      "Bool": {
                          "elasticache:TransitEncryptionEnabled": "true"
                      }
                  }
              }
          ]
      }
      ```

------

      Quando la chiave di `elasticache:TransitEncryptionEnabled` condizione è impostata su `true` in una politica per l'[CreateReplicationGroup](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_CreateReplicationGroup.html)azione, una `CreateReplicationGroup` richiesta sarà consentita solo se la richiesta include un `TransitEncryptionEnabled` parametro impostato su `true` e un `TransitEncryptionMode` parametro impostato su. `required`

   1. Imposta `elasticache:TransitEncryptionEnabled` su `true` per l'azione `ModifyReplicationGroup` per specificare che i gruppi di replica possono essere modificati solo quando viene utilizzato TLS:

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

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [               
                      "elasticache:ModifyReplicationGroup"
                  ],
                  "Resource": [               
                      "arn:aws:elasticache:*:*:replicationgroup:*"
                  ],
                  "Condition": {
                      "BoolIfExists": {
                          "elasticache:TransitEncryptionEnabled": "true"
                      }
                  }
              }
          ]
      }
      ```

------

      Quando la chiave di `elasticache:TransitEncryptionEnabled` condizione è impostata su `true` in una politica per l'[ModifyReplicationGroup](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_ModifyReplicationGroup.html)azione, una `ModifyReplicationGroup` richiesta sarà consentita solo se la richiesta include un `TransitEncryptionMode` parametro impostato su`required`. Facoltativamente, è anche possibile includere il parametro `TransitEncryptionEnabled` impostato su `true`, ma in questo caso non è necessario abilitare TLS.

1. **elasticache:AutomaticFailoverEnabled:** Specificate che i gruppi di replica verranno creati solo con il failover automatico abilitato.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "Bool": {
                       "elasticache:AutomaticFailoverEnabled": "true"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:multi AZEnabled**: Specificate che i gruppi di replica non possono essere creati con Multi-AZ disabilitato.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
           {
               "Effect": "Deny",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "Bool": {
                       "elasticache:MultiAZEnabled": "false"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:ClusterModeEnabled:** Specificate che i gruppi di replica possono essere creati solo con la modalità cluster abilitata.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "Bool": {
                       "elasticache:ClusterModeEnabled": "true"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:AuthTokenEnabled:** Specificate che i gruppi di replica possono essere creati solo con il token AUTH abilitato.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
   
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "Bool": {
                       "elasticache:AuthTokenEnabled": "true"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:SnapshotRetentionLimit:** Specificate il numero di giorni (o min/max) per conservare l'istantanea. Di seguito la policy impone l'archiviazione dei backup per almeno 30 giorni.

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
   
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup",
                   "elasticache:CreateServerlessCache"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*",
                   "arn:aws:elasticache:*:*:serverlesscache:*"
               ],
               "Condition": {
                   "NumericGreaterThanEquals": {
                       "elasticache:SnapshotRetentionLimit": "30"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:KmsKeyId:** Specificate l'utilizzo delle chiavi KMS gestite dal cliente.AWS

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

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
           "Sid": "AllowDependentResources",
           "Effect": "Allow",
           "Action": [
               "elasticache:CreateServerlessCache"
           ],
           "Resource": [
               "arn:aws:elasticache:*:*:serverlesscachesnapshot:*",
               "arn:aws:elasticache:*:*:snapshot:*",
               "arn:aws:elasticache:*:*:usergroup:*"
           ]
       },
       {
           "Effect": "Allow",
           "Action": [
               "elasticache:CreateServerlessCache"
           ],
           "Resource": [
               "arn:aws:elasticache:*:*:serverlesscache:*"
           ],
           "Condition": {
               "StringEquals": {
                   "elasticache:KmsKeyId": "my-key"
               }
           }
       }
     ]
   }
   ```

------

1. **elasticache:CacheParameterGroupName:** Specificate un gruppo di parametri non predefinito con parametri specifici di un'organizzazione sui cluster. È inoltre possibile specificare un modello di denominazione per i gruppi di parametri o eliminare blocchi su un nome di gruppo di parametri specifico. Di seguito è riportato un esempio che limita l'uso del solo "». my-org-param-group

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
   
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:CreateReplicationGroup"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:CacheParameterGroupName": "my-org-param-group"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:CacheParameterGroupName:** Con Memcached, specifica un gruppo di parametri non predefinito con parametri specifici di un'organizzazione sui tuoi cluster. È inoltre possibile specificare un modello di denominazione per i gruppi di parametri o eliminare blocchi su un nome di gruppo di parametri specifico. Di seguito è riportato un esempio che limita l'utilizzo del solo "». my-org-param-group

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
   
            {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*"
               ]
           },
   
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "elasticache:CacheParameterGroupName": "my-org-param-group"
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:CreateCacheCluster:** Negare l'`CreateCacheCluster`azione se il tag di richiesta `Project` è mancante o non è uguale a, o. `Dev` `QA` `Prod`

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
             {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*",
                   "arn:aws:elasticache:*:*:securitygroup:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ]
           },
           {
               "Effect": "Deny",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*"
               ],
               "Condition": {
                   "Null": {
                       "aws:RequestTag/Project": "true"
                   }
               }
           },
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:AddTagsToResource"
               ],
               "Resource": "arn:aws:elasticache:*:*:cluster:*",
               "Condition": {
                   "StringEquals": {
                       "aws:RequestTag/Project": [
                           "Dev",
                           "Prod",
                           "QA"
                       ]
                   }
               }
           }
       ]
   }
   ```

------

1. **elasticache:CacheNodeType:** Consentire `CreateCacheCluster` con `cacheNodeType` cache.r5.large o cache.r6g.4xlarge e tag. `Project=XYZ` 

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

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
         {
         "Effect": "Allow",
         "Action": [
           "elasticache:CreateCacheCluster",
           "elasticache:CreateReplicationGroup"
         ],
         "Resource": [
           "arn:aws:elasticache:*:*:parametergroup:*",
           "arn:aws:elasticache:*:*:subnetgroup:*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "elasticache:CreateCacheCluster"
         ],
         "Resource": [
           "arn:aws:elasticache:*:*:cluster:*"
         ],
         "Condition": {
           "StringEqualsIfExists": {
             "elasticache:CacheNodeType": [
               "cache.r5.large",
               "cache.r6g.4xlarge"
             ]
           },
           "StringEquals": {
             "aws:RequestTag/Project": "XYZ"
           }
         }
       }
     ]
   }
   ```

------

1. **elasticache:CacheNodeType:** Permesso `CreateCacheCluster` con `cacheNodeType` cache.r5.large o cache.r6g.4xlarge e tag. `Project=XYZ` 

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

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
         {
         "Effect": "Allow",
         "Action": [
           "elasticache:CreateCacheCluster"
         ],
         "Resource": [
           "arn:aws:elasticache:*:*:parametergroup:*",
           "arn:aws:elasticache:*:*:subnetgroup:*"
         ]
       },
       {
         "Effect": "Allow",
         "Action": [
           "elasticache:CreateCacheCluster"
         ],
         "Resource": [
           "arn:aws:elasticache:*:*:cluster:*"
         ],
         "Condition": {
           "StringEqualsIfExists": {
             "elasticache:CacheNodeType": [
               "cache.r5.large",
               "cache.r6g.4xlarge"
             ]
           },
           "StringEquals": {
             "aws:RequestTag/Project": "XYZ"
           }
         }
       }
     ]
   }
   ```

------

**Nota**  
Quando si creano policy per applicare tag e altre chiavi di condizione insieme, il condizionale `IfExists` può essere richiesto su elementi di condizione chiave a causa dei requisiti della policy `elasticache:AddTagsToResource` aggiuntivi per le richieste di creazione con il parametro `--tags`.