

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à.

# Lavorare con le sovvenzioni utilizzando l' AWS KMS API e la AWS SDK per PHP versione 3
<a name="kms-example-grants"></a>

Una concessione è un altro meccanismo per fornire le autorizzazioni. È un'alternativa alla politica chiave. Puoi utilizzare le sovvenzioni per concedere un accesso a lungo termine che consenta ai AWS mandanti di utilizzare i servizi AWS Key Management Service (AWS KMS) gestiti dai clienti. [AWS KMS keys](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#kms_keys) *Per ulteriori informazioni, consulta [Grants nella AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html) Developer Guide.AWS Key Management Service *

Gli esempi seguenti mostrano come:
+ Crea una sovvenzione per una chiave KMS utilizzando. [CreateGrant](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-kms-2014-11-01.html#creategrant)
+ Visualizza una concessione per una chiave KMS utilizzando. [ListGrants](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-kms-2014-11-01.html#listgrants)
+ Ritirare una sovvenzione per l'utilizzo di una chiave KMS. [RetireGrant](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-kms-2014-11-01.html#retiregrant)
+ Revoca una concessione per una chiave KMS utilizzando. [RevokeGrant](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-kms-2014-11-01.html#revokegrant)

[Tutto il codice di esempio per il AWS SDK per PHP è disponibile qui. GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code)

## Credenziali
<a name="examplecredentials"></a>

Prima di eseguire il codice di esempio, configurate AWS le vostre credenziali, come descritto in[Autenticazione con l' AWS utilizzo AWS SDK per PHP della versione 3](credentials.md). Quindi importate il file AWS SDK per PHP, come descritto in[Installazione della AWS SDK per PHP versione 3](getting-started_installation.md).

Per ulteriori informazioni sull'utilizzo di AWS Key Management Service (AWS KMS), consulta la [Guida per gli AWS KMS sviluppatori](https://docs.aws.amazon.com/kms/latest/developerguide/).

## Creazione di una concessione
<a name="create-a-grant"></a>

Per creare una sovvenzione per un AWS KMS key, usa l'[CreateGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html)operazione.

 **Importazioni** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Codice di esempio** 

```
$KmsClient = new Aws\Kms\KmsClient([
    'profile' => 'default',
    'version' => '2014-11-01',
    'region' => 'us-east-2'
]);

$keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab';
$granteePrincipal = "arn:aws:iam::111122223333:user/Alice";
$operation = ['Encrypt', 'Decrypt']; // A list of operations that the grant allows.

try {
    $result = $KmsClient->createGrant([
        'GranteePrincipal' => $granteePrincipal,
        'KeyId' => $keyId,
        'Operations' => $operation
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## Visualizza una concessione
<a name="view-a-grant"></a>

Per ottenere informazioni dettagliate sulle sovvenzioni concesse a an AWS KMS key, usa l'[ListGrants](https://docs.aws.amazon.com/kms/latest/APIReference/API_ListGrants.html)operazione.

 **Importazioni** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Codice di esempio** 

```
$KmsClient = new Aws\Kms\KmsClient([
    'profile' => 'default',
    'version' => '2014-11-01',
    'region' => 'us-east-2'
]);

$keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab';
$limit = 10;

try {
    $result = $KmsClient->listGrants([
        'KeyId' => $keyId,
        'Limit' => $limit,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## Ritirare una borsa di studio
<a name="retire-a-grant"></a>

Per ritirare una sovvenzione per un AWS KMS key, usa l'[RetireGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_RetireGrant.html)operazione. Ritira una concessione al termine del suo utilizzo.

 **Importazioni** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Codice di esempio** 

```
$KmsClient = new Aws\Kms\KmsClient([
    'profile' => 'default',
    'version' => '2014-11-01',
    'region' => 'us-east-2'
]);

$grantToken = 'Place your grant token here';

try {
    $result = $KmsClient->retireGrant([
        'GrantToken' => $grantToken,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}

//Can also identify grant to retire by a combination of the grant ID
//and the Amazon Resource Name (ARN) of the customer master key (CMK)
$keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab';
$grantId = 'Unique identifier of the grant returned during CreateGrant operation';

try {
    $result = $KmsClient->retireGrant([
        'GrantId' => $grantToken,
        'KeyId' => $keyId,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```

## Revocare una sovvenzione
<a name="revoke-a-grant"></a>

Per revocare una concessione a un AWS KMS key, usa l'operazione. [RevokeGrant](https://docs.aws.amazon.com/kms/latest/APIReference/API_RevokeGrant.html) Puoi revocare una concessione per negare esplicitamente le operazioni che dipendono da essa.

 **Importazioni** 

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
```

 **Codice di esempio** 

```
$KmsClient = new Aws\Kms\KmsClient([
    'profile' => 'default',
    'version' => '2014-11-01',
    'region' => 'us-east-2'
]);

$keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab';
$grantId = "grant1";

try {
    $result = $KmsClient->revokeGrant([
        'KeyId' => $keyId,
        'GrantId' => $grantId,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    echo $e->getMessage();
    echo "\n";
}
```