Aws Ec2 1
Aws Ec2 1
● Amazon Machine Images (AMIs) - Preconfigured templates for your instances that package the
components you need for your server (including the operating system and additional software).
● Instance types - Various configurations of CPU, memory, storage, networking capacity, and
graphics hardware for your instances.
● Amazon EBS volumes - Persistent storage volumes for your data using Amazon Elastic
Block Store (Amazon EBS).
● Instance store volumes - Storage volumes for temporary data that is deleted
when you stop,hibernate, or terminate your instance.
● Key pair - Secure login information for your instances. AWS stores the public key
and you store the private key in a secure place.
● Security groups- A virtual firewall that allows you to specify the protocols, ports,
and source IP ranges that can reach your instances, and the destination IP
ranges to which your instances can connect.
Instances
● Instance is a VM that runs on the AWS datacenter.
● Instance hardware specifications can be given through the Instance type
● Instance OS can be specified through AMI (Amazon Machine Image).
One AMI can be used to create multiple Instances.
● An Instance can be created through the web console or CLI.
Instances
Create Instance
● aws ec2 run-instances --image-id ami-080660c9757080771 --count 1 --instance-type
t2.micro --key-name Desktop-key --security-group-ids sg-0df4f7865ece65369
The above command creates a t2.micro instance using my key named Desktop-key and
attaches the default security group into it.
To add a EBS volume to it use --block-device-mapping option
● --block-device-mappings
"[{\"DeviceName\":\"/dev/sdf\",\"Ebs\":{\"VolumeSize\":20,\"DeleteOnTermination\"
:false}}]"
Instances
List Instances
You can use the AWS CLI to list your instances and view information about them. You can list all
your instances, or filter the results based on the instances that you're interested in.
The following command filters the list to only your t2.micro instances and outputs
only the InstanceId values for each match.
● $ aws ec2 describe-instances --filters
"Name=instance-type,Values=t2.micro" --query
"Reservations[].Instances[].InstanceId"
Terminate Instance
● aws ec2 terminate-instances --instance-ids i-5203422c
Assignments
1. Write a Bash script to create a t2.micro instance and
ubuntu 22.04 as the AMI.
2. Write a Bash script to create a t2.micro instance and
add a ebs volume to it. In the same script, Terminate the
earlier instance and create a new t2.micro instance.
Attach the EBS volume to the new instance and display
the instance ID of the new instance
Spot Instances
Assignment
● Write a Bash Script to create an Ec2 instance and ssh
into it from the script.
● Write a script to create an EC2 instance and ssh into it
and install nginx. How can you access the nginx page.
● Write a script to create a key-pair, security-group, and
and create the instance using the key-pair and
security-group.
Elastic IP
An Elastic IP address is a static IPv4 address designed for dynamic cloud computing. An
Elastic IP address is allocated to your AWS account, and is yours until you release it. By
using 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. Alternatively, you can specify
the Elastic IP address in a DNS record for your domain, so that your domain points to your
instance.
Elastic IP
● An Elastic IP address is static; it does not change over time.
● An Elastic IP address is for use in a specific Region only, and cannot be moved to a
different Region.
● An Elastic IP address comes from Amazon's pool of IPv4 addresses, or from a custom
IPv4 address pool that you have brought to your AWS account.
● To use an Elastic IP address, you first allocate one to your account, and then associate it
with your instance or a network interfaces.
● When you associate an Elastic IP address with an instance, it is also associated with the
instance's primary network interface. When you associate an Elastic IP address with a
network interface that is attached to an instance, it is also associated with the instance.
Allocate an Elastic IP
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses
-eip.html#using-instance-addressing-eips-allocating