/// <summary>
        /// Initializes the Amazon EC2 client object and then calls the
        /// DeleteKeyPairAsync method to delete the key pair.
        /// </summary>
        public static async Task Main()
        {
            string keyName = "sdk-example-key-pair";

            // If the key pair was not created in the same AWS Region as
            // the default user on your system, you need to supply
            // the AWS Region as a parameter to the client constructor.
            var client = new AmazonEC2Client();

            var request = new DeleteKeyPairRequest
            {
                KeyName = keyName,
            };

            var response = await client.DeleteKeyPairAsync(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine($"Successfully deleted the key pair: {keyName}.");
            }
            else
            {
                Console.WriteLine("Could not delete the key pair.");
            }
        }
Example #2
0
        public bool reload_key_pair(string private_key, string tag)
        {
            write_log("鍵を生成します。");
            try
            {
                var client = get_client();

                write_log(region + " のキーペアを削除しています。");
                var delete_req = new DeleteKeyPairRequest();
                delete_req.KeyName = Helper.build_name(setting_, tag);
                client.DeleteKeyPair(delete_req);

                var create_req = new CreateKeyPairRequest();
                create_req.KeyName = Helper.build_name(setting_, tag);
                var create_res = client.CreateKeyPair(create_req);

                write_log("キーペア保存をしています。");
                File.WriteAllText(private_key, create_res.KeyPair.KeyMaterial);
            }
            catch (Exception ex)
            {
                write_log("ERROR: " + ex.ToString());
                return(false);
            }
            return(true);
        }
Example #3
0
 public bool delete_key_pair(string tag)
 {
     try
     {
         var client         = get_client();
         var delete_key_req = new DeleteKeyPairRequest();
         delete_key_req.KeyName = Helper.build_name(setting_, tag);
         client.DeleteKeyPair(delete_key_req);
     }
     catch (Exception ex)
     {
         write_log("ERROR: " + ex.ToString());
         return(false);
     }
     return(true);
 }
Example #4
0
 /// <summary>
 /// Delete Key Pair
 /// </summary>
 /// <param name="request">Delete Key Pair  request</param>
 /// <returns>Delete Key Pair  Response from the service</returns>
 /// <remarks>
 /// The DeleteKeyPair operation deletes a key pair.
 ///
 /// </remarks>
 public DeleteKeyPairResponse DeleteKeyPair(DeleteKeyPairRequest request)
 {
     return(Invoke <DeleteKeyPairResponse>("DeleteKeyPairResponse.xml"));
 }