How to transfer files to S3 using the AWS CLI?

To transfer files to Amazon S3 using the AWS Command Line Interface (CLI), you can use the aws s3 cp command. Here's how you can do it:

  1. Install the AWS CLI: If you haven't already, you can install the AWS CLI by following the instructions in the AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

  2. Configure the AWS CLI: Once you have installed the AWS CLI, you need to configure it with your AWS credentials. You can do this by running the aws configure command and entering your AWS Access Key ID, Secret Access Key, default region, and output format.

  3. Transfer files to S3: Once the AWS CLI is configured, you can use the aws s3 cp command to transfer files to S3. The basic syntax of the command is:

aws s3 cp <local-file> s3://<bucket-name>/<path>

For example, to transfer a file named example.txt from your local machine to a bucket named my-bucket in S3, you can run the following command:

aws s3 cp example.txt s3://my-bucket/

If you want to transfer a directory and all its contents to S3, you can use the --recursive flag:

aws s3 cp <local-directory> s3://<bucket-name>/<path> --recursive

For example, to transfer a directory named my-folder and all its contents to the my-bucket bucket in S3, you can run the following command:

aws s3 cp my-folder s3://my-bucket/ --recursive

That's it! You have successfully transferred files to Amazon S3 using the AWS CLI.