简体   繁体   中英

Unable to send the MessageAttributes to AWS SQS using Python 3

I am trying to write to an SQS message attributes using boto3 library.

import boto3
sqs = boto3.client('sqs')

response = sqs.send_message(
    QueueUrl = 'https://queue.amazonaws.com/xxxxx/test',
    MessageBody='test01',
    MessageAttributes={
        'from': {
            'StringValue': '2019-12-11',
            'DataType': 'string'
        }
    }
)

But I got error message:

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the SendMessage operation: The type of message (user) attribute 'from' is invalid. You must use only the following supported type prefixes: Binary, Number, String.

I also tried several ways but it did not work too. Could anyone please help me to fix that error?

I also would highly appreciate if there is another way to do it? Thanks!

This should fix your code but right way is to have a look at this

import boto3
sqs = boto3.client('sqs')[enter link description here][1]

response = sqs.queue.send_message(
  QueueUrl = 'https://queue.amazonaws.com/xxxxx/test',
  MessageBody='test01',
  MessageAttributes={
      'from': {
        'StringValue': '2019-12-11',
        'DataType': 'String'
    }
}
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM