Cloud & DevOps
Hands-onIntermediate 50 min· Cloud · 8 of 16

AWS core services: IAM, EC2, S3, RDS and Lambda

Create an AWS account safely, then use the five services behind most applications: IAM for permissions, S3 for files, EC2 for servers, RDS for databases and Lambda for functions. Each step ends with cleanup so you do not pay for leftovers.

What you'll do: open an AWS account safely, set up a limited user, store a file in S3, start (and stop) an EC2 server, understand when to use RDS, and run a Lambda function. Prerequisites: the lessons *Linux command line essentials* and *Cloud fundamentals*, a laptop with a terminal, and a debit or credit card for sign-up. Console screens change often, so follow the names of things rather than exact button positions.

This lesson can cost money

Anything you create may be billed once a free plan or credit ends, and some services (RDS, NAT gateways, load balancers) are rarely free for long. Do the cleanup step at the end of every section. Never leave an instance or database running overnight by accident.

Step 0: the account and the free plan

Sign up at the AWS website. At the time of writing (2026), AWS accounts created after mid-July 2025 choose between a free plan and a paid plan. The free plan gives a credit balance (AWS advertised up to $200 for new customers: part at sign-up, part earned by trying some services) and lasts up to six months or until credits are used, whichever comes first; it cannot be extended. A free-plan account has some services restricted until you upgrade to the paid plan. Older accounts may still be on the previous 12-month free tier model. These rules change, so read the current page at aws.amazon.com/free before you sign up.

Secure the account first

  1. 1Sign in as the root user (the email you used) and immediately turn on multi-factor authentication (MFA) with an authenticator app. Find it under your account name, then Security credentials.
  2. 2Open Billing, then Budgets, and create a monthly cost budget with an email alert at a small amount you are comfortable with, such as ₹500.
  3. 3Open IAM and create an administrator identity for daily use (see below). From now on, do not use the root user except for rare account-level tasks.
  4. 4Pick one region (for example Asia Pacific (Mumbai), ap-south-1) and stay in it. The region name is shown top right in the console. Resources in other regions do not appear in your list.

IAM: who can do what

IAM (Identity and Access Management) decides which identity may perform which action on which resource. Four pieces:

User: a person or program with credentials. Group: a set of users sharing permissions. Role: an identity that is assumed temporarily, with no password of its own; services such as EC2 and Lambda use roles. Policy: a JSON document that lists allowed or denied actions.

The golden rule is least privilege: give only the permissions needed. By default everything is denied until a policy allows it.

read-only-menu-bucket.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:ListBucket"],
      "Resource": [
        "arn:aws:s3:::brewbean-menu-YOURNAME",
        "arn:aws:s3:::brewbean-menu-YOURNAME/*"
      ]
    }
  ]
}

Allows reading and listing one bucket only. Effect is Allow or Deny, Action is the API call, Resource is identified by an ARN (Amazon Resource Name). Replace YOURNAME to match your bucket.

For your own daily user, AWS recommends IAM Identity Center for people; a simpler path for learning is an IAM user in a group with the AWS managed policy AdministratorAccess. That is powerful: protect it with MFA, and never create access keys unless you need the command line. For apps running on AWS, prefer roles over keys.

Install and configure the AWS CLI

  1. 1Install the AWS CLI version 2 from the official AWS documentation for your operating system.
  2. 2Create an access key for your IAM user (IAM, Users, your user, Security credentials, Create access key, choose Command Line Interface).
  3. 3Run aws configure and enter the key id, the secret, the region ap-south-1 and output format json.
  4. 4Test with aws sts get-caller-identity. It prints your account number and user.

Never commit access keys

Bots scan public GitHub repositories for AWS keys within minutes. If a key leaks, deactivate it in IAM at once. Keys are stored in ~/.aws/credentials; keep that file out of every repository.

S3: object storage

S3 stores files as objects inside buckets. A bucket name is globally unique across all AWS customers. Objects are accessed by key (the file path), over HTTP and the API. S3 is used for images, backups, logs, static websites and data lakes. It is not a file system you mount like a disk, and it is not a database.

