InvalidMessageContents aws config_error ai_generated true

An error occurred (InvalidMessageContents) when calling the SendMessage operation: Message attributes are required but missing

ID: aws/sqs-message-attributes-missing

Also available as: JSON · Markdown · 中文
82%Fix Rate
84%Confidence
1Evidence
2023-10-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
SQS 2012-11-05 active
AWS CLI 2.13.0 active
Lambda 2023-08-01 active

Root Cause

The SQS queue is configured with a policy or a Lambda trigger that expects specific message attributes, but the sent message does not include them.

generic

中文

SQS队列配置了期望特定消息属性的策略或Lambda触发器,但发送的消息不包含这些属性。

Official Documentation

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html

Workarounds

  1. 90% success Include the required message attributes when sending the message. Use the AWS CLI: aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --message-body "Hello" --message-attributes "{\"AttributeName\":{\"DataType\":\"String\",\"StringValue\":\"Value\"}}"
    Include the required message attributes when sending the message. Use the AWS CLI:
    aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --message-body "Hello" --message-attributes "{\"AttributeName\":{\"DataType\":\"String\",\"StringValue\":\"Value\"}}"
  2. 80% success Check the queue's policy or Lambda event source mapping to identify required attributes: aws sqs get-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --attribute-names Policy # Review the policy for conditions on message attributes.
    Check the queue's policy or Lambda event source mapping to identify required attributes:
    aws sqs get-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --attribute-names Policy
    # Review the policy for conditions on message attributes.
  3. 70% success Modify the Lambda trigger or queue policy to make attributes optional, if feasible: # Example: remove the condition that requires 'AttributeName' from the policy aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --attributes Policy='{"Version":"2012-10-17","Statement":[]}'
    Modify the Lambda trigger or queue policy to make attributes optional, if feasible:
    # Example: remove the condition that requires 'AttributeName' from the policy
    aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --attributes Policy='{"Version":"2012-10-17","Statement":[]}'

中文步骤

  1. 发送消息时包含必需的消息属性。使用AWS CLI:
    aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --message-body "Hello" --message-attributes "{\"AttributeName\":{\"DataType\":\"String\",\"StringValue\":\"Value\"}}"
  2. 检查队列策略或Lambda事件源映射以识别必需的属性:
    aws sqs get-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --attribute-names Policy
    # 审查策略中关于消息属性的条件。
  3. 如果可行,修改Lambda触发器或队列策略使属性变为可选:
    # 示例:从策略中移除要求'AttributeName'的条件
    aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-queue --attributes Policy='{"Version":"2012-10-17","Statement":[]}'

Dead Ends

Common approaches that don't work:

  1. Recreate the SQS queue with default settings 90% fail

    Recreating the queue does not change the requirement for message attributes; the Lambda trigger or policy still expects them.

  2. Send an empty message body 95% fail

    The error is about missing message attributes, not the body; an empty body does not resolve the attribute requirement.

  3. Increase the message retention period 98% fail

    Retention period does not affect message contents or attribute validation.