2 - S3
2 - S3
2 - S3
1. Sign Up for AWS: Go to the AWS website and sign up for an account. AWS offers a free tier that
includes limited usage of S3.
2. Open the S3 Dashboard: Once logged in, navigate to the S3 Dashboard from the AWS
Management Console.
3. Create a Bucket:
○ Click on "Create bucket": This will open a wizard to set up your bucket.
○ Configure Bucket Settings: Provide a unique bucket name and select a region where
the bucket will be created. You can also configure options such as versioning, encryption,
and access control.
○ Create the Bucket: Review your settings and create the bucket.
4. Upload an Object:
○ Select Your Bucket: Click on the bucket name to open it.
○ Upload: Click the "Upload" button, then "Add files" to select the file you want to upload.
Configure any additional settings and click "Upload".
S3 Storage Classes
Amazon S3 offers different storage classes to optimize costs based on your access patterns:
1. S3 Standard: General-purpose storage with high durability and availability. Suitable for frequently
accessed data.
2. S3 Intelligent-Tiering: Automatically moves data to the most cost-effective access tier based on
changing access patterns.
3. S3 Standard-IA (Infrequent Access): For data that is accessed less frequently but requires
rapid access when needed. Lower storage cost with a retrieval fee.
4. S3 One Zone-IA: Lower-cost option for infrequently accessed data that doesn’t require multiple
Availability Zone resilience.
5. S3 Glacier: Low-cost storage for data archiving with retrieval times ranging from minutes to
hours.
6. S3 Glacier Deep Archive: The lowest-cost storage class for long-term data archiving with
retrieval times of 12 hours or more.
Security Features
1. Access Control: Control access to your S3 buckets and objects using AWS Identity and Access
Management (IAM) policies, bucket policies, and Access Control Lists (ACLs).
2. Encryption: Protect your data using server-side encryption (SSE) with AWS-managed keys
(SSE-S3), AWS Key Management Service (SSE-KMS), or customer-provided keys (SSE-C). You
can also use client-side encryption.
3. Logging and Monitoring: Use AWS CloudTrail to log API calls and Amazon CloudWatch to
monitor and generate alerts for S3 operations.
Use Cases
1. Backup and Restore: Reliable and durable storage for backing up data, with options for different
access and cost requirements.
2. Archiving: Cost-effective storage for long-term data retention with S3 Glacier and Glacier Deep
Archive.
3. Big Data Analytics: Store large datasets and integrate with AWS analytics services like Amazon
EMR, Athena, and Redshift.
4. Content Distribution: Store and deliver media files, static websites, and other content using
Amazon CloudFront for global distribution.
5. Disaster Recovery: Use cross-region replication to create backups in different geographic
locations for disaster recovery.
Pricing
Amazon S3 pricing is based on several factors, including the storage class, the amount of data stored,
data transfer out, and the number of requests made to S3. The main components of S3 pricing are:
1. Storage Pricing: The cost per GB of data stored per month.
2. Request and Data Retrieval Pricing: The cost per request and data retrieval, depending on the
storage class.
3. Data Transfer Pricing: The cost for data transferred out of S3 to the internet or to other AWS
regions.
Conclusion
Amazon S3 is a powerful and flexible object storage service that provides scalable, durable, and cost-
effective storage for a wide range of use cases. By understanding the key concepts, features, and best
practices of S3, you can effectively manage and protect your data in the cloud. Whether you are storing
backups, archiving data, or running big data analytics, S3 offers the tools and capabilities you need to
meet your storage requirements.
Detailed Write Up On S3
Amazon Simple Storage Service (S3) is a scalable object storage service provided by Amazon Web
Services (AWS). It offers industry-leading scalability, data availability, security, and performance. Amazon
S3 is designed to make web-scale computing easier for developers by allowing them to store and retrieve
any amount of data at any time, from anywhere on the web.
Key Concepts
Buckets
Buckets are containers for storing objects in Amazon S3. Every object is stored in a bucket. Each bucket
is identified by a unique key (name) within AWS.
Key Points:
● Global Namespace: Bucket names must be unique across all AWS accounts and regions
because bucket names are part of the URL for accessing the bucket.
● Regions: When creating a bucket, you specify the AWS region where the bucket will be stored.
This determines the physical location of your data.
● Data Organization: While buckets do not have a directory structure, you can simulate directories
using prefixes and delimiters.
Objects
Objects are the fundamental entities stored in Amazon S3. An object consists of the data itself, metadata
(name-value pairs), and a unique identifier called a key.
Key Points:
● Keys: The unique identifier for an object within a bucket. Keys can include slashes (/) to create a
folder-like structure.
● Metadata: Includes standard HTTP headers such as Content-Type and custom metadata defined
by the user.
● Data: The actual content stored in the object, which can range from a few bytes to 5 terabytes.
Storage Classes
Amazon S3 offers different storage classes designed for varying access needs and cost requirements.
Versioning
Versioning in Amazon S3 allows you to keep multiple versions of an object in the same bucket. This helps
to preserve, retrieve, and restore every version of every object stored in the bucket.
Key Points:
Uploading Objects
1. Select a Bucket:
○ In the S3 console, select the bucket where you want to upload an object.
2. Upload an Object:
○ Click "Upload".
○ Add files or folders.
○ Configure object properties (e.g., storage class, encryption).
○ Review and upload the object.
Setting Permissions
1. Bucket Policies:
○ Define bucket policies to manage permissions for your bucket and the objects within it.
○ Policies are written in JSON format and allow for granular control over access.
2. Access Control Lists (ACLs):
○ ACLs provide a way to manage access to individual objects and buckets.
○ ACLs are less flexible than bucket policies but can be used for simple access control.
Advanced Features
Security
1. Encryption:
○ Server-Side Encryption (SSE): S3 encrypts your data at rest using SSE-S3, SSE-KMS,
or SSE-C.
○ Client-Side Encryption: Encrypt data on the client side before uploading it to S3.
2. Access Management:
○ IAM Policies: Use AWS Identity and Access Management (IAM) to control access to S3
resources.
○ Bucket Policies: Define policies at the bucket level for granular access control.
○ ACLs: Control access at the object and bucket level.
3. Logging and Monitoring:
○ S3 Server Access Logs: Enable logging to track access requests to your S3 bucket.
○ AWS CloudTrail: Monitor S3 API calls for auditing and security purposes.
Data Management
1. Lifecycle Policies:
○ Define rules to automatically transition objects between storage classes or delete them
after a certain period.
2. Cross-Region Replication (CRR):
○ Automatically replicate objects across different AWS regions for disaster recovery and
compliance.
3. Object Lock:
○ Enable Object Lock to prevent objects from being deleted or overwritten for a specified
retention period.
1. Create a Bucket:
○ Name the bucket with your website’s domain name (e.g., example.com).
2. Upload Website Files:
○ Upload your static files (HTML, CSS, JS) to the bucket.
3. Configure Bucket for Website Hosting:
○ In the bucket properties, enable "Static website hosting".
○ Specify the index document (e.g., index.html) and error document (e.g.,
error.html).
4. Set Permissions:
○ Configure the bucket policy to allow public read access to the website files.
5. Access Your Website:
○ Access your website using the bucket's website endpoint (e.g.,
http://example.com.s3-website-us-east-1.amazonaws.com).
Basic Commands:
● List Buckets:
aws s3 ls
● Create a Bucket:
aws s3 mb s3://my-new-bucket
● Upload a File:
aws s3 cp myfile.txt s3://my-new-bucket/
● Download a File:
aws s3 cp s3://my-new-bucket/myfile.txt .
●
AWS SDK
AWS provides SDKs for various programming languages to interact with S3 programmatically.
Install Boto3:
pip install boto3
import boto3
s3 = boto3.client('s3')
s3.upload_file('myfile.txt', 'my-new-bucket', 'myfile.txt')
import boto3
s3 = boto3.client('s3')
s3.download_file('my-new-bucket', 'myfile.txt', 'myfile.txt')
// uploadToS3.js
const fs = require('fs');
const path = require('path');
const AWS = require('aws-sdk');
// Configure AWS SDK with your credentials and region
AWS.config.update({
accessKeyId: 'YOUR_ACCESS_KEY_ID',
secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',
region: 'YOUR_AWS_REGION' // e.g., 'us-east-1'
});
// Example usage
const filePath = path.join(__dirname, 'example.txt'); // Replace with the
path to your file
const bucketName = 'your-bucket-name'; // Replace with your S3 bucket name
const keyName = 'example.txt'; // Replace with the desired key name in S3
node <filename.js>
Conclusion
Amazon S3 is a versatile and powerful object storage service that can handle a wide range of storage
needs. From basic storage of files to advanced data management and security features, S3 provides the
tools you need to build robust, scalable applications. Whether you're hosting a static website, managing
large datasets, or integrating with other AWS services, Amazon S3 offers the flexibility and performance
required to meet your storage requirements.
References
● https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-node-examples.html
● https://docs.aws.amazon.com/s3/?icmpid=docs_homepage_featuredsvcs
● https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html
● Amazon S3 - Cloud Object Storage - AWS
Annexures
Code snippet to make bucket public
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}