Name:
interface
Value:
Extend your Amplify Gen 2 app with AWS Blocks — self-contained backend capabilities you compose into your existing backend.

Page updated Apr 29, 2024

NewDeploy web apps with Git or your AI coding agent using the latest AWS Amplify. Add managed databases and authentication as you grow. Explore the documentation.
Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade.

Use AWS SDK

These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.

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