CodexBloom - Programming Q&A Platform

AWS S3 Multipart Upload scenarios with 'InvalidPart' scenarios When Using Boto3

👀 Views: 553 💬 Answers: 1 📅 Created: 2025-06-08
AWS S3 Boto3 Python

I'm converting an old project and Quick question that's been bugging me - I'm relatively new to this, so bear with me..... I'm working with an scenario with multipart uploads to an S3 bucket using Boto3 in Python. After uploading the parts, I'm attempting to complete the multipart upload but I receive an 'InvalidPart' behavior. Here's the relevant portion of my code: ```python import boto3 s3_client = boto3.client('s3') bucket_name = 'my-bucket' key = 'large_file.zip' # Start multipart upload response = s3_client.create_multipart_upload(Bucket=bucket_name, Key=key) upload_id = response['UploadId'] parts = [] for i in range(1, 6): # Assuming I want to upload 5 parts with open(f'part_{i}.zip', 'rb') as data: part_response = s3_client.upload_part( Bucket=bucket_name, Key=key, PartNumber=i, UploadId=upload_id, Body=data ) parts.append({ 'ETag': part_response['ETag'], 'PartNumber': i }) # Completing the upload try: s3_client.complete_multipart_upload( Bucket=bucket_name, Key=key, UploadId=upload_id, MultipartUpload={ 'Parts': parts } ) except Exception as e: print(f'behavior completing upload: {e}') ``` I double-checked that the ETags captured during the upload process match what S3 is expecting, and I am using the latest version of Boto3 (1.19.0). The bucket policy allows for multipart uploads and everything seems correctly set up. However, the behavior returned is: ``` An behavior occurred (InvalidPart) when calling the CompleteMultipartUpload operation: The part number is invalid. ``` I’ve tried running the upload process multiple times, and even with different file sizes, but I keep getting the same behavior. Is there something I'm missing in the way I'm specifying the part information or the upload process itself? My development environment is macOS. Any ideas what could be causing this? This is part of a larger CLI tool I'm building. I'd really appreciate any guidance on this. I've been using Python for about a year now.