Amazon Ec2 Instance Management with C#: Part 2 – Deleting a Key Pair

Before getting started

Skill Level: Beginner

Assumptions:

  1. You have completed Part 1 of Managing Amazon AWS with C# – EC2

Additional Information: I sometimes cover small sub-topics in a post. Along with AWS, you will also be exposed to:

  • .NET Core 2.0 – If you use .NET Framework, the steps will be slightly different, but as this is a beginner level tutorial, it should be simple.
  • Rhyous.SimpleArgs

Step 1 – Edit InstanceManager.cs file

We’ve created InstanceManager.cs in Part 1. Let’s edit it.

  1. Add a method to delete the key pair.
  2.         public static async Task DeleteKeyPair(AmazonEC2Client ec2Client, string keyName)
            {
                await ec2Client.DeleteKeyPairAsync(new DeleteKeyPairRequest { KeyName = keyName });
            }
    

Step 5 – Configure command line Arguments.

We already have an Actions arguments to edit.

  1. Add DeleteKeyPair as a valid action to the Action argument.
  2.                 . . .
                    new Argument
                    {
                        Name = "Action",
                        ShortName = "a",
                        Description = "The action to run.",
                        Example = "{name}=default",
                        DefaultValue = "Default",
                        AllowedValues = new ObservableCollection<string>
                        {
                            "CreateKeyPair",
                            "DeleteKeyPair"
                        },
                        IsRequired = true,
                        Action = (value) =>
                        {
                            Console.WriteLine(value);
                        }
                    },
                    . . .
    

Next:

  • Part 3 – Uploading and Importing a Key Pair
  • Return to: Managing Amazon AWS with C#

    One Comment

    1. 920 says:

      919

      Amazon Ec2 Instance Management with C#: Part 2 – Deleting a Key Pair | Rhyous

    Leave a Reply

    How to post code in comments?