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

Page updated Apr 29, 2024

LegacyYou are viewing Gen 1 documentation. Switch to the latest Gen 2 docs →

Use AWS SDK

If you need functionality in the AWS services used by the Amplify Predictions category that isn't available, we provide an escape hatch so you can get a reference to that service. For example, to get a reference to RekognitionClient:

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

// Obtain reference to the plugin
AWSPredictionsPlugin predictionsPlugin = (AWSPredictionsPlugin)
Amplify.Predictions.getPlugin("awsPredictionsPlugin");
AWSPredictionsEscapeHatch escapeHatch = predictionsPlugin.getEscapeHatch();
// Send a new request to the Rekognition endpoint directly using the client
RekognitionClient client = escapeHatch.getRekognitionClient();
CreateCollectionRequest request = CreateCollectionRequest.Companion.invoke((requestBuilder) -> {
requestBuilder.setCollectionId("<new-collection-id-here>");
return Unit.INSTANCE;
});
client.createCollection(request, new Continuation<CreateCollectionResponse>() {
@NonNull
@Override
public CoroutineContext getContext() {
return GlobalScope.INSTANCE.getCoroutineContext();
}
@Override
public void resumeWith(@NonNull Object resultOrException) {
Log.i("MyAmplifyApp", resultOrException.toString());
}
});
// Obtain reference to the plugin
val plugin = Amplify.Predictions.getPlugin("awsPredictionsPlugin")
val escapeHatch = (plugin as AWSPredictionsPlugin).escapeHatch
// Send a new request to the Rekognition endpoint directly using the client
val client = escapeHatch.rekognitionClient
val request = CreateCollectionRequest {
collectionId = "<new-collection-id-here>"
}
client.createCollection(request)

In addition to the Amazon Polly APIs, the PollyClient returned in the escape hatch provides a way to create a presigned URL for a text to speech request. An example of creating a presigned URL is below.

// Obtain reference to the plugin
AWSPredictionsPlugin predictionsPlugin = (AWSPredictionsPlugin)
Amplify.Predictions.getPlugin("awsPredictionsPlugin");
AWSPredictionsEscapeHatch escapeHatch = predictionsPlugin.getEscapeHatch();
// Create a presigned URL to convert text to speech using the client
AmazonPollyPresigningClient client = (AmazonPollyPresigningClient) escapeHatch.getPollyClient();
SynthesizeSpeechRequest request = SynthesizeSpeechRequest.Companion.invoke((requestBuilder) -> {
requestBuilder.setLanguageCode(LanguageCode.EnUs.INSTANCE);
requestBuilder.setText("I like to eat spaghetti");
return Unit.INSTANCE;
});
// The presigned URL needs to be created on a worker thread
runOnUiThread(new Runnable() {
@Override
public void run() {
URL url = client.getPresignedSynthesizeSpeechUrl(request);
}
});
// Obtain reference to the plugin
val plugin = Amplify.Predictions.getPlugin("awsPredictionsPlugin")
val escapeHatch = (plugin as AWSPredictionsPlugin).escapeHatch
// Create a presigned URL to convert text to speech using the client
val client = escapeHatch.pollyClient as AmazonPollyPresigningClient
val request = SynthesizeSpeechRequest {
languageCode = LanguageCode.EnUs
text = "I like to eat spaghetti"
}
// The presigned URL needs to be created on a worker thread
runOnUiThread {
val url = client.getPresignedSynthesizeSpeechUrl(request)
}

API Documentation Resources