---
title: "Use AWS SDK"
section: "build-a-backend/auth"
platforms: ["swift", "android"]
gen: 2
last-updated: "2024-09-24T23:57:23.000Z"
url: "https://docs.amplify.aws/react/build-a-backend/auth/use-aws-sdk/"
---

For advanced use cases where Amplify does not provide the functionality, you can retrieve an escape hatch to access the underlying Amazon Cognito client.

<!-- Platform: swift -->
The escape hatch provides access to the underlying `AWSCognitoIdentityProvider` instance. Import the necessary types:

```swift
import AWSCognitoAuthPlugin
import AWSCognitoIdentityProvider
```

Then retrieve the escape hatch with this code:

```swift
func getEscapeHatch() {
    let client: CognitoIdentityProviderClient

    // Get the instance of AWSCognitoAuthPlugin
    let plugin = try? Amplify.Auth.getPlugin(for: "awsCognitoAuthPlugin") as? AWSCognitoAuthPlugin

    // Get the instance of CognitoIdentityProviderClient
    if case .userPoolAndIdentityPool(let userPoolClient, _) = plugin?.getEscapeHatch() {
        client = userPoolClient
    } else if case .userPool(let userPoolClient) = plugin?.getEscapeHatch() {
        client = userPoolClient
    } else {
        fatalError("No user pool configuration found")
    }
    print("Fetched escape hatch - \(String(describing: client))")
}
```
<!-- /Platform -->

<!-- Platform: android -->
You can access the underlying `CognitoIdentityProviderClient` and `CognitoIdentityClient` as shown below

```kotlin
implementation "aws.sdk.kotlin:cognitoidentityprovider:1.0.44"
implementation "aws.sdk.kotlin:cognitoidentity:1.0.44"
```

#### [Kotlin]

```kotlin
suspend fun resendCodeUsingEscapeHatch() {
    // Get the instance of AWSCognitoAuthPlugin
    val cognitoAuthPlugin = Amplify.Auth.getPlugin("awsCognitoAuthPlugin")
    val cognitoAuthService = cognitoAuthPlugin.escapeHatch as AWSCognitoAuthService

    // Get the instance of CognitoIdentityProviderClient
    val cognitoIdentityProviderClient = cognitoAuthService.cognitoIdentityProviderClient
    val request = ResendConfirmationCodeRequest {
        clientId = "xxxxxxxxxxxxxxxx"
        username = "user1"
    }
    val response = cognitoIdentityProviderClient?.resendConfirmationCode(request)
}
```

#### [Java]

<Callout>

[Learn more about consuming Kotlin clients from Java using either a blocking interface or an equivalent async interface based on futures](https://github.com/awslabs/smithy-kotlin/blob/main/docs/design/kotlin-smithy-sdk.md#java-interop).

</Callout>

```java
// Get the instance of AWSCognitoAuthPlugin
AWSCognitoAuthPlugin cognitoAuthPlugin = (AWSCognitoAuthPlugin) Amplify.Auth.getPlugin("awsCognitoAuthPlugin");

// Get the instance of CognitoIdentityProviderClient
CognitoIdentityProviderClient client = cognitoAuthPlugin.getEscapeHatch().getCognitoIdentityProviderClient();
ResendConfirmationCodeRequest request = ResendConfirmationCodeRequest.Companion.invoke(dslBuilder -> {
    dslBuilder.setClientId("xxxxxxxxxxxxxxxx");
    dslBuilder.setUsername("user1");
    return null;
});

assert client != null;
client.resendConfirmationCode(request, new Continuation<ResendConfirmationCodeResponse>() {
    @NonNull
    @Override
    public CoroutineContext getContext() {
        return GlobalScope.INSTANCE.getCoroutineContext();
    }

    @Override
    public void resumeWith(@NonNull Object resultOrException) {
        Log.i(TAG, "Result: " + resultOrException);
    }
});
```

<!-- /Platform -->
