How to upload a file to an S3 bucket using s3cmd?

To upload a file to an S3 bucket using s3cmd, you can follow the steps below:

  1. Install s3cmd on your machine if you haven't already. You can download it from the official s3cmd website or use a package manager like apt or yum if available for your operating system.

  2. Open a terminal or command prompt and configure s3cmd by running the following command:

    s3cmd --configure

    This command will prompt you to enter your Access Key ID and Secret Access Key, which you can obtain from the AWS Management Console. It will also ask you to specify the default region and encryption settings.

  3. Once configured, navigate to the directory where your file is located using the cd command.

  4. Use the following command to upload the file to your S3 bucket:

    s3cmd put <file_name> s3://<bucket_name>/<path_to_file>

    Replace <file_name> with the name of the file you want to upload, <bucket_name> with the name of your S3 bucket, and <path_to_file> with the desired path within the bucket.

    For example, to upload a file named example.txt to a bucket named my-bucket and store it under the folder files, you would use the following command:

    s3cmd put example.txt s3://my-bucket/files/
  5. The file will be uploaded to your S3 bucket, and you should see a progress indicator in the command line. Once the upload is complete, you'll receive a response indicating the uploaded file's URL and other details.

Note: If your bucket is in a region other than the default region configured in s3cmd, you can specify the region using the --region flag followed by the appropriate AWS region code. For example:

s3cmd put --region=us-west-2 example.txt s3://my-bucket/files/