0% found this document useful (0 votes)
2 views18 pages

Aws Ec2 1

Amazon EC2 is a web service that provides scalable compute capacity in the cloud, offering over 750 instance types and various configurations for developers. Key features include virtual servers (instances), Amazon Machine Images (AMIs), Elastic Block Store (EBS) for persistent storage, and security groups for firewall management. The document also outlines commands for creating, listing, and terminating instances, as well as managing Elastic IP addresses and other related services.

Uploaded by

harshitganesh16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Aws Ec2 1

Amazon EC2 is a web service that provides scalable compute capacity in the cloud, offering over 750 instance types and various configurations for developers. Key features include virtual servers (instances), Amazon Machine Images (AMIs), Elastic Block Store (EBS) for persistent storage, and security groups for firewall management. The document also outlines commands for creating, listing, and terminating instances, as well as managing Elastic IP addresses and other related services.

Uploaded by

harshitganesh16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

AWS-EC2

Elastic Compute Cloud


CONTENTS
1. Instances
2. Spot Instances
3. AMI
4. Volumes
5. Snapshots
6. Security Groups
7. Elastic IP
8. Load Balancers
9. Autoscaling Groups
AWS EC2
● Amazon EC2 is a web service that provides sizable compute capacity in
the cloud. It is designed to make web-scale computing easier for
developers.
● Amazon Elastic Compute Cloud (Amazon EC2) offers the broadest and
deepest compute platform, with over 750 instances and choice of the
latest processor, storage, networking, operating system.
Features
● Instances - Virtual servers.

● 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

Follow the above documentation to create and assign an elastic IP to an


instance. Can the nginx page be served on the elastic IP instance?
Types of IP in an Instance
● A private IPv4 address is an IP address that's not reachable over the Internet. You
can use private IPv4 addresses for communication between instances in the same
VPC.
● A public IP address is an IPv4 address that's reachable from the Internet. You can use
public addresses for communication between your instances and the Internet.When
you launch an instance in a default VPC, we assign it a public IP address by
default. When you launch an instance into a nondefault VPC, the subnet has an
attribute that determines whether instances launched into that subnet receive a public
IP address from the public IPv4 address pool. By default, we don't assign a public IP
address to instances launched in a nondefault subnet.
Assignment
● Write a bash script to create an instance and display its
public IP and DNS.
● Write a bash script to create an instance and check whether
it has a elastic IP assigned to it or not.
Load Balancers
Autoscaling Groups
EC2 CLI Commands
https://docs.aws.amazon.com/cli/latest/reference/ec2/

You might also like