AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-04-23 · Documentation low

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

Summary

Added Swift code example for Cognito Identity Provider SignUp API with error handling

Security assessment

The change adds a code example for user registration with error handling but does not address a specific security vulnerability or introduce new security features. It focuses on general API usage.

Diff

diff --git a/code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md b/code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md
index 10b6ff307..f11e629f2 100644
--- a//code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md
+++ b//code-library/latest/ug/cognito-identity-provider_example_cognito-identity-provider_SignUp_section.md
@@ -413,0 +414,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_. 
+
+
+
+