diff --git a/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx b/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx index 777c899d688..117fc45372f 100644 --- a/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/use-aws-sdk/index.mdx @@ -4,7 +4,8 @@ export const meta = { title: 'Use AWS SDK', description: 'For advanced use cases where Amplify does not provide the functionality, you can retrieve the escape hatch to access the AWSCognito instance.', platforms: [ - 'swift' + 'swift', + 'android' ], }; @@ -21,9 +22,10 @@ export function getStaticProps(context) { }; } - For advanced use cases where Amplify does not provide the functionality, you can retrieve an escape hatch to access the underlying Amazon Cognito client. + + **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](https://github.com/awslabs/aws-sdk-swift/blob/main/Sources/Core/AWSSDKForSwift/Documentation.docc/stability.md) on the stability of the SDK. @@ -58,3 +60,69 @@ func getEscapeHatch() { } ``` + + +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 +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) +} +``` + + + + + + +[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). + + + +```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() { + @NonNull + @Override + public CoroutineContext getContext() { + return GlobalScope.INSTANCE.getCoroutineContext(); + } + + @Override + public void resumeWith(@NonNull Object resultOrException) { + Log.i(TAG, "Result: " + resultOrException); + } +}); +``` + + + +