# Cloud basics: what you're actually renting

What the cloud really is, IaaS vs PaaS vs SaaS, public vs private vs hybrid, and how regions and Availability Zones keep apps running.

Course: [AWS for DevOps](https://devops.rajeev.pro/courses/aws), lesson 1. About 25 minutes, intermediate. Source: https://devops.rajeev.pro/courses/aws/01-cloud-basics

## What you will learn

- Explain in one sentence what you rent when you use the cloud
- Tell IaaS, PaaS and SaaS apart, and know what you still manage in each
- Pick an AWS Region for a real app and explain why
- Explain why production runs in at least two Availability Zones

## What "the cloud" actually is

Before cloud services, a team that needed another server raised a purchase request. Someone
waited for hardware, installed an operating system, and wired it into the network. A Friday
release could wait days for capacity. If traffic dropped later, the paid-for server sat mostly
idle. The process was slow because every change depended on a person and a physical machine.

Cloud computing changes that request into an API call. You ask a provider to create a defined
resource, such as a virtual server, and the provider allocates it from its data centres. You can
change or delete it without handling the hardware. The provider still owns the physical machines;
you rent access to a portion of their capacity.

Three properties make that useful:

- **On demand.** You create and delete resources yourself, with a click or a command. No tickets, no sales call.
- **Pay for what you use.** Most services bill by the second, hour or gigabyte. A server that runs for 20 minutes costs 20 minutes.
- **Elastic.** Need 50 servers for a sale weekend and 5 on Monday? Scale up, then scale back down.

That last point is why DevOps and the cloud fit together. If infrastructure is an API call, you
can put the request in a script or a reviewed configuration file. A team can repeat the same setup,
see who changed it, and remove it when the workload ends. The provider operates the physical
facilities, but you still choose the configuration and remain responsible for your data and access.

In this course, you'll use the AWS console and CLI to create a small resource, inspect its region,
and learn what to secure before using an account for real work.

## IaaS, PaaS and SaaS

Every app sits on the same stack of layers, from the network at the bottom to your code and
data at the top. The service model decides **where AWS stops and you start**.

| Model | You get                          | You still manage                     | AWS example                                     |
| ----- | -------------------------------- | ------------------------------------ | ----------------------------------------------- |
| IaaS  | Virtual servers, disks, networks | Operating system, runtime, app, data | EC2                                             |
| PaaS  | A platform that runs your code   | Your app and its data                | Elastic Beanstalk, App Runner                   |
| SaaS  | A finished product               | Your data and who can access it      | Amazon WorkMail, or Gmail and Slack outside AWS |

> **Figure.** Shared responsibility model: you secure your data, IAM, OS and apps, network settings and encryption; AWS secures the service software, hardware, global network and data centres.
>
> The shared responsibility model. The more managed the service, the smaller your share.

> **Your data is always your job.** AWS calls this the **shared responsibility model**: AWS secures the cloud itself (buildings, hardware, the hypervisor), and you secure what you put in it. Even with SaaS, a weak password or a public link to private data is on you.

## Public, private and hybrid cloud

These names describe **who owns or shares the infrastructure**, not whether a web page is visible
on the internet. A public-cloud account can contain a private database; a private cloud can host a
public website.

| Type    | What it means                                                               | When teams use it                                                   |
| ------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| Public  | Shared provider infrastructure, like AWS, Azure or Google Cloud             | Most new projects. No hardware to buy                               |
| Private | Cloud-style tooling on hardware only you use, often in your own data centre | Strict rules, or big steady workloads already on owned hardware     |
| Hybrid  | Some workloads on-premises, some in the public cloud, connected             | Moving to the cloud step by step, or keeping regulated data at home |

In this course we use AWS, a public cloud provider. The account and its network controls still let
you decide which resources are reachable. Choose a private cloud when control over dedicated
hardware or a local environment is a firm requirement and the team can operate it. Choose a hybrid
setup when some systems must remain local but still need to communicate with cloud services. A
common mistake is to treat "public cloud" as "publicly accessible"; check each resource's network
and access policy instead.

## Regions and Availability Zones

AWS runs data centres all over the world, grouped in two levels:

- A **Region** is a geographic area, like `ap-south-1` (Mumbai) or `ap-south-2` (Hyderabad). Regions are independent of each other. Your resources stay in the Region you create them in.
- An **Availability Zone (AZ)** is one or more data centres inside a Region, with their own power, cooling and network. AZs in a Region are far enough apart that a fire or flood shouldn't hit two at once, but close enough for fast private links between them. Mumbai has three: `ap-south-1a`, `ap-south-1b` and `ap-south-1c`.

> **Figure.** Rows of server racks in a data centre server room
>
> What an Availability Zone is made of: rooms full of server racks with their own power and cooling. This one is at CERN; AWS doesn't publish photos from inside its own data centres.

The rule that follows: **run anything that matters in at least two AZs.** If one AZ has a
problem, the copy in the other AZ keeps serving users. Most of the high availability you'll
build in this course comes from that one idea.

### How to pick a Region

1. **Where your users are.** Closer means lower latency. Users in India → Mumbai or Hyderabad.
2. **Where the data is allowed to live.** Some data must stay in the country by law or by contract.
3. **Which services exist there.** New services often reach a few Regions first.
4. **Price.** The same server can cost a little more or less depending on the Region.

> **Video.** [AWS Global Infrastructure Explained in 3 Minutes: Regions, Availability Zones and Edge Locations](https://www.youtube.com/watch?v=Fi1KaVrWYTE&t=16s) (Tiny Technical Tutorials)

## Look around with the AWS CLI

The quickest way to start is **AWS CloudShell**: a terminal in your browser, opened from the
AWS console, with the AWS CLI installed and signed in as you. No keys to create or leak.

```sh
$ aws --version
aws-cli/2.x.x Python/3.x Linux/x86_64        # your exact versions will differ
$ aws sts get-caller-identity                # which account and identity am I using?
{
    "UserId": "AIDAEXAMPLEUSERID",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:user/rajeev"
}
$ aws ec2 describe-regions --query "Regions[].RegionName" --output text
$ aws ec2 describe-availability-zones --region ap-south-1 --query "AvailabilityZones[].ZoneName" --output text
ap-south-1a	ap-south-1b	ap-south-1c
```

`--query` filters the service response with JMESPath, AWS CLI's query language. Here it selects
only the `RegionName` or `ZoneName` fields instead of printing the full response object.
`--output text` prints those values as plain text. Without it, the CLI usually formats results as
JSON, which is easier to read for nested objects but noisier for a short list.

`aws sts get-caller-identity` is a useful safety check before a change. It asks AWS Security Token
Service which identity signed the request; it does not create or modify a resource. Confirm the
account and role before running commands that create, change or delete infrastructure. The example
identity above is illustrative, so its account and user values will not match yours.

The final command requests Availability Zones from the selected region. A region name in a command
doesn't change your account's default region; pass `--region` when you need the command to use a
specific one. Use CloudShell when you need a signed-in shell without storing keys on your laptop.
Use a local CLI when your team manages its credentials safely and wants scripts in its normal
development workflow. Never put access keys in a lesson file, shell history or source repository.

> **Protect the root user first.** The email you signed up with is the **root user**: it can do anything, including closing the account. Turn on MFA for it today, never create access keys for it, and don't use it for daily work. The next lesson sets up a safer identity with IAM.

> **Set a budget before you build anything.** New accounts get free usage and starter credits, but the rules change, so read the current AWS Free Tier page first. Then create a **zero-spend budget** in Billing → Budgets. It emails you the moment anything starts costing money, which turns a surprise bill into a quick fix.

## Mission: Choose a Region for a new app

Your team is launching an app for customers in India. Legal says customer data must stay in India, and the app needs EC2 and RDS. Pick the Region, list its AZs, and prove both services are offered there.

- You need: Users in India, data stays in India
- You'll have: ~/region-choice.txt

```sh
$ aws ec2 describe-availability-zones --region ap-south-1 --query "AvailabilityZones[].ZoneName" --output text > ~/region-choice.txt
$ aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/regions/ap-south-1/services --query "Parameters[].Value" --output text | tr '\t' '\n' | grep -x -e ec2 -e rds
ec2
rds
$ cat ~/region-choice.txt
ap-south-1a	ap-south-1b	ap-south-1c
```

`ap-south-1` (Mumbai) fits: it's in India, close to users, has three AZs and offers both
services. `ap-south-2` (Hyderabad) would also work, and is a good second Region for disaster
recovery later.

## Try it

- Create an AWS account and turn on MFA for the root user.
- In Billing → Budgets, create a zero-spend budget with your email as the alert.
- Open CloudShell in the Mumbai Region (`ap-south-1`) and run `aws sts get-caller-identity`.
- List the Availability Zones in `ap-south-1` and in `ap-south-2`. How many does each have?
- Run the mini mission and check that `~/region-choice.txt` lists three AZs.

## Quiz

1. Your app runs on one EC2 server in ap-south-1a. That AZ has a power problem and the app goes down. What would have prevented it?
   - A bigger instance type
   - **Running copies in at least two AZs behind a load balancer** (answer)
   - Moving to a different Region
   Why: An AZ is a failure boundary. A copy in a second AZ keeps serving while the first one recovers.

2. You run your app on EC2. Who installs operating system security patches?
   - AWS, automatically
   - **You** (answer)
   - Nobody, the cloud is always patched
   Why: EC2 is IaaS. AWS runs the hardware and hypervisor; the operating system and everything above it are yours.

3. Which of these is SaaS?
   - EC2
   - Elastic Beanstalk
   - **A team chat app like Slack** (answer)
   Why: With SaaS you use a finished product and manage only your data and users. EC2 is IaaS and Elastic Beanstalk is PaaS.

4. Customers are in India and their data must stay in India. Which Region fits best?
   - us-east-1 (N. Virginia)
   - **ap-south-1 (Mumbai)** (answer)
   - eu-west-1 (Ireland)
   Why: Mumbai keeps data in India and is closest to the users. Hyderabad (ap-south-2) would also work.

## Resources

- [Types of cloud computing (IaaS, PaaS, SaaS)](https://aws.amazon.com/types-of-cloud-computing/) (AWS)
- [AWS global infrastructure map](https://aws.amazon.com/about-aws/global-infrastructure/) (AWS)
- [Regions and Availability Zones](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html) (AWS Docs)
- [Shared responsibility model](https://aws.amazon.com/compliance/shared-responsibility-model/) (AWS)
- [AWS Well-Architected Framework](https://aws.amazon.com/architecture/well-architected/) (AWS)
- [Getting started with AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) (AWS Docs)
- [Root user best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/root-user-best-practices.html) (AWS Docs)
- [Managing costs with AWS Budgets](https://docs.aws.amazon.com/cost-management/latest/userguide/budgets-managing-costs.html) (AWS Docs)
- [AWS Free Tier](https://aws.amazon.com/free/) (AWS)
