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.
JavaScript v5Amplify JavaScript v5 has entered maintenance mode. We recommend upgrading to v6. A migration guide is available to help you upgrade from v5 to v6.

Publish

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.

To send a message to a topic, use publish() method with your topic name and the message:

await PubSub.publish('myTopic1', { msg: 'Hello to all subscribers!' });

If multiple providers are defined in your app you can pass the message to a specific provider:

await PubSub.publish('myTopic1', { msg: 'Hello to all subscribers!' }, { provider: 'AWSIoTProvider' });

You can also publish a message to multiple topics:

await PubSub.publish(['myTopic1','myTopic2'], { msg: 'Hello to all subscribers!' });

Note: If you do not include a specific provider it will publish a message to all of the configured PubSub providers in your app.