Publish - AWS IoT


Publishes an MQTT message.

Requires permission to access the Publish action.

For more information about MQTT messages, see MQTT Protocol in the AWS IoT Developer Guide.

For more information about messaging costs, see AWS IoT Core pricing - Messaging.

Request Syntax

POST /topics/topic?qos=qos&retain=retain HTTP/1.1 payload

URI Request Parameters

The request uses the following URI parameters.


The Quality of Service (QoS) level. The default QoS level is 0.

Valid Range: Minimum value of 0. Maximum value of 1.


A Boolean value that determines whether to set the RETAIN flag when the message is published.

Setting the RETAIN flag causes the message to be retained and sent to new subscribers to the topic.

Valid values: true | false

Default value: false


The name of the MQTT topic.

Required: Yes

Request Body

The request accepts the following binary data.


The message body. MQTT accepts text, binary, and empty (null) message payloads.

Publishing an empty (null) payload with retain = true deletes the retained message identified by topic from AWS IoT Core.

Response Syntax

HTTP/1.1 200

Response Elements

If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.



An unexpected error has occurred.

HTTP Status Code: 500


The request is not valid.

HTTP Status Code: 400


The specified combination of HTTP verb and URI is not supported.

HTTP Status Code: 405


You are not authorized to perform this operation.

HTTP Status Code: 401

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: