What is AWS?

Amazon Web Services (AWS) is the world's most comprehensive cloud platform, offering over 200 services. For beginners, you only need to know a handful of core services to get started.

AWS offers a Free Tier that lets you explore many services for free for 12 months, making it perfect for learning.

Essential AWS Services

Service          Purpose                   Free Tier
────────────────────────────────────────────────────────
EC2              Virtual servers           750 hrs/month
S3               File storage              5 GB
RDS              Managed databases         750 hrs/month
Lambda           Serverless functions      1M requests/month
DynamoDB         NoSQL database            25 GB
CloudFront       CDN                       50 GB transfer
Route 53         DNS                       Not free
IAM              Security/Access           Always free
CloudWatch       Monitoring                Basic free

EC2: Virtual Servers

EC2 (Elastic Compute Cloud) provides resizable virtual servers in the cloud.

# Launch an EC2 instance for your Python app:
1. Choose AMI (Amazon Machine Image)
   → Amazon Linux 2023 or Ubuntu 22.04

2. Choose Instance Type
   → t2.micro (Free Tier eligible)
   → t3.small for production

3. Configure Security Group
   → Allow SSH (port 22) from your IP
   → Allow HTTP (port 80) from anywhere
   → Allow HTTPS (port 443) from anywhere

4. Create Key Pair
   → Download .pem file (keep it safe!)

# Connect via SSH
chmod 400 my-key.pem
ssh -i my-key.pem ec2-user@your-public-ip

# Install Python and deploy
sudo yum update -y
sudo yum install python3 python3-pip -y
pip3 install gunicorn flask
python3 app.py

S3: Object Storage

S3 (Simple Storage Service) stores files, images, backups - anything.

# Install AWS SDK for Python
pip install boto3

# Upload file to S3
import boto3

s3 = boto3.client('s3')

# Upload a file
s3.upload_file('local_file.jpg', 'my-bucket', 'images/photo.jpg')

# Download a file
s3.download_file('my-bucket', 'images/photo.jpg', 'downloaded.jpg')

# Generate presigned URL (for temporary access)
url = s3.generate_presigned_url(
    'get_object',
    Params={'Bucket': 'my-bucket', 'Key': 'images/photo.jpg'},
    ExpiresIn=3600  # 1 hour
)

# List objects in bucket
response = s3.list_objects_v2(Bucket='my-bucket')
for obj in response.get('Contents', []):
    print(obj['Key'])

Common uses: Static website hosting, file uploads, backups, data lakes

RDS: Managed Databases

RDS (Relational Database Service) manages PostgreSQL, MySQL, and other databases for you.

# Create RDS instance:
1. Choose engine: PostgreSQL (recommended for Python)
2. Choose template: Free Tier
3. DB instance identifier: myapp-db
4. Master username: admin
5. Master password: (secure password)
6. Instance type: db.t3.micro
7. Storage: 20 GB
8. VPC: Default VPC
9. Public access: No (use VPC)

# Connect from Python
import psycopg2

conn = psycopg2.connect(
    host="myapp-db.xxxx.us-east-1.rds.amazonaws.com",
    database="myapp",
    user="admin",
    password="your-password"
)

# With SQLAlchemy
DATABASE_URL = "postgresql://admin:password@myapp-db.xxxx.rds.amazonaws.com/myapp"

Lambda: Serverless Functions

Run code without managing servers. Perfect for event-driven workloads.

# Lambda function (Python)
import json

def lambda_handler(event, context):
    # event contains the input data
    name = event.get('name', 'World')

    return {
        'statusCode': 200,
        'body': json.dumps(f'Hello, {name}!')
    }

# Triggers:
# - API Gateway (HTTP requests)
# - S3 (file uploads)
# - DynamoDB (database changes)
# - CloudWatch Events (scheduled)
# - SNS/SQS (messages)

