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

- **ID:** `aws/sqs-message-attributes-missing`
- **Domain:** aws
- **Category:** config_error
- **Error Code:** `InvalidMessageContents`
- **Verification:** ai_generated
- **Fix Rate:** 82%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| SQS 2012-11-05 | active | — | — |
| AWS CLI 2.13.0 | active | — | — |
| Lambda 2023-08-01 | active | — | — |

## Workarounds

1. **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\"}}"** (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\"}}"
   ```
2. **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.** (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.
   ```
3. **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":[]}'** (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":[]}'
   ```

## Dead Ends

- **Recreate the SQS queue with default settings** — Recreating the queue does not change the requirement for message attributes; the Lambda trigger or policy still expects them. (90% fail)
- **Send an empty message body** — The error is about missing message attributes, not the body; an empty body does not resolve the attribute requirement. (95% fail)
- **Increase the message retention period** — Retention period does not affect message contents or attribute validation. (98% fail)
