0
0
AWScloud~5 mins

Uploading and downloading objects in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to save files in the cloud or get them back later. Uploading means sending your files to cloud storage. Downloading means getting those files back to your computer.
When you want to save photos from your phone to cloud storage for backup.
When you need to share a document with your team using cloud storage.
When your app needs to store user files safely in the cloud.
When you want to download a report generated and saved in cloud storage.
When you want to move files between your computer and cloud storage quickly.
Commands
This command uploads the file 'myphoto.jpg' from your computer to the cloud storage bucket named 'example-bucket'.
Terminal
aws s3 cp myphoto.jpg s3://example-bucket/myphoto.jpg
Expected OutputExpected
upload: ./myphoto.jpg to s3://example-bucket/myphoto.jpg
--acl - Set access permissions for the uploaded file
This command downloads the file 'myphoto.jpg' from the cloud storage bucket to your computer and saves it as 'downloaded-photo.jpg'.
Terminal
aws s3 cp s3://example-bucket/myphoto.jpg downloaded-photo.jpg
Expected OutputExpected
download: s3://example-bucket/myphoto.jpg to ./downloaded-photo.jpg
This command lists all files inside the 'example-bucket' to check what is stored there.
Terminal
aws s3 ls s3://example-bucket/
Expected OutputExpected
2024-06-01 12:00:00 12345 myphoto.jpg
Key Concept

If you remember nothing else from this pattern, remember: use 'aws s3 cp' to copy files to and from cloud storage buckets.

Common Mistakes
Using the wrong bucket name or file path in the command
The command will fail because it cannot find the file or bucket specified.
Double-check the bucket name and file path before running the command.
Not having AWS credentials configured
The AWS CLI will not be able to authenticate and will return an error.
Run 'aws configure' to set up your access key, secret key, and region.
Trying to upload a file without read permission
The upload will fail because the CLI cannot read the local file.
Ensure the file has proper read permissions before uploading.
Summary
Use 'aws s3 cp' to upload files from your computer to an S3 bucket.
Use 'aws s3 cp' to download files from an S3 bucket to your computer.
Use 'aws s3 ls' to list files inside an S3 bucket.