Skip to content

codewithmuh/aws-s3-course

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Amazon S3 Guide

Introduction

Welcome to this in-depth guide to Amazon S3, part of the Amazon Web Services (AWS) suite. Whether you're an AWS beginner or looking to deepen your knowledge, this guide will provide everything you need to understand, configure, and manage S3 for a variety of use cases. By the end of this guide, you'll know how to leverage S3's powerful features for storage, backups, hosting static websites, and more.


What Will Be Covered?

  • What is AWS? Overview of AWS and how S3 fits into its ecosystem.
  • What is Amazon S3? How it compares to storage services like Google Drive and Dropbox.
  • Creating an S3 Bucket: Step-by-step guide, including enabling versioning and managing public access.
  • Bucket Policy: How to configure policies for secure and effective access management.
  • Advanced Features: Intelligent-Tiering, Archive Configurations, Notifications (SNS), Lifecycle Rules, Replication Rules, Advanced Controls, and AWS Storage Lens.
  • Hosting a Static Website on S3.
  • Managing S3 with AWS CLI: Learn how to interact with S3 programmatically.
  • Extras: Access Points, Metrics, and their applications.

Why Learn Amazon S3?

By mastering Amazon S3, you gain:

  • Scalable Storage: Store unlimited data reliably and securely.
  • Cost Efficiency: Pay for only what you use with tiered pricing models.
  • Enhanced Functionality: Leverage advanced features like lifecycle management, access controls, and static website hosting.
  • Career Advancement: AWS skills are highly sought after in IT and DevOps roles.

1. What is AWS?

AWS (Amazon Web Services) is a cloud computing platform that provides a range of services like compute power, storage, databases, machine learning, and more. Amazon S3 (Simple Storage Service) is one of its most popular services, offering secure, scalable, and highly available object storage.

Real-World Analogy:

Think of S3 as your personal cloud storage, similar to Google Drive or Dropbox. However, it is far more powerful and flexible, designed for developers, businesses, and enterprises with demanding storage needs.

Key features include:

  • Unlimited Storage
  • Pay-as-you-go Pricing
  • Durability and Availability (99.999999999% durability)

2. Creating an S3 Bucket

Step-by-Step Guide:

  1. Log in to the AWS Management Console: Navigate to the S3 service.
  2. Create Bucket: Click on "Create Bucket," provide a unique bucket name, and select a region.
  3. Set Permissions:
    • Enable Versioning: Allows you to keep multiple versions of the same object. This is useful for data recovery and auditing.
  4. Review and Create: Review your settings and create the bucket.

3. Bucket Policies in S3

A bucket policy is a JSON document that defines permissions for your bucket.

Example Policy:

Allow read-only access to everyone:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::your-bucket-name/*"
    }
  ]
}

Use policies to:

  • Enforce encryption.
  • Restrict access by IP.
  • Enable specific actions for users or groups.

4. Intelligent-Tiering and Archive Configurations

  • Intelligent-Tiering: Automatically moves data between storage tiers based on access patterns, saving costs.

  • Archive Configurations:

    • Glacier Instant Retrieval: For infrequently accessed data with milliseconds retrieval.
    • Deep Archive: For long-term data storage with 12-hour retrieval.

5. Notifications (SNS), Lifecycle Rules, and Replication Rules

Notifications:

Use SNS to send notifications for S3 events like object creation or deletion.

Steps:

  1. Set up an SNS topic.
  2. Configure your bucket to trigger notifications.

Example SNS Policy Configuration:

{
  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
    {
      "Sid": "__default_statement_ID",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": [
        "SNS:Publish",
        "SNS:RemovePermission",
        "SNS:SetTopicAttributes",
        "SNS:DeleteTopic",
        "SNS:ListSubscriptionsByTopic",
        "SNS:GetTopicAttributes",
        "SNS:AddPermission",
        "SNS:Subscribe"
      ],
      "Resource": "arn:aws:sns:us-west-1:<ACCOUNT-ID>:<SNS-TOPIC-NAME>",
      "Condition": {
        "StringEquals": {
          "AWS:SourceOwner": "167365792572"
        }
      }
    },
    {
      "Sid": "AllowS3BucketToPublish",
      "Effect": "Allow",
      "Principal": {
        "Service": "s3.amazonaws.com"
      },
      "Action": "SNS:Publish",
      "Resource": "arn:aws:sns:us-west-1:<ACCOUNT-ID>:<SNS-TOPIC-NAME>",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:s3:::<BUCKET_NAME>"
        }
      }
    }
  ]
}

Lifecycle Rules:

  • Manage data automatically with lifecycle policies.
  • Transition objects to cheaper storage tiers.
  • Expire objects after a certain time.

Replication Rules:

  • Enable Cross-Region Replication (CRR) for disaster recovery.
  • Specify the destination bucket and configure replication rules.

6. Advanced Controls (ACL, CORS, Object Ownership)

  • Access Control Lists (ACL): Grant fine-grained permissions to objects or buckets.
  • CORS: Enable cross-origin requests for web applications.
  • Object Ownership: Ensure that the bucket owner automatically owns uploaded objects.

Example CORS Configuration:

{
  "CORSRules": [
    {
      "AllowedOrigins": [
        "https://www.example.com",
        "https://www.anotherdomain.com"
      ],
      "AllowedMethods": [
        "GET",
        "POST",
        "PUT"
      ],
      "AllowedHeaders": [
        "*"
      ],
      "ExposeHeaders": [
        "x-amz-request-id",
        "x-amz-id-2"
      ],
      "MaxAgeSeconds": 3000
    }
  ]
}

7. AWS Storage Lens

Monitor and analyze storage usage with AWS Storage Lens. Gain insights into:

  • Object count trends
  • Cost optimization
  • Data transfer patterns

8. Hosting a Static Website

Steps:

  1. Upload your website files (HTML, CSS, JS) to the bucket.
  2. Enable "Static Website Hosting" in the bucket properties.
  3. Provide the index and error document names.
  4. Use a custom domain and route traffic via Amazon Route 53 if needed.

9. Managing S3 with AWS CLI

Key Commands:

  • Create Bucket:

    aws s3 mb s3://your-bucket-name
  • Upload File:

    aws s3 cp file.txt s3://your-bucket-name/
  • Download File:

    aws s3 cp s3://your-bucket-name/file.txt ./
  • List Buckets:

    aws s3 ls
  • Sync Local Folder to Bucket:

    aws s3 sync /local/folder s3://your-bucket-name
  • Delete Bucket:

    aws s3 rb s3://your-bucket-name --force
  • List Files in a Bucket:

    aws s3 ls s3://your-bucket-name/
  • Move File:

    aws s3 mv s3://your-bucket-name/file.txt s3://your-bucket-name/new-location/file.txt

10. Extra Features

  • Access Points: Simplify managing access to large datasets.
  • Metrics: Track performance and usage patterns.

Conclusion

Amazon S3 is a powerful tool that can transform the way you manage data, from storage and backups to hosting and analytics. By following this guide, you’ll be equipped to use S3 effectively and optimize its advanced features for your needs. Start your journey with S3 today and unlock the potential of AWS cloud storage!