Terminal
# bucket names must be unique, lowercase, no spaces
export BUCKET=brewbean-menu-yourname-2026
aws s3 mb s3://$BUCKET --region ap-south-1

echo '[{"id":"espresso","price":120}]' > menu.json
aws s3 cp menu.json s3://$BUCKET/menu.json
aws s3 ls s3://$BUCKET
aws s3 cp s3://$BUCKET/menu.json downloaded.json
cat downloaded.json

New buckets are private by default and block public access. Keep it that way.

Expected output of the ls command
2026-10-31 10:15:02         34 menu.json
The date and time will differ.

To share a private file for a short time, create a presigned URL, which is a link that works for a limited period:

Terminal
aws s3 presign s3://$BUCKET/menu.json --expires-in 300

Prints a long URL that anyone with it can open for 300 seconds.

Cleanup for S3

  1. aws s3 rb s3://$BUCKET --force deletes the objects and the bucket
  2. Open the S3 console to confirm the bucket is gone

EC2: virtual servers

EC2 gives you a virtual machine. You pick an AMI (the operating system image, for example Amazon Linux or Ubuntu), an instance type (CPU and memory, such as t3.micro), a key pair (for SSH login), a security group (a firewall of allowed ports), and storage. You pay while the instance is running (per second, with a minimum for Linux). Free plans limit which instance types you can use; the launch screen marks eligible ones.

Launch a small server in the console

  1. 1Open EC2, then Launch instance. Name it lab-server.
  2. 2Choose Amazon Linux as the AMI and a small instance type marked as free-plan eligible (or the cheapest, such as t3.micro; check the price shown).
  3. 3Create a new key pair, type RSA, format .pem, and save the file safely.
  4. 4In network settings, allow SSH only from My IP, not from anywhere. Add HTTP only if you will run a web server.
  5. 5Launch, wait until the state is Running, then copy the public IPv4 address.
  6. 6Connect from your terminal: chmod 400 lab-server.pem then ssh -i lab-server.pem ec2-user@PUBLIC_IP (Windows 10 and 11 have ssh built in; skip chmod).
  7. 7Run uname -a and df -h to look around, then type exit.

Security groups work like a firewall list: they only allow, never deny, and are stateful (replies to allowed traffic are let back). An SSH rule open to 0.0.0.0/0 invites password-guessing bots, so restrict it.

Cleanup for EC2

  1. In the console choose the instance, then Instance state, then Terminate (Stop only pauses compute; the disk still costs a little)
  2. Check the Elastic IPs and Volumes pages are empty
  3. Delete the key pair if you no longer need it

RDS: managed databases

RDS runs a database engine (PostgreSQL, MySQL, MariaDB and others) for you: installation, backups, patching and optional replicas in another availability zone. You still design tables and queries (see the Backend track). You could install Postgres on an EC2 machine yourself, but then backups, upgrades and failover become your job.

For learning, create a small PostgreSQL instance only if your plan allows it, and delete it when done. Key settings: engine and version, instance class, storage, a username and strong password, and Public access = No unless you have a reason. Put it in a security group that allows port 5432 only from your app's security group. Your app then connects with a host name that RDS shows (the endpoint), for example through postgresql://user:password@ENDPOINT:5432/dbname.

EC2 with your own database versus RDS

TopicPostgres on EC2RDS
SetupYou install and tunePick settings in a form
BackupsYou script themAutomated, with point-in-time restore
PatchingYouManaged, in a window you choose
CostLower for tiny labsHigher, but saves time
Best forLearning LinuxReal applications

Stopped databases still cost money

A running database bills by the hour. A stopped RDS instance is started again automatically by AWS after a number of days, and its storage still costs. Delete test databases (skip the final snapshot if it holds no real data).

Lambda: functions without servers

