AWS code-library documentation change
Summary
Added Swift SDK code example for DescribeKeyPairs API with key pair metadata display
Security assessment
Documents key pair inspection capabilities which relate to security infrastructure, but merely shows how to list existing keys without addressing vulnerabilities or security incidents. Key pair management is a security feature but this is routine documentation.
Diff
diff --git a/code-library/latest/ug/ec2_example_ec2_DescribeKeyPairs_section.md b/code-library/latest/ug/ec2_example_ec2_DescribeKeyPairs_section.md index f800ab07c..e646c7d46 100644 --- a//code-library/latest/ug/ec2_example_ec2_DescribeKeyPairs_section.md +++ b//code-library/latest/ug/ec2_example_ec2_DescribeKeyPairs_section.md @@ -580,0 +581,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 + + /// Describe the key pairs associated with the user by outputting each key + /// pair's name and fingerprint. + func describeKeyPairs() async { + do { + let output = try await ec2Client.describeKeyPairs( + input: DescribeKeyPairsInput() + ) + + guard let keyPairs = output.keyPairs else { + print("*** No key pairs list available.") + return + } + + for keyPair in keyPairs { + print(keyPair.keyName ?? "<unknown>", ":", keyPair.keyFingerprint ?? "<unknown>") + } + } catch { + print("*** Error: Unable to obtain a key pair list.") + } + } + + + + * For API details, see [DescribeKeyPairs](https://sdk.amazonaws.com/swift/api/awsec2/latest/documentation/awsec2/ec2client/describekeypairs\(input:\)) in _AWS SDK for Swift API reference_. + + + +