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à.
Utilizzare EnableKey
con un AWS SDKo CLI
I seguenti esempi di codice mostrano come utilizzareEnableKey
.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nei seguenti esempi di codice:
- .NET
-
- AWS SDK for .NET
-
Nota
C'è altro su. GitHub Trova l'esempio completo e scopri come configurare ed eseguire in AWS Repository
di esempi di codice. using System; using System.Threading.Tasks; using Amazon.KeyManagementService; using Amazon.KeyManagementService.Model; /// <summary> /// Enable an AWS Key Management Service (AWS KMS) key. /// </summary> public class EnableKey { public static async Task Main() { var client = new AmazonKeyManagementServiceClient(); // The identifier of the AWS KMS key to enable. You can use the // key Id or the Amazon Resource Name (ARN) of the AWS KMS key. var keyId = "1234abcd-12ab-34cd-56ef-1234567890ab"; var request = new EnableKeyRequest { KeyId = keyId, }; var response = await client.EnableKeyAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { // Retrieve information about the key to show that it has now // been enabled. var describeResponse = await client.DescribeKeyAsync(new DescribeKeyRequest { KeyId = keyId, }); Console.WriteLine($"{describeResponse.KeyMetadata.KeyId} - state: {describeResponse.KeyMetadata.KeyState}"); } } }
-
Per API i dettagli, vedere EnableKeyin AWS SDK for .NET APIRiferimento.
-
- CLI
-
- AWS CLI
-
Per abilitare una KMS chiave
L'
enable-key
esempio seguente abilita una chiave gestita dal cliente. È possibile utilizzare un comando come questo per abilitare una KMS chiave che è stata temporaneamente disabilitata utilizzando ildisable-key
comando. Puoi anche usarlo per abilitare una KMS chiave che è disabilitata perché era stata pianificata per l'eliminazione e l'eliminazione è stata annullata.Per specificare la KMS chiave, utilizzare il
key-id
parametro. Questo esempio utilizza un valore ID chiave, ma è possibile utilizzare un ID chiave o un ARN valore chiave in questo comando.Prima di eseguire questo comando, sostituite l'ID della chiave di esempio con uno valido.
aws kms enable-key \ --key-id
1234abcd-12ab-34cd-56ef-1234567890ab
Questo comando non produce alcun output. Per verificare che la KMS chiave sia abilitata, utilizzate il
describe-key
comando. Visualizza i valori deiEnabled
campiKeyState
e nell'describe-key
output.Per ulteriori informazioni, vedere Abilitazione e disabilitazione delle chiavi nel AWS Guida per gli sviluppatori del servizio di gestione delle chiavi.
-
Per API i dettagli, vedere EnableKey
in AWS CLI Riferimento ai comandi.
-
- Java
-
- SDKper Java 2.x
-
Nota
C'è di più su. GitHub Trova l'esempio completo e scopri come configurare ed eseguire in AWS Repository
di esempi di codice. /** * Asynchronously enables the specified key. * * @param keyId the ID of the key to enable * @return a {@link CompletableFuture} that completes when the key has been enabled */ public CompletableFuture<Void> enableKeyAsync(String keyId) { EnableKeyRequest enableKeyRequest = EnableKeyRequest.builder() .keyId(keyId) .build(); CompletableFuture<EnableKeyResponse> responseFuture = getAsyncClient().enableKey(enableKeyRequest); responseFuture.whenComplete((response, exception) -> { if (exception == null) { logger.info("Key with ID [{}] has been enabled.", keyId); } else { if (exception instanceof KmsException kmsEx) { throw new RuntimeException("KMS error occurred while enabling key: " + kmsEx.getMessage(), kmsEx); } else { throw new RuntimeException("An unexpected error occurred while enabling key: " + exception.getMessage(), exception); } } }); return responseFuture.thenApply(response -> null); }
-
Per API i dettagli, vedere EnableKeyin AWS SDK for Java 2.x APIRiferimento.
-
- Kotlin
-
- SDKper Kotlin
-
Nota
c'è altro da fare. GitHub Trova l'esempio completo e scopri come configurare ed eseguire in AWS Repository
di esempi di codice. suspend fun enableKey(keyIdVal: String?) { val request = EnableKeyRequest { keyId = keyIdVal } KmsClient { region = "us-west-2" }.use { kmsClient -> kmsClient.enableKey(request) println("$keyIdVal was successfully enabled.") } }
-
Per API i dettagli, vedere EnableKey
in AWS SDKper riferimento a KotlinAPI.
-
- Python
-
- SDKper Python (Boto3)
-
Nota
C'è di più su. GitHub Trova l'esempio completo e scopri come configurare ed eseguire in AWS Repository
di esempi di codice. class KeyManager: def __init__(self, kms_client): self.kms_client = kms_client self.created_keys = [] def enable_disable_key(self, key_id): """ Disables and then enables a key. Gets the key state after each state change. """ answer = input("Do you want to disable and then enable that key (y/n)? ") if answer.lower() == "y": try: self.kms_client.disable_key(KeyId=key_id) key = self.kms_client.describe_key(KeyId=key_id)["KeyMetadata"] except ClientError as err: logging.error( "Couldn't disable key '%s'. Here's why: %s", key_id, err.response["Error"]["Message"], ) else: print(f"AWS KMS says your key state is: {key['KeyState']}.") try: self.kms_client.enable_key(KeyId=key_id) key = self.kms_client.describe_key(KeyId=key_id)["KeyMetadata"] except ClientError as err: logging.error( "Couldn't enable key '%s'. Here's why: %s", key_id, err.response["Error"]["Message"], ) else: print(f"AWS KMS says your key state is: {key['KeyState']}.")
-
Per API i dettagli, vedere EnableKeyin AWS SDKper Python (Boto3) Reference. API
-
Per un elenco completo di AWS SDKguide per sviluppatori ed esempi di codice, vediUtilizzo AWS KMS con un AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle SDK versioni precedenti.