AWS code-library documentation change
Summary
Added Swift SDK example for DeleteKeyPair API
Security assessment
Documents proper credential lifecycle management through key pair deletion, which is a security best practice but does not address a specific active security issue.
Diff
diff --git a/code-library/latest/ug/ec2_example_ec2_DeleteKeyPair_section.md b/code-library/latest/ug/ec2_example_ec2_DeleteKeyPair_section.md index 7ca349e7b..0548dde47 100644 --- a//code-library/latest/ug/ec2_example_ec2_DeleteKeyPair_section.md +++ b//code-library/latest/ug/ec2_example_ec2_DeleteKeyPair_section.md @@ -589,0 +590,41 @@ There's more on GitHub. Find the complete example and learn how to set up and ru +Swift + + +**SDK for Swift** + + +###### Note + +There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/swift/example_code/ec2#code-examples). + + + import AWSEC2 + + /// Delete an EC2 key pair. + /// + /// - Parameter keyPair: The name of the key pair to delete. + /// + /// - Returns: `true` if the key pair is deleted successfully; otherwise + /// `false`. + func deleteKeyPair(keyPair: String) async -> Bool { + do { + _ = try await ec2Client.deleteKeyPair( + input: DeleteKeyPairInput( + keyName: keyPair + ) + ) + + return true + } catch { + print("*** Error deleting the key pair: \(error.localizedDescription)") + return false + } + } + + + + * For API details, see [DeleteKeyPair](https://sdk.amazonaws.com/swift/api/awsec2/latest/documentation/awsec2/ec2client/deletekeypair\(input:\)) in _AWS SDK for Swift API reference_. + + + +