Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Uploading and downloading objects
📖 Scenario: You are working with Amazon S3, a cloud storage service. You want to upload a file to a bucket and then download it back to your local machine.
🎯 Goal: Build a simple script that uploads a file named example.txt to an S3 bucket called my-test-bucket and then downloads it back as downloaded_example.txt.
📋 What You'll Learn
Use the AWS SDK for Python (boto3).
Create a variable for the bucket name my_test_bucket with value 'my-test-bucket'.
Upload the file example.txt to the bucket with the key example.txt.
Download the file from the bucket with the key example.txt and save it locally as downloaded_example.txt.
💡 Why This Matters
🌍 Real World
Uploading and downloading files to cloud storage is common for backups, sharing data, and hosting content.
💼 Career
Cloud engineers and developers often automate file transfers to and from cloud storage services like Amazon S3.
Progress0 / 4 steps
1
Set up AWS S3 client
Import the boto3 library and create an S3 client called s3_client.
AWS
Hint
Use import boto3 and then boto3.client('s3') to create the client.
2
Create bucket name variable
Create a variable called my_test_bucket and set it to the string 'my-test-bucket'.
AWS
Hint
Use a simple assignment like my_test_bucket = 'my-test-bucket'.
3
Upload the file to S3
Use s3_client.upload_file to upload the local file 'example.txt' to the bucket my_test_bucket with the key 'example.txt'.
AWS
Hint
Call s3_client.upload_file('example.txt', my_test_bucket, 'example.txt') to upload.
4
Download the file from S3
Use s3_client.download_file to download the file with key 'example.txt' from the bucket my_test_bucket and save it locally as 'downloaded_example.txt'.
AWS
Hint
Call s3_client.download_file(my_test_bucket, 'example.txt', 'downloaded_example.txt') to download.
Practice
(1/5)
1. What does uploading an object to an AWS S3 bucket mean?
easy
A. Deleting a file from the cloud storage
B. Saving a file from your computer to the cloud storage
C. Copying a file from one folder to another on your computer
D. Viewing a file stored in the cloud without downloading
Solution
Step 1: Understand uploading concept
Uploading means moving or saving a file from your local device to a remote place, like cloud storage.
Step 2: Apply to AWS S3 context
In AWS S3, uploading an object means saving your local file into an S3 bucket in the cloud.
Final Answer:
Saving a file from your computer to the cloud storage -> Option B
Quick Check:
Uploading = Save local file to cloud [OK]
Hint: Uploading means sending files from your PC to cloud storage [OK]
Common Mistakes:
Confusing uploading with downloading
Thinking uploading deletes files
Mixing local file moves with cloud uploads
2. Which AWS CLI command correctly uploads a file named photo.jpg to a bucket called mybucket?
easy
A. aws s3 get photo.jpg s3://mybucket/
B. aws s3 download photo.jpg s3://mybucket/
C. aws s3 cp photo.jpg s3://mybucket/
D. aws s3 remove photo.jpg s3://mybucket/
Solution
Step 1: Identify correct AWS CLI upload command
The command to upload files to S3 is aws s3 cp followed by the local file and the bucket path.
Step 2: Match command with given file and bucket
Using aws s3 cp photo.jpg s3://mybucket/ uploads the file photo.jpg to the bucket mybucket.
Final Answer:
aws s3 cp photo.jpg s3://mybucket/ -> Option C
Quick Check:
Upload command = aws s3 cp [OK]
Hint: Use 'aws s3 cp' to copy files to S3 bucket [OK]
Common Mistakes:
Using 'download' instead of 'cp' for upload
Confusing 'get' with upload command
Using 'remove' which deletes files
3. What will be the result of this AWS CLI command? aws s3 cp s3://mybucket/report.pdf ./
medium
A. Downloads report.pdf from the bucket to current folder
B. Uploads report.pdf from local to the bucket
C. Deletes report.pdf from the bucket
D. Lists all files in the bucket
Solution
Step 1: Understand the command structure
The command aws s3 cp copies files. The source is s3://mybucket/report.pdf and destination is ./ (current folder).
Step 2: Determine direction of copy
Since source is S3 and destination is local, the file is downloaded from the bucket to the local folder.
Final Answer:
Downloads report.pdf from the bucket to current folder -> Option A
Quick Check:
Source S3 to local = download [OK]
Hint: Source path starting with s3:// means download to local [OK]
Common Mistakes:
Thinking 'cp' always uploads
Confusing source and destination order
Assuming it deletes files
4. You run this command to download a file but get an error: aws s3 cp s3://mybucket/data.csv ./ What is the most likely cause?
medium
A. You forgot to add --recursive flag
B. You used the wrong command; should be aws s3 upload
C. The local folder ./ does not exist
D. The file data.csv does not exist in the bucket
Solution
Step 1: Analyze the error context
The command is correct for downloading a single file. An error usually means the file is missing or inaccessible.
Step 2: Check common causes
If the file data.csv is not in the bucket, the command fails. The local folder ./ always exists as current directory, and --recursive is not needed for single files.
Final Answer:
The file data.csv does not exist in the bucket -> Option D
Quick Check:
Missing file in bucket causes download error [OK]
Hint: Check if file exists in bucket before downloading [OK]
Common Mistakes:
Using wrong command for download
Assuming local folder missing causes error
Adding unnecessary flags
5. You want to upload all files from your local folder photos/ to the S3 bucket mybucket preserving folder structure. Which command should you use?
hard
A. aws s3 sync photos/ s3://mybucket/
B. aws s3 cp photos/ s3://mybucket/
C. aws s3 cp photos/ s3://mybucket/ --no-recursive
D. aws s3 mv photos/ s3://mybucket/ --recursive
Solution
Step 1: Understand folder upload options
To upload multiple files preserving folder structure, aws s3 sync is preferred as it copies all files and folders efficiently.
Step 2: Compare commands
aws s3 cp --recursive can copy folders but sync is better for syncing changes and preserving structure. mv moves files (deletes local), which may not be desired.
Final Answer:
aws s3 sync photos/ s3://mybucket/ -> Option A
Quick Check:
Use 'sync' to upload folders preserving structure [OK]
Hint: Use 'aws s3 sync' for folder uploads preserving structure [OK]