SendMessage
In this article:
SendMessage#
Description#
Sends a message to the specified queue.
Request Syntax#
POST / HTTP/1.1
Content-type: application/json
{
"QueueUrl": "string",
"MessageBody": "string",
"DelaySeconds": integer
}
Request Parameters#
Required parameters#
MessageBody — The body of the message to be sent.
Type: String
Required: Yes
Constraints: Minimum length — 1 byte, maximum length is determined by the MaximumMessageSize queue attribute
QueueUrl — The URL of the queue to which the message is to be sent.
Type: String
Required: Yes
Optional parameters#
DelaySeconds — Time (in seconds) for which the message delivery should be delayed.
Type: Integer
Required: No
Range: From 0 to 900 (15 minutes)
Default value: If not specified, the default value of the DelaySeconds queue attribute is used.
Response Syntax#
HTTP/1.1 200
Content-type: application/json
{
"MD5OfMessageBody": "string",
"MessageId": "string"
}
Response Elements#
MD5OfMessageBody — The MD5 digest of the message body.
Type: String
MessageId — The unique ID of the sent message.
Type: String
Errors#
InvalidMessageContents — Invalid message content.
InvalidParameterValue — The parameter value is invalid (for example, the message size exceeds the maximum message size MaximumMessageSize specified for the queue).
UnsupportedOperation — The operation is not supported for this queue type.
Examples#
boto3
import boto3
session = boto3.Session(
aws_access_key_id="<AWS_ACCESS_KEY_ID>",
aws_secret_access_key="<AWS_SECRET_ACCESS_KEY>",
region_name="",
)
sqs_client = session.client(
'sqs',
endpoint_url='https://sqs.ru-msk.k2.cloud/'
)
response = sqs_client.send_message(
QueueUrl='https://sqs.ru-msk.k2.cloud/123456789012/my-queue',
MessageBody='Hello from SQS!'
)
print(f"Message ID: {response['MessageId']}")
print(f"MD5: {response['MD5OfMessageBody']}")
boto3 - With Delay
import boto3
session = boto3.Session(
aws_access_key_id="<AWS_ACCESS_KEY_ID>",
aws_secret_access_key="<AWS_SECRET_ACCESS_KEY>",
region_name="",
)
sqs_client = session.client(
'sqs',
endpoint_url='https://sqs.ru-msk.k2.cloud/'
)
response = sqs_client.send_message(
QueueUrl='https://sqs.ru-msk.k2.cloud/123456789012/my-queue',
MessageBody='Delayed message',
DelaySeconds=60
)
aws-cli
aws sqs --endpoint https://sqs.ru-msk.k2.cloud/ send-message \\
--queue-url https://sqs.ru-msk.k2.cloud/123456789012/my-queue \\
--message-body "Hello from SQS!"