Advanced 45 min read Module 8 of 8

AWS Deployment

Learn how to deploy real applications to AWS using best practices, CI/CD, and zero-downtime strategies.

Deployment Options on AWS

EC2

Full control
SSH access

ECS

Containers
Docker

Lambda

Serverless
No servers

Elastic Beanstalk

PaaS
Easy deployment

Deploying to EC2

  1. Launch an EC2 instance with Amazon Linux or Ubuntu
  2. SSH into it: ssh -i key.pem ec2-user@your-ip
  3. Install your app dependencies: sudo yum install nodejs npm -y
  4. Clone your code: git clone https://github.com/your/repo.git
  5. Run the app: node server.js
  6. Setup Nginx as reverse proxy (optional but recommended)
Pro Tip: Use User Data to auto-install and run your app on launch!

Deploying to Lambda

Manual
  • Click "Upload from" in Lambda console
  • Select ZIP file
  • Click "Deploy"
CI/CD
  • Use GitHub Actions
  • Use AWS CodePipeline
  • Automated deployment
# Deploy Lambda with AWS CLI
aws lambda update-function-code \
    --function-name MyFunction \
    --zip-file fileb://function.zip

CI/CD Pipeline

CI/CD (Continuous Integration/Continuous Deployment) automates your deployment process.

Source
GitHub, CodeCommit

Build
CodeBuild, GitHub Actions

Deploy
CodeDeploy, ECS, Lambda

Benefits: Automated testing, zero-downtime deployments, faster releases.

Zero-Downtime Deployment Strategies

Blue/Green
  • Two identical environments
  • Green = live, Blue = new
  • Switch traffic instantly
  • Instant rollback
Canary
  • Gradual rollout
  • Small % first
  • Monitor errors
  • Auto-rollback on issues
Remember: Always test your deployment in a staging environment first!

Exercise: Deploy a Web App

Task: Deploy a simple web application to AWS.

  1. Create a simple Node.js or Python web app
  2. Launch an EC2 instance
  3. Install dependencies (Node, npm, Nginx)
  4. Upload your code to the instance
  5. Run the app and test it
  6. Set up auto-start with systemd
  7. Set up a CI/CD pipeline with GitHub Actions
Show Solution
# GitHub Actions workflow (.github/workflows/deploy.yml)
name: Deploy to EC2

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      
      - name: Deploy to EC2
        uses: appleboy/ssh-action@v0.1.2
        with:
          host: ${{ secrets.EC2_HOST }}
          username: ${{ secrets.EC2_USER }}
          key: ${{ secrets.EC2_KEY }}
          script: |
            cd /var/www/myapp
            git pull
            npm install
            pm2 restart app
Key Takeaway

AWS offers multiple deployment options. Use EC2 for full control, Lambda for serverless, and CI/CD pipelines for automated deployments. Always use zero-downtime strategies for production applications!