본문 바로가기
AWS Solutions Architect Associate 자격증

Section 6 : EC2 Solutions

by Jackykim 2023. 7. 26.

Private vs public IP (IPv4)
Ipv4 is still the most common format used online and IPv6 is newer and solves problems for iot.


Public IP:

Public IP means the machine can be identified on the internet (WWW)

Must be unique across the whole web (not two machines can have the same public IP).

Can be geo-located easily


Private IP:

Private IP means the machine can only be identified on a private network only

The IP must be unique across the private network

BUT two different private networks (two companies) can have the same IPs.

Machines connect to WWW using a NAT + internet gateway (a proxy)

Only a specified range of IPs can be used as private IP

Elastic IPs
When you stop and then start an EC2 instance, it can change its public IP.

If you need to have a fixed public IP for your instance, you need an Elastic IP

An Elastic IP is a public IPv4 IP you own as long as you don’t delete it

You can attach it to one instance at a time

With an Elastic IP address, you can mask the failure of an instance or software

by rapidly remapping the address to another instance in your account.

You can only have 5 Elastic IP in your account (you can ask AWS to increase that).

Overall, try to avoid using Elastic IP:

They often reflect poor architectural decisions

Instead, use a random public IP and register a DNS name to it

Or, as we’ll see later, use a Load Balancer and don’t use a public IP

 

For elastic ip for EC2 instances
Go to network & security -> click Elastic IPs -> Allocate new IP address -> action associate elastic ip address -> select EC2 -> EC2 IP address will be the same as the elastic IP address
Even if you stop the instance the public IP address will not change (when elastic IP is associated)

EC2 placement groups
-  Sometimes you want control over the EC2 Instance placement strategy
When you create a placement group, you specify one of the following strategies for the group:

Cluster—clusters instances into a low-latency group in a single Availability Zone

Spread—spreads instances across underlying hardware (max 7 instances per group per AZ)

Partition—spreads instances across many different partitions (which rely on different sets of racks) within an AZ. Scales to 100s of EC2 instances per group (Hadoop, Cassandra, Kafka)


Cluster
: Same rack and same AZ
- Pros: Great network
- Cons: If the rack fails, all instances fails at the same time
Why use it:
- Big data job that needs to complete fast
- Application that needs extremely low latency and high network throughput


Spread : Located in different hardware and AZ
Pros:

- Can span across Availability Zones (AZ)

- Reduced risk is simultaneous failure
- EC2 Instances are on different physical hardware

Cons:

- Limited to 7 instances per AZ per placement group

Why use it:

- Application that needs to maximize high availability

- Critical Applications where each instance must be isolated from failure from each other

Partition :
- Up to 7 partitions per AZ
- Can span across multiple AZs in the same region

- Up to 100s of EC2 instances

- The instances in a partition do not share racks with the instances in the other partitions

- A partition failure can affect many EC2 but won’t affect other partitions

- EC2 instances get access to the partition information as metadata

- Use cases: HDFS, HBase, Cassandra, Kafka


Placement groups hands on
EC2 network & Security -> click placement groups -> select type -> Launch instances -> advanced details and select placement group

Elastic Network Interfaces (ENI)
- Logical component in a VPC that represents a virtual network car
The ENI can have the following attributes:

Primary private IPv4, one or more secondary IPv4

One Elastic IP (IPv4) per private IPv4

One Public IPv4

One or more security groups

A MAC address

- You can create ENI independently and attach them on the fly (move them) on EC2 instances for failover

- Bound to a specific availability zone (AZ)

Elastic Network Interfaces (hands on)
Launch 2 EC2 instances -> go to Network & security -> click network interfaces -> create new network interface -> select subnet -> attach security group -> action and attach to a certain instance
- We can move the ENI to other instances very quickly and easily
- ENI does not cost money

EC2 Hibernate
We know we can stop, terminate instances

Stop – the data on disk (EBS) is kept intact in the next start

Terminate – any EBS volumes (root) also set-up to be destroyed is lost

On start, the following happens:

First start: the OS boots & the EC2 User Data script is run

Following starts: the OS boots up

Then your application starts, caches get warmed up, and that can take time!

However if you use hibernate :
- The in-memory (RAM) state is preserved

- The instance boot is much faster! (the OS is not stopped / restarted)

- Under the hood: the RAM state is written to a file in the root EBS volume

- The root EBS volume must be encrypted

Use cases:

- Long-running processing

- Saving the RAM state

- Services that take time to initialize

Good to know about EC2 hibernate
- Supported Instance Families – C3, C4, C5, I3, M3, M4, R3, R4, T2, T3, …

- Instance RAM Size – must be less than 150 GB.

- Instance Size – not supported for bare metal instances.

- AMI – Amazon Linux 2, Linux AMI, Ubuntu, RHEL, CentOS & Windows…

- Root Volume – must be EBS, encrypted, not instance store, and large

- Available for On-Demand, Reserved and Spot Instances

- An instance can NOT be hibernated more than 60 days

EC2 Hibernate hands on
Create EC2 instance -> advanced details -> enable (Stop – hibernate behavior) -> select KMS key to encrypt it -> create instance -> instance state and select hibernate (if you use uptime the timer still goes on compared to being stopped)