Amazon Ec2 Instance Management with C#: Part 2 – Deleting a Key Pair
Before getting started
Skill Level: Beginner
Assumptions:
- 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.
- Add a method to delete the key pair.
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.
- Add DeleteKeyPair as a valid action to the Action argument.
. . .
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:
Return to: Managing Amazon AWS with C#

