Prerequisites:
- An AWS Acoount
- Two bucket one for source and one for destination
- Aws CLI configured.
For demonstration, I created to new bucket which is publicly accessible.
Uploading Individual Files to S3
To upload a file to S3, you’ll need to provide two arguments (source and destination) to the aws s3 cp command.
Note: S3 bucket names are always prefixed with S3:// when used with AWS CLI
Use the command below to list the objects at the root of the S3 bucket.
aws s3 ls s3://bucket-name
Uploading Multiple Files and Folders to S3
What if you need to upload multiple files from a folder and sub-folders? Surely you wouldn’t want to run the same command multiple times for different filenames, right?
The aws s3 cp command has an option to process files and folders recursively, and this is the --recursive option.
If we don't use --recursive option it shows an error.
*Uploading Multiple Files and Folders to S3 Selectively
*
In some cases, uploading ALL types of files is not the best option. Like, when you only need to upload files with specific file extensions.
Options available to the cp command is the --include and --exclude.
Downloading Objects from S3
Copying from S3 to local would require you to switch the positions of the source and the destination. The source being the S3 location, and the destination is the local path, like the one shown below.
You can also use --recursive option for multiple download.
Copy from one bucket to oneother bucket.
aws s3 cp source-bucket destination-bucket
Top comments (2)
Hi Havi! Interesting experiment on the S3 cp commands. I found this command very handy when moving around files from one s3 bucket to another, instead of download it in my local and reuploading it back to s3.
Thank you.