Amazon AWS SDK Guide de l'utilisateur Page 77 : Enumerating Your Key Pairs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
4.
Pass the request object to the
AuthorizeSecurityGroupIngress
method, which returns an
AuthorizeSecurityGroupIngressResponse
object.
var ingressResponse =
ec2Client.AuthorizeSecurityGroupIngress(ingress
Request);
Console.WriteLine("New RDP rule for: " + ipRange);
Create a Key Pair Using the SDK for .NET
You must specify a key pair when you launch an EC2 instance and specify the private key of the key pair
when you connect to the instance.You can create a key pair or use an existing key pair that you've used
when launching other instances. For more information, see
Amazon EC2 Key Pairs
in the
Amazon EC2
User Guide for Microsoft Windows Instances
.
Enumerating Your Key Pairs
You can enumerate your key pairs and check whether a particular key pair exists.
To enumerate your key pairs
Get the complete list of your key pairs using
DescribeKeyPairs
with no parameters.The following example
checks each key pair to see whether its name is
my-sample-key
.
string keyPairName = "my-sample-key";
KeyPairInfo myKeyPair = null;
var dkpRequest = new DescribeKeyPairsRequest();
var dkpResponse = ec2Client.DescribeKeyPairs(dkpRequest);
List<KeyPairInfo> myKeyPairs = dkpResponse.KeyPairs;
foreach (KeyPairInfo item in myKeyPairs)
{
Console.WriteLine("Existing key pair: " + item.KeyName);
if (item.KeyName == keyPairName)
{
myKeyPair = item;
}
}
Creating a Key Pair and Saving the Private Key
The example in this section follows from the example in the previous section. If the key pair doesn't already
exist, create it. Be sure to save the private key now, because you can't retrieve it later.
To create a key pair and save the private key
Create and initialize a
CreateKeyPairRequest
object. Set the
KeyName
property to the name of the key
pair.
Pass the request object to the
CreateKeyPair
method, which returns a
CreateKeyPairResponse
object.
The response object includes a
CreateKeyPairResult
property that contains the new key's
KeyPair
object.
The
KeyPair
object's
KeyMaterial
property contains the unencrypted private key for the key pair. Save
the private key as a
.pem
file in a safe location.You'll need this file when you connect to your instance.
Version v2.0.0
73
AWS SDK for .NET Developer Guide
Tutorial: Creating Amazon EC2 Instances
Fichier PDF · ·
Questions sur Amazon AWS SDK
Pas encore de questions sur ce manuel. Posez la première.
Produits connexes et manuels pour Logiciel Amazon AWS SDK
- Logiciel Amazon Redshift Manuel d'utilisateur
(24 pages) - Logiciel Amazon Redshift Manuel d'utilisateur
(11 pages) - Logiciel Amazon AWS SDK Guide de l'utilisateur
(73 pages)