Aws Ec2
Aws Ec2
starting/stopping instance you may lose its public ip and get a new one.
Ports:
One NSG can be assigned to multiple ec2 instances.. One ec2 instance can attach multiple nsgs.
NSGs belong to a VPC (vnet) and are local to a region.
First time running aws cli “aws configure”.. Then asks for “access key”
But passing access keys like this on a vm is not a good idea.. Its better to attach IAM roles to the vm…
You first create an IAM role for this VM, say a role has permission to get-users. Then attach that role to the vm.
This iam role (SP/MI) will be able to run aws-cli commands without user logged into to use his own iam permissions.
Spot Instances
When we create an ec2 instance, we can say we need a spot instance based on current demand price. When demand
increases our price increases. We can set a fixed price and select to terminate our instance when price exceeds…
Then if price increases our instances will be terminated, but they will launch back by themselves when price drops…
Note: Ec2 reserved instance can either be chosen for 1 or 3 years… its not 1 to 3.. Either 1 or 3 years.
SPOT-FLEET Instances
To lower the costs for customers, spot fleet is a fleet of instances..
Some spot, optionally some on-demand… (fleet of cars are easily spotted and can be called on demand).
Spot Fleets: across different instance types, Availability Zones.
—-------------------------------------------------------------------------------------------------------------------------------------------------------
Hibernate a vm
hibernate saves ram. Actually ram data is written to root EBS disk and copied back when restarted.
Ensure EBS volume is larger than ram attached. Ram max is 150GB.
We need to enable hibernation when we create an instance. And ebs volume should be chosen to be encrypted.
Limit of hibernation is 60 days…. Only benefit is fast restart.
The instances that support hibernation use Amazon EBS (Elastic Block Store) for the root volume.
==========================================================================================
🙂
This works within same availability zone and have 3 options:
1. Cluster: all ec2 on same rack.. Benefit: low latency, Risk: all going down together
2. Spread: all on different rasks. Benefit: HA, risk: high latency if they wanna talk to each other
3. Partition: some on same, some on another. Based on logic groupings, like same type of instances together. Up
to 7 partitions per availability zone.
NIC or ENI → Elastic Network Interface
We can attach one or more NSG to ENI. They can have one private ip, and 1 public ip.
We can attach more than one ENI to an instance.
We can move NIC/ENI from one vm to another. They belong to one Availability Zone and stay there..
—--------------------------------------------------------------------------------------------------------------------------------------------------------
1. EBS: elastic block storage can be attached as a drive for ec2. One can be attached to one ec2 instance. We
can enable to persist data even after instance is terminated.
🙂
We can take one vm’s ebs volume and attach to another, they are like a pen drive but available through n/w, so some
latency… so like wireless pendrive.
Sadly, they have to be in same region as ec2 to be attached to an ec2 instance.
We can create a new EBS volume from a snapshot by using “FSR”.. fast snapshot restore.
Goto ec2 > volume .. create snaphot.. Then goto ec2 > snapshot..
- if you wanna give it to a friend to take home..choose “copy snapshot” and choose a new region.
- To create new ebs volume from a snapshot…. ec2 > snapshot > actions > create volume…
Note: from a snapshot in us-east-1, we can only create new EBS volume in same region.. But us-east has 3
availability zones.. You can create ebs volume in any availability zone in same region as snapshot..
Remember: only way to copy an ebs volume in same region or another region is by making a snapshot of it..
Then using that snapshot copy it into a new volume…
preserve pondies from deletion…. Ec2 > snapshot > recycle bin.. create retention rules like no. of days etc..
To archive a snapshot for saving money… ec2 > snapshot > actions > archive…
General Purpose Highest throughput For frequently accessed For less accessed data
data
Can be boot/root vol Can be boot/root vol Can not be boot/root vol Can not be boot/root vol
Encryption at rest
When we create an ebs volume we can choose to encrypt it.. If we dont then it cant be encrypted later… if you create a
snapshot of unencrypted volume, it wont be encrypted also… but what u can do is copy that snapshot into another
snapshot or a new volume and at that time you can encrypt it..
Since EFS is fucking expensive, we can set lifecycle policies on it to move files not used in 60 days to “INFREQUENT
ACCESSED” part. This saves money…
Question: We wanna have a great HA prod system but dont give a shit about dev env.. How to do and save money?
Answer: for prod use EFS in multi-availability zone.. But for dev use single zone EFS.
Note: EFS belongs to one region.. But in one region we can choose it for multi-availability zones.
EBS vs EFS
1. EBS for one instance, except io-2…. While EFS for many…
2. EBS are fixed to one availability zone.. While EFS are for all az’s in a regions
3. Root ebs volumes are deleted if instance is deleted.. This is default behavior we can override..
Why instance store? =>> IOPS > 250k…. MAX IOPS WITH EBS io2 is 250k
Example indian ami not possible to use in pakistan