AWS CLI Launching Instance and attaching Block Storage to the Instance

Creating a AWS key pair in CLI


This is the command to create a key pair for AWS instance. Here aws specifies command, ec2 specifies the service, create-key-pair is the command, --key-name is the sub command, aws_instance_key is the parameter. After the key has been created the key will be displayed in the form of JSON.


Creating security group in CLI


This is the command to create a security group for ec2 service. create_security_group is the command,  --description, --group-name are the sub commands. "This security group is created by me" is the description given to the security group. This will return the security group id created by aws in the JSON form.


Adding permissions to the created security group


The command authorize-security-group-ingress is used to add rules to the security group. --protocol takes the type of protocol, --port takes the port number, --cidr takes the IP addresses which can access the instance.

 Launching an instance using the key pair and security group created previously


The command run-instances is used to launch anew instance. --image-id takes the AMI ID,                     --instance-type will take the hardware type. After the instance is launched the details are displayed in the form of JSON.

Creating an EBS volume of 1 GB



1 GB volume of EBS storage is created in ap-south-1b zone. This will return details of volume in JSON format.

Attaching previously created 1 GB volume to the instance


This will attach the specified volume with ID to the mentioned instance ID to the specified device.

Comments