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:
// Obtain reference to the pluginAWSPredictionsPlugin predictionsPlugin = (AWSPredictionsPlugin) Amplify.Predictions.getPlugin("awsPredictionsPlugin");AWSPredictionsEscapeHatch escapeHatch = predictionsPlugin.getEscapeHatch();
// Send a new request to the Rekognition endpoint directly using the clientRekognitionClient 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 pluginval plugin = Amplify.Predictions.getPlugin("awsPredictionsPlugin")val escapeHatch = (plugin as AWSPredictionsPlugin).escapeHatch
// Send a new request to the Rekognition endpoint directly using the clientval client = escapeHatch.rekognitionClientval 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 pluginAWSPredictionsPlugin predictionsPlugin = (AWSPredictionsPlugin) Amplify.Predictions.getPlugin("awsPredictionsPlugin");AWSPredictionsEscapeHatch escapeHatch = predictionsPlugin.getEscapeHatch();
// Create a presigned URL to convert text to speech using the clientAmazonPollyPresigningClient 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 threadrunOnUiThread(new Runnable() { @Override public void run() { URL url = client.getPresignedSynthesizeSpeechUrl(request); }});// Obtain reference to the pluginval plugin = Amplify.Predictions.getPlugin("awsPredictionsPlugin")val escapeHatch = (plugin as AWSPredictionsPlugin).escapeHatch
// Create a presigned URL to convert text to speech using the clientval client = escapeHatch.pollyClient as AmazonPollyPresigningClientval request = SynthesizeSpeechRequest { languageCode = LanguageCode.EnUs text = "I like to eat spaghetti"}
// The presigned URL needs to be created on a worker threadrunOnUiThread { val url = client.getPresignedSynthesizeSpeechUrl(request)}API Documentation Resources