Learning Notes:
What is AWS Elastic Beanstalk?
- A Platform-as-a-Service (PaaS) by AWS that allows developers to deploy and scale web applications without worrying about infrastructure management.
- Supports multiple programming languages & runtimes: Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker.
Why use Elastic Beanstalk?
Before Elastic Beanstalk, developers struggled with:
- Sharing software modules across distributed teams.
- Managing scaling, deployment, and environments manually.
Elastic Beanstalk solves this by:
- Automating deployment
- Handling scaling (vertical & horizontal)
- Managing monitoring & updates
- Simplifying app sharing & collaboration
Advantages of Elastic Beanstalk
- setup & deployment
- Highly scalable
- Cost-efficient (pay for AWS resources used)
- Supports multi-tenant architecture
- Simplifies operations
Components of Elastic Beanstalk
- Application Version → A release of your application’s code.
- Environment → AWS resources (EC2, Load Balancer, etc.) running an application version.
- Environment Tier → Defines usage:
- Web Server (frontend, accessed via URL)
- Worker (backend/microservices)
- Configuration Template → Predefined environment settings (e.g., instance types, scaling policies).
Task-A: Deploy the 2048 Game on Elastic Beanstalk
Steps:
- Go to AWS Elastic Beanstalk Console.
- Create a new Application → Upload the 2048-game source code (ZIP).
- Choose Web Server Environment (Node.js recommended).
- Configure environment (instance type, scaling, monitoring).
- Deploy → Elastic Beanstalk provisions EC2, S3, Load Balancer, etc. automatically.
- Access your game at the provided Elastic Beanstalk URL
Task-01: EC2 Basics
Launch an EC2 instance, deploy a web app, and monitor with CloudWatch.
Step 1: Launch EC2 Instance
- Log in to AWS Management Console → go to EC2.
- Click Launch Instance.
- Enter details:
-
Name →
MyWebServer
- AMI → Amazon Linux 2 AMI (free tier)
- Instance type → t2.micro (free tier)
-
Key pair → Create/download a
.pem
file (used for SSH). -
Security group → Allow SSH (22) + HTTP (80).
- Click Launch Instance.
Step 2: Connect to EC2 via SSH
On your local terminal:
ssh -i my-key.pem ec2-user@<EC2-Public-IP>
Step 3: Install a Web Server (Apache)
sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
Step 4: Deploy a Simple Web App
Create a simple HTML page:
echo "<h1>Hello from my AWS EC2 Web Server </h1>" | sudo tee /var/www/html/index.html
Now, open http:// in your browser → you should see the page
Step 5: Monitor with CloudWatch
- In AWS Console → CloudWatch → Logs/Alarms, enable monitoring for your EC2 instance.
- Check CPU Utilization, Memory, and Network metrics.
- Optionally, set an alarm (e.g., notify if CPU > 70%).
⚡ Task-02: Auto Scaling Group (ASG) + CloudWatch + CLI
Set up Auto Scaling so EC2 instances launch automatically when demand changes.
Step 1: Create Launch Template
- Go to EC2 → Launch Templates → Create.
- Use Amazon Linux 2 AMI,
t2.micro
, and your security group. - Save.
Step 2: Create Auto Scaling Group (ASG)
- Go to EC2 → Auto Scaling Groups → Create.
- Select your Launch Template.
- Choose at least 2 Availability Zones for high availability.
- Set Group size:
- Desired capacity: 1
- Min capacity: 1
- Max capacity: 3
- Attach a Load Balancer (optional, but good practice).
- Create.
Step 3: Add Scaling Policy
- Go to your ASG → Automatic Scaling → Add policy.
- Example: Scale out when CPU > 70% for 5 minutes, scale in when CPU < 20%.
Step 4: Monitor with CloudWatch
- CloudWatch will now show metrics per instance and scaling activity.
- Check if new instances launch automatically when demand increases.
Step 5: Verify with AWS CLI
Run these commands to confirm instance scaling:
# Check Auto Scaling groups
aws autoscaling describe-auto-scaling-groups --region <your-region>
## List EC2 instances
aws ec2 describe-instances --region <your-region> --query "Reservations[*].Instances[*].[InstanceId,State.Name,PublicIpAddress]"
Top comments (0)