Page updated Nov 14, 2023

Use AWS SDK

For advanced use cases where Amplify does not provide the functionality you're looking for, you can retrieve the escape hatch to access the underlying SDK.

Note: While the Amplify Library for Swift is production ready, please note that the underlying AWS SDK for Swift is currently in Developer Preview, and is not yet intended for production workloads. Here is additional reading material on the stability of the SDK

The escape hatch provides access to the underlying AWSCognitoIdentityProvider instance. Import the necessary types:

1import AWSCognitoAuthPlugin
2import AWSCognitoIdentityProvider

Then retrieve the escape hatch with this code:

1func getEscapeHatch() {
2 let client: CognitoIdentityProviderClient
3
4 // Get the instance of AWSCognitoAuthPlugin
5 let plugin = try? Amplify.Auth.getPlugin(for: "awsCognitoAuthPlugin") as? AWSCognitoAuthPlugin
6
7 // Get the instance of CognitoIdentityProviderClient
8 if case .userPoolAndIdentityPool(let userPoolClient, _) = plugin?.getEscapeHatch() {
9 client = userPoolClient
10 } else if case .userPool(let userPoolClient) = plugin?.getEscapeHatch() {
11 client = userPoolClient
12 } else {
13 fatalError("No user pool configuration found")
14 }
15 print("Fetched escape hatch - \(String(describing: client))")
16}