AWS Lambda and SQS, reserved header X-Amzn-Trace-Id error

Question:

Edit*
Looks like it was fixed. https://github.com/boto/botocore/commit/315c8353228fa03e2d613a4f3d94119ed9c3c6b0

I am trying to send a message to a standard AWS SQS queue using a Lambda function running Python 3.9.

When i send the message like this using the ‘Test’ function in the AWS console or if the function is triggered by a cron timer from EventBridge. It works if i run it from my IDE.

sqs.send_message(
    QueueUrl=queue_url,
    DelaySeconds=0,
    MessageAttributes={
        'Bucket': {
            'DataType': 'String',
            'StringValue': bucket
        }
    },
    MessageBody=(
        'Test')
    )
)

I get this error.

[ERROR] ClientError: An error occurred (InvalidParameterValue) when calling the 
SendMessage operation: The request has a 'X-Amzn-Trace-Id' HTTP header which is 
reserved for AWS X-Ray trace header and has an invalid value 
'Root%3D1-62e53a62-32fe44f063cc71297ba219f1%3BParent%3D161b7ec516b8d267%3BSampled%3D0'

Traceback (most recent call last):
  File "/var/task/main.py", line 27, in lambda_handler
    sqs.queue_message(config['queue_url'],
  File "/var/task/sqs.py", line 9, in queue_message
    response = sqs.send_message(
  File "/var/task/botocore/client.py", line 508, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/task/botocore/client.py", line 915, in _make_api_call
    raise error_class(parsed_response, operation_name)

I am using these package versions.

boto3==1.24.41
jmespath~=1.0.1
s3transfer~=0.6.0
brotlicffi~=1.0.9.2
cryptography~=37.0.4
six~=1.16.0
python-dateutil~=2.8.2
urllib3==1.26.11
awscrt==0.13.14
certifi~=2022.6.15
requests~=2.28.1

And my Lambda function has these permissions for the SQS queue.

"Action": [
    "sqs:SendMessageBatch",
    "sqs:SendMessage",
    "sqs:ListQueueTags",
    "sqs:ListDeadLetterSourceQueues",
    "sqs:GetQueueUrl",
    "sqs:GetQueueAttributes",
    "sqs:ChangeMessageVisibilityBatch",
    "sqs:ChangeMessageVisibility"
],
"Effect": "Allow",
"Resource": "arn:aws:sqs:eu-central-1:<redacted>:test-function",
"Sid": ""
Asked By: Zucchini

||

Answers:

Looks like they broke this functionality in the last few releases. I had been deploying a Lambda safely where I didn’t have the boto3 version pinned. Then, all of a sudden it stopped working (I was using boto3-1.24.41 when I saw the error), and I was getting the exact same error you show. It was working from my machine (running version of boto3 of 1.20.52). So I changed my requirements.txt in my Lambda to pin to that version

boto3 == 1.20.52

I ran my Lambda again and the issue is gone. You probably don’t need to go back that far in the version, maybe 1.24.27 would work; I think they broke it within the last week or two.

Answered By: David Karim

Seems to be an issue introduced in botocore (actually a bug fix that caused the bugs) and has just been reverted two hours ago

https://github.com/boto/botocore/commit/315c8353228fa03e2d613a4f3d94119ed9c3c6b0

Answered By: Morten Olsen