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
- Launch an EC2 instance with Amazon Linux or Ubuntu
- SSH into it:
ssh -i key.pem ec2-user@your-ip - Install your app dependencies:
sudo yum install nodejs npm -y - Clone your code:
git clone https://github.com/your/repo.git - Run the app:
node server.js - Setup Nginx as reverse proxy (optional but recommended)
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
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
Exercise: Deploy a Web App
Task: Deploy a simple web application to AWS.
- Create a simple Node.js or Python web app
- Launch an EC2 instance
- Install dependencies (Node, npm, Nginx)
- Upload your code to the instance
- Run the app and test it
- Set up auto-start with systemd
- 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!