Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

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

implementation "aws.sdk.kotlin:cognitoidentityprovider:KOTLIN_SDK_VERSION"
implementation "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.

// 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);
}
});
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)
}