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.

The escape hatch provides access to the underlying CognitoIdentityProviderClient and CognitoIdentityClient instance. Then retrieve the escape hatch with this code:

Gradle Imports

1implementation "aws.sdk.kotlin:cognitoidentityprovider:KOTLIN_SDK_VERSION"
2implementation "aws.sdk.kotlin:cognitoidentity:KOTLIN_SDK_VERSION"

Learn more about consuming Kotlin clients from Java using either a blocking interface or an equivalent async interface based on futures here.

1// Get the instance of AWSCognitoAuthPlugin
2AWSCognitoAuthPlugin cognitoAuthPlugin = (AWSCognitoAuthPlugin) Amplify.Auth.getPlugin("awsCognitoAuthPlugin");
3
4// Get the instance of CognitoIdentityProviderClient
5CognitoIdentityProviderClient client = cognitoAuthPlugin.getEscapeHatch().getCognitoIdentityProviderClient();
6ResendConfirmationCodeRequest request = ResendConfirmationCodeRequest.Companion.invoke(dslBuilder -> {
7 dslBuilder.setClientId("xxxxxxxxxxxxxxxx");
8 dslBuilder.setUsername("user1");
9 return null;
10});
11
12assert client != null;
13client.resendConfirmationCode(request, new Continuation<ResendConfirmationCodeResponse>() {
14 @NonNull
15 @Override
16 public CoroutineContext getContext() {
17 return GlobalScope.INSTANCE.getCoroutineContext();
18 }
19
20 @Override
21 public void resumeWith(@NonNull Object resultOrException) {
22 Log.i(TAG, "Result: " + resultOrException);
23 }
24});
1suspend fun resendCodeUsingEscapeHatch() {
2 // Get the instance of AWSCognitoAuthPlugin
3 val cognitoAuthPlugin = Amplify.Auth.getPlugin("awsCognitoAuthPlugin")
4 val cognitoAuthService = cognitoAuthPlugin.escapeHatch as AWSCognitoAuthService
5
6 // Get the instance of CognitoIdentityProviderClient
7 val cognitoIdentityProviderClient = cognitoAuthService.cognitoIdentityProviderClient
8 val request = ResendConfirmationCodeRequest {
9 clientId = "xxxxxxxxxxxxxxxx"
10 username = "user1"
11 }
12 val response = cognitoIdentityProviderClient?.resendConfirmationCode(request)
13}