- 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.
SendMessageCommand
Delivers a message to the specified queue.
A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed. For more information, see the W3C specification for characters .
#x9
| #xA
| #xD
| #x20
to #xD7FF
| #xE000
to #xFFFD
| #x10000
to #x10FFFF
Amazon SQS does not throw an exception or completely reject the message if it contains invalid characters. Instead, it replaces those invalid characters with U+FFFD
before storing the message in the queue, as long as the message body contains at least one valid character.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs"; // ES Modules import
// const { SQSClient, SendMessageCommand } = require("@aws-sdk/client-sqs"); // CommonJS import
const client = new SQSClient(config);
const input = { // SendMessageRequest
QueueUrl: "STRING_VALUE", // required
MessageBody: "STRING_VALUE", // required
DelaySeconds: Number("int"),
MessageAttributes: { // MessageBodyAttributeMap
"<keys>": { // MessageAttributeValue
StringValue: "STRING_VALUE",
BinaryValue: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
StringListValues: [ // StringList
"STRING_VALUE",
],
BinaryListValues: [ // BinaryList
new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
],
DataType: "STRING_VALUE", // required
},
},
MessageSystemAttributes: { // MessageBodySystemAttributeMap
"<keys>": { // MessageSystemAttributeValue
StringValue: "STRING_VALUE",
BinaryValue: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
StringListValues: [
"STRING_VALUE",
],
BinaryListValues: [
new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
],
DataType: "STRING_VALUE", // required
},
},
MessageDeduplicationId: "STRING_VALUE",
MessageGroupId: "STRING_VALUE",
};
const command = new SendMessageCommand(input);
const response = await client.send(command);
// { // SendMessageResult
// MD5OfMessageBody: "STRING_VALUE",
// MD5OfMessageAttributes: "STRING_VALUE",
// MD5OfMessageSystemAttributes: "STRING_VALUE",
// MessageId: "STRING_VALUE",
// SequenceNumber: "STRING_VALUE",
// };
SendMessageCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
MessageBody Required | string | undefined | The message to send. The minimum size is one character. The maximum size is 256 KiB. A message can include only XML, JSON, and unformatted text. The following Unicode characters are allowed. For more information, see the W3C specification for characters . Amazon SQS does not throw an exception or completely reject the message if it contains invalid characters. Instead, it replaces those invalid characters with |
QueueUrl Required | string | undefined | The URL of the Amazon SQS queue to which a message is sent. Queue URLs and names are case-sensitive. |
DelaySeconds | number | undefined | The length of time, in seconds, for which to delay a specific message. Valid values: 0 to 900. Maximum: 15 minutes. Messages with a positive When you set |
MessageAttributes | Record<string, MessageAttributeValue> | undefined | Each message attribute consists of a |
MessageDeduplicationId | string | undefined | This parameter applies only to FIFO (first-in-first-out) queues. The token used for deduplication of sent messages. If a message with a particular
The If a message is sent successfully but the acknowledgement is lost and the message is resent with the same Amazon SQS continues to keep track of the message deduplication ID even after the message is received and deleted. The maximum length of For best practices of using |
MessageGroupId | string | undefined | This parameter applies only to FIFO (first-in-first-out) queues. The tag that specifies that a message belongs to a specific message group. Messages that belong to the same message group are processed in a FIFO manner (however, messages in different message groups might be processed out of order). To interleave multiple ordered streams within a single queue, use
The maximum length of For best practices of using |
MessageSystemAttributes | Partial<Record<MessageSystemAttributeNameForSends, MessageSystemAttributeValue> | undefined | The message system attribute to send. Each message system attribute consists of a
|
SendMessageCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
MD5OfMessageAttributes | string | undefined | An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For information about MD5, see RFC1321 . |
MD5OfMessageBody | string | undefined | An MD5 digest of the non-URL-encoded message body string. You can use this attribute to verify that Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For information about MD5, see RFC1321 . |
MD5OfMessageSystemAttributes | string | undefined | An MD5 digest of the non-URL-encoded message system attribute string. You can use this attribute to verify that Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. |
MessageId | string | undefined | An attribute containing the |
SequenceNumber | string | undefined | This parameter applies only to FIFO (first-in-first-out) queues. The large, non-consecutive number that Amazon SQS assigns to each message. The length of |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
InvalidAddress | client | The specified ID is invalid. |
InvalidMessageContents | client | The message contains characters outside the allowed set. |
InvalidSecurity | client | The request was not made over HTTPS or did not use SigV4 for signing. |
KmsAccessDenied | client | The caller doesn't have the required KMS access. |
KmsDisabled | client | The request was denied due to request throttling. |
KmsInvalidKeyUsage | client | The request was rejected for one of the following reasons:
|
KmsInvalidState | client | The request was rejected because the state of the specified resource is not valid for this request. |
KmsNotFound | client | The request was rejected because the specified entity or resource could not be found. |
KmsOptInRequired | client | The request was rejected because the specified key policy isn't syntactically or semantically correct. |
KmsThrottled | client | Amazon Web Services KMS throttles requests for the following conditions. |
QueueDoesNotExist | client | Ensure that the |
RequestThrottled | client | The request was denied due to request throttling.
|
UnsupportedOperation | client | Error code 400. Unsupported operation. |
SQSServiceException | Base exception class for all service exceptions from SQS service. |