Introduction to AWS: IAM, CloudFront, and S3
Tags: aws, cloud, beginners
Published: 2021-06-03 00:00:00

---
title: "Introduction to AWS: IAM, CloudFront, and S3"
date: "2021-06-03"
categories: 
  - "aws"
tags:
  - "aws"
  - "cloud"
  - "beginners"
series: [Introduction to AWS]
---

### These are the services to start with when trying to conquer the AWS world

![cupofcode_blog_main_picture](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_main_photo-768x432.png)

Starting with AWS can be overwhelming, and the main reason for that is the number of services they offer! When you open the _All Services_ tab, you see a long list and no indication of where to start!

|![cupofcode_blog_part2_boo](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_boo-1024x576.png)|
|--|
|Too many services… and this is only a partial list. That’s scary!|

So what’s a good strategy to tackle this huge list? Should you go from mandatory to nice-to-have services? From most to least common? By decreasing dependency? The latter option could be a good method, but the problem is that services depend on each other!

Worry no more, because I have an answer! I’ve combined material from course outlines I found online and references from within AWS services. On today’s agenda: IAM, CloudFront, and S3.

Are you ready to start?

|![cupofcode_blog_part2_meme1](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_meme1.jpeg)|
|--|
|Don’t worry, you’ll understand this meme after the next section ;)|

* * *

## Identity Access Management (IAM)

![cupofcode_blog_part2_iam](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_iam-1024x576.png)

