0
0
AWScloud~5 mins

S3 storage classes (Standard, IA, Glacier) in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Amazon S3 storage classes help you save money by choosing how often you access your files and how quickly you need them. Different classes like Standard, Infrequent Access (IA), and Glacier offer options for fast access, lower cost for rare access, and long-term archiving.
When you want to keep frequently used files with quick access and high durability.
When you have files you access less often but still need fast retrieval.
When you want to archive files for long-term storage and can wait hours to retrieve them.
When you want to reduce storage costs by moving old backups to cheaper storage.
When you want to balance cost and access speed depending on file usage patterns.
Commands
Create a new S3 bucket named 'example-storage-classes' in the US East (N. Virginia) region to store files with different storage classes.
Terminal
aws s3api create-bucket --bucket example-storage-classes --region us-east-1
Expected OutputExpected
No output (command runs silently)
--bucket - Specifies the name of the bucket to create
--region - Specifies the AWS region for the bucket
Upload 'sample-file.txt' to the bucket using the Standard storage class for frequent access and low latency.
Terminal
aws s3 cp sample-file.txt s3://example-storage-classes/sample-standard.txt --storage-class STANDARD
Expected OutputExpected
upload: ./sample-file.txt to s3://example-storage-classes/sample-standard.txt
--storage-class - Sets the storage class for the uploaded object
Upload the same file using the Standard-Infrequent Access storage class for less frequent access but lower cost.
Terminal
aws s3 cp sample-file.txt s3://example-storage-classes/sample-ia.txt --storage-class STANDARD_IA
Expected OutputExpected
upload: ./sample-file.txt to s3://example-storage-classes/sample-ia.txt
--storage-class - Sets the storage class for the uploaded object
Upload the file using the Glacier storage class for long-term archival storage with retrieval times of hours.
Terminal
aws s3 cp sample-file.txt s3://example-storage-classes/sample-glacier.txt --storage-class GLACIER
Expected OutputExpected
upload: ./sample-file.txt to s3://example-storage-classes/sample-glacier.txt
--storage-class - Sets the storage class for the uploaded object
Check the storage class of the uploaded Glacier object to confirm it was set correctly.
Terminal
aws s3api head-object --bucket example-storage-classes --key sample-glacier.txt
Expected OutputExpected
{ "AcceptRanges": "bytes", "LastModified": "2024-06-01T12:00:00.000Z", "ContentLength": 12345, "ETag": "\"abcdef1234567890abcdef1234567890\"", "StorageClass": "GLACIER", "Metadata": {} }
--bucket - Specifies the bucket name
--key - Specifies the object key (file name)
Key Concept

If you remember nothing else from this pattern, remember: choosing the right S3 storage class balances cost and access speed based on how often and how fast you need your files.

Common Mistakes
Uploading files without specifying the storage class defaults to STANDARD, which can be costly for rarely accessed files.
You pay more for storage when you don't use cheaper classes for infrequent or archival data.
Always specify the storage class flag when uploading files based on their access needs.
Trying to retrieve Glacier objects immediately after upload without initiating a restore.
Glacier objects require a restore process that takes hours before you can access them.
Use the restore API to start retrieval and wait for completion before accessing Glacier objects.
Summary
Create an S3 bucket to hold your files.
Upload files with the --storage-class flag to choose Standard, Standard-IA, or Glacier.
Verify the storage class of objects using the head-object command.