AWS Security ChangesHomeSearch

AWS cognito documentation change

Service: cognito · 2025-04-23 · Documentation low

File: cognito/latest/developerguide/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md

Summary

Added Swift SDK code example for SignUp API with error handling for username conflicts and invalid passwords

Security assessment

The change adds a code example demonstrating proper usage of the SignUp API with error handling, but does not address any specific security vulnerability or introduce new security documentation. It reinforces existing security practices through example code.

Diff

diff --git a/cognito/latest/developerguide/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md b/cognito/latest/developerguide/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md
index 0bf3c3256..327e7c094 100644
--- a//cognito/latest/developerguide/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md
+++ b//cognito/latest/developerguide/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md
@@ -411,0 +412,67 @@ 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). 
+    
+    
+    import AWSCognitoIdentityProvider
+    
+        /// Create a new user in a user pool.
+        /// 
+        /// - Parameters:
+        ///   - cipClient: The `CognitoIdentityProviderClient` to use.
+        ///   - clientId: The ID of the app client to create a user for.
+        ///   - userName: The username for the new user.
+        ///   - password: The new user's password.
+        ///   - email: The new user's email address.
+        ///
+        /// - Returns: `true` if successful; otherwise `false`.
+        func signUp(cipClient: CognitoIdentityProviderClient, clientId: String, userName: String, password: String, email: String) async -> Bool {
+            let emailAttr = CognitoIdentityProviderClientTypes.AttributeType(
+                name: "email",
+                value: email
+            )
+    
+            let userAttrsList = [emailAttr]
+    
+            do {
+                _ = try await cipClient.signUp(
+                    input: SignUpInput(
+                        clientId: clientId,
+                        password: password,
+                        userAttributes: userAttrsList,
+                        username: userName
+                    )
+    
+                )
+    
+                print("=====> User \(userName) signed up.")
+            } catch _ as AWSCognitoIdentityProvider.UsernameExistsException {
+                print("*** The username \(userName) already exists. Please use a different one.")
+                return false
+            } catch let error as AWSCognitoIdentityProvider.InvalidPasswordException {
+                print("*** Error: The specified password is invalid. Reason: \(error.properties.message ?? "<none available>").")
+                return false
+            } catch _ as AWSCognitoIdentityProvider.ResourceNotFoundException {
+                print("*** Error: The specified client ID (\(clientId)) doesn't exist.")
+                return false
+            } catch {
+                print("*** Unexpected error: \(error)")
+                return false
+            }
+    
+            return true
+        }
+    
+    
+
+  * For API details, see [SignUp](https://sdk.amazonaws.com/swift/api/awscognitoidentityprovider/latest/documentation/awscognitoidentityprovider/cognitoidentityproviderclient/signup\(input:\)) in _AWS SDK for Swift API reference_. 
+
+
+
+