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 Kotlin is production ready, please note that the underlying AWS SDK for Kotlin 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 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"
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.

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