Using the S3 console is a good way to start, but the AWS CLI lets you run the same steps from a terminal. This guide walks through a short practice session with a single test file.
Before you start
- Install the AWS CLI and confirm it runs: aws --version
- Sign in with an IAM user, not the root account. Give the user only the S3 permissions it needs for this practice.
- Run aws configure and enter that user's access key, secret key, and default region. Keep your keys private and never paste them into an article or a screenshot.
Step 1: Confirm who you're signed in as
aws sts get-caller-identity
The output shows the account ID, user ID, and ARN. Check that it's the IAM user you intended to use.
Step 2: Create a bucket
Bucket names must be globally unique across all AWS accounts, so choose your own name.
aws s3 mb s3://your-unique-bucket-name --region ap-southeast-1
Use the region closest to you. If you choose a different one, change --region to match.
Step 3: Create and upload a file
echo "Hello from the AWS CLI" > hello.txt
aws s3 cp hello.txt s3://your-unique-bucket-name/
aws s3 cp copies a file from your computer to the bucket. The file keeps its name in S3.
Step 4: List the bucket contents
aws s3 ls s3://your-unique-bucket-name/
You should see hello.txt in the output, along with its size and timestamp.
Step 5: Download the file
aws s3 cp s3://your-unique-bucket-name/hello.txt downloaded-hello.txt
Open downloaded-hello.txt to confirm it contains the same text as the original file.
Step 6: Clean up
Remove the object first, then the bucket. The rb command only works on an empty bucket.
aws s3 rm s3://your-unique-bucket-name/hello.txt
aws s3 rb s3://your-unique-bucket-name
Leaving test buckets and objects in place can still incur storage charges, so always finish with this step.
Key takeaways
- aws s3 mb creates a bucket, and aws s3 rb removes an empty one.
- aws s3 cp copies files in either direction, depending on whether the source or destination starts with s3://.
- aws s3 ls lists what's in a bucket or a prefix.
- Always check your identity with aws sts get-caller-identity before running commands on a shared machine.
Next steps
Once you're comfortable with single files, try aws s3 cp folder/ s3://your-unique-bucket-name/folder/ --recursive to upload a whole folder.
Loading article