DEV Community

Udoh Deborah
Udoh Deborah

Posted on

Day 47: AWS Elastic Beanstalk

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

  1. Application Version → A release of your application’s code.
  2. Environment → AWS resources (EC2, Load Balancer, etc.) running an application version.
  3. Environment Tier → Defines usage:
  • Web Server (frontend, accessed via URL)
  • Worker (backend/microservices)
    1. Configuration Template → Predefined environment settings (e.g., instance types, scaling policies).

Task-A: Deploy the 2048 Game on Elastic Beanstalk

Steps:

  1. Go to AWS Elastic Beanstalk Console.
  2. Create a new Application → Upload the 2048-game source code (ZIP).
  3. Choose Web Server Environment (Node.js recommended).
  4. Configure environment (instance type, scaling, monitoring).
  5. Deploy → Elastic Beanstalk provisions EC2, S3, Load Balancer, etc. automatically.
  6. 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

  1. Log in to AWS Management Console → go to EC2.
  2. Click Launch Instance.
  3. Enter details:
  • NameMyWebServer
  • 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).
    1. Click Launch Instance.

Step 2: Connect to EC2 via SSH

On your local terminal:

ssh -i my-key.pem ec2-user@<EC2-Public-IP>
Enter fullscreen mode Exit fullscreen mode

Step 3: Install a Web Server (Apache)

sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Now, open http:// in your browser → you should see the page

Step 5: Monitor with CloudWatch

  1. In AWS Console → CloudWatch → Logs/Alarms, enable monitoring for your EC2 instance.
  2. Check CPU Utilization, Memory, and Network metrics.
  3. 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

  1. Go to EC2 → Launch Templates → Create.
  2. Use Amazon Linux 2 AMI, t2.micro, and your security group.
  3. Save.

Step 2: Create Auto Scaling Group (ASG)

  1. Go to EC2 → Auto Scaling Groups → Create.
  2. Select your Launch Template.
  3. Choose at least 2 Availability Zones for high availability.
  4. Set Group size:
  • Desired capacity: 1
  • Min capacity: 1
  • Max capacity: 3
    1. Attach a Load Balancer (optional, but good practice).
    2. 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]"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)