AWS

IncompleteBody - Incomplete Body

Getting an **IncompleteBody** error means the Content-Length HTTP header doesn't match the actual request body size—the body is incomplete, truncated, or the header value is wrong. This client-side error (4xx) happens when AWS validates request body completeness. Most common when Content-Length header is incorrect, but also appears when request body is incomplete or truncated, network interruptions occur during upload, body size mismatches the header, or uploads terminate early.

#Common Causes

  • Identity: IAM policy allows upload but body incomplete. Service Control Policy (SCP) enforces body validation.
  • Network: Network interruption during upload. VPC endpoint body size restrictions. Request body truncated.
  • Limits: Content-Length header doesn't match actual body size. Request body incomplete or truncated. Body size mismatch with header. Upload terminated early.

Solutions

  1. 1Step 1: Diagnose - Check Content-Length header: Review request headers. Verify Content-Length value. Compare with actual body size. Check if header is set correctly.
  2. 2Step 2: Diagnose - Verify actual body size: Calculate actual body size. Compare with Content-Length header. Check if body is complete. Verify no truncation occurred.
  3. 3Step 3: Diagnose - Check for network issues: Review network logs. Check for connection drops. Verify upload completed fully. Check for timeout errors.
  4. 4Step 4: Fix - Set correct Content-Length: Calculate actual body size. Set Content-Length header to match: Content-Length: ACTUAL_SIZE. Or let AWS SDK/CLI set it automatically.
  5. 5Step 5: Fix - Retry with complete body: Ensure complete request body is sent. Use AWS CLI which handles Content-Length automatically: aws s3 cp FILE s3://BUCKET/KEY. Or use streaming upload for large bodies.

</>Code Examples

Verify Content-Length Matches Body Size
1#!/bin/bash
2FILE_PATH="file.txt"
3BUCKET_NAME="my-bucket"
4OBJECT_KEY="file.txt"
5
6# Calculate actual file size
7ACTUAL_SIZE=$(stat -f%z "${FILE_PATH}" 2>/dev/null || stat -c%s "${FILE_PATH}" 2>/dev/null)
8
9echo "=== File Size Check ==="
10echo "Actual file size: ${ACTUAL_SIZE} bytes"
11
12# AWS CLI automatically sets Content-Length correctly
13echo "\n=== Uploading with AWS CLI (Auto Content-Length) ==="
14aws s3 cp ${FILE_PATH} s3://${BUCKET_NAME}/${OBJECT_KEY}
15
16if [ $? -eq 0 ]; then
17  echo "✓ Upload successful - Content-Length handled automatically"
18else
19  echo "✗ Upload failed - check error message"
20  echo "If IncompleteBody error, verify file wasn't modified during upload"
21fi
22
23# Verify uploaded object size
24echo "\n=== Verifying Uploaded Object ==="
25UPLOADED_SIZE=$(aws s3api head-object \
26  --bucket ${BUCKET_NAME} \
27  --key ${OBJECT_KEY} \
28  --query 'ContentLength' \
29  --output text)
30
31if [ "${UPLOADED_SIZE}" = "${ACTUAL_SIZE}" ]; then
32  echo "✓ Uploaded size matches: ${UPLOADED_SIZE} bytes"
33else
34  echo "✗ Size mismatch: Expected ${ACTUAL_SIZE}, Got ${UPLOADED_SIZE}"
35fi
Check for Network Interruptions During Upload
1#!/bin/bash
2# Check network connectivity before upload
3echo "=== Checking Network Connectivity ==="
4ping -c 3 s3.amazonaws.com 2>&1 | head -5
5
6# Upload with retry on failure
7FILE_PATH="large-file.zip"
8BUCKET_NAME="my-bucket"
9OBJECT_KEY="large-file.zip"
10
11echo "\n=== Uploading with Retry Logic ==="
12MAX_RETRIES=3
13RETRY_COUNT=0
14
15while [ ${RETRY_COUNT} -lt ${MAX_RETRIES} ]; do
16  echo "Attempt $(expr ${RETRY_COUNT} + 1) of ${MAX_RETRIES}"
17  
18  aws s3 cp ${FILE_PATH} s3://${BUCKET_NAME}/${OBJECT_KEY} 2>&1
19  
20  if [ $? -eq 0 ]; then
21    echo "✓ Upload successful"
22    break
23  else
24    RETRY_COUNT=$(expr ${RETRY_COUNT} + 1)
25    if [ ${RETRY_COUNT} -lt ${MAX_RETRIES} ]; then
26      echo "✗ Upload failed - retrying in 5 seconds..."
27      sleep 5
28    else
29      echo "✗ Upload failed after ${MAX_RETRIES} attempts"
30      echo "Check network connection and file integrity"
31    fi
32  fi
33done

Related Errors

Provider Information

This error code is specific to AWS services. For more information, refer to the official AWS documentation.

IncompleteBody - Incomplete Body | AWS Error Reference | Error Code Reference