IAM allows you to give access to AWS services by creating **_IAM identities_**: **Users**, **Groups**, and **Roles**. These identities are created **globally**, and not per region. (I talked about regions in [_the previous blog post_](https://cupofcode.blog/cloud-computing-and-aws/))

You can access the AWS platform in 3 ways:

- **Via the AWS console:** Logging in to the website with your AWS account, the [GUI](https://www.google.com/search?q=gui&rlz=1C1GCEA_enIE926IE926&oq=GUI&aqs=chrome.0.0i67i433j0i67j46i67j0i67j0i433l3j69i61.633j0j7&sourceid=chrome&ie=UTF-8) version.
- **Programatically (using the command line), with access key and password:** We’ll see an example when we talk about S3.
- **Using the SDK (Software Developers Kit)**: Within your code, calling AWS services using your desired programming language’s API. This is not part of the AWS [Cloud Practitioner Certification exam](https://aws.amazon.com/certification/certified-cloud-practitioner/), so it won’t be covered here.

Let’s talk about IAM Service’s basic terms and features:  

### Security Status

When you go to `The AWS Console -> IAM -> Dashboard` you will see the Security Status. The goal is to make all these 5 ticks green.

![cupofcode_blog_part2_iam_status](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_iam_status-1024x576.png)

Let’s go over them and see what each one of them means:

#### 1\. Delete your root access keys

Ok, before talking about **root** access keys, what are access keys?

**_Access keys_** are long-term credentials for an IAM user or the AWS account root user. You can use access keys to sign programmatic requests to the AWS CLI or AWS API (directly or using the AWS SDK). Access keys consist of two parts: an access key ID and a secret access key. As a user name and password, you must use both together to authenticate your requests.

**_Root user/account_** is the email address you signed up with. As a best practice, you shouldn’t use root in the AWS console! The root can do anything, and therefore — you shouldn't give it to anyone.

#### 2\. Activate MFA on your root account

_Multi-factor authentication (MFA)_ is a method in which a user is granted access to a website or application only after successfully presenting two or more pieces of evidence to an authentication mechanism.

For example, when I want to log into my Gmail account from a new computer, I need to both enter my password and then approve on my phone that I am trying to sign in.

![cupofcode_blog_part2_mfa](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_mfa-1024x576.png)

#### 3\. Create individual IAM users

You manage access in AWS by creating **_policies_** and attaching them to IAM **identities** or AWS resources. 

**_A policy_** is an object in AWS that, when associated with an identity or resource, defines its permissions.  
Policies always come in JSON format. In the IAM policies list, the policies with the orange logo next to them are the ones AWS manages.

![cupofcode_blog_part2_policies](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_policies-1024x576.png)

**The only opportunity** to access the _secret access key and password_ of a new user **is right after creating it**, so you should download it. 

#### 4\. Use groups to assign permissions

**_A group_** is the second type of IAM identity we’ll learn today and is simply a way to store your users and they will inherit all permissions that the group has. For example Administrators, developers, HR (human resources), finances, etc.  
Setting up permission in a group is done by applying a **policy** to that group.

#### 5\. Apply an IAM password policy

This is where you decide the rules for the password your users can create: length, characters demand, rotation period, etc.  

### IAM Credential Reports

_A credential report_ lists all the users in your account, including:

- **For each password:** enabled or not, when it was last used, when it was changed and when it must be changed.
- **For each Access Key:**  
    active or not, when it was last used, when it was last rotated, and what service was it last used on.
- **MFA:** whether MFA has been enabled

You can generate and download a credential report by going to _Credential Report_ on the sidebar menu in the AWS console.  

### IAM Best Practices

Here are 8 techniques to get maximum security from IAM service:

- **Root Access:** Only use the root account to create your AWS account. Do not use it to log in.
- **Users:** One user = One person. Don’t create phantom users.
- **Policies to Groups:** Always place users in groups and then apply policies to the groups.
- **Password Policies:** Have a strong password rotation policy.
- **MFA:** Always enable MFA wherever possible.
- **Roles:** Use roles to access various other AWS services.
- **Access Keys:** Use access keys for programmatic access to AWS (access via the CLI or the code).
- **IAM Credential Report:** Use IAM Credential Reports to audit the permissions of your users/accounts.

And here is the best practices summary for those of us with visual memory:

![cupofcode_blog_part2_iam_best_practices](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_iam_best_practices-1024x576.png)

* * *

## CloudFront

![cupofcode_blog_part2_cloudfront](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_cloudfront-1024x576.png)

**_Amazon CloudFront_** is a fast _content delivery network_ (CDN) service that securely delivers content to customers globally with low latency, high transfer speeds, all within a developer-friendly environment.

**_A content delivery network (CDN)_** refers to a geographically distributed group of servers that work together to provide fast delivery of Internet content.  
A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, javascript files, stylesheets, images, and videos.

![cupofcode_blog_part2_cdn](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_cdn-1024x576.png)

As you can see above, **without CDN** all 3 users need to access the content from the origin. **With CDN**, only the first user will access the content from the origin and the rest will enjoy a faster delivery because the data is already cached.

But what happens if the cached resource is not up to date? There is a solution for that: **_TTL = time to live_**. You define for how long the resource you stored is relevant.  

### Key Terminology for CloudFront

- **_Origin_** is the origin of the files that the CDN will distribute. This can be, for example, an S3 Bucket, an EC2 instance, or an Elastic load balancer. (We will learn what EC2 and Elastic load balancer are in the next blog post. I told you the services are dependent on each other!)
- **_Edge Location_** is the location where content will be cached. This is separate from an _AWS region/Availability zone_.
- **_Distribution_** is the name given to the CDN which consists of a collection of edge locations.  

### How CloudFront Delivers Content to Your Users

After configuring CloudFront to deliver the content, here’s what happens when users request the files:

1\. **A user accesses your website** or application and requests one or more files, such as an image file and an HTML file.

2\. **DNS routes the request to the nearest CloudFront _POP_** (Points of Presence: Edge locations and regional mid-tier caches) that can best serve the request and routes the request to that edge location.

3\. In the POP, **CloudFront checks its cache for the requested files.** If the files are in the cache, CloudFront returns them to the user. 

**If the files are _not_ in the cache**, it does the following:  
a. CloudFront compares the request with the specifications in your distribution and forwards the request for the files to your origin server for the corresponding file type — for example, to your Amazon S3 bucket for image files and to your HTTP server for HTML files.  
b. **The origin servers send the files back** to the edge location.  
c. As soon as the first byte arrives from the origin, **CloudFront begins to forward the files to the user. CloudFront also adds the files to the cache** in the edge location for the next time someone requests those files.

|![cupofcode_blog_how-cloudfront-delivers-content](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_how-cloudfront-delivers-content.png)|
|--|
|[source](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/HowCloudFrontWorks.html)|

Amazon CloudFront can be used to deliver an entire website, including dynamic, static, streaming, and interactive content using a global network of edge locations. Requests for content are automatically routed to the nearest edge location, so content is delivered with the best possible performance.

There are two different types of distributions on CloudFront:

- **_Web distribution_** — typically used for websites
- **_RTPM_** — used for media streaming  

#### Important to know:

- **Edge locations are not read-only** — you can write to them too, which means you can put an object to them. For example, you can use _S3 transfer acceleration_ (which we will learn about soon!) and that’s using your edge locations to write files up to S3.
- **You can clear cached objects but you’ll be charged** for doing that.
- **Deleting distribution is done first by enabling deletion**. This is an additional step to protect you from oopsies.
- When you create a distribution, you will have an option to restrict bucket access. **_Restrict bucket access_** means the access from the bucket link is disabled, and that way the only access is through the distribution. Here is an example for a CloudFront URL, so you’ll know how it looks like: **_hd38q7yr38ih.cloudfront.net/cupofcodelogo.jpg_**

* * *

## S3 — Simple Storage Service

Introduction and basic features, storage classes, 

![cupofcode_blog_part2_s3](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_s3-1024x576.png)
  
### What Is S3?

**_Simple Storage Service (S3)_** provides secure, durable, and highly scalable object storage. S3 stores and retrieves **any amount** of data from anywhere on the web. It’s perfect for **_flat_** files, which are files that don't change, such as movies and static HTML pages. The data is spread across multiple devices and facilities.

S3 is Object-based, which means you can upload files (as opposed to other storage architectures like file systems and block storage). The files can be from 0 bytes to 5 TB and are stored in **_buckets_**: it’s like a folder in the cloud. You get an HTTP 200 code if the upload was successful.

An example for bucket URL:   
[https://s3-eu-west-1.amazonaws.com/desktopdir](https://s3-eu-west-1.amazonaws.com/desktopdir). Because it is creating a DNS entry it must be unique globally.
  
### Basic Features

- Tiered Storage and lifecycle management (which storage tier it goes to)
- Versioning: so you could roll back
- Encryption: Encrypt at rest. Usually, we hear about encryption when **transferring** data, like with HTTPS. But here, S3 gives you Encryption at rest, which is kind of like keeping your money **in a safe** in your house.
- Secure your data using **Access Control Lists and Bucket Policies**: Access Control Lists are on an individual file basis, bucket policies work across an entire bucket.
- Unlimited Storage: S3 has the following guarantees from amazon — **You can always\* upload a file, and it won’t\*\* get lost.  
    **\* Amazon guarantees 99.9% availability.  
    \*\* Amazon guarantees 99.999999999% durability for S3 information (11X9). it’s very unlikely you are going to lose a file/access to that file.

#### Data Consistency In S3

- **_Read after Write consistency_** for PUTs of new objects: Right after you write **a new file** you can **immediately** view the data.
- **_Eventual Consistency_** for overwriting PUTs and DELETEs (changes to existing object) (which can take some time to propagate): when you update an existing file or delete a file and then read it immediately, you may get an **older version, or you may not**.

#### S3 Transfer Acceleration

Enables fast, easy, and secure transfers of files over long distances between your end-users and an S3 bucket.

Transfer Acceleration takes advantage of Amazon _CloudFront_’s globally distributed edge locations. As the data arrives at an edge location, data is routed to Amazon S3 over an optimized network path.

Users all around the world want to upload a file to the bucket. When you enable transfer acceleration, those users will actually upload the buckets to the nearest edge location, and the edge location will use Amazon’s internal network and upload it directly to the S3 bucket

![cupofcode_blog_part2_s3_accelerator](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_s3_accelerator-1024x576.png)

#### Cross-Region Replication For Disaster Recovery

We have a bucket in one region and as soon as a user uploads a file to the bucket, that file will automatically be generated or replicated over to a bucket in another region. It results in a primary and a secondary bucket for disaster recovery.

#### S3 Versioning

AWS gives you the option to go to the bucket properties and enable **bucket versioning.** Once it is enabled you can only suspend it, not delete versioning — which means it cannot be disabled!

After enabling the bucket versioning, when you go to the objects table you will see there is [a toggle switch](https://www.google.com/search?q=toggle+switch+css&rlz=1C1GCEA_enIE926IE926&sxsrf=ALeKk01UA6JduVkcFcHPoEpig6dWbWhNRQ:1619639083569&source=lnms&tbm=isch&sa=X&ved=2ahUKEwil6vXh2aHwAhUpURUIHfAICckQ_AUoAXoECAEQAw&biw=1536&bih=754) named **List Versions**. Enabling this will add a column called **Version ID** and expand our list to show all versions of all objects.

**For the files you uploaded before enabling versioning**, it won’t show any version ID, but from now on, when you upload/update a file, you will see a version ID.

**How do you roll the version back?** You click on the updated file and delete it. Now you will see in the list only the previous version. Note that S3 stores all versions of an object, even if you delete an object!

**Good to know:**

- **S3 versioning can integrate with life cycle tools**: Old versions that are not often used can be stored in another storage class.
- You can use versioning with **MFA delete capabilities**, so you can minimize the risk of malicious deleting of an object.  

### Storage Classes

S3 provides _Tiered Storage_, which are 6 classes of storage that provide different advantages. S3 also provides _Lifecycle Management,_ which gives you the ability to decide which storage tier your file goes to and when.

1. **S3 Standard:** good availability and durability, stored redundantly across multiple devices in multiple facilities, and is designed to sustain the loss of 2 facilities concurrently.
2. **S3 IA (Infrequently Accessed):** For data that is accessed less frequently, but requires rapid access when needed. Lower fee than standard, but you are charged a retrieval fee.
3. **S3 One Zone IA:** Ideal when you want a lower-cost option for infrequently accessed data, but do not require the multiple AZ data resilience.
4. **S3 Intelligent Tiering:** Designed to optimize costs by automatically moving data to the most cost-effective access tier, without performance impact or operational overhead.
5. **S3 Glacier:** A secure, durable, and low-cost storage class for data archiving. You can reliably store any amount of data at costs that are competitive with or cheaper than on-premises solutions. Retrieval times configure from minutes to hours.
6. **S3 Glacier Deep Archive:** S3’s lowest-cost storage class where a retrieval time of 12 hours is acceptable.

![cupofcode_blog_part2_s3_buckets](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_s3_buckets-1024x576.png)

And here is a more detailed comparison:

![cupofcode_blog_part2_s3_table](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_s3_table-1024x576.png)

You are charged for S3 in the following ways:

- storage
- requests
- storage management pricing
- data transfer pricing
- _transfer acceleration_
- _cross-region replication_ pricing

Wow wow wow, that was a lot! We **need** a meme break.

![cupofcode_blog_part2_meme2](https://cupofcode.blog/wp-content/uploads/2021/06/cupofcode_blog_part2_meme2-768x548.jpg)

Lastly, we will see a hands-on example of creating an S3 bucket and building a website in S3. You can follow along or just read my actions. This will teach us in more depth about the existing S3 features and actions.
  
### Creating an S3 Bucket

First, notice that when you go to S3 in the AWS console — the region changed to global. **The bucket is viewed globally, but it’s stored in individual regions.**

Your buckets are always a web address and should be DNS compliant.  
**_DNS compliance_** means that it’s a valid web address: one that doesn’t contain upper-case letters, underscores, etc.

You will see an option to **block public access**, which ensures that our buckets are always private, so you need to uncheck that box.

The bucket has a few sections:

- **Properties:** contains actions like **adding static website hosting** and **enable transfer acceleration**.
- **Permissions**, where you canmanage public access settings.
- **Management:** life cycle, replication, analytics, Metrics, inventory.
  
### Uploading a file

Uploading a file will return HTTP 200(OK) response.

**Files are stored in a key-value pair:**

- Key is the name of the object
- Value is the data that is made up of a sequence of bytes.
- Version ID
- Metadata (data about data you are storing)
- Subresources: Access control lists, torrent

Click on the bucket name, and click the upload button and upload a file. After uploading, if you click on the file and then on the Link, you will get an error message: access denied, and that is because the file is not public.

**By default, anything you put into S3 is not public.** How to make it public? Click on _the file->actions->make public_.

another way is to click on the _permissions->public access->everyone_

Clicking on a specific file -> properties, you will see **storage class**, Encryption, metadata, tags, and object lock.

You can **change your storage class on demand** and it doesn’t require any boot.

**Restricting Bucket Access:**

- Bucket Policies — Applies across the whole bucket
- Object Policies — Applies to individual files
- IAM Policies to Users & Groups — Applies to Users & Groups.
  
### Creating A Website On S3

You can use S3 to host **static** websites ( `something.html`). Websites that require a DB connection cannot be hosted on S3.

**S3 scales automatically** to meet your demand. Many enterprises will put static websites on S3 when they think there is going to be a large number of requests (such as for a movie preview).

Creating a website on S3 is done by: 

1. Uploading `index.html` and `error.html` files into the bucket and giving them public access
2. Enabling the bucket to become a website

Let’s dive deep:

#### 1\. Uploading HTML files into the bucket and giving them public access

When you create the bucket with all the **default settings — it will block all public access,** but we want our HTML files to be public. This is done by clicking on _the file -> actions -> make public_. 

This action is blocked **initially**, because of the bucket settings. In order to unblock this action, we’ll go to our **bucket permissions** and edit it to enable public access. Now clicking on _the file -> actions -> make public_ will work.

Enabling access per file is not the best practice in this case. We want the whole bucket to be public, and that’s done by **bucket policy**. you can modify the policy by going to _permissions-> bucket policy ->edit_.

Here is an example for a policy: Let’s assume my bucket name is **BucketOfCode**
```
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": [
          "s3:GetObject"
      ],
      "Resource": [
          "arn:aws:s3:::BucketOfCode/*"
      ]
    }
  ]
}
```
S3 is extra safe, so in order to make an entire S3 bucket public you need to: untick the **Block public access** boxes and then use the bucket policy.

#### 2\. Enabling the bucket to become a website

Two public HTML files are not a website!!! In order for it to be, we go to _the bucket -> properties->static website hosting->edit_ and here we are actually requested to provide index document and error document.

* * *

That’s it! And to finish with a smile, here is a precious video I found on YouTube (start at 0:51):

{% youtube I\_flXB6BqiE %}

> _“If you’re planning to use S3_  
> _Encrypt at rest_  
> _Rotate your keys_  
> _MFA your IAMs_  
> _Use SDKs for hiding them, and_  
> _Minimize your ACL_  
> _Password strength on overkill_  
> _And if configured properly_  
> _Buckets never leak”_

**Pop quiz!** Which of these lyrics are IAM practices and which are S3 practices?

* * *

Wow, we learned a lot today! We started with IAM and its best practices, continued with CloudFront and CDN, and finished with the wondrous world of S3. It’s not so scary anymore, right?

I hope you enjoyed reading this article and learned something new! Want to learn more? [In the previous blog post](https://cupofcode.blog/cloud-computing-and-aws/), we talked about Cloud Computing and global AWS infrastructure, and in the next blog post, we will talk about more AWS services. Stay tuned!

If you read this, you’ve reached the end of the blog post, and I would love to hear your thoughts! Was I helpful? Do you also use AWS at work? Here are the ways to contact me:  
Facebook: [https://www.facebook.com/cupofcode.blog/](https://www.facebook.com/cupofcode.blog/)  
Instagram: [https://www.instagram.com/cupofcode.blog/](https://www.instagram.com/cupofcode.blog/)  
Email: cupofcode.blog@gmail.com

![[https://cupofcode.blog/](https://cupofcode.blog/)](https://cdn-images-1.medium.com/max/3170/0*vLdjjgtBfeBxj_f8.png)