Quick debug: AWS S3 Invalid length for parameter Key

Nazreen Mohamad
1 min readJul 30, 2022

You’re here (hopefully) because you were trying to run the aws s3 cp command but got the error:

Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-infLet’s cut to the chase.

Are you trying to upload a whole directory (e.g. the current directory)to your bucket ? A little bit like so:

aws s3 cp . s3://bucket-name

Then what you need to do is add the --recursive flag, like so:

aws s3 cp . s3://bucket-name --recursive

Without the --recursive flag, the CLI was expecting you to specify a Key as it thought that you wanted to upload a single object.

That should fix it, but wait! There might be a better command for you.

Quick comparison between the 2 commands at your disposal:

aws s3 cp — copies all files to the s3 bucket, even if they already exists.

aws s3 sync — checks the destination bucket first before copying, thereby avoiding copying files that already exist in the destination bucket.

Running the sync command (with the current directory as the source directory) looks like so:

aws s3 sync . s3://bucket-name

If you already have some objects/files in the destination bucket from a previous cp operation, then sync might be better for you.

That’s it, hope that helped you, and let me know if it didn’t.

Nazreen Mohamad

Technical Instructor and Software Engineer.