AWS CLI has made working with S3 very easy. Once you get AWS CLI installed you might ask “How do I start copying local files to S3?”
The syntax for copying files to/from S3 in AWS CLI is:aws s3 cp <source> <destination>
The “source” and “destination” arguments can either be local paths or S3 locations. The three possible variations of this are:aws s3 cp <Local Path> <S3 URI>
aws s3 cp <S3 URI> <Local Path>
aws s3 cp <S3 URI> <S3 URI>
To copy all the files in a directory (local or S3) you must use the --recursive
option. For more complex Linux type “globbing” functionality, you must use the --include
and --exclude
options. See this post for more details.
Here are a couple of simple examples of copying local files to S3:
#!/bin/bash
#copy my-file.txt to the to the "data" directory located in my-s3-bucket
aws s3 cp my-file.txt s3://my-s3-bucket/data/
#copy all files in my-data-dir into the "data" directory located in my-s3-bucket
aws s3 cp my-data-dir/ s3://my-s3-bucket/data/ --recursive