AWS CLI commands to automate file upload to an S3 bucket.

Chris Utley
1 min readJul 11, 2023

--

To automate the file upload process to an S3 bucket using the AWS Command Line Interface (CLI), you can utilize the aws s3 cp or aws s3 sync command. Here are examples of both commands:

  1. Uploading a Single File:
aws s3 cp /path/to/local/file.txt s3://your-bucket-name/path/to/destination/file.txt

Replace /path/to/local/file.txt with the local file path you want to upload and s3://your-bucket-name/path/to/destination/file.txt with the S3 bucket and destination file path.

  1. Synchronizing a Directory:
aws s3 sync /path/to/local/directory s3://your-bucket-name/path/to/destination/

Replace /path/to/local/directory with the local directory you want to synchronize and s3://your-bucket-name/path/to/destination/ with the S3 bucket and destination directory path.

The aws s3 cp command is used to upload a single file, while the aws s3 sync command is used to synchronize a directory, including all its contents, to the S3 bucket.

You may also include additional options and flags with these commands to control the behavior, such as --recursive to upload or sync directories recursively, --exclude to exclude specific files or patterns, and --acl to set the access control list for the uploaded files.

Ensure that you have the AWS CLI installed and configured with appropriate credentials and permissions to access the desired S3 bucket.

--

--