AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-06-28 · Documentation low

File: code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_ListUsers_section.md

Summary

Added Swift SDK example for ListUsers API with error handling

Security assessment

Adds routine user listing functionality without discussing access controls or sensitive data handling

Diff

diff --git a/code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_ListUsers_section.md b/code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_ListUsers_section.md
index a77ba4594..b167fc9b2 100644
--- a//code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_ListUsers_section.md
+++ b//code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_ListUsers_section.md
@@ -390,0 +391,45 @@ 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/cognito-identity-provider#code-examples). 
+    
+    
+            do {
+                let output = try await cognitoClient.listUsers(
+                    input: ListUsersInput(
+                        userPoolId: poolId
+                    )
+                )
+                
+                guard let users = output.users else {
+                    print("No users found.")
+                    return
+                }
+    
+                print("\(users.count) user(s) found.")
+                for user in users {
+                    print("  \(user.username ?? "<unknown>")")
+                }
+            } catch _ as NotAuthorizedException {
+                print("*** Please authenticate with AWS before using this command.")
+                return
+            } catch _ as ResourceNotFoundException {
+                print("*** The specified User Pool was not found.")
+                return
+            } catch {
+                print("*** An unexpected type of error occurred.")
+                return
+            }
+    
+    
+
+  * For API details, see [ListUsers](https://sdk.amazonaws.com/swift/api/awscognitoidentityprovider/latest/documentation/awscognitoidentityprovider/cognitoidentityproviderclient/listusers\(input:\)) in _AWS SDK for Swift API reference_. 
+
+
+
+