-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathEnableKey.cs
45 lines (39 loc) · 1.5 KB
/
EnableKey.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
namespace EnableKeyExample
{
// snippet-start:[KMS.dotnetv3.EnableKeyExample]
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}");
}
}
}
// snippet-end:[KMS.dotnetv3.EnableKeyExample]
}