Table of Contents
Optimizing AWS EC2: Sizing and Configuration Options
- When configuring EC2 instances, the choice of Operating System is flexible, supporting Linux, Windows, or Mac OS.
- For Computing Resources, users can tailor the amount of compute power and CPU cores to meet their specific workload demands.
- Random-access memory (RAM) is customizable, allowing users to allocate the appropriate memory for optimal performance.
- Storage options include Elastic Block Store (EBS) and Elastic File System (EFS) for network-attached storage, as well as EC2 Instance Store for hardware-based storage.
- Network configurations involve specifying the network card speed and determining the need for a Public IP address.
- Security is managed through security groups, enabling users to define firewall rules for the effective protection of EC2 instances.
Overview
- It is possible to bootstrap our instances using an EC2 User Data Script.
- Bootstrapping means launching commands when a machine starts.
- That script is only run once at the instance’s first start.
Use Cases
EC2 user data is used to automate boot tasks such as:
- Installing updates
- Installing software
- Downloading common files
- Anything you can think of
The EC2 User Data Script runs with the root user.
AWS EC2 Instance Type Overview
You can use different types of EC2 instances that are optimized for different use cases

Naming Convention

AWS has the following naming convention:
- m5.4xlarge
- m: instance class
- 5: generation (AWS improvement over time)
- 4xlarge: size within the instance class
Great for a diversity of workloads, such as web servers or code repositories. Balance between:
- Compute
- Memory
- Networking
Great for compute-intensive tasks that require high-performance processors:
- High-performance web servers
- Batch processing workloads
- Scientific modeling and machine learning
Fast performance for workloads that process large data sets in memory. Use-case:
• High-performance, relational/non-relational databases
• Distributed web-scale cache stores
Great for storage-intensive tasks that require high, sequential read and write access to large data sets on local storage.
Use-Case:
• High-frequency online transaction processing (OLTP) systems
• Relational and NoSQL databases
Find more details:- https://aws.amazon.com/ec2/instance-types/
In-Depth Look at Security Groups
Security Groups are acting as a firewall on EC2 instances. They regulate:

• Access to Ports
• Authorised IP ranges IPv4 and IPv6
• Control of inbound network (from other to the instance) Inbound rules control the incoming traffic that’s allowed to reach the instance.
• Control of outbound network (from the instance to other) Outbound rules control the outgoing traffic that’s allowed to leave the instance.
Security Groups Good to know
• Can be attached to multiple instances
• Locked down to a region / VPC combination
• Does live “outside” the EC2 – if traffic is blocked the EC2 instance won’t see it
• It’s good to maintain one separate security group for SSH access
• If your application is not accessible (time out), then it’s a security group issue
• If your application gives a “connection refused“ error, then it’s an application error or it’s not launched
• All inbound traffic is blocked by default
• All outbound traffic is authorised by default
Choosing the Right AWS EC2 Purchasing Option

EC2 On Demand
You Pay only for what you use:
• Linux or Windows – billing per second, after the first minute
• All other operating systems – billing per hour
Costly than other options but no upfront payment is needed.
Recommended for short-term and uninterrupted workloads, where you can’t predict how the application will behave.
EC2 Reserved Instances
• Up to 72% discount compared to On-demand
• You reserve a specific instance of attributes
(Instance Type, Region, Tenancy, OS)
• Reservation Period – 1 year or 3 years
• Recommended for steady-state usage applications (think database)
• You can buy and sell in the Reserved Instance Marketplace
EC2 Savings Plans
• Get a discount based on long-term usage (up to 72% – same as RIs)
• Commit to a certain type of usage ($8/hour for 1 or 3 years)
• Usage beyond EC2 Savings Plans is billed at the On-Demand price
• Locked to a specific instance family & AWS region
• Flexible across:
• Instance Size (e.g., m5.xlarge, m5.2xlarge) • OS (e.g., Linux, Windows)
• Tenancy (Host, Dedicated, Default)
EC2 Spot Instances
• Can get a discount of up to 90% compared to On-demand
• Instances that you can “lose” at any point of time if your max price is less than the current spot price
• The MOST cost-efficient instances in AWS
• Useful for workloads that are resilient to failure
• Not suitable for critical jobs or databases
EC2 Dedicated Hosts
• A physical server with EC2 instance capacity fully dedicated to your use
• Allows you to address compliance requirements
Purchasing Options:
• On-demand – pay per second for active Dedicated Host
• Reserved – 1 or 3 years (No Upfront, Partial Upfront, All Upfront)
• The most expensive option
EC2 Dedicated Instances
• Instances run on hardware that’s dedicated to you
• May share hardware with other instances in the same account
• No control over instance placement (can move hardware after Stop / Start)
Find more details:- AWS Pricing Calculator
Understanding AWS EC2 Instance Storage Options
EC2 EBS Volume
• An EBS (Elastic Block Store) Volume is a network drive you can attach to your instances while they run
• It allows your instances to persist data, even after their termination
• They can only be mounted to one instance at a time
EC2 Instance Store
• High-performance hardware disk
• Better I/O performance
• EC2 Instance Store lose their storage if they’re stopped
• Good for buffer/cache/scratch data / temporary content
• Backups and Replication are your Responsibility
EC2 Elastic File System
• Managed NFS (network file system) that can be mounted on many EC2
• EFS works with EC2 instances in multi-AZ
• Highly available, scalable, expensive (3x gp2), pay per use
• Use cases: content management, web serving, data sharing, WordPress
• File system scales automatically, pay-per-use,no capacity planning!