- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
PublishCommand
Publishes an MQTT message.
Requires permission to access the Publish action.
For more information about MQTT messages, see MQTT Protocol in the IoT Developer Guide.
For more information about messaging costs, see Amazon Web Services IoT Core pricing - Messaging .
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { IoTDataPlaneClient, PublishCommand } from "@aws-sdk/client-iot-data-plane"; // ES Modules import
// const { IoTDataPlaneClient, PublishCommand } = require("@aws-sdk/client-iot-data-plane"); // CommonJS import
const client = new IoTDataPlaneClient(config);
const input = { // PublishRequest
topic: "STRING_VALUE", // required
qos: Number("int"),
retain: true || false,
payload: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
userProperties: "STRING_VALUE",
payloadFormatIndicator: "UNSPECIFIED_BYTES" || "UTF8_DATA",
contentType: "STRING_VALUE",
responseTopic: "STRING_VALUE",
correlationData: "STRING_VALUE",
messageExpiry: Number("long"),
};
const command = new PublishCommand(input);
const response = await client.send(command);
// {};
PublishCommand Input
See PublishCommandInput for more details
PublishCommandInput extends PublishCommandInputType
PublishCommand Output
See PublishCommandOutput for details
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
InternalFailureException | server | An unexpected error has occurred. |
InvalidRequestException | client | The request is not valid. |
MethodNotAllowedException | client | The specified combination of HTTP verb and URI is not supported. |
ThrottlingException | client | The rate exceeds the limit. |
UnauthorizedException | client | You are not authorized to perform this operation. |
IoTDataPlaneServiceException | Base exception class for all service exceptions from IoTDataPlane service. |