Skip to main content

S3: Amazon's Simple Storage Service Explained

What is Simple Storage Service (S3)?​

S3 is an object storage service designed to store and retrieve any amount of data from anywhere on the web at any time. It’s reliable, scalable, and secure, making it ideal for businesses of all sizes.

What Can S3 Store?​

Amazon S3 can store any type of data, including but not limited to:

  • Images and Videos

  • Static Web Hosting files (HTML, CSS, JS)

  • Installers and Binaries

  • Backups

  • Documents like PDF, Word, etc.

Advantages of Amazon S3​

  • Scalability: S3 automatically scales to handle growing amounts of data, whether you need to store a few megabytes or petabytes.

  • Durability: S3 provides 99.999999999% (11 9's) of data durability, which means your data is highly protected against loss.

  • Availability: S3 is designed for 99.99% availability over a given year, ensuring your data is accessible when you need it.

  • Cost-Effective: You pay only for the storage you use, without upfront costs, making it a flexible and budget-friendly solution.

  • Security: S3 offers a range of security features, including encryption, bucket policies, and access controls, to keep your data safe.

  • Integration: Easily integrates with other AWS services, making it a versatile choice for developers and IT teams.

Key Terminologies in S3​

  • Buckets: Think of buckets as containers that store your data in S3. Each bucket has a unique name within AWS, and you can configure settings like region, access control, and logging.

  • Objects: Objects are the files you store in S3, consisting of data, metadata, and a unique identifier known as a key.

  • Keys: A key is the unique identifier for an object within a bucket. It's similar to a file path on your computer.

You can access objects stored in S3 using the Object URL. This URL typically looks like this: https://{bucket-name}.{aws-region}.s3.amazonaws.com/{object-key}.

Note

Both the bucket and the object need to be publicly accessible for others to access the data via the URL.

Programmatic Access using JavaScript​

You can interact with S3 programmatically using the AWS SDK for JavaScript. Here's a simple example to demonstrate how to upload a file to S3:

JavaScript
npm install aws-sdk

const AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: 'your-access-key-id',
secretAccessKey: 'your-secret-access-key',
region: 'your-region'
});

// Uploading a file
const uploadParams = {
Bucket: 'your-bucket-name',
Key: 'file.txt',
Body: 'Hello, S3!'
};

s3.upload(uploadParams, (err, data) => {
if (err) {
console.log("Error", err);
} else {
console.log("Upload Success", data.Location);
}
});

S3 Events​

Amazon S3 can notify you when specific events occur. Common events include:

  • Object Created: Triggered when a new object is added.

  • Object Deleted: Triggered when an object is deleted.

  • Object Restore: Triggered when an object is restored from Glacier.

You can configure these events to send notifications to AWS Lambda functions, SNS topics, or SQS queues.

S3 Storage Classes​

Amazon S3 offers different storage classes, each designed for different use cases:

  • Standard: Used for frequently accessed data. Provides high durability and availability.

  • Standard-IA (Infrequent Access): For data that is accessed less frequently but still requires quick retrieval when needed.

  • Glacier: Ideal for long-term archival of data that is rarely accessed but still must be retained.

  • Glacier Deep Archive: The lowest-cost storage option for data that is accessed very rarely, such as archives.

Note

Costs decrease from top to bottom, with the Standard class having the highest cost and Glacier Deep Archive being the most cost-effective option.

Moving Objects Between Storage Classes​

In applications like social media, files are accessed frequently when newly uploaded but rarely accessed after some time. To optimize costs, it's wise to move files from the Standard class to Standard-IA as they age. Lifecycle policies can automate this process.

Example Lifecycle Rule:​

Lifecycle Rule
{
"Rules": [
{
"ID": "MoveToIAThenGlacier",
"Status": "Enabled",
"Filter": {
"Prefix": ""
},
"Transitions": [
{
"Days": 30,
"StorageClass": "STANDARD_IA"
},
{
"Days": 90,
"StorageClass": "GLACIER"
}
],
"Expiration": {
"Days": 365
}
}
]
}
  1. Frequent Access: For the first 30 days, store objects in the STANDARD storage class.

  2. Infrequent Access: After 30 days, transition objects to the STANDARD_IA storage class.

  3. Archival: After 90 days, move objects to GLACIER for long-term storage.

  4. Deletion: After 365 days, delete the objects to save on storage costs.

S3 Security Best Practices​

  • Public Access: Ensure buckets and objects are not publicly accessible unless explicitly required. Use Bucket Policies and Access Control Lists (ACLs) to manage permissions carefully.

  • Data Protection: S3 supports both server-side and client-side encryption for data protection. Enable versioning to keep multiple versions of an object to protect against accidental deletion.

  • Audit and Monitoring: Enable S3 Access Logs to track detailed information about requests made to your bucket. Logs can be stored in a target bucket for auditing and monitoring purposes.