11
votes

I am trying to upload multiple files from my local to an AWS S3 bucket,
I am able to use aws s3 cp to copy files one by one,
But I need to upload multiple but not all ie. selective files to the same S3 folder,
Is it possible to do this in a single AWS CLI call, if so how?

Eg -

aws s3 cp test.txt s3://mybucket/test.txt

Reference -
https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html

1

1 Answers

25
votes

If you scroll down the documentation link you provided to the section entitled "Recursively copying local files to S3", you will see the following:

When passed with the parameter --recursive, the following cp command recursively copies all files under a specified directory to a specified bucket and prefix while excluding some files by using an --exclude parameter. In this example, the directory myDir has the files test1.txt and test2.jpg

So, assuming you wanted to copy all .txt files in some subfolder to the same bucket in S3, you could try something like:

aws s3 cp yourSubFolder s3://mybucket/ --recursive

If there are any other files in this subfolder, you need to add the --exclude and --include parameters (otherwise all files will be uploaded):

aws s3 cp yourSubFolder s3://mybucket/ --recursive --exclude "*" --include "*.txt"