# Deploy with AWS CLI
aws lambda create-function \
    --function-name my-function \
    --runtime python3.11 \
    --handler lambda_function.lambda_handler \
    --zip-file fileb://function.zip \
    --role arn:aws:iam::123456789:role/lambda-role

IAM: Security

IAM (Identity and Access Management) controls who can access what in your AWS account.

# Key concepts:
Users     - Individual people/services
Groups    - Collections of users
Roles     - Temporary permissions for services
Policies  - JSON documents defining permissions

# Example policy: Allow S3 read access
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket",
                "arn:aws:s3:::my-bucket/*"
            ]
        }
    ]
}

# Best practices:
1. Never use root account for daily tasks
2. Enable MFA on all accounts
3. Use roles instead of access keys when possible
4. Follow principle of least privilege
5. Rotate access keys regularly

Elastic Beanstalk: Easy Deployment

Easiest way to deploy Python apps to AWS. Just upload your code.

# Install EB CLI
pip install awsebcli

# Initialize your project
cd myapp
eb init

# Create environment and deploy
eb create my-env
eb deploy

# View your app
eb open

# Required files:
# requirements.txt - Python dependencies
# application.py - Your Flask/FastAPI app

# Example application.py for Flask
from flask import Flask
application = Flask(__name__)  # Must be named 'application'

@application.route('/')
def home():
    return 'Hello from Elastic Beanstalk!'

if __name__ == '__main__':
    application.run()

Typical Python App Architecture

┌─────────────────────────────────────────────────────────┐
│                         Users                            │
└───────────────────────────┬─────────────────────────────┘
                            │
                    ┌───────┴───────┐
                    │   Route 53    │  DNS
                    │  (optional)   │
                    └───────┬───────┘
                            │
                    ┌───────┴───────┐
                    │  CloudFront   │  CDN (optional)
                    └───────┬───────┘
                            │
         ┌──────────────────┴──────────────────┐
         │                                      │
┌────────┴────────┐                    ┌───────┴───────┐
│  S3 (Static)    │                    │ Load Balancer │
│  CSS, JS, Images│                    │               │
└─────────────────┘                    └───────┬───────┘
                                               │
                    ┌──────────────────────────┼──────────────────────────┐
                    │                          │                          │
           ┌────────┴────────┐       ┌────────┴────────┐       ┌────────┴────────┐
           │   EC2 / ECS     │       │   EC2 / ECS     │       │   EC2 / ECS     │
           │  (Python App)   │       │  (Python App)   │       │  (Python App)   │
           └────────┬────────┘       └────────┬────────┘       └────────┬────────┘
                    │                          │                          │
                    └──────────────────────────┼──────────────────────────┘
                                               │
                              ┌────────────────┴────────────────┐
                              │                                  │
                     ┌────────┴────────┐              ┌─────────┴─────────┐
                     │    RDS          │              │    ElastiCache    │
                     │  (PostgreSQL)   │              │    (Redis)        │
                     └─────────────────┘              └───────────────────┘

AWS CLI Essentials

# Install AWS CLI
pip install awscli

# Configure credentials
aws configure
# Enter Access Key ID, Secret Key, Region

# Common commands
aws s3 ls                          # List S3 buckets
aws s3 cp file.txt s3://bucket/    # Upload to S3
aws ec2 describe-instances         # List EC2 instances
aws rds describe-db-instances      # List RDS databases
aws lambda list-functions          # List Lambda functions

# Use profiles for multiple accounts
aws configure --profile production
aws s3 ls --profile production

Cost Management Tips

  • Use Free Tier: Monitor usage to stay within limits
  • Set billing alerts: Get notified before charges spike
  • Stop unused resources: Turn off dev instances at night
  • Right-size instances: Don't over-provision
  • Use Reserved Instances: Save 30-75% for steady workloads
  • Use Spot Instances: Save up to 90% for flexible workloads

Master AWS with Expert Mentorship

Our Full Stack Python program covers AWS deployment and cloud services. Learn to deploy scalable Python applications with personalized guidance.

Explore Full Stack Python Program

Related Articles