-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathDisableKey.cs
47 lines (40 loc) · 1.59 KB
/
DisableKey.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
namespace DisableKeyExample
{
// snippet-start:[KMS.dotnetv3.DisableKeyExample]
using System;
using System.Threading.Tasks;
using Amazon.KeyManagementService;
using Amazon.KeyManagementService.Model;
/// <summary>
/// Disable an AWS Key Management Service (AWS KMS) key and then retrieve
/// the key's status to show that it has been disabled.
/// </summary>
public class DisableKey
{
public static async Task Main()
{
var client = new AmazonKeyManagementServiceClient();
// The identifier of the AWS KMS key to disable. 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 DisableKeyRequest
{
KeyId = keyId,
};
var response = await client.DisableKeyAsync(request);
if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
{
// Retrieve information about the key to show that it has now
// been disabled.
var describeResponse = await client.DescribeKeyAsync(new DescribeKeyRequest
{
KeyId = keyId,
});
Console.WriteLine($"{describeResponse.KeyMetadata.KeyId} - state: {describeResponse.KeyMetadata.KeyState}");
}
}
}
// snippet-end:[KMS.dotnetv3.DisableKeyExample]
}