选择您的 Cookie 首选项

我们使用必要 Cookie 和类似工具提供我们的网站和服务。我们使用性能 Cookie 收集匿名统计数据,以便我们可以了解客户如何使用我们的网站并进行改进。必要 Cookie 无法停用,但您可以单击“自定义”或“拒绝”来拒绝性能 Cookie。

如果您同意,AWS 和经批准的第三方还将使用 Cookie 提供有用的网站功能、记住您的首选项并显示相关内容,包括相关广告。要接受或拒绝所有非必要 Cookie,请单击“接受”或“拒绝”。要做出更详细的选择,请单击“自定义”。

Publish - AWS IoT
此页面尚未翻译为您的语言。 请求翻译

Publish

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?contentType=contentType&messageExpiry=messageExpiry&qos=qos&responseTopic=responseTopic&retain=retain HTTP/1.1 x-amz-mqtt5-user-properties: userProperties x-amz-mqtt5-payload-format-indicator: payloadFormatIndicator x-amz-mqtt5-correlation-data: correlationData payload

URI Request Parameters

The request uses the following URI parameters.

contentType

A UTF-8 encoded string that describes the content of the publishing message.

correlationData

The base64-encoded binary data used by the sender of the request message to identify which request the response message is for when it's received. correlationData is an HTTP header value in the API.

messageExpiry

A user-defined integer value that represents the message expiry interval in seconds. If absent, the message doesn't expire. For more information about the limits of messageExpiry, see AWS IoT Core message broker and protocol limits and quotas from the AWS Reference Guide.

payloadFormatIndicator

An Enum string value that indicates whether the payload is formatted as UTF-8. payloadFormatIndicator is an HTTP header value in the API.

Valid Values: UNSPECIFIED_BYTES | UTF8_DATA

qos

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

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

responseTopic

A UTF-8 encoded string that's used as the topic name for a response message. The response topic is used to describe the topic which the receiver should publish to as part of the request-response flow. The topic must not contain wildcard characters.

retain

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

topic

The name of the MQTT topic.

Required: Yes

userProperties

A JSON string that contains an array of JSON objects. If you don’t use AWS SDK or AWS CLI, you must encode the JSON string to base64 format before adding it to the HTTP header. userProperties is an HTTP header value in the API.

The following example userProperties parameter is a JSON string which represents two User Properties. Note that it needs to be base64-encoded:

[{"deviceName": "alpha"}, {"deviceCnt": "45"}]

Request Body

The request accepts the following binary data.

payload

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.

Errors

InternalFailureException

An unexpected error has occurred.

HTTP Status Code: 500

InvalidRequestException

The request is not valid.

HTTP Status Code: 400

MethodNotAllowedException

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

HTTP Status Code: 405

ThrottlingException

The rate exceeds the limit.

HTTP Status Code: 429

UnauthorizedException

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:

隐私网站条款Cookie 首选项
© 2025, Amazon Web Services, Inc. 或其附属公司。保留所有权利。