EC2: Dedicated to serving virtual machines
ECS & EKS: Designed for Docker and/or Windows containers
Lambda: Serverless Functions
Batch: Batch processes in containers
Beanstalk & LightSail: Dedicated for website service
AZ scoped with regional endpoints that serves as a virtual machine that is launched in a single subnet
EC2 offers AMD, Intel, Gravitron, Apple M1 chips.
The compute power is defined by vCPUs, which are roughly equivalent to a thread on a processor core.
Instance storage is attached directly to the hardware that is running the hypervisor.
It is volatile but free and quick. This is usually for temporary data.
EBS is attached over the network but it's not a NAS (Network Attached Storage) because these volumes are presented to the gues operating system as if they were directly attached.
These are persistent, durable, and usually holds the primary OS volume and data storage.
Region scoped image that is used for OS volume
Customizing can be done with an EC2 Image Builder or Packer.
Region scoped resource that allows connection and login to the OS
Scenario: We need the same key pair for every single region in that account
$ aws ec2 create-key-pair --key-name YOUR_KEY_NAME
> --query "KeyMaterial" --output text --region YOUR_REGION > key-pair.pem
$ vi key-pair.pem
$ chmod 400 key-pair.pem
$ ssh-keygen -y -f ./key-pair.pem > key-pair.pub
$ vi key-pair.pub
import_key_pair.sh
#!/bin/bash
MAINREGION=$1
REGIONS=`aws ec2 describe-regions --output text --query Regions[].RegionName |ts -s '\t' '\n'`
for i in $REGIONS; do
if [[ $i == $MAINREGION]]; then
echo "Ignoring main region $i"
else
echo "Importing key pair to $i"
aws ec2 import-key-pair --region $i --key-name YOUR_KEY_NAME --public-key-material file://key-pair.pub
fi
done
$ bash ./import_key_pair.sh YOUR_MAIN_REGION
$ aws ec2 import-key-pair help
It is possible to bootstrap your EC2 instances with configurations that might not normally be available to the guest OS (AMIs)
Metadata is actually available from the service itself and it is hosted at every EC2 client OS at 169.254.169.254
It is possible to retrieve instance ID, Security Group, etc.
With a command like
# View metadata categories
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v
https://169.254.169.254/latest/meta-data/
# View Instance-id
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v
https://169.254.169.254/latest/meta-data/instance-id
# View security-group
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v
https://169.254.169.254/latest/meta-data/security-groups
V1 does not require a token whereas, V2 does.
Hence, V2 is a more secure option.
Make a script that is executed once with the initial launch of an instance
It's almost like __init__.py
Launch an instance running Linux that allows connection from local IP
Amazon Linux
Type: ssh, Source type: My IP
$ aws ssm get-parameters
--name /aws/service/ami-amazon-linux-latest/aman2-ami-hvm-x86_64-gp2
--query 'Parameters[0].[Value]'
--output text --region YOUR_REGION
$ aws ec2 run-instance --image-id AMI_ID --region YOUR_REGION
Note that this command will launch the instance with ALL DEFAULT settings.
So it's not that useful in a sense..
Scenario: JVM is deployed on the instance and it keeps running out of memory and crashing. So I'd like to upsize the instance
This summary is made possible by Oreilly's AWS, 3rd Edition - Chad Smith.
If the above post violates any copyright permissions, please let me know!