Lambda runs your function in response to an event: an HTTP request, a file landing in S3, a schedule. You upload code; AWS runs it on demand and bills per request and per duration. No requests, no compute cost. Limits include a maximum run time of 15 minutes and cold starts (the first call after idle is slower). The Serverless applications lesson builds on this.

lambda_function.py
import json


def lambda_handler(event, context):
    name = (event or {}).get("name", "friend")
    return {
        "statusCode": 200,
        "body": json.dumps({"message": f"Welcome to Brew & Bean, {name}!"}),
    }

The handler receives the triggering event and a context object. The returned dict mimics an HTTP response.

Create and test it

  1. 1Open Lambda, then Create function, choose Author from scratch, name it welcome, runtime Python (a current version).
  2. 2Replace the default code in the editor with the handler above and click Deploy.
  3. 3Click Test, create a test event with {"name": "Asha"}, and run it.
  4. 4Read the response and the log lines shown under the result.
  5. 5Optional: under Configuration, then Function URL, create a URL with auth type NONE only for this demo, open it in a browser, then delete the URL.
Test result
{
  "statusCode": 200,
  "body": "{\"message\": \"Welcome to Brew & Bean, Asha!\"}"
}
Terminal
aws lambda invoke --function-name welcome --cli-binary-format raw-in-base64-out --payload '{"name":"Ravi"}' response.json
cat response.json

Runs the function from the CLI. The flag lets the CLI accept a plain JSON payload. On Windows PowerShell, quoting the JSON differs; use the console test if it gives trouble.

Lambda automatically writes logs to CloudWatch Logs, and its execution role decides what AWS resources it may touch. To let it read your S3 bucket you attach a policy like the one shown earlier to that role, not an access key in the code.

Cleanup for Lambda

  1. Delete the Function URL if you created one
  2. Delete the function (free to keep, but untidy)
  3. Delete the log group in CloudWatch if you want a clean account

Choosing between them

Which service for which job

NeedUse
Store images, backups, static filesS3
Run a long-lived server or special softwareEC2
Relational data for an appRDS
Short event-driven codeLambda
Control who can access whatIAM (always)
Prompt · Review my IAM policy
Act as an AWS security reviewer. Here is an IAM policy:

```
[paste policy JSON]
```

Explain in plain English what it allows, point out anything broader than needed (wildcards, missing Resource limits), and rewrite it to follow least privilege for this task: [describe what the app must do].

What to expect: Check that the rewritten policy lists specific actions and resource ARNs. Test it in a throwaway account before relying on it.

How this comes up in interviews

Frequent questions: the difference between a user, a role and a policy; why avoid root and access keys; S3 versus EBS versus EFS (object, block disk for one server, shared file system); what a security group is; when you would choose Lambda over EC2; and why RDS instead of self-managed databases. Practical answers that mention least privilege, MFA and cleanup show good habits.

Try it: A private file with a time limit

Create a new bucket, upload a text file, confirm that opening its normal URL is denied, then create a presigned URL that works for 60 seconds and test it before and after it expires. Finish by deleting the bucket.

Key takeaways

  1. Secure the root user with MFA, set a budget alert, and use an IAM identity for daily work.
  2. IAM policies are JSON allow rules; start from deny and grant the minimum.
  3. S3 stores objects in private buckets; share with presigned URLs, not public buckets.
  4. EC2 is a rented virtual machine: restrict SSH, and terminate it when finished.
  5. RDS manages database operations for you; Lambda runs code per event with no server to manage.
  6. Clean up after every lab; billing follows resources, not your attention.

Check yourself

Finishing the quiz marks the lesson as done.

1. What is the safest way to give an EC2 instance or Lambda function access to S3?

2. A bucket must hold private files but one user needs a download link for five minutes. What do you use?

3. Why should the SSH rule on a security group be limited to your IP?

4. Which statement about Lambda is correct?

5. What is the main advantage of RDS over installing Postgres yourself on EC2?

6. In IAM, what does a policy do?

Saved on this device. Create a free account to keep it on every device.

Practise this with Sam

A real mock interview, out loud, with an honest scorecard. Free to start.

Start free