Amplify CLI Notifications Plugin

2.23.2 · active · verified Wed Apr 22

The `@aws-amplify/amplify-category-notifications` package is a core plugin for the AWS Amplify Command Line Interface (CLI), enabling developers to manage notification channels, primarily through Amazon Pinpoint. It allows for the addition, removal, updating, and status checking of notification channels directly from the command line, and provides a shortcut to the Pinpoint console for detailed configuration. This package is part of the larger Amplify CLI monorepo, with its latest stable version being `2.26.42`. It receives frequent updates, typically alongside the rapid release cadence of the Amplify CLI itself, ensuring compatibility with the latest AWS services and addressing security concerns. Its key differentiator is its deep integration into the Amplify development workflow, abstracting complex AWS Pinpoint configurations into simple CLI commands. This package is primarily for internal use by the Amplify CLI and for advanced users extending the CLI functionality.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically interact with the Amplify CLI to add and configure a push notification channel using the underlying `amplify-category-notifications` plugin. It simulates the `amplify add notifications` command, which is the primary way developers utilize this package.

import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

async function setupAmplifyNotifications() {
  try {
    console.log('Initializing Amplify project (if not already initialized)...');
    // Ensure Amplify project is initialized. This is a prerequisite.
    await execAsync('amplify init --yes');

    console.log('Adding notifications category via Amplify CLI...');
    // This simulates running `amplify add notifications` interactively.
    // In a real script, you'd handle prompts or use headless mode.
    const { stdout, stderr } = await execAsync(
      `amplify add notifications --channel APNS --json-file-path './path/to/your-apns-key.json' --no-override`,
      {
        env: {
          ...process.env,
          // Example: Provide environment variables for non-interactive prompts if available
          // AMH_APP_ID: process.env.AMH_APP_ID ?? '',
          // AMH_REGION: process.env.AMH_REGION ?? ''
        }
      }
    );
    console.log('Amplify CLI Output (add notifications):', stdout);
    if (stderr) console.error('Amplify CLI Error (add notifications):', stderr);

    console.log('Pushing Amplify backend changes...');
    await execAsync('amplify push --yes');
    console.log('Amplify notifications setup complete. Review `amplify status` for details.');
  } catch (error) {
    console.error('Failed to set up Amplify notifications:', error);
    process.exit(1);
  }
}

// For an actual application, you'd then use @aws-amplify/pushnotification in your client-side code.
// import Amplify from 'aws-amplify';
// import PushNotification from '@aws-amplify/pushnotification';
// import awsconfig from './aws-exports';
// Amplify.configure(awsconfig);
// PushNotification.onNotification(notification => {
//   console.log('Notification received:', notification);
// });

setupAmplifyNotifications();

view raw JSON →