Amplify CLI Predictions Category Plugin

raw JSON →
4.3.2 verified Thu Apr 23 auth: no javascript

The `amplify-category-predictions` package is a core plugin for the AWS Amplify Command Line Interface (CLI), enabling developers to provision and manage AWS AI/ML services within their Amplify projects. It facilitates the integration of services like Amazon Rekognition (for image identification), Amazon Translate (for language conversion), Amazon Polly (for text-to-speech), Amazon Transcribe (for speech-to-text), Amazon Comprehend (for text interpretation), and Amazon Textract (for document text extraction). This plugin abstracts complex AWS resource configuration, including IAM permissions, into a streamlined CLI workflow. While the broader Amplify CLI ecosystem is currently on version `14.x.x` (e.g., `14.3.0` as of March 2026), this specific plugin's latest stable version is `5.5.25` (as of October 2025). It adheres to the rapid release cadence of the Amplify CLI, with frequent updates often bundled with broader CLI releases, and is primarily differentiated by its opinionated, CLI-driven approach to integrating sophisticated AI/ML capabilities into web and mobile applications for frontend consumption via the `@aws-amplify/predictions` client library.

error AccessDeniedException: User: arn:aws:sts::... is not authorized to perform: rekognition:DetectLabels on resource: arn:aws:rekognition:...
cause The authenticated or unauthenticated IAM role configured by Amplify for predictions lacks the necessary permissions for the specific AWS AI service being invoked (e.g., Rekognition, Translate, Comprehend).
fix
Ensure that during amplify add predictions, you grant the correct access levels (authenticated or guest) and that the automatically generated IAM policies (visible in the AWS console under your Identity Pool roles) have the required actions for the services you intend to use. You may need to manually update the IAM policy for the roles if default options were insufficient or a new feature was added.
error Amplify has not been configured. Please call Amplify.configure() before using any Amplify APIs.
cause The `Amplify.configure(amplifyconfig)` call is missing or not executed before attempting to use `Predictions` APIs in your client-side application.
fix
Make sure to import and call Amplify.configure(amplifyconfig) at the root level of your application (e.g., index.js or main.ts) after amplify push has generated the amplifyconfiguration.json file. Ensure the amplifyconfiguration.json file is correctly imported and available.
error Error: Cannot find module '@aws-amplify/predictions'
cause The `@aws-amplify/predictions` package is not installed as a dependency in your client-side project.
fix
Install the predictions library: npm install @aws-amplify/predictions aws-amplify or yarn add @aws-amplify/predictions aws-amplify. Ensure both aws-amplify and @aws-amplify/predictions are present and at compatible versions.
breaking Amplify CLI `v7` introduced significant changes to project structure and override capabilities for IAM, Cognito, and S3. Projects created with older CLI versions require a migration process, which involves updating resource configurations and potentially re-deploying your backend.
fix Run `amplify override <category>` or `amplify update <category>` in a test environment first, then `amplify push`. Follow the official Amplify migration guides for detailed steps.
breaking AWS Amplify Hosting will deprecate support for Node.js 14, 16, and 18 runtimes after September 15, 2025. Applications deployed on Amplify Hosting should target Node.js 20 or 22 for build and runtime environments to ensure continued support and performance. The Amplify CLI itself requires Node.js 12.x or greater and npm 6.x or greater.
fix Ensure your local development environment meets Node.js requirements (v12+). For Amplify Hosting, update your `amplify.yaml` or console settings to use Node.js 20 or 22.
gotcha When using `Identify Labels` or `Identify Text` features via `amplify add predictions` in older versions of the CLI, some configuration items (e.g., `identifyDoc`, `access`, `format`, `type`) might need to be manually added to specific `parameters.json` files within your `amplify/backend` directory. This was a known issue that might still affect projects on older CLI versions.
fix Refer to the Amplify documentation for the exact `parameters.json` updates needed for `identify-text-resource` and `identify-labels-resource` if you encounter unexpected behavior or permission issues with these features.
gotcha The `amplify-category-predictions` package version (`5.5.25`) may not directly align with the main `amplify-cli` version (`14.x.x`). While plugins are generally compatible with the latest CLI, unexpected behaviors can occur if there's a significant mismatch, especially during core CLI updates or SDK migrations within the monorepo.
fix Always keep your global `amplify-cli` installation updated (`npm install -g @aws-amplify/cli@latest`). When issues arise, verify the versions of core `@aws-amplify/*` packages in your project's `node_modules` and ensure they are consistent with the `amplify-cli` version.
npm install amplify-category-predictions
yarn add amplify-category-predictions
pnpm add amplify-category-predictions

This quickstart guides you through setting up an Amplify project with predictions via the CLI, deploying the backend, and then demonstrates client-side text translation using the configured resources. It also includes commented examples for other prediction features.

/* --- CLI Setup (Run in your terminal) --- */
# Install the Amplify CLI globally
npm install -g @aws-amplify/cli

# Configure the CLI with your AWS account (interactive flow)
amplify configure

# Initialize a new Amplify project
mkdir my-predictions-app
cd my-predictions-app
amplify init # Follow prompts: choose frontend, framework, project name, environment

# Add the Predictions category (interactive flow)
amplify add predictions
# Prompts example:
# ? Please select from one of the categories below: Convert
# ? What would you like to convert?: translateText
# ? Would you like to allow unauthenticated users to use this category?: No
# ? Who should have access?: Auth users only
# ? What is the default language?: English
# ? What other languages do you want to support?: Spanish, French

# Deploy your backend resources to AWS
amplify push

/* --- Client-Side Usage (e.g., src/App.js or src/main.ts) --- */
import { Amplify } from 'aws-amplify';
import { Predictions } from 'aws-amplify'; // Or 'import { Predictions } from '@aws-amplify/predictions';
import amplifyconfig from './amplifyconfiguration.json'; // Ensure this file exists after `amplify push`

// Configure Amplify with your backend details
Amplify.configure(amplifyconfig);

async function translateExample() {
  try {
    const textToTranslate = 'Hello, how are you?';
    console.log(`Translating: "${textToTranslate}"`);

    const result = await Predictions.convert({
      translateText: {
        source: {
          text: textToTranslate,
          language: 'en' // Source language
        },
        targetLanguage: 'es' // Target language
      }
    });
    console.log('Translated text (Spanish):', result.text);

    const resultFrench = await Predictions.convert({
      translateText: {
        source: {
          text: textToTranslate,
          language: 'en'
        },
        targetLanguage: 'fr'
      }
    });
    console.log('Translated text (French):', resultFrench.text);

  } catch (error) {
    console.error('Error during translation:', error);
  }
}

translateExample();

// Example for identifying text in an image (requires appropriate backend config)
/*
async function identifyTextInImage(file: File) {
  try {
    const result = await Predictions.identify({
      text: {
        source: { file },
        format: 'PLAIN' // or 'FORM', 'TABLE', 'ALL'
      }
    });
    console.log('Detected text:', result.text.fullText);
  } catch (error) {
    console.error('Error identifying text:', error);
  }
